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.
10 # This test does not make any sense for pure pnacl
11 if env.Bit('bitcode') and env.Bit('pnacl_generate_pexe'):
14 # This test is disabled for MIPS because we do not have a MIPS-enabled nacl-gcc
15 # to test PNaCl against.
16 if env.Bit('target_mips32'):
19 if env.Bit('bitcode'):
20 # Disabling the PNaCl ABI checker is necessary for the
21 # PNaCl-calling-PNaCl case below because the test uses the __m128
22 # type, which the checker rejects.
23 env.Append(LINKFLAGS=['--pnacl-disable-abi-check'])
25 # Case-by-case calling Convention Test for PNaCl and nacl-gcc compatibility.
28 # CC1 emits MODULE0 and CC2 MODULE1, CC2 emits MODULE2 and CC1 MODULE3
30 # MODULE0(cc1) -> MODULE0(cc1) -> MODULE1(cc2) -> MODULE2(cc2) -> MODULE3(cc1).
31 # For the return test, the dataflow is reversed.
33 # List of (4 envs for the modules, link_env, test_name_suffix)
34 # to apply to each source. The 4 envs may have different flags.
35 test_configurations = []
37 def AddCommonFlags(envlist):
38 for (i, e) in enumerate(envlist):
39 # Add -Wno-long-long because we use c99 long long constants in C++ code.
40 e.Append(CCFLAGS=['-DMODULE' + str(i), '-Wno-long-long'])
42 def MakeSelfTestEnv(base_env, extra_flags):
43 """ Make a list of four (nearly identical) envs which use the same CC
44 for compiling the four modules to test self-consistency. """
45 base_env = base_env.Clone()
46 base_env.Append(CCFLAGS=extra_flags)
47 # Same CC for all, but assign different module defines later.
48 envlist = [base_env.Clone() for dummy_count in xrange(4)]
49 AddCommonFlags(envlist)
51 return (envlist, link_env)
53 def MakeCrossEnvs(base_env, gcc_flags, clang_flags):
54 """ Make a list of four (nearly identical) envs, some of which use gcc
55 and some use pnacl, for compiling the four modules to test consistency.
59 cc1_env = base_env.Clone()
60 cc1_env.PNaClForceNative()
61 cc1_env.Append(CCFLAGS=clang_flags)
62 envlist.append(cc1_env)
64 cc2_env = base_env.PNaClGetNNaClEnv()
65 cc2_env.Append(CCFLAGS=gcc_flags)
66 # GCC's C++ EH support requires GCC's runtime, which we don't link with.
67 cc2_env.Append(CXXFLAGS=['-fno-exceptions'])
68 # This can generate references to runtime code we won't link with.
69 cc2_env.FilterOut(CCFLAGS=['-fasynchronous-unwind-tables'])
70 envlist.append(cc2_env)
72 envlist.append(cc2_env.Clone()) # For module2
73 envlist.append(cc1_env.Clone()) # For module3
74 link_env = cc1_env # To allow linking native objects (from ForceNative).
75 AddCommonFlags(envlist)
76 return (envlist, link_env)
79 if not env.Bit('bitcode'):
80 # For gcc, only do a self-consistency test.
81 if env.Bit('target_x86'):
82 # Assume for nacl-gcc the bots have at least SSE2.
83 extra_flags = ['-msse2']
86 envlist, link_env = MakeSelfTestEnv(env, extra_flags)
87 test_configurations.append((envlist, link_env, ''))
89 # For clang, do a self-consistency + a cross toolchain check.
90 envlist, link_env = MakeSelfTestEnv(env, [])
91 test_configurations.append((envlist, link_env, '_self'))
92 if env.Bit('target_arm'):
93 envlist, link_env = MakeCrossEnvs(
96 clang_flags=['--target=armv7a-unknown-nacl-gnueabi','-mfloat-abi=hard'])
97 test_configurations.append((envlist, link_env, ''))
98 elif env.Bit('target_x86_32'):
99 envlist, link_env = MakeCrossEnvs(
101 gcc_flags=['-msse2'],
102 clang_flags=['--target=i686-unknown-nacl'])
103 test_configurations.append((envlist, link_env, ''))
104 elif env.Bit('target_x86_64'):
105 envlist, link_env = MakeCrossEnvs(
107 gcc_flags=['-msse2'],
108 clang_flags=['--target=x86_64-unknown-nacl'])
109 test_configurations.append((envlist, link_env, ''))
111 raise SCons.Errors.UserError("Unknown target architecture!")
114 ######################################################################
116 for test_source in ['return_structs.cc',
118 test_name = test_source.split('.')[0]
119 for (envlist, link_env, test_suffix) in test_configurations:
121 test_full_name = test_name + test_suffix
122 for (i, e) in enumerate(envlist):
123 obj = e.ComponentObject(test_full_name + '.' + str(i),
126 prog = link_env.ComponentProgram(test_full_name,
128 EXTRA_LIBS=['${NONIRT_LIBS}'])
129 node = env.CommandSelLdrTestNacl(test_full_name + '.out',
131 env.AddNodeToTestSuite(node, ['small_tests', 'toolchain_tests',
133 'run_' + test_full_name + '_test')