Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / native_client / tests / dynamic_code_loading / 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('env')
7
8 # Do not run these tests with pexes, assuming they are portable.
9 if env.Bit('bitcode') and env.Bit('pnacl_generate_pexe'):
10   Return()
11
12 # The test works with PNaCl-ARM but not with PNaCl-x86, because the
13 # assembler #defines __arm__ rather than __i386__ or __x86_64__ even
14 # when we are targetting x86.
15 # http://code.google.com/p/nativeclient/issues/detail?id=2368
16 # TODO(dschuff): re-enable this test in a sensible way after we fully switch
17 # to the new layout, or remove all the pnacl-specific stuff here.
18 if env.Bit('bitcode'):
19   Return()
20
21 # These tests assume they can allocate address ranges from the dynamic
22 # code area themselves.  However, this does not work when ld.so
23 # assumes it can do the same.
24 # TODO(mseaborn): To fix this, ld.so will need an interface, like
25 # mmap() or brk(), for reserving space in the dynamic code area.
26 # See http://code.google.com/p/nativeclient/issues/detail?id=1112
27 is_broken = not env.Bit('nacl_static_link')
28
29 # there is fair amount of assembly code in these tests
30 asm_env = env.Clone()
31 if env.Bit('bitcode'):
32   asm_env.PNaClForceNative()
33   asm_env.AddBiasForPNaCl()
34 if env.Bit('bitcode'):
35   # NOTE: we cannot use PNaClForceNative here as we want the
36   #       the .c files to actually go to bc files - but this is not
37   #       completely understood.
38   env.AddBiasForPNaCl()
39   env.Append(LINKFLAGS=['--pnacl-allow-native'])
40
41 # When using the IRT, this value must be at least IRT_DATA_REGION_START.
42 # Otherwise, it can be smaller.
43 code_segment_end = '${IRT_DATA_REGION_START}'
44 # This leaves a gap between the code and data segments.  When using
45 # dynamic linking, the dynamic linker is responsible for reserving
46 # this space rather than the executable.
47 if env.Bit('nacl_static_link'):
48   env.Append(LINKFLAGS='-Wl,-Trodata-segment=' + code_segment_end)
49 env.Append(CPPDEFINES=[['DYNAMIC_CODE_SEGMENT_END', code_segment_end]])
50
51 def GetTemplate(env):
52   if env.Bit('target_arm'):
53     return 'templates_arm.S'
54   else:
55     return 'templates_x86.S'
56
57 template_obj = asm_env.ComponentObject(GetTemplate(env))
58
59 dynamic_load_test_nexe = env.ComponentProgram(
60     env.ProgramNameForNmf('dynamic_load_test'),
61     ['dynamic_load_test.c',
62      'dynamic_load_test_threaded.c',
63      'dynamic_delete_test_threaded.c',
64      template_obj],
65     EXTRA_LIBS=['${NONIRT_LIBS}', '${DYNCODE_LIBS}',
66                 '${PTHREAD_LIBS}', '${TESTRUNNER_LIBS}'])
67
68 dynamic_modify_test_nexe = env.ComponentProgram(
69     env.ProgramNameForNmf('dynamic_modify_test'),
70     ['dynamic_modify_test.c', template_obj],
71     EXTRA_LIBS=['${NONIRT_LIBS}', '${DYNCODE_LIBS}', '${TESTRUNNER_LIBS}'])
72
73 write_to_dyncode_nexe = env.ComponentProgram(
74     'write_to_dyncode',
75     ['write_to_dyncode.c'],
76     EXTRA_LIBS=['${NONIRT_LIBS}', '${DYNCODE_LIBS}'])
77
78 dyncode_disabled_test_nexe = env.ComponentProgram(
79     'dyncode_disabled_test',
80     ['dyncode_disabled_test.c'],
81     EXTRA_LIBS=['${DYNCODE_LIBS}', '${NONIRT_LIBS}'])
82
83 dyncode_syscall_disabled_test_nexe = env.ComponentProgram(
84     env.ProgramNameForNmf('dyncode_syscall_disabled_test'),
85     ['dyncode_syscall_disabled.c', template_obj],
86     EXTRA_LIBS=['${NONIRT_LIBS}', '${DYNCODE_LIBS}', '${TESTRUNNER_LIBS}'])
87
88 debug_mode_test_nexe = env.ComponentProgram('debug_mode_test',
89                                             ['debug_mode_test.c',
90                                              template_obj],
91                                             EXTRA_LIBS=['${DYNCODE_LIBS}',
92                                                         '${NONIRT_LIBS}'])
93
94 dyncode_demand_alloc_test_nexe = env.ComponentProgram(
95     'dyncode_demand_alloc_test',
96     ['dyncode_demand_alloc_test.c'],
97     EXTRA_LIBS=['${DYNCODE_LIBS}', '${NONIRT_LIBS}'])
98
99 test_suites = ['small_tests', 'sel_ldr_tests', 'dynamic_load_tests',
100                'nonpexe_tests']
101
102 sel_ldr_flags = ['-E', 'OUTSIDE_BROWSER=1']
103 if env.Bit('target_arm') and env.UsingEmulator():
104   sel_ldr_flags.extend(['-E', 'UNDER_QEMU_ARM=1'])
105 if env.IsRunningUnderValgrind():
106   sel_ldr_flags.extend(['-E', 'RUNNING_ON_VALGRIND=1'])
107
108 node = env.CommandSelLdrTestNacl('dynamic_load_test.out',
109                                  dynamic_load_test_nexe,
110                                  sel_ldr_flags=sel_ldr_flags)
111 env.AddNodeToTestSuite(node, test_suites, 'run_dynamic_load_test',
112                        is_broken=is_broken or
113 # This test is flaky on mac10.7-newlib-dbg-asan.
114 # See https://code.google.com/p/nativeclient/issues/detail?id=3906
115                                  (env.Bit('asan') and env.Bit('host_mac')) or
116 # This test is flaky on nacl-clang:
117 # See https://code.google.com/p/nativeclient/issues/detail?id=3980
118                                  (env.Bit('nacl_clang') and
119                                   env.Bit('target_x86_32')))
120
121 node = env.CommandSelLdrTestNacl(
122     'write_to_dyncode_before_alloc.out',
123     write_to_dyncode_nexe,
124     ['0'], # alloc_dest_first argument
125     exit_status='untrusted_segfault',
126     stdout_golden=env.File('write_to_dyncode.stdout'))
127 env.AddNodeToTestSuite(node, test_suites,
128                        'run_write_to_dyncode_before_alloc_test',
129                        is_broken=is_broken)
130
131 node = env.CommandSelLdrTestNacl(
132     'write_to_dyncode_after_alloc.out',
133     write_to_dyncode_nexe,
134     ['1'], # alloc_dest_first argument
135     exit_status='untrusted_segfault',
136     stdout_golden=env.File('write_to_dyncode.stdout'))
137 env.AddNodeToTestSuite(node, test_suites,
138                        'run_write_to_dyncode_after_alloc_test',
139                        is_broken=is_broken)
140
141 node = env.CommandSelLdrTestNacl(
142     'debug_mode_test.out',
143     debug_mode_test_nexe,
144     # NOTE: the data we are loading does not pass the validator
145     sel_ldr_flags=["-c"])
146 env.AddNodeToTestSuite(node, test_suites, 'run_dyncode_debug_mode_test',
147                        is_broken=is_broken)
148
149 # This tests, from untrusted code, that dyncode pages are inaccessible
150 # before they are allocated.
151 node = env.CommandSelLdrTestNacl(
152     'dyncode_demand_alloc_test.out',
153     dyncode_demand_alloc_test_nexe, declares_exit_status=True)
154 env.AddNodeToTestSuite(node, test_suites, 'run_dyncode_demand_alloc_test',
155                        is_broken=is_broken)
156
157 # The IRT itself counts as dynamic code loading, so we cannot disable
158 # dynamic loading when using the IRT.
159 if not env.Bit('tests_use_irt'):
160   node = env.CommandSelLdrTestNacl(
161       'dyncode_disabled_test.out',
162       dyncode_disabled_test_nexe,
163       osenv='NACL_DISABLE_DYNAMIC_LOADING=1')
164   env.AddNodeToTestSuite(node, test_suites, 'run_dyncode_disabled_test',
165                          is_broken=is_broken)
166
167 node = env.CommandSelLdrTestNacl(
168     'dyncode_syscall_disabled_test.out',
169     dyncode_syscall_disabled_test_nexe,
170     osenv='NACL_DISABLE_DYNCODE_SYSCALLS=1')
171 env.AddNodeToTestSuite(node, test_suites, 'run_dyncode_syscall_disabled_test',
172                        is_broken=is_broken)
173
174 node = env.CommandSelLdrTestNacl('dynamic_modify_test.out',
175                                  dynamic_modify_test_nexe,
176                                  sel_ldr_flags=['-E', 'OUTSIDE_BROWSER=1'])
177 # This test fails under Valgrind presumably because Valgrind cannot
178 # handle dynamic code modifications that occur via our doubly-mapped
179 # shared memory segment.  It does not know to flush its code
180 # translation cache.
181 env.AddNodeToTestSuite(node, test_suites, 'run_dynamic_modify_test',
182                        is_broken=is_broken or env.IsRunningUnderValgrind())