2 # Copyright 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 # This test does not make any sense for pure pnacl.
9 if env.Bit('bitcode') and env.Bit('pnacl_generate_pexe'):
12 # This test is disabled for MIPS because we do not have a MIPS-enabled nacl-gcc
13 # to test PNaCl against.
14 if env.Bit('target_mips32'):
17 # If this test is failing on the bots, you can find the seed
18 # from the output of the bot. Look for "--seed=".
19 # To reproduce the exact problem, set settings['seed'] below
20 # to the fixed seed you found on the bot.
23 # Calling Convention Test
25 # The "generate.py" script generates 4 modules (module0.c ... module3.c).
26 # Each module has functions, and calls to other functions in other modules.
27 # Each function has multiple fixed and variable arguments.
28 # This tests (by brute force) the correctness of the calling convention.
30 # To test toolchain compatibility, some of the modules are built
31 # using PNaCl, and some with NNaCl.
33 # Note: having random tests has been a little controversial,
34 # we are also intentionally hiding the randomness from scons, c.f.:
35 # http://codereview.chromium.org/7215028
37 base_env = env.Clone()
38 callingconv_h = base_env.File('callingconv.h').srcnode()
39 extra_cflags = [ '-Wno-long-long', '-I' + callingconv_h.dir.abspath ]
42 'num_functions' : 200,
44 'max_args_per_func': 16,
45 # Note: 'seed' is intentionally not mentioned here which results in
46 # generate.py picking one (see above)
47 # Having a seed here would make the commandline flags random,
48 # which would force scons to always rebuild.
51 def AddTest(env, test_variant, envlist, settings):
52 envlist = list(envlist)
53 settings = dict(settings)
54 # Add custom CFLAGS: this must be done here, since PNaClGetNNaClEnv
57 e.Append(CFLAGS = extra_cflags)
58 # This can generate references to runtime code we won't link with
59 # (__aeabi_unwind_cpp_pr0, etc.) when using PNaCl as the linker.
60 e.FilterOut(CCFLAGS=['-fasynchronous-unwind-tables'])
62 # Create two modules for each environment,
63 # so that we test toolchain self-interaction.
64 envlist = envlist + envlist
65 num_modules = len(envlist)
66 settings['num_modules'] = num_modules
67 module_filenames = [ 'module%d_%s.c' % (i, test_variant)
68 for i in xrange(num_modules) ]
70 # Generate the module source files (module0.c, module1.c, ...).
71 settings_args = ['--%s=%s' % (k,str(v)) for k,v in settings.iteritems()]
72 base_env = env.Clone()
73 base_env['GENERATOR_SETTINGS'] = ' '.join(settings_args)
75 if not env.Bit('built_elsewhere'):
76 # On the QEMU bot, generate the golden file and c files.
77 nodes = base_env.Command(
78 [test_variant + '.golden'] + module_filenames,
79 base_env.File('generate.py'),
80 Action('${PYTHON} ${SOURCE} ${GENERATOR_SETTINGS} -- ${TARGETS}'))
82 # On the hardware bot, do not regenerate the files.
84 nodes.append(base_env.File(test_variant + '.golden'))
85 nodes.extend([ base_env.File(module_filenames[i])
86 for i in xrange(num_modules) ])
88 # Create the module objects
90 for i in xrange(num_modules):
91 obj = envlist[i].ComponentObject(nodes[i+1])
92 envlist[i].Depends(obj, callingconv_h)
95 # Compile callingconv.c
96 callingconv = link_env.ComponentObject(
99 link_env.Depends(callingconv, callingconv_h)
101 prog = link_env.ComponentProgram(test_variant,
102 [callingconv] + modules,
103 EXTRA_LIBS=['${NONIRT_LIBS}'])
105 node = link_env.CommandSelLdrTestNacl(
106 test_variant + '.out',
108 stdout_golden=nodes[0])
110 env.AddNodeToTestSuite(node, ['medium_tests', 'nonpexe_tests'],
111 'run_' + test_variant + '_test')
114 if env.Bit('bitcode'):
115 # For PNaCl, we do a mixed test and a self-consistency test.
116 # The mixed test checks self-consistency as well, but it is currently
117 # broken on several platforms, so we check it separately as well
118 # (where it is not broken).
120 # (1) Self-consistency.
121 settings = dict(base_settings)
124 AddTest(base_env, 'callingconv_self', envlist, settings)
127 if env.Bit('target_arm'):
128 # Constant pool items are sometimes too far away with nacl-gcc.
129 # BUG: http://code.google.com/p/nativeclient/issues/detail?id=3205
130 settings['allow_double'] = 0
133 pnacl_env = base_env.Clone()
134 pnacl_env.PNaClForceNative()
135 # PNaCl only uses the standard ABI if given special flags.
136 if env.Bit('target_arm'):
137 pnacl_env.Append(CCFLAGS=[
138 '--target=armv7a-unknown-nacl-gnueabi',
141 elif env.Bit('target_x86_32'):
142 pnacl_env.Append(CCFLAGS=['--target=i686-unknown-nacl'])
143 elif env.Bit('target_x86_64'):
144 pnacl_env.Append(CCFLAGS=['--target=x86_64-unknown-nacl'])
146 raise Exception('Unknown architecture')
148 envlist.append(pnacl_env)
150 native_env = base_env.PNaClGetNNaClEnv()
151 envlist.append(native_env)
154 AddTest(base_env, 'callingconv', envlist, settings)
156 # For NNaCl toolchain, just test self-consistency.
157 settings = dict(base_settings)
160 if env.Bit('target_arm'):
161 # Constant pool items sometimes too far away:
162 # BUG: http://code.google.com/p/nativeclient/issues/detail?id=3205
163 settings['allow_double'] = 0
164 AddTest(base_env, 'callingconv', envlist, settings)