2 # Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
8 # Do not run these tests with pexes, assuming they are portable.
9 if env.Bit('bitcode') and env.Bit('pnacl_generate_pexe'):
12 # The test works with PNaCl-ARM but not with PNaCl-x86, because the
13 # assembler #defines __arm__ rather than __i386__ or __x86_64__ even
14 # when we are targetting x86.
15 # http://code.google.com/p/nativeclient/issues/detail?id=2368
16 # TODO(dschuff): re-enable this test in a sensible way after we fully switch
17 # to the new layout, or remove all the pnacl-specific stuff here.
18 if env.Bit('bitcode'):
21 # These tests assume they can allocate address ranges from the dynamic
22 # code area themselves. However, this does not work when ld.so
23 # assumes it can do the same.
24 # TODO(mseaborn): To fix this, ld.so will need an interface, like
25 # mmap() or brk(), for reserving space in the dynamic code area.
26 # See http://code.google.com/p/nativeclient/issues/detail?id=1112
27 is_broken = not env.Bit('nacl_static_link')
29 # there is fair amount of assembly code in these tests
31 if env.Bit('bitcode'):
32 asm_env.PNaClForceNative()
33 asm_env.AddBiasForPNaCl()
34 if env.Bit('bitcode'):
35 # NOTE: we cannot use PNaClForceNative here as we want the
36 # the .c files to actually go to bc files - but this is not
37 # completely understood.
39 env.Append(LINKFLAGS=['--pnacl-allow-native'])
41 # When using the IRT, this value must be at least IRT_DATA_REGION_START.
42 # Otherwise, it can be smaller.
43 code_segment_end = '${IRT_DATA_REGION_START}'
44 # This leaves a gap between the code and data segments. When using
45 # dynamic linking, the dynamic linker is responsible for reserving
46 # this space rather than the executable.
47 if env.Bit('nacl_static_link'):
48 env.Append(LINKFLAGS='-Wl,-Trodata-segment=' + code_segment_end)
49 env.Append(CPPDEFINES=[['DYNAMIC_CODE_SEGMENT_END', code_segment_end]])
52 if env.Bit('target_arm'):
53 return 'templates_arm.S'
55 return 'templates_x86.S'
57 template_obj = asm_env.ComponentObject(GetTemplate(env))
59 dynamic_load_test_nexe = env.ComponentProgram(
60 env.ProgramNameForNmf('dynamic_load_test'),
61 ['dynamic_load_test.c',
62 'dynamic_load_test_threaded.c',
63 'dynamic_delete_test_threaded.c',
65 EXTRA_LIBS=['${NONIRT_LIBS}', '${DYNCODE_LIBS}',
66 '${PTHREAD_LIBS}', '${TESTRUNNER_LIBS}'])
68 dynamic_modify_test_nexe = env.ComponentProgram(
69 env.ProgramNameForNmf('dynamic_modify_test'),
70 ['dynamic_modify_test.c', template_obj],
71 EXTRA_LIBS=['${NONIRT_LIBS}', '${DYNCODE_LIBS}', '${TESTRUNNER_LIBS}'])
73 write_to_dyncode_nexe = env.ComponentProgram(
75 ['write_to_dyncode.c'],
76 EXTRA_LIBS=['${NONIRT_LIBS}', '${DYNCODE_LIBS}'])
78 dyncode_disabled_test_nexe = env.ComponentProgram(
79 'dyncode_disabled_test',
80 ['dyncode_disabled_test.c'],
81 EXTRA_LIBS=['${DYNCODE_LIBS}', '${NONIRT_LIBS}'])
83 dyncode_syscall_disabled_test_nexe = env.ComponentProgram(
84 env.ProgramNameForNmf('dyncode_syscall_disabled_test'),
85 ['dyncode_syscall_disabled.c', template_obj],
86 EXTRA_LIBS=['${NONIRT_LIBS}', '${DYNCODE_LIBS}', '${TESTRUNNER_LIBS}'])
88 debug_mode_test_nexe = env.ComponentProgram('debug_mode_test',
91 EXTRA_LIBS=['${DYNCODE_LIBS}',
94 dyncode_demand_alloc_test_nexe = env.ComponentProgram(
95 'dyncode_demand_alloc_test',
96 ['dyncode_demand_alloc_test.c'],
97 EXTRA_LIBS=['${DYNCODE_LIBS}', '${NONIRT_LIBS}'])
99 test_suites = ['small_tests', 'sel_ldr_tests', 'dynamic_load_tests',
102 sel_ldr_flags = ['-E', 'OUTSIDE_BROWSER=1']
103 if env.Bit('target_arm') and env.UsingEmulator():
104 sel_ldr_flags.extend(['-E', 'UNDER_QEMU_ARM=1'])
105 if env.IsRunningUnderValgrind():
106 sel_ldr_flags.extend(['-E', 'RUNNING_ON_VALGRIND=1'])
108 node = env.CommandSelLdrTestNacl('dynamic_load_test.out',
109 dynamic_load_test_nexe,
110 sel_ldr_flags=sel_ldr_flags)
111 env.AddNodeToTestSuite(node, test_suites, 'run_dynamic_load_test',
114 node = env.CommandSelLdrTestNacl(
115 'write_to_dyncode_before_alloc.out',
116 write_to_dyncode_nexe,
117 ['0'], # alloc_dest_first argument
118 exit_status='untrusted_segfault',
119 stdout_golden=env.File('write_to_dyncode.stdout'))
120 env.AddNodeToTestSuite(node, test_suites,
121 'run_write_to_dyncode_before_alloc_test',
124 node = env.CommandSelLdrTestNacl(
125 'write_to_dyncode_after_alloc.out',
126 write_to_dyncode_nexe,
127 ['1'], # alloc_dest_first argument
128 exit_status='untrusted_segfault',
129 stdout_golden=env.File('write_to_dyncode.stdout'))
130 env.AddNodeToTestSuite(node, test_suites,
131 'run_write_to_dyncode_after_alloc_test',
134 node = env.CommandSelLdrTestNacl(
135 'debug_mode_test.out',
136 debug_mode_test_nexe,
137 # NOTE: the data we are loading does not pass the validator
138 sel_ldr_flags=["-c"])
139 env.AddNodeToTestSuite(node, test_suites, 'run_dyncode_debug_mode_test',
142 # This tests, from untrusted code, that dyncode pages are inaccessible
143 # before they are allocated.
144 node = env.CommandSelLdrTestNacl(
145 'dyncode_demand_alloc_test.out',
146 dyncode_demand_alloc_test_nexe, declares_exit_status=True)
147 env.AddNodeToTestSuite(node, test_suites, 'run_dyncode_demand_alloc_test',
150 # The IRT itself counts as dynamic code loading, so we cannot disable
151 # dynamic loading when using the IRT.
152 if not env.Bit('tests_use_irt'):
153 node = env.CommandSelLdrTestNacl(
154 'dyncode_disabled_test.out',
155 dyncode_disabled_test_nexe,
156 osenv='NACL_DISABLE_DYNAMIC_LOADING=1')
157 env.AddNodeToTestSuite(node, test_suites, 'run_dyncode_disabled_test',
160 node = env.CommandSelLdrTestNacl(
161 'dyncode_syscall_disabled_test.out',
162 dyncode_syscall_disabled_test_nexe,
163 osenv='NACL_DISABLE_DYNCODE_SYSCALLS=1')
164 env.AddNodeToTestSuite(node, test_suites, 'run_dyncode_syscall_disabled_test',
167 node = env.CommandSelLdrTestNacl('dynamic_modify_test.out',
168 dynamic_modify_test_nexe,
169 sel_ldr_flags=['-E', 'OUTSIDE_BROWSER=1'])
170 # This test fails under Valgrind presumably because Valgrind cannot
171 # handle dynamic code modifications that occur via our doubly-mapped
172 # shared memory segment. It does not know to flush its code
174 env.AddNodeToTestSuite(node, test_suites, 'run_dynamic_modify_test',
175 is_broken=is_broken or env.IsRunningUnderValgrind())