Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / native_client / tests / fixedfeaturecpu / 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 # Tests for Native Client fixed-feature CPU mode. The fixed-feature CPU
7 # mode requires SSE and disallows MMX and x87. By fixing the instruction set
8 # it allows exclusion of the CPUID instruction and use of a read-only text
9 # segment. See http://code.google.com/p/nativeclient/issues/detail?id=2684
10 Import('env')
11
12 # We cannot run these tests as pexes as they are not portable,
13 # they also do not work in non-pexe mode and are very limited in
14 # that case anyway, i.e. only run_ff_null_test, run_ff_null_Z_test are active
15 if env.Bit('bitcode'):
16   Return()
17
18 if 'TRUSTED_ENV' not in env:
19   Return()
20
21 # The fixed feature CPU mode is currently x86 specific
22 if env.Bit('target_arm'):
23   Return()
24
25 # For speed, SConstruct disables the validator (using '-cc') for
26 # Valgrind+nacl-glibc tests, which breaks one test below.
27 # Also valgrind misdetects CPU capabilities on some systems which gives
28 # different results for newlib on trybots and on buildbots.
29 # See http://code.google.com/p/nativeclient/issues/detail?id=3380
30 # TODO(bradchen): Consolidate into env.ValidationIsDisabled()
31 is_validation_broken = env.IsRunningUnderValgrind()
32
33 # The next sequence of conditionals captures the status test on various
34 # NaCl configurations. At this point many of the '-Z' configurations fail
35 # due to MMX or x87 instructions that are included in shared runtime
36 # components. The production fixed-function toolchain must remove these
37 # problems.
38 if env.Bit('tests_use_irt'):
39   if (env.Bit('target_x86_64') and
40       not env.Bit('nacl_glibc')):
41     # R-DFA ignores LM bit and assumes it's always enabled
42     expect_null_Z_status=0
43     expect_sse_Z_status=0
44   else:
45     # 32-bit irt newlib: requeres MMX(prefetchnta),CLFLUSH/FXSR(sfence)
46     # 64-bit irt newlib: requires LM(cltq),MMX(prefetchnta),CLFLUSH/FXSR(sfence)
47     expect_null_Z_status=1
48     expect_sse_Z_status=1
49   expect_x87_Z_status=1
50 elif env.Bit('nacl_glibc'):
51   if env.Bit('target_x86_32'):
52     # Validation fails with code 127 when dynamic linking
53     expect_null_Z_status=127
54     expect_sse_Z_status=127
55     expect_x87_Z_status=127
56   elif env.Bit('target_x86_64'):
57     # 64-bit glibc: fails, runnable-ld.so requires RDTSC, x87
58     expect_null_Z_status=1
59     expect_sse_Z_status=1
60     expect_x87_Z_status=1
61 else:
62   if env.Bit('target_x86_32'):
63     # 32-bit newlib: passes, except nacl-clang's ff_null_z for reasons which
64     # are unknown because ncval is broken and ncval_new doesn't support
65     # FF mode.
66     if env.Bit('nacl_clang'):
67       expect_null_Z_status=1
68     else:
69       expect_null_Z_status=0
70     expect_sse_Z_status=1
71     expect_x87_Z_status=1
72   elif env.Bit('target_x86_64'):
73     # R-DFA ignores LM bit and assumes it's always enabled
74     expect_null_Z_status=0
75     expect_sse_Z_status=0
76     expect_x87_Z_status=1
77
78 test_suites = ['small_tests', 'sel_ldr_tests', 'validator_tests']
79 ff_null_nexe = env.ComponentProgram('ff_null', 'ff_null.c',
80                                     EXTRA_LIBS=['${NONIRT_LIBS}'])
81 node = env.CommandSelLdrTestNacl('ff_null.out', ff_null_nexe)
82 env.AddNodeToTestSuite(node, test_suites, 'run_ff_null_test')
83
84 node = env.CommandSelLdrTestNacl(
85     'ff_null_Z.out', ff_null_nexe,
86     exit_status=expect_null_Z_status,
87     sel_ldr_flags=['-Z'])
88 env.AddNodeToTestSuite(node, test_suites, 'run_ff_null_Z_test',
89                        is_broken=is_validation_broken)
90
91 # The bitcode compiler doesn't support -mfpmath=387 or -mfpmath=sse
92 if not env.Bit('bitcode'):
93   sse_env = env.Clone()
94   sse_env.Append(CCFLAGS=['-mfpmath=sse', '-msse'])
95   sse_o = sse_env.ComponentObject('ff_hello_world_sse.o', 'ff_hello_world.c')
96
97   ff_hello_world_sse_nexe = sse_env.ComponentProgram(
98       'ff_hello_world_sse',
99       'ff_hello_world_sse.o',
100       EXTRA_LIBS=['${NONIRT_LIBS}'])
101
102   node = env.CommandSelLdrTestNacl(
103       'ff_hello_world_sse.out', ff_hello_world_sse_nexe,
104       stdout_golden=env.File('ff_hello_world.stdout'))
105   env.AddNodeToTestSuite(node, test_suites, 'run_ff_sse_test')
106
107   # ff_hello_world_sse should succeed in fixed function CPU mode
108   # It fails due to conditions noted above.
109   node = env.CommandSelLdrTestNacl(
110       'ff_hello_world_sse_Z.out', ff_hello_world_sse_nexe,
111       exit_status=expect_sse_Z_status,
112       sel_ldr_flags=['-Z'])
113   env.AddNodeToTestSuite(node, test_suites, 'run_ff_sse_Z_test',
114                          is_broken=is_validation_broken)
115
116 # NOTE: -mfpmath=387 does not work for x86-64. See:
117 # http://code.google.com/p/nativeclient/issues/detail?id=2692
118 if not env.Bit('target_x86_64') and not env.Bit('bitcode'):
119   x87_env = env.Clone()
120   x87_env.Append(CCFLAGS=['-mfpmath=387', '-mno-sse'])
121   x87_o = x87_env.ComponentObject('ff_hello_world_x87.o', 'ff_hello_world.c')
122   ff_hello_world_x87_nexe = x87_env.ComponentProgram(
123       'ff_hello_world_x87',
124       'ff_hello_world_x87.o',
125       EXTRA_LIBS=['${NONIRT_LIBS}'])
126
127   # ff_hello_world_x87 should pass in default mode
128   node = env.CommandSelLdrTestNacl(
129       'ff_hello_world_x87.out', ff_hello_world_x87_nexe,
130       stdout_golden=env.File('ff_hello_world.stdout'))
131   env.AddNodeToTestSuite(node, test_suites, 'run_ff_x87_test')
132
133   # ff_hello_world_x87 should fail in fixed function CPU mode
134   node = env.CommandSelLdrTestNacl(
135       'ff_hello_world_x87_Z.out', ff_hello_world_x87_nexe,
136       exit_status=expect_x87_Z_status,
137       sel_ldr_flags=['-Z'])
138   env.AddNodeToTestSuite(node, test_suites, 'run_ff_x87_Z_test',
139                          is_broken=is_validation_broken)