2 # Copyright (c) 2013 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 def AddLibcTest(env, src, exit_status='0', golden_file=None, test_suffix='',
9 is_broken=False, compile_env=None, link_env=None,
11 """Convenience function for adding new tests.
13 src: name of the source file for the test. The test name is derived from it
14 by removing the extension and appending the optional test_suffix.
15 exit_status: expected exit status, as a string
16 golden_file: golden file for stdout, if applicable
17 is_broken: is the test expected to be broken?
18 compile_env, link_env: if passed, these are used as the envs for compiling and
19 linking the code, respectively.
20 EXTRA_LIBS: extra libraries to provide during linking.
22 name = src.split('.')[0]
25 compile_env = compile_env or env
26 link_env = link_env or env
28 obj = compile_env.ComponentObject(name, src)
29 nexe = link_env.ComponentProgram(
30 name, obj, EXTRA_LIBS=['${NONIRT_LIBS}'] + EXTRA_LIBS)
31 node = env.CommandSelLdrTestNacl(name + '.out',
33 exit_status=exit_status,
34 stdout_golden=golden_file)
35 env.AddNodeToTestSuite(node,
36 ['toolchain_tests', 'small_tests'],
37 'run_' + name + '_test',
40 AddLibcTest(env, 'memcpy_move_set.c', '0',
41 golden_file=env.File('memcpy_move_set.stdout'))
42 AddLibcTest(env, 'malloc_realloc_calloc_free.c', '0')
44 AddLibcTest(env, 'snprintf.c', '0', golden_file=env.File('snprintf.stdout'))
45 AddLibcTest(env, 'strtoll.c', '0')
46 AddLibcTest(env, 'strtoull.c', '0')
47 AddLibcTest(env, 'wcstoll.c', '0', is_broken=env.Bit('nacl_glibc'))
49 iconv_broken = (env.Bit('nacl_glibc') or
50 # The PNaCl archived frontend tests use an archived newlib,
51 # but the iconv test requires a new-enough newlib with fixes.
52 (env.Bit('bitcode') and env['TOOLCHAIN_FEATURE_VERSION'] < 3))
53 AddLibcTest(env, 'iconv.c', '0', is_broken=iconv_broken)
55 # Test that using link-time optimization does not convert calls to
56 # library functions that were never linked in.
57 if env.Bit('bitcode'):
58 unopt_env = env.Clone()
59 unopt_env.Append(CFLAGS=['-O0'])
60 unopt_env.Append(CCFLAGS=['-O0'])
62 opt_env.Append(CFLAGS=['-O3'])
63 opt_env.Append(CCFLAGS=['-O3'])
64 opt_env.Append(LINKFLAGS=['-O3'])
65 AddLibcTest(env, 'printf_to_puts.c', '0',
66 compile_env=unopt_env, link_env=opt_env)
68 # This was only made to compile without warnings/hacks after modifying newlib
69 # headers, so the PNaCl archived frontend test with older headers can't
70 # compile the non-hacky version of the test. We don't test archived
71 # GCC toolchains, so always let those run the test.
72 if not env.Bit('bitcode') or env['TOOLCHAIN_FEATURE_VERSION'] >= 3:
73 AddLibcTest(env, 'posix_memalign.c')