Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / native_client / tests / minsfi / nacl.scons
1 # Copyright (c) 2014 The Native Client Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 Import('env')
6
7 if 'TRUSTED_ENV' not in env:
8   Return()
9 trusted_env = env['TRUSTED_ENV']
10
11 if not env.Bit('bitcode') or not env.Bit('minsfi') or \
12    not trusted_env.Bit('build_x86') or trusted_env.Bit('windows'):
13   Return()
14
15 def CompileSandbox(test_name, exerciser_src, sandbox_src, ptrsize=0):
16   if ptrsize == 0:
17     ptrsize = 24 if trusted_env.Bit('build_x86_32') else 32
18
19   bc_env = env.Clone()
20   bc_env.Append(LIBS=['minsfi_support', 'c'])
21
22   # Force the bitcode linker to group libraries.
23   bc_env['_LIBFLAGS'] = '-Wl,--start-group ' + bc_env['_LIBFLAGS'] + \
24                         ' -Wl,--end-group'
25
26   # Compile the untrusted file.
27   # We cannot pass the source file directly to the ComponentProgram call
28   # because we want to reuse the same sandbox source for multiple tests and
29   # that requires giving each instance a different object file name.
30   input_obj = bc_env.ComponentObject(
31       test_name + '.obj.bc',
32       [sandbox_src])
33
34   # Link bitcode files into a single module. (flags set in naclsdk.py)
35   input_module = bc_env.ComponentProgram(
36       test_name + '.preopt.bc',
37       [input_obj])
38
39   # Run the PNaCl and MinSFI passes.
40   opt_result = env.Command(
41       test_name + '.postopt.bc',
42       [input_module],
43       '${PNACLOPT} '
44       '-strip-debug '
45       '-minsfi-strip-tls '
46       '-pnacl-abi-simplify-preopt '
47       '-pnacl-abi-simplify-postopt '
48       '-minsfi '
49       '-pnaclabi-allow-minsfi-syscalls '
50       '-minsfi-ptrsize=%d '
51       '${SOURCES} -o ${TARGET}'
52        % ptrsize)
53
54   # Translate bitcode into native code.
55   llc_result = env.Command(
56       test_name + '.minsfi.o',
57       [opt_result],
58       '${LLC} ${SOURCES} -o ${TARGET}')
59
60   # Compile trusted part of the test and link everything together.
61   prog = trusted_env.ComponentProgram(
62       test_name,
63       [llc_result,  exerciser_src],
64       LIBS=['minsfi_runtime'])
65
66   # Register the test.
67   node = env.CommandTest('%s.out' % test_name, [prog])
68   env.AddNodeToTestSuite(
69       node,
70       ['small_tests', 'toolchain_tests', 'minsfi_tests'],
71       'run_minsfi_' + test_name + '_test')
72
73 CompileSandbox('memory_layout', 'test_memory_layout.c', 'sandbox_dummy.c')
74 CompileSandbox('initializer', 'test_initializer.c', 'sandbox_dummy.c')
75 CompileSandbox('pointer_conversion', 'test_pointer_conversion.c',
76                'sandbox_dummy.c')
77 CompileSandbox('invoke_args', 'test_invoke_args.c', 'sandbox_invoke_args.c')
78 CompileSandbox('exit', 'test_exit.c', 'sandbox_exit.c')
79 CompileSandbox('sysconf', 'test_sysconf.c', 'sandbox_sysconf.c')
80 CompileSandbox('heap_alloc', 'test_heap_alloc.c', 'sandbox_heap_alloc.c')