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.
11 time_test_is_broken_on_this_os=False
12 if 'TRUSTED_ENV' in env and env['TRUSTED_ENV'].Bit('windows'):
13 time_test_is_broken_on_this_os=True
15 env.ComponentLibrary('syscall_test_framework', ['test.cc'])
17 env.Append(CPPDEFINES=[['PNACL_UNSANDBOXED',
18 str(int(env.Bit('pnacl_unsandboxed')))]])
20 # The syscall tests need to know if they are compiling with the IRT
21 # since glibc only partially functions without the IRT and therefore
22 # some tests don't make sense.
23 env.Append(CPPDEFINES=[['TESTS_USE_IRT', str(int(env.Bit('tests_use_irt')))]])
25 syscalls_nexe = env.ComponentProgram('syscalls',
27 EXTRA_LIBS=['${PTHREAD_LIBS}',
30 # Creating a R/W test file in the output directory.
31 # Because this test gets built on one platform and run on another (arm),
32 # explaining to scons that this file is a dependency of the build and not
33 # a test is tricky. As a simple work-around, the test inputs have been made
34 # a 'default' scons target.
35 # TODO(bradnelson): find a better way to make the plumbing on this work.
36 inputs = env.Command(env.File('file_ok_rdwr.txt'), env.File('file_ok.txt'),
37 [Copy(env.File('file_ok_rdwr.txt'), env.File('file_ok.txt')),
38 Chmod(env.File('file_ok_rdwr.txt'), 0644)])
41 # syscalls_test exercise open/read/write, so need filesystem access
42 # via the debug flag to sel_ldr
43 node = env.CommandSelLdrTestNacl(
46 args=[env.File('file_ok_rdwr.txt')],
48 env.AddNodeToTestSuite(node, ['small_tests'], 'run_syscall_test')
50 # getpid() works with nacl-glibc, but only via the IRT (there is no
51 # direct syscall version).
52 getpid_is_broken = env.Bit('nacl_glibc') and not env.Bit('tests_use_irt')
54 getpid_test_nexe = env.ComponentProgram('getpid_test',
56 EXTRA_LIBS=['syscall_test_framework',
58 node = env.CommandSelLdrTestNacl(
61 # Pass '-a' to enable the getpid() syscall.
63 env.AddNodeToTestSuite(node,
64 ['small_tests', 'sel_ldr_tests'],
66 is_broken=getpid_is_broken)
68 raw_syscall_objects = env.RawSyscallObjects(['getpid_test.cc'])
69 raw_getpid_test_nexe = env.ComponentProgram(
72 EXTRA_LIBS=['syscall_test_framework',
74 node = env.CommandSelLdrTestNacl('raw_getpid_test.out',
76 # Pass '-a' to enable the getpid() syscall.
79 env.AddNodeToTestSuite(node,
80 ['small_tests', 'sel_ldr_tests'],
81 'run_raw_getpid_test')
83 # getpid_disabled test must be run without -a, but glibc requires -a.
84 getpid_disabled_is_broken = (
85 'TRUSTED_ENV' in env and
86 env['TRUSTED_ENV'].Bit('coverage_enabled') and
87 env.Bit('host_mac')) or env.Bit('nacl_glibc')
89 getpid_disabled_test_nexe = env.ComponentProgram(
90 'getpid_disabled_test', ['getpid_disabled_test.c'],
91 EXTRA_LIBS=['${NONIRT_LIBS}'])
92 node = env.CommandSelLdrTestNacl('getpid_disabled_test.out',
93 getpid_disabled_test_nexe)
94 env.AddNodeToTestSuite(node,
95 ['small_tests', 'sel_ldr_tests'],
96 'run_getpid_disabled_test',
97 is_broken=getpid_disabled_is_broken)
99 # The next few tests test the exit syscall.
100 # The first one checks for exit success.
101 exit_test_nexe = env.ComponentProgram('exit_test', ['exit_test.cc'],
102 EXTRA_LIBS=['${NONIRT_LIBS}'])
103 node = env.CommandSelLdrTestNacl('exit_success_test.out', exit_test_nexe)
104 env.AddNodeToTestSuite(node,
105 ['small_tests', 'sel_ldr_tests'],
106 'run_exit_success_test')
108 # The next two test positive and negative return values.
109 node = env.CommandSelLdrTestNacl(
115 env.AddNodeToTestSuite(node,
116 ['small_tests', 'sel_ldr_tests'],
119 # The last one tests some unusually large number.
120 node = env.CommandSelLdrTestNacl(
121 'exit_large_test.out',
126 env.AddNodeToTestSuite(node,
127 ['small_tests', 'sel_ldr_tests'],
128 'run_exit_large_test')
130 # Test the semaphore system calls.
131 semaphore_tests_nexe = env.ComponentProgram(
133 ['semaphore_tests.cc'],
134 EXTRA_LIBS=['${PTHREAD_LIBS}', 'syscall_test_framework', '${NONIRT_LIBS}'])
136 node = env.CommandSelLdrTestNacl(
137 'semaphore_tests.out',
138 semaphore_tests_nexe,
140 env.AddNodeToTestSuite(node,
141 ['small_tests', 'sel_ldr_tests'],
142 'run_semaphore_tests')
144 mem_test_nexe = env.ComponentProgram('mem_test',
146 EXTRA_LIBS=['syscall_test_framework',
148 node = env.CommandSelLdrTestNacl('mem_test.out',
150 env.AddNodeToTestSuite(node,
151 ['small_tests', 'sel_ldr_tests'],
154 nonstable_env = env.Clone()
155 if nonstable_env.AllowNonStableBitcode():
156 if nonstable_env.Bit('bitcode'):
157 # sysbrk_test.cc has an external reference to "end", a symbol
158 # defined by the native linker, which is disallowed by PNaCl's
160 nonstable_env.Append(LINKFLAGS=['--pnacl-disable-abi-check'])
161 sysbrk_test_nexe = nonstable_env.ComponentProgram(
162 'sysbrk_test', ['sysbrk_test.cc'],
163 EXTRA_LIBS=['syscall_test_framework',
166 node = nonstable_env.CommandSelLdrTestNacl('sysbrk_test.out',
168 nonstable_env.AddNodeToTestSuite(node,
169 ['small_tests', 'sel_ldr_tests'],
172 # These are timing tests, so we only run on real hardware
173 is_on_vm = env.Bit('running_on_vm')
175 # additions to add syscall tests 40-42
176 timefuncs_test_nexe = env.ComponentProgram(
178 ['timefuncs_test.cc'],
179 EXTRA_LIBS=['${PTHREAD_LIBS}', 'syscall_test_framework', '${NONIRT_LIBS}'])
181 node = env.CommandSelLdrTestNacl(
182 'timefuncs_test.out',
185 env.AddNodeToTestSuite(node,
186 ['small_tests', 'sel_ldr_tests'],
187 'run_timefuncs_test',
188 is_broken=is_on_vm or time_test_is_broken_on_this_os
191 raw_syscall_timefunc_objects = env.RawSyscallObjects(['timefuncs_test.cc'])
192 raw_timefuncs_test_nexe = env.ComponentProgram(
193 'raw_timefuncs_test',
194 raw_syscall_timefunc_objects,
195 EXTRA_LIBS=['syscall_test_framework', '${NONIRT_LIBS}'])
197 node = env.CommandSelLdrTestNacl('raw_timefuncs_test.out',
198 raw_timefuncs_test_nexe)
199 env.AddNodeToTestSuite(node,
200 ['small_tests', 'sel_ldr_tests'],
201 'run_raw_timefuncs_test',
202 is_broken=is_on_vm or time_test_is_broken_on_this_os)
204 sysconf_pagesize_nexe = env.ComponentProgram('sysconf_pagesize_test',
205 ['sysconf_pagesize.c'],
206 EXTRA_LIBS=['${NONIRT_LIBS}'])
208 node = env.CommandSelLdrTestNacl('sysconf_pagesize_test.out',
209 sysconf_pagesize_nexe)
210 env.AddNodeToTestSuite(node,
211 ['small_tests', 'sel_ldr_tests'],
212 'run_sysconf_pagesize_test')
214 # We create the temporary file at runtime rather than insisting on an
215 # empty file as checked-in testdata. Unfortunately, our trybot
216 # infrastructure doesn't like empty files as a patch, so try jobs
219 file_path = env.MakeEmptyFile(prefix='tmp_syscalls')
221 sysconf_nprocessors_nexe = env.ComponentProgram('sysconf_nprocessors_test',
222 ['sysconf_nprocessors.c'],
223 EXTRA_LIBS=['${NONIRT_LIBS}'])
225 node = env.CommandSelLdrTestNacl(
226 'sysconf_nprocessors_test.out',
227 sysconf_nprocessors_nexe,
228 filter_regex='"= ' + str(multiprocessing.cpu_count()) + ' processors"',
230 stdout_golden=file_path)
232 # TODO(jfb): Remove the conditional. The OSX coverage bots are
233 # failing due to library versioning issues. See
234 # https://code.google.com/p/nativeclient/issues/detail?id=3333 for
236 if not env.Bit('coverage_enabled'):
237 env.AddNodeToTestSuite(node,
238 ['small_tests', 'sel_ldr_tests'],
239 'run_sysconf_nprocessors_test')
241 filepos_nexe = env.ComponentProgram('filepos_test',
243 EXTRA_LIBS=['imc_syscalls',
247 node = env.CommandSelLdrTestNacl(
250 ['-t', env.MakeTempDir(prefix='tmp_syscalls')],
251 sel_ldr_flags=['-a'])
253 env.AddNodeToTestSuite(node,
254 ['small_tests', 'sel_ldr_tests'],