Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / native_client / tests / callingconv_case_by_case / 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 SCons.Errors
7
8 Import('env')
9
10 # This test does not make any sense for pure pnacl
11 if env.Bit('bitcode') and env.Bit('pnacl_generate_pexe'):
12   Return()
13
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'):
17   Return()
18
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'])
24
25 # Case-by-case calling Convention Test for PNaCl and nacl-gcc compatibility.
26
27 # We make 4 modules.
28 # CC1 emits MODULE0 and CC2 MODULE1, CC2 emits MODULE2 and CC1 MODULE3
29 # For the call test:
30 # MODULE0(cc1) -> MODULE0(cc1) -> MODULE1(cc2) -> MODULE2(cc2) -> MODULE3(cc1).
31 # For the return test, the dataflow is reversed.
32
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 = []
36
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'])
41
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)
50   link_env = base_env
51   return (envlist, link_env)
52
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.
56   """
57   envlist = []
58   # For module0
59   cc1_env = base_env.Clone()
60   cc1_env.PNaClForceNative()
61   cc1_env.Append(CCFLAGS=clang_flags)
62   envlist.append(cc1_env)
63   # For module1
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)
71
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)
77
78
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']
84   else:
85     extra_flags = []
86   envlist, link_env = MakeSelfTestEnv(env, extra_flags)
87   test_configurations.append((envlist, link_env, ''))
88 else:
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(
94         env,
95         gcc_flags=[],
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(
100         env,
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(
106         env,
107         gcc_flags=['-msse2'],
108         clang_flags=['--target=x86_64-unknown-nacl'])
109     test_configurations.append((envlist, link_env, ''))
110   else:
111     raise SCons.Errors.UserError("Unknown target architecture!")
112
113
114 ######################################################################
115
116 for test_source in ['return_structs.cc',
117                     'call_structs.cc']:
118   test_name = test_source.split('.')[0]
119   for (envlist, link_env, test_suffix) in test_configurations:
120     objfiles = []
121     test_full_name = test_name + test_suffix
122     for (i, e) in enumerate(envlist):
123       obj = e.ComponentObject(test_full_name + '.' + str(i),
124                               test_source)
125       objfiles.append(obj)
126     prog = link_env.ComponentProgram(test_full_name,
127                                      objfiles,
128                                      EXTRA_LIBS=['${NONIRT_LIBS}'])
129     node = env.CommandSelLdrTestNacl(test_full_name + '.out',
130                                      prog)
131     env.AddNodeToTestSuite(node, ['small_tests', 'toolchain_tests',
132                                   'nonpexe_tests'],
133                            'run_' + test_full_name + '_test')