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.
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
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'):
18 if 'TRUSTED_ENV' not in env:
21 # The fixed feature CPU mode is currently x86 specific
22 if env.Bit('target_arm'):
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()
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
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
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
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
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
66 if env.Bit('nacl_clang'):
67 expect_null_Z_status=1
69 expect_null_Z_status=0
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
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')
84 node = env.CommandSelLdrTestNacl(
85 'ff_null_Z.out', ff_null_nexe,
86 exit_status=expect_null_Z_status,
88 env.AddNodeToTestSuite(node, test_suites, 'run_ff_null_Z_test',
89 is_broken=is_validation_broken)
91 # The bitcode compiler doesn't support -mfpmath=387 or -mfpmath=sse
92 if not env.Bit('bitcode'):
94 sse_env.Append(CCFLAGS=['-mfpmath=sse', '-msse'])
95 sse_o = sse_env.ComponentObject('ff_hello_world_sse.o', 'ff_hello_world.c')
97 ff_hello_world_sse_nexe = sse_env.ComponentProgram(
99 'ff_hello_world_sse.o',
100 EXTRA_LIBS=['${NONIRT_LIBS}'])
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')
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)
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}'])
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')
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)