Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / native_client / tests / syscalls / nacl.scons
1 # -*- python -*-
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.
5
6 import multiprocessing
7 import os
8
9 Import('env')
10
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
14
15 env.ComponentLibrary('syscall_test_framework', ['test.cc'])
16
17 env.Append(CPPDEFINES=[['PNACL_UNSANDBOXED',
18                         str(int(env.Bit('pnacl_unsandboxed')))]])
19
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')))]])
24
25 syscalls_nexe = env.ComponentProgram('syscalls',
26                                      'syscalls.cc',
27                                      EXTRA_LIBS=['${PTHREAD_LIBS}',
28                                                  '${NONIRT_LIBS}'])
29
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)])
39 Default(inputs)
40
41 # syscalls_test exercise open/read/write, so need filesystem access
42 # via the debug flag to sel_ldr
43 node = env.CommandSelLdrTestNacl(
44     'syscalls_test.out',
45     syscalls_nexe,
46     args=[env.File('file_ok_rdwr.txt')],
47     sel_ldr_flags=['-a'])
48 env.AddNodeToTestSuite(node, ['small_tests'], 'run_syscall_test')
49
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')
53
54 getpid_test_nexe = env.ComponentProgram('getpid_test',
55                                         ['getpid_test.cc'],
56                                         EXTRA_LIBS=['syscall_test_framework',
57                                                     '${NONIRT_LIBS}'])
58 node = env.CommandSelLdrTestNacl(
59     'getpid_test.out',
60     getpid_test_nexe,
61     # Pass '-a' to enable the getpid() syscall.
62     sel_ldr_flags=['-a'])
63 env.AddNodeToTestSuite(node,
64                        ['small_tests', 'sel_ldr_tests'],
65                        'run_getpid_test',
66                        is_broken=getpid_is_broken)
67
68 raw_syscall_objects = env.RawSyscallObjects(['getpid_test.cc'])
69 raw_getpid_test_nexe = env.ComponentProgram(
70                            'raw_getpid_test',
71                            raw_syscall_objects,
72                            EXTRA_LIBS=['syscall_test_framework',
73                                        '${NONIRT_LIBS}'])
74 node = env.CommandSelLdrTestNacl('raw_getpid_test.out',
75                                  raw_getpid_test_nexe,
76                                  # Pass '-a' to enable the getpid() syscall.
77                                  sel_ldr_flags=['-a'])
78
79 env.AddNodeToTestSuite(node,
80                        ['small_tests', 'sel_ldr_tests'],
81                        'run_raw_getpid_test')
82
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')
88
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)
98
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')
107
108 # The next two test positive and negative return values.
109 node = env.CommandSelLdrTestNacl(
110     'exit_one_test.out',
111     exit_test_nexe,
112     args=['1'],
113     exit_status='1',
114     )
115 env.AddNodeToTestSuite(node,
116                        ['small_tests', 'sel_ldr_tests'],
117                        'run_exit_one_test')
118
119 # The last one tests some unusually large number.
120 node = env.CommandSelLdrTestNacl(
121     'exit_large_test.out',
122     exit_test_nexe,
123     args=['123'],
124     exit_status='123',
125     )
126 env.AddNodeToTestSuite(node,
127                        ['small_tests', 'sel_ldr_tests'],
128                        'run_exit_large_test')
129
130 # Test the semaphore system calls.
131 semaphore_tests_nexe = env.ComponentProgram(
132     'semaphore_tests',
133     ['semaphore_tests.cc'],
134     EXTRA_LIBS=['${PTHREAD_LIBS}', 'syscall_test_framework', '${NONIRT_LIBS}'])
135
136 node = env.CommandSelLdrTestNacl(
137       'semaphore_tests.out',
138       semaphore_tests_nexe,
139       )
140 env.AddNodeToTestSuite(node,
141                        ['small_tests', 'sel_ldr_tests'],
142                        'run_semaphore_tests')
143
144 mem_test_nexe = env.ComponentProgram('mem_test',
145                                      ['mem_test.cc'],
146                                      EXTRA_LIBS=['syscall_test_framework',
147                                                  '${NONIRT_LIBS}'])
148 node = env.CommandSelLdrTestNacl('mem_test.out',
149                                  mem_test_nexe)
150 env.AddNodeToTestSuite(node,
151                        ['small_tests', 'sel_ldr_tests'],
152                        'run_mem_test')
153
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
159     # ABI.
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',
164                   '${NONIRT_LIBS}',
165                   'nacl_sys_private'])
166   node = nonstable_env.CommandSelLdrTestNacl('sysbrk_test.out',
167                                              sysbrk_test_nexe)
168   nonstable_env.AddNodeToTestSuite(node,
169                                    ['small_tests', 'sel_ldr_tests'],
170                                    'run_sysbrk_test')
171
172 # These are timing tests, so we only run on real hardware
173 is_on_vm = env.Bit('running_on_vm')
174
175 # additions to add syscall tests 40-42
176 timefuncs_test_nexe = env.ComponentProgram(
177     'timefuncs_test',
178     ['timefuncs_test.cc'],
179     EXTRA_LIBS=['${PTHREAD_LIBS}', 'syscall_test_framework', '${NONIRT_LIBS}'])
180
181 node = env.CommandSelLdrTestNacl(
182     'timefuncs_test.out',
183     timefuncs_test_nexe)
184
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
189                        )
190
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}'])
196
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)
203
204 sysconf_pagesize_nexe = env.ComponentProgram('sysconf_pagesize_test',
205                                              ['sysconf_pagesize.c'],
206                                              EXTRA_LIBS=['${NONIRT_LIBS}'])
207
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')
213
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
217 # would always fail.
218
219 file_path = env.MakeEmptyFile(prefix='tmp_syscalls')
220
221 sysconf_nprocessors_nexe = env.ComponentProgram('sysconf_nprocessors_test',
222                                                 ['sysconf_nprocessors.c'],
223                                                 EXTRA_LIBS=['${NONIRT_LIBS}'])
224
225 node = env.CommandSelLdrTestNacl(
226     'sysconf_nprocessors_test.out',
227     sysconf_nprocessors_nexe,
228     filter_regex='"= ' + str(multiprocessing.cpu_count()) + ' processors"',
229     filter_inverse=True,
230     stdout_golden=file_path)
231
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
235 # more info.
236 if not env.Bit('coverage_enabled'):
237   env.AddNodeToTestSuite(node,
238                          ['small_tests', 'sel_ldr_tests'],
239                          'run_sysconf_nprocessors_test')
240
241 filepos_nexe = env.ComponentProgram('filepos_test',
242                                     ['filepos_test.c'],
243                                     EXTRA_LIBS=['imc_syscalls',
244                                                 '${NONIRT_LIBS}',
245                                                 '${PTHREAD_LIBS}'])
246
247 node = env.CommandSelLdrTestNacl(
248   'filepos_test.out',
249   filepos_nexe,
250   ['-t', env.MakeTempDir(prefix='tmp_syscalls')],
251   sel_ldr_flags=['-a'])
252
253 env.AddNodeToTestSuite(node,
254                        ['small_tests', 'sel_ldr_tests'],
255                        'run_filepos_test')