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.
7 if 'TRUSTED_ENV' not in env:
9 trusted_env = env['TRUSTED_ENV']
11 if not env.Bit('bitcode') or not env.Bit('minsfi') or \
12 not trusted_env.Bit('build_x86') or trusted_env.Bit('windows'):
15 def CompileSandbox(test_name, exerciser_src, sandbox_src, ptrsize=0):
17 ptrsize = 24 if trusted_env.Bit('build_x86_32') else 32
20 bc_env.Append(LIBS=['minsfi_support', 'c'])
22 # Force the bitcode linker to group libraries.
23 bc_env['_LIBFLAGS'] = '-Wl,--start-group ' + bc_env['_LIBFLAGS'] + \
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',
34 # Link bitcode files into a single module. (flags set in naclsdk.py)
35 input_module = bc_env.ComponentProgram(
36 test_name + '.preopt.bc',
39 # Run the PNaCl and MinSFI passes.
40 opt_result = env.Command(
41 test_name + '.postopt.bc',
46 '-pnacl-abi-simplify-preopt '
47 '-pnacl-abi-simplify-postopt '
49 '-pnaclabi-allow-minsfi-syscalls '
51 '${SOURCES} -o ${TARGET}'
54 # Translate bitcode into native code.
55 llc_result = env.Command(
56 test_name + '.minsfi.o',
58 '${LLC} ${SOURCES} -o ${TARGET}')
60 # Compile trusted part of the test and link everything together.
61 prog = trusted_env.ComponentProgram(
63 [llc_result, exerciser_src],
64 LIBS=['minsfi_runtime'])
67 node = env.CommandTest('%s.out' % test_name, [prog])
68 env.AddNodeToTestSuite(
70 ['small_tests', 'toolchain_tests', 'minsfi_tests'],
71 'run_minsfi_' + test_name + '_test')
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',
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')