Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / native_client / tests / callingconv / nacl.scons
1 # -*- python -*-
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.
5
6 Import('env')
7
8 # This test does not make any sense for pure pnacl.
9 if env.Bit('bitcode') and env.Bit('pnacl_generate_pexe'):
10   Return()
11
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'):
15   Return()
16
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.
21
22 #
23 # Calling Convention Test
24 #
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.
29 #
30 # To test toolchain compatibility, some of the modules are built
31 # using PNaCl, and some with NNaCl.
32 #
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
36
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 ]
40
41 base_settings = {
42   'num_functions'    : 200,
43   'calls_per_func'   : 4,
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.
49 }
50
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
55   # wipes CFLAGS.
56   for e in envlist:
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'])
61
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) ]
69
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)
74
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}'))
81   else:
82     # On the hardware bot, do not regenerate the files.
83     nodes = []
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) ])
87
88   # Create the module objects
89   modules = []
90   for i in xrange(num_modules):
91     obj = envlist[i].ComponentObject(nodes[i+1])
92     envlist[i].Depends(obj, callingconv_h)
93     modules.append(obj)
94
95   # Compile callingconv.c
96   callingconv = link_env.ComponentObject(
97       test_variant,
98       'callingconv.c')
99   link_env.Depends(callingconv, callingconv_h)
100
101   prog = link_env.ComponentProgram(test_variant,
102                                    [callingconv] + modules,
103                                    EXTRA_LIBS=['${NONIRT_LIBS}'])
104
105   node = link_env.CommandSelLdrTestNacl(
106       test_variant + '.out',
107       prog,
108       stdout_golden=nodes[0])
109
110   env.AddNodeToTestSuite(node, ['medium_tests', 'nonpexe_tests'],
111                          'run_' + test_variant + '_test')
112
113
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).
119
120   # (1) Self-consistency.
121   settings = dict(base_settings)
122   envlist = [base_env]
123   link_env = base_env
124   AddTest(base_env, 'callingconv_self', envlist, settings)
125
126   # (2) Cross-check.
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
131
132   envlist = []
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',
139         '-mfloat-abi=hard',
140         ])
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'])
145   else:
146     raise Exception('Unknown architecture')
147
148   envlist.append(pnacl_env)
149
150   native_env = base_env.PNaClGetNNaClEnv()
151   envlist.append(native_env)
152   link_env = pnacl_env
153
154   AddTest(base_env, 'callingconv', envlist, settings)
155 else:
156   # For NNaCl toolchain, just test self-consistency.
157   settings = dict(base_settings)
158   link_env = base_env
159   envlist = [base_env]
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)