Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / native_client / tests / toolchain / 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('env')
7
8 # force inclusion of entire library, so that we can validate it
9 # NOTE: This approach does not work for -lc because of tons of
10 #       undefined symbols which would have to be stubbed out
11 DEP_LIBS = ['nacl', 'srpc', 'imc_syscalls', 'platform', 'gio', 'pthread', 'm']
12
13 # -lgcc is not exposed to the bitcode in PNaCl
14 if env.Bit('bitcode'):
15   LIBGCC = []
16 else:
17   LIBGCC = ['-lgcc']
18
19 DEP_LINKFLAGS = (['-Wl,--whole-archive'] + LIBGCC +
20                    ['-l' + name for name in DEP_LIBS] +
21                    ['-Wl,--no-whole-archive'])
22
23 # TODO(robertm): get rid of -allow-asm once we can distinguish
24 #                real asms from the redirect ones used here
25 if env.Bit('bitcode'):
26   env.Append(CCFLAGS=['-allow-asm'])
27
28 # Test C++11 code with both supported C++ standard libraries.
29 cpp11_libs = ['libc++']
30 if env.Bit('bitcode'):
31   # PNaCl still supports libstdc++ but nacl-clang does not.
32   cpp11_libs.append('libstdc++')
33 cpp11_envs = {}
34 for lib in cpp11_libs:
35   cpp11_envs[lib] = env.Clone()
36   cpp11_envs[lib].Append(CCFLAGS=['-std=c++11', '-stdlib=' + lib])
37   cpp11_envs[lib].Append(LINKFLAGS=['-stdlib=' + lib])
38   if lib == 'libstdc++':
39     # c++ is added to NONIRT_LIBS for clang to ensure that its dependence on
40     # pthreads can be satisfied by pthread_private instead of pthread. Filter it
41     # out here to ensure that we use libstdc++.
42     cpp11_envs[lib].FilterOut(NONIRT_LIBS=['c++'])
43
44 # All the libraries were already included via -l switches in LINKFLAGS.
45 # But we use them again in LIBS so scons knows about the dependencies.
46 # _LIBFLAGS is the internal variable that puts the expansion of LIBS
47 # into the command line; so by clearing that, we prevent scons from
48 # adding repeated -l switches at the end of the link.
49 nexe = env.ComponentProgram('dummy', 'dummy.c',
50                             EXTRA_LINKFLAGS=DEP_LINKFLAGS,
51                             LIBS=DEP_LIBS,
52                             _LIBFLAGS='')
53 node = env.CommandValidatorTestNacl('whole_archive_test.out',
54                                     image=nexe)
55 env.AddNodeToTestSuite(node,
56                        ['toolchain_tests', 'small_tests'],
57                        'run_whole_archive_test')
58
59
60 def AddIntrinsicTest(test_env, src, exit_status,
61                      golden_file=None, test_suffix='', is_broken=False,
62                      EXTRA_LIBS=[]):
63   name = src.split('.')[0]
64   name += test_suffix
65
66   obj = test_env.ComponentObject(name, src)
67   nexe = test_env.ComponentProgram(
68       name, obj, EXTRA_LIBS=['${NONIRT_LIBS}'] + EXTRA_LIBS)
69   node = test_env.CommandSelLdrTestNacl(name + '.out',
70                                         nexe,
71                                         exit_status=exit_status,
72                                         stdout_golden=golden_file)
73   test_env.AddNodeToTestSuite(node,
74                               ['toolchain_tests','small_tests'],
75                               'run_' + name + '_test',
76                               is_broken=is_broken)
77
78
79 # Test various intrinsics.
80 AddIntrinsicTest(env, 'intrinsics.cc', '55'),
81 AddIntrinsicTest(env, 'float2.c', '0', golden_file=env.File('float2.stdout'))
82 AddIntrinsicTest(env, 'synchronization_sync.c', '0',
83                  # TODO(jfb) Blocked on bugs 3579 and 2981. This should
84                  # work on PNaCl because it avoids the broken 16-bit
85                  # instructions on x86-32 by using 32-bit instructions.
86                  # The test also exercises instructions that confuse valgrind.
87                  is_broken=((env.Bit('target_x86_32') and
88                              not env.Bit('bitcode')) or
89                             env.IsRunningUnderValgrind()))
90 AddIntrinsicTest(env, 'synchronization_volatile.c', '0')
91 if env.Bit('bitcode') or env.Bit('nacl_clang'):
92   # The following tests were only made to work on LLVM for
93   # PNaCl. Command-line flags and libraries need to be updated for GCC
94   # support.
95   # pthread is needed when building with libc++.
96   for lib in cpp11_envs:
97     AddIntrinsicTest(cpp11_envs[lib], 'condition_variable_cpp11.cc', '0',
98                      test_suffix=lib, EXTRA_LIBS=['${PTHREAD_LIBS}'])
99     AddIntrinsicTest(cpp11_envs[lib], 'future_cpp11.cc', '0',
100                      test_suffix=lib, EXTRA_LIBS=['${PTHREAD_LIBS}'])
101     AddIntrinsicTest(cpp11_envs[lib], 'mutex_cpp11.cc', '0',
102                      test_suffix=lib, EXTRA_LIBS=['${PTHREAD_LIBS}'])
103     AddIntrinsicTest(cpp11_envs[lib], 'synchronization_cpp11.cc', '0',
104                      test_suffix=lib, EXTRA_LIBS=['${PTHREAD_LIBS}'])
105     AddIntrinsicTest(cpp11_envs[lib], 'thread_cpp11.cc', '0',
106                      test_suffix=lib, EXTRA_LIBS=['${PTHREAD_LIBS}'])
107     if lib != 'libstdc++':
108       # TODO(jfb) Can't compile with libstdc++.
109       AddIntrinsicTest(cpp11_envs[lib], 'long_double_cpp11.cc', '0',
110                        test_suffix=lib, EXTRA_LIBS=['${PTHREAD_LIBS}'])
111
112 # This test redirects C function calls to llvm instrinsic functions,
113 # so they only work w/ PNaCl.
114 if env.Bit('bitcode') or env.Bit('nacl_clang'):
115   AddIntrinsicTest(env, 'llvm_bitmanip_intrinsics.c', '0',
116                    golden_file=env.File('llvm_bitmanip_intrinsics.stdout'))
117   AddIntrinsicTest(env, 'llvm_math_intrinsics.c', '0',
118                    golden_file=env.File('llvm_math_intrinsics.stdout'))
119   # Also test the math functions with -ffast-math, so we are a tiny bit more
120   # confident that sin() or __builtin_sin() doesn't get turned into
121   # something like llvm.sin.f64.
122   fastmath_env = env.Clone()
123   fastmath_env.Append(CCFLAGS=['-ffast-math'])
124   AddIntrinsicTest(fastmath_env, 'llvm_math_intrinsics.c', '0',
125                    golden_file=env.File('llvm_math_intrinsics.stdout'),
126                    test_suffix='_fast_math')
127
128 # Some of the intrinsic tests cover intrinsics that we do not want to
129 # support. For example, llvm.frameaddress. If that is the case, we will
130 # use the nonstable_env as our test_env in AddIntrinsicTest.
131 nonstable_env = env.Clone()
132 if env.Bit('bitcode'):
133   nonstable_env.Append(LINKFLAGS=['--pnacl-disable-abi-check'])
134 if nonstable_env.AllowNonStableBitcode():
135   # Consider llvm.frameaddress and llvm.returnaddress non-stable,
136   # since we may want to hide return and stack addresses in the future.
137   AddIntrinsicTest(nonstable_env, 'frame_addresses.c', '0'),
138   AddIntrinsicTest(nonstable_env, 'return_address.c', '55')
139
140
141 # initfini test
142 initfini_obj = env.ComponentObject('initfini.c')
143
144 def AddInitFiniTest(env, name, extra_libs):
145   nexe = env.ComponentProgram(name,
146                               [initfini_obj],
147                               EXTRA_LIBS=extra_libs + ['${NONIRT_LIBS}'])
148   golden_file = env.File(name + '.stdout')
149   node = env.CommandSelLdrTestNacl(name + '.out',
150                                    nexe,
151                                    stdout_golden=golden_file)
152   # This test checks the ".init_array" and ".fini_array" sections,
153   # which are an internal detail of how the toolchain works.  We do
154   # not support these sections in PNaCl's static linking ABI, because
155   # PNaCl connects up initializers at bitcode linking time.  PNaCl
156   # does support __attribute__((constructor)) and
157   # __attribute__((destructor)) which are tested via
158   # run_initfini_attributes_test below.
159   is_broken = env.Bit('bitcode') and env.Bit('nacl_static_link')
160   env.AddNodeToTestSuite(node,
161                          ['toolchain_tests', 'small_tests'],
162                          'run_' + name + '_test',
163                          is_broken=is_broken)
164
165 AddInitFiniTest(env, 'initfini_static', [])
166 if env.Bit('nacl_glibc') and not env.Bit('nacl_disable_shared'):
167   # Additional case: Add initfini_shared.c as a shared object.
168   # For a shared object, the init/fini arrays are executed by
169   # the dynamic loader. This exercises a different code path.
170   env.NaClSdkLibrary('initfini_s', 'initfini_shared.c')
171   AddInitFiniTest(env, 'initfini_shared', ['initfini_s'])
172
173
174 nexe = env.ComponentProgram(
175     'initfini_attributes', ['initfini_attributes.c'],
176     EXTRA_LIBS=['${NONIRT_LIBS}'])
177 node = env.CommandSelLdrTestNacl(
178     'initfini_attributes.out', nexe,
179     stdout_golden=env.File('initfini_attributes.stdout'))
180 env.AddNodeToTestSuite(
181     node, ['toolchain_tests', 'small_tests'],
182     'run_initfini_attributes_test',
183     # __attribute__((destructor)) is broken in nacl-glibc on x86-64.
184     # See http://code.google.com/p/nativeclient/issues/detail?id=3056
185     # TODO(mseaborn): Enable this test there when this is fixed.
186     is_broken=env.Bit('nacl_glibc') and env.Bit('target_x86_64'))
187
188
189 nexe = env.ComponentProgram('pthread_cleanup', 'pthread_cleanup.c',
190                             EXTRA_LIBS=['${PTHREAD_LIBS}',
191                                         '${NONIRT_LIBS}'])
192 node = env.CommandSelLdrTestNacl('pthread_cleanup.out', nexe)
193 env.AddNodeToTestSuite(node, ['toolchain_tests', 'small_tests'],
194                        'run_pthread_cleanup_test',
195 # This test is flaky on mac10.7-newlib-dbg-asan.
196 # See https://code.google.com/p/nativeclient/issues/detail?id=3906
197                        is_broken=(env.Bit('asan') and env.Bit('host_mac')))
198
199
200 nexe = env.ComponentProgram('cpp_threadsafe_static_init',
201                             'cpp_threadsafe_static_init.cc',
202                             EXTRA_LIBS=['${PTHREAD_LIBS}',
203                                         '${NONIRT_LIBS}'])
204 node = env.CommandSelLdrTestNacl('cpp_threadsafe_static_init.out', nexe)
205 # This test fails with the newlib-based builds of libstdc++ that have
206 # multi-threading disabled internally.  In x86 nacl-gcc, libstdc++'s
207 # threading works on x86-32 but is disabled on x86-64 via an #ifdef.  In
208 # ARM nacl-gcc, libstdc++'s threading isn't enabled at all.
209 # See https://code.google.com/p/nativeclient/issues/detail?id=3948
210 env.AddNodeToTestSuite(node, ['toolchain_tests', 'small_tests'],
211                        'run_cpp_threadsafe_static_init_test',
212                        is_broken=(not env.Bit('bitcode') and
213                                   not env.Bit('nacl_glibc') and
214                                   not env.Bit('target_x86_32')))
215
216
217 # NOTE: the tests below break easily under valgrid and since
218 #       they do not exercise malloc/free we exclude
219 if env.IsRunningUnderValgrind():
220   Return()
221
222
223 # NOTE: we assume that the incoming env contains '-O2', '-fomit-frame-pointer'
224 def MakeEnv(env, use_opts, use_frames):
225   new_env = env.Clone()
226   # AddBiasForPNaCl() is only needed for stack_frame.cc and eh_return.c.
227   if new_env.Bit('bitcode'):
228     new_env.AddBiasForPNaCl()
229   new_env.FilterOut(CFLAGS=['-pedantic'])
230   new_env.FilterOut(CCFLAGS=['-pedantic'])
231   if use_frames:
232     new_env.FilterOut(CFLAGS=['-fomit-frame-pointer'])
233     new_env.FilterOut(CCFLAGS=['-fomit-frame-pointer'])
234     if env.Bit('bitcode'):
235       # To use frame pointers for PNaCl, we need to change the translate-flags.
236       new_env.Append(TRANSLATEFLAGS=[
237           '--pnacl-driver-set-LLC_FLAGS_EXTRA=-disable-fp-elim'])
238   else:
239     new_env.Append(CFLAGS=['-fomit-frame-pointer'])
240     new_env.Append(CCFLAGS=['-fomit-frame-pointer'])
241   if use_opts:
242     new_env.Append(CFLAGS=['-O2'])
243     new_env.Append(CCFLAGS=['-O2'])
244   else:
245     new_env.FilterOut(CFLAGS=['-O2'])
246     new_env.FilterOut(CCFLAGS=['-O2'])
247     new_env.FilterOut(LINKFLAGS=['-O3'])
248   return new_env
249
250 EH_ENVIRONMENTS_TO_TRY = []
251
252 base_eh_env = env.Clone()
253
254 supports_cxx11 = env.Bit('bitcode') or env.Bit('target_arm')
255 base_eh_env.Append(CPPDEFINES=[['SUPPORTS_CXX11', str(int(supports_cxx11))]])
256 if supports_cxx11:
257   # This flag is necessary for testing std::rethrow_exception(), at
258   # least when using libstdc++.
259   base_eh_env.Append(CXXFLAGS=['-std=gnu++11'])
260
261 if env.Bit('bitcode') and env['TOOLCHAIN_FEATURE_VERSION'] >= 1:
262   for lib in ('libstdc++', 'libc++'):
263     sjlj_eh_env = base_eh_env.Clone()
264     sjlj_eh_env.Append(LINKFLAGS=['--pnacl-exceptions=sjlj',
265                                   '-stdlib=%s' % lib])
266     sjlj_eh_env.Append(CCFLAGS=['-stdlib=%s' % lib])
267     # c++ is added to NONIRT_LIBS for clang to ensure that its dependence on
268     # pthreads can be satisfied by pthread_private instead of pthread. Filter it
269     # out here to ensure that we use libstdc++.
270     if lib == 'libstdc++':
271       sjlj_eh_env.FilterOut(NONIRT_LIBS=['c++'])
272     EH_ENVIRONMENTS_TO_TRY.append(('sjlj_%s' % lib, sjlj_eh_env))
273
274 if env.Bit('bitcode'):
275   zerocost_eh_env = base_eh_env.Clone()
276   zerocost_eh_env.Append(LINKFLAGS=['--pnacl-allow-exceptions'])
277   zerocost_eh_env.Append(TRANSLATEFLAGS=['--pnacl-allow-exceptions'])
278 else:
279   zerocost_eh_env = base_eh_env
280 # Zero-cost C++ exception handling is not currently supported in
281 # PNaCl's stable ABI.
282 if zerocost_eh_env.AllowNonStableBitcode():
283   EH_ENVIRONMENTS_TO_TRY.extend(
284       [('noopt_frame', MakeEnv(zerocost_eh_env, False, True)),
285        ('noopt_noframe', MakeEnv(zerocost_eh_env, False, False)),
286        ('opt_frame', MakeEnv(zerocost_eh_env, True, True)),
287        ('opt_noframe', MakeEnv(zerocost_eh_env, True, False))])
288
289 for tag, env_to_try in EH_ENVIRONMENTS_TO_TRY:
290   for src in ['stack_frame.cc',
291               'eh_return.c',
292               'eh_virtual_dtor.cc',
293               'eh_loop_single.cc',
294               'eh_loop_many.cc',
295               'eh_catch_many.cc',
296               'eh_loop_break.cc',
297               'eh_floating_point.cc',
298               'eh_uncaught_exception.cc',
299               'eh_throw_tests.cc',
300               ]:
301
302     if not env.Bit('bitcode') and src in ['eh_return.c']:
303       # for some reason gcc does not allow us to use
304       #  __builtin_eh_return
305       continue
306
307     is_broken = False
308     if (env.Bit('bitcode') and
309         env.Bit('pnacl_generate_pexe') and
310         src in ['stack_frame.cc', 'eh_return.c']):
311       # stack_frame.cc and eh_return.c have bias see above
312       is_broken = True
313
314     if not env.Bit('bitcode') and src in ['stack_frame.cc']:
315       # This test makes pnacl specific assumptions which
316       # may not hold for the nacl-gcc TC
317       is_broken = True
318
319     # The following tests don't work as PNaCl ABI-stable pexes.
320     non_abi_stable_tests = [
321         'eh_floating_point.cc', # Uses vector types
322         'stack_frame.cc', # Uses llvm.eh.dwarf.cfa
323         'eh_return.c', # Uses llvm.eh.dwarf.cfa, and llvm.eh.return.i32
324         ]
325     if tag.startswith('sjlj_') and src in non_abi_stable_tests:
326       continue
327
328     if '--pnacl-exceptions=sjlj' in env_to_try['LINKFLAGS']:
329       if (src == 'eh_uncaught_exception.cc' and
330           env_to_try['TOOLCHAIN_FEATURE_VERSION'] < 2):
331         is_broken = True
332       if (src == 'eh_throw_tests.cc' and
333           env_to_try['TOOLCHAIN_FEATURE_VERSION'] < 3):
334         is_broken = True
335
336     name = src.split('.')[0] + '_' + tag
337     nobj = env_to_try.ComponentObject(name + '.o', src)
338     nexe = env_to_try.ComponentProgram(name, nobj,
339                                        EXTRA_LIBS=['${NONIRT_LIBS}'])
340     node = env_to_try.CommandSelLdrTestNacl(name + '.out',
341                                             nexe,
342                                             exit_status='55')
343     env_to_try.AddNodeToTestSuite(
344         node, ['eh_tests', 'toolchain_tests', 'small_tests'],
345         'run_' + name  +'_test', is_broken=is_broken)
346
347
348 # Test that Exception Handling works with the calling conventions that
349 # match the PPAPI PNaCl IRT shim's calling conventions.
350 exc_env = env.Clone()
351 if exc_env.Bit('bitcode') and exc_env.AllowNonStableBitcode():
352   # Test what happens when all objects are bitcode w/ bitcode linking.
353   exc_env.Append(LINKFLAGS=['--pnacl-allow-exceptions'])
354   exc_env.Append(TRANSLATEFLAGS=['--pnacl-allow-exceptions'])
355   bobj1 = exc_env.ComponentObject('eh_separate_files1_bc.o',
356                                   'eh_separate_files1.cc')
357   bobj2 = exc_env.ComponentObject('eh_separate_files2_bc.o',
358                                   'eh_separate_files2.cc')
359   nexe = exc_env.ComponentProgram('eh_separate_files_bc',
360                                   [bobj1, bobj2],
361                                   EXTRA_LIBS=['${NONIRT_LIBS}'])
362   node = exc_env.CommandSelLdrTestNacl('eh_separate_files_bc.out',
363                                        nexe,
364                                        exit_status='55')
365   env.AddNodeToTestSuite(node, ['toolchain_tests', 'small_tests'],
366                          'run_eh_separate_files_bc_test')
367   # Also test ahead of time translation, which may be used when debugging.
368   if not env.Bit('pnacl_generate_pexe'):
369     native_env = exc_env.Clone()
370     native_env.PNaClForceNative()
371     testsuite = ['toolchain_tests', 'small_tests', 'nonpexe_tests']
372     nobj1 = native_env.ComponentObject('eh_separate_files1_native.o',
373                                        'eh_separate_files1.cc')
374     nobj2 = native_env.ComponentObject('eh_separate_files2_native.o',
375                                        'eh_separate_files2.cc')
376     nexe = native_env.ComponentProgram('eh_separate_files_native',
377                                        [nobj1, nobj2],
378                                        EXTRA_LIBS=['${NONIRT_LIBS}'])
379     node = native_env.CommandSelLdrTestNacl('eh_separate_files_native.out',
380                                             nexe,
381                                             exit_status='55')
382     env.AddNodeToTestSuite(node,
383                            testsuite,
384                            'run_eh_separate_files_native_test')
385     # Test mixed objects, one native, one bitcode.
386     nexe = native_env.ComponentProgram('eh_separate_files_mixed1',
387                                        [bobj1, nobj2],
388                                        EXTRA_LIBS=['${NONIRT_LIBS}'])
389     node = native_env.CommandSelLdrTestNacl('eh_separate_files_mixed1.out',
390                                             nexe,
391                                             exit_status='55')
392     env.AddNodeToTestSuite(node,
393                            testsuite,
394                            'run_eh_separate_files_mixed1_test')
395     # Test having the bitcode and native objects swapped.
396     nexe = native_env.ComponentProgram('eh_separate_files_mixed2',
397                                        [nobj1, bobj2],
398                                        EXTRA_LIBS=['${NONIRT_LIBS}'])
399     node = native_env.CommandSelLdrTestNacl('eh_separate_files_mixed2.out',
400                                             nexe,
401                                             exit_status='55')
402     env.AddNodeToTestSuite(node,
403                            testsuite,
404                            'run_eh_separate_files_mixed2_test')
405
406
407
408 abi_types_nexe = env.ComponentProgram('abi_types',
409                                       'abi_types.cc',
410                                       EXTRA_LIBS=['${NONIRT_LIBS}'])
411
412 node = env.CommandSelLdrTestNacl('abi_types_test.out',
413                                  abi_types_nexe)
414 env.AddNodeToTestSuite(node,
415                        ['toolchain_tests', 'small_tests'],
416                        'run_abi_types_test')
417
418 getpagesize_test_nexe = env.ComponentProgram(
419     'getpagesize_test', 'getpagesize_test.c',
420     EXTRA_LIBS=['${NONIRT_LIBS}'])
421 node = env.CommandSelLdrTestNacl('getpagesize_test.out', getpagesize_test_nexe)
422 env.AddNodeToTestSuite(node, ['toolchain_tests', 'small_tests'],
423                        'run_getpagesize_test')
424
425 getid_test_nexe = env.ComponentProgram(
426     'getid_test', 'getid_test.c',
427     EXTRA_LIBS=['${NONIRT_LIBS}'])
428 node = env.CommandSelLdrTestNacl('getid_test.out', getid_test_nexe)
429 env.AddNodeToTestSuite(node, ['toolchain_tests', 'small_tests'],
430                        'run_getid_test')
431
432 prefetch_test_nexe = env.ComponentProgram(
433     'prefetch_test', 'prefetch_test.c',
434     EXTRA_LIBS=['${NONIRT_LIBS}'])
435 node = env.CommandSelLdrTestNacl('prefetch_test.out', prefetch_test_nexe)
436 env.AddNodeToTestSuite(node, ['toolchain_tests', 'small_tests'],
437                        'run_prefetch_test')
438
439
440 # Test that local variable dwarf info is preserved with linking and LTO.
441 # Force '-g' on in case it was not turned on for some reason, and lower
442 # optimization settings to prevent some optimizations that would convert
443 # locals from llvm allocas to registers.
444 # We may be able to remove this test once LLVM has an upstream regression test.
445 debug_env = env.Clone()
446 debug_env.Append(CFLAGS=['-g', '-O0'])
447 debug_env.Append(CCFLAGS=['-g', '-O0'])
448 debug_env.Append(LINKFLAGS=['-O0'])
449 # This requires preserving nonstable bitcode debug metadata.
450 if debug_env.AllowNonStableBitcode():
451   dwarf_local_var_nexe = debug_env.ComponentProgram(
452       'dwarf_local_var',
453       ['dwarf_local_var.c',
454        'dwarf_local_var_dummy.c'],
455       EXTRA_LIBS=['${NONIRT_LIBS}'])
456   # Sanity-check -- make sure it runs.
457   node = debug_env.CommandSelLdrTestNacl('dwarf_local_var_run.out',
458                                          dwarf_local_var_nexe,
459                                          exit_status=55)
460   debug_env.AddNodeToTestSuite(node,
461                                ['toolchain_tests', 'small_tests'],
462                                'run_dwarf_local_var_run_test')
463   node = debug_env.CommandTestFileDumpCheck('dwarf_local_var_objdump.out',
464                                             dwarf_local_var_nexe,
465                                             debug_env.File('dwarf_local_var.c'),
466                                             '-W')
467   debug_env.AddNodeToTestSuite(node,
468                                ['small_tests', 'toolchain_tests'],
469                                'run_dwarf_local_var_objdump_test')
470
471 if env.Bit('nacl_glibc'):
472   nexe = env.ComponentProgram('byteswap64', 'byteswap64.c',
473                               EXTRA_LIBS=['${NONIRT_LIBS}'])
474   node = env.CommandSelLdrTestNacl('byteswap64.out', nexe)
475   env.AddNodeToTestSuite(node,
476                          ['toolchain_tests', 'small_tests'],
477                          'run_byteswap64_test')
478
479 if env.Bit('nacl_glibc') or not env.Bit('bitcode'):
480   def AddAlignedCodeTest(name, object_file):
481     node = env.CommandTest(name + '.out',
482                            ['${PYTHON}', env.File('aligned_code.py'),
483                             '${OBJDUMP}', nexe],
484                            # don't run ${PYTHON} under the emulator.
485                            direct_emulation=False)
486     env.AddNodeToTestSuite(node,
487                            ['toolchain_tests', 'small_tests'],
488                            'run_' + name + '_test')
489   AddAlignedCodeTest('aligned_code',
490                      env.ComponentProgram('aligned_code', ['aligned_code.c'],
491                                           EXTRA_LIBS=['${NONIRT_LIBS}']))
492   if not env.Bit('nacl_disable_shared'):
493     AddAlignedCodeTest('aligned_code_lib',
494                        env.NaClSharedLibrary('aligned_code_lib',
495                                              ['aligned_code_lib.c']))
496
497 nexe = env.ComponentProgram('method_pointer_repr', 'method_pointer_repr.cc',
498                             EXTRA_LIBS=['${NONIRT_LIBS}'])
499 node = env.CommandSelLdrTestNacl('method_pointer_repr.out', nexe)
500 env.AddNodeToTestSuite(node, ['toolchain_tests', 'small_tests'],
501                        'run_method_pointer_repr_test')
502
503 c99_env = env.Clone()
504 c99_env.Append(CFLAGS=['-std=c99'])
505 # VLA test is broken on nacl-gcc x86-64 (segfaults in test_two_recursion()).
506 # http://code.google.com/p/nativeclient/issues/detail?id=3527
507 vla_is_broken = not env.Bit('bitcode') and env.Bit('target_x86_64')
508 nexe = c99_env.ComponentProgram('vla', 'vla.c',
509                                 EXTRA_LIBS=['${NONIRT_LIBS}'])
510 node = env.CommandSelLdrTestNacl('vla.out', nexe,
511                                  stdout_golden=env.File('vla.stdout'))
512 env.AddNodeToTestSuite(node, ['toolchain_tests', 'small_tests'],
513                        'run_vla_test',
514                        is_broken=vla_is_broken)
515
516 if not env.Bit('pnacl_generate_pexe'):
517   asm_env = env.Clone()
518   if env.Bit('bitcode'):
519     asm_env.PNaClForceNative()
520     asm_env.AddBiasForPNaCl()
521   testsuite = ['toolchain_tests', 'small_tests', 'nonpexe_tests']
522
523   def FarCallObjects(env, suffix=''):
524     return [env.ComponentObject(file[:-2] + suffix + '.o', file)
525             for file in ['far_caller.c', 'far_padding.S', 'far_callee.c']]
526   nexe = asm_env.ComponentProgram('far_call', FarCallObjects(asm_env),
527                                   EXTRA_LIBS=['${NONIRT_LIBS}'])
528   node = asm_env.CommandSelLdrTestNacl('far_call.out', nexe)
529   # TODO(mcgrathr): Broken for bitcode pending fixes to gold; see
530   # https://code.google.com/p/nativeclient/issues/detail?id=3568
531   asm_env.AddNodeToTestSuite(node, testsuite,
532                              'run_far_call_test',
533                              is_broken=env.Bit('bitcode'))
534
535   # TODO(mcgrathr): Disabled for bitcode because pnacl-ld doesn't grok
536   # --pic-veneer.  Another tack to test this would be to generate a shared
537   # object and validate it, but -shared is not really supported either.
538   # Since PNaCl has no reason to generate PIC at all until there is some
539   # form of ELF shared object support (if that ever happens at all),
540   # perhaps we'll never really need to test this.
541   if not env.Bit('bitcode'):
542     pic_env = asm_env.Clone()
543     pic_env.Append(CFLAGS=['-fPIC'])
544     if pic_env.Bit('target_arm'):
545       pic_env.Append(LINKFLAGS=['-Wl,--pic-veneer'])
546     nexe = pic_env.ComponentProgram('far_call_pic',
547                                     FarCallObjects(pic_env, '_pic'),
548                                     EXTRA_LIBS=['${NONIRT_LIBS}'])
549     node = pic_env.CommandSelLdrTestNacl('far_call_pic.out', nexe)
550     pic_env.AddNodeToTestSuite(node, testsuite,
551                                'run_far_call_pic_test')
552
553   dummy_obj = asm_env.ComponentObject('nop_test_main.o', 'dummy.c')
554   nexe = asm_env.ComponentProgram('nop_test', [dummy_obj, 'nop_test.S'],
555                                   EXTRA_LIBS=['${NONIRT_LIBS}'])
556   node = asm_env.CommandSelLdrTestNacl('nop_test.out', nexe)
557   asm_env.AddNodeToTestSuite(node, testsuite,
558                              'run_nop_test')
559
560   # Test that both the layout and the nops are not munged by stripping.
561   stripped_nexe = asm_env.Command('strip_test.nexe', nexe,
562                                   '${STRIP} -o ${TARGET} ${SOURCES}')
563   node = asm_env.CommandSelLdrTestNacl('strip_test.out', stripped_nexe)
564   asm_env.AddNodeToTestSuite(node, testsuite,
565                              'run_strip_test')
566
567 if not env.Bit('nacl_disable_shared') and not env.Bit('nacl_static_link'):
568   env.NaClSharedLibrary('pic_constant_lib', ['pic_constant_lib.c'])
569   nexe = env.ComponentProgram('pic_constant', ['pic_constant.c'],
570                               EXTRA_LIBS=['pic_constant_lib', '${NONIRT_LIBS}'])
571   node = env.CommandSelLdrTestNacl('pic_constant.out', nexe)
572   env.AddNodeToTestSuite(node, testsuite,
573                          'run_pic_constant_test')
574
575 WRAP_LINK_FLAGS = ['-Wl,--wrap=foo', '-Wl,--wrap=bar']
576 env.ComponentLibrary('wrap_lib', ['wrap_lib1.c', 'wrap_lib2.c'])
577 nexe = env.ComponentProgram('wrap', ['wrap_main.c'],
578                             EXTRA_LINKFLAGS=WRAP_LINK_FLAGS,
579                             EXTRA_LIBS=['wrap_lib', '${NONIRT_LIBS}'])
580 node = env.CommandSelLdrTestNacl('wrap.out', nexe,
581                                  stdout_golden=env.File('wrap.stdout'))
582 env.AddNodeToTestSuite(node, ['toolchain_tests','small_tests'], 'run_wrap_test')
583
584 if (env.Bit('target_x86_32') and env.Bit('bitcode') and
585     not env.Bit('pnacl_generate_pexe') and
586     env['TOOLCHAIN_FEATURE_VERSION'] >= 8):
587   # This test compiles a file that will need to generate a call to a compiler-rt
588   # function (__udivdi3) on x86-32. Ensure that when we pre-translate to a
589   # native object file, libgcc is included in the bitcode link to satisfy the
590   # reference.
591   mixedlink_env = env.Clone()
592   mixedlink_env.Append(CCFLAGS=['--pnacl-allow-translate',
593                                 '--pnacl-allow-native',
594                                 '-arch', 'x86-32'])
595   mixedlink_env.Append(LINKFLAGS=['--pnacl-allow-translate',
596                                   '--pnacl-allow-native',
597                                   '-arch', 'x86-32'])
598
599   nexe = mixedlink_env.ComponentProgram('libgcc_mixed_link', 'needs_libgcc.c',
600                                         EXTRA_LIBS=['${NONIRT_LIBS}'])
601   node = mixedlink_env.CommandSelLdrTestNacl('libgcc_mixed_link.out', nexe,
602                                              ['9', '3'])
603   mixedlink_env.AddNodeToTestSuite(node, ['nonpexe_tests', 'small_tests',
604                                           'toolchain_tests'],
605                                    'run_libgcc_mixed_link_test')
606
607   # This tests the translator's -force-align-stack flag, which means that the
608   # compiler cannot assume that the stack pointer is aligned to a 16-byte
609   # boundary, and must force realignment on entry to each function.
610   mixedlink_env.Append(ASFLAGS=['-arch', 'x86-32'])
611   mixedlink_env.Append(CCFLAGS=['-Wt,-force-align-stack'])
612   nexe = mixedlink_env.ComponentProgram(
613       'stackalign_test',
614       ['call_with_misaligned_stack.S', 'stackalign_test.c'],
615       EXTRA_LIBS=['${NONIRT_LIBS}'])
616   node = mixedlink_env.CommandSelLdrTestNacl('stackalign.out', nexe)
617   mixedlink_env.AddNodeToTestSuite(
618       node,
619       ['nonpexe_tests', 'small_tests', 'toolchain_tests'],
620       'run_stackalign_test')