Upstream version 10.38.208.0
[platform/framework/web/crosswalk.git] / src / native_client / src / shared / platform / build.scons
1 # -*- python -*-
2 #
3 # Copyright (c) 2012 The Native Client Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7
8 import os
9 import platform
10
11 Import('env')
12
13 platform_inputs = []
14
15 # On OSX and Windows, we have observed sleep returning early.  The
16 # time_slop_args is used in nacl_clock_test to permit some extra slop
17 # in the elapsed time (in ms).
18 time_slop_args = []
19
20 # On Linux the older scheduler implementation did not account properly for
21 # the time process spent waiting on the futex in thread join. This affects
22 # the CLOCK_PROCESS/THREAD_CPUTIME_ID clock test and we therefore disable
23 # this test on older kernels.  In a coverage build, the test becomes
24 # unreasonably slow.  This test seems to crash sometimes under QEMU.
25 cputime_test_enabled = (not env.Bit('coverage_enabled') and
26                         not env.UsingEmulator())
27
28 if env.Bit('windows'):
29   platform_inputs += [
30     'win/aligned_malloc.c',
31     'win/condition_variable.cc',
32     'win/lock.cc',
33     'win/nacl_clock.c',
34     'win/nacl_error.c',
35     'win/nacl_exit.c',
36     'win/nacl_fast_mutex.c',
37     'win/nacl_find_addrsp.c',
38     'win/nacl_host_desc.c',
39     'win/nacl_host_dir.c',
40     'win/lock_impl_win.cc',
41     'win/nacl_secure_random.c',
42     'win/nacl_semaphore.c',
43     'win/nacl_sync_win.cc',
44     'win/nacl_threads.c',
45     'win/nacl_time.c',
46     'win/nacl_timestamp.c',
47     'win/port_win.c',
48     'win/time.cc',
49     'win/time_win.cc',
50     'win/xlate_system_error.c',
51   ]
52   time_slop_args += [ '-s', '10' ]
53   # Needed for rand_s().
54   env.Append(
55         CCFLAGS = ['/D_CRT_RAND_S',
56                    '/D_UNICODE',
57                    '/DUNICODE'],
58   )
59 elif env.Bit('linux'):
60   platform_inputs += [
61     'linux/nacl_clock.c',
62     'linux/nacl_host_dir.c',
63     'linux/nacl_semaphore.c',
64     ]
65   kernel_version = map(int, platform.release().split('.', 2)[:2])
66   if kernel_version < [3, 0]:
67     cputime_test_enabled = False
68 elif env.Bit('mac'):
69   platform_inputs += [
70     'osx/nacl_clock.c',
71     'osx/nacl_host_dir.c',
72     'osx/nacl_semaphore.c',
73     'osx/strnlen_osx.c',
74     ]
75   time_slop_args += [ '-s', '10' ]
76
77 if env.Bit('posix'):
78   platform_inputs += [
79     'posix/aligned_malloc.c',
80     'posix/condition_variable.c',
81     'posix/lock.c',
82     'posix/nacl_error.c',
83     'posix/nacl_exit.c',
84     'posix/nacl_fast_mutex.c',
85     'posix/nacl_file_lock.c',  # only used on Linux, but built/tested on Posix
86     'posix/nacl_find_addrsp.c',
87     'posix/nacl_host_desc.c',
88     'posix/nacl_secure_random.c',
89     'posix/nacl_thread_id.c',
90     'posix/nacl_threads.c',
91     'posix/nacl_time.c',
92     'posix/nacl_timestamp.c',
93     ]
94
95 platform_inputs += [
96     'nacl_check.c',
97     'nacl_global_secure_random.c',
98     'nacl_host_desc_common.c',
99     'nacl_interruptible_condvar.c',
100     'nacl_interruptible_mutex.c',
101     'nacl_log.c',
102     'nacl_secure_random_common.c',
103     'nacl_sync_checked.c',
104     'nacl_time_common.c',
105     'platform_init.c',
106     'refcount_base.cc',
107     ]
108
109 env.DualLibrary('platform', platform_inputs)
110
111
112 PORT_TEST_SOURCES = ['platform_tests.cc']
113
114 if env.Bit('windows'):
115   PORT_TEST_SOURCES = [PORT_TEST_SOURCES,
116                        'win/port_win_test.c']
117   if env.Bit('build_x86_64'):
118     PORT_TEST_SOURCES = [PORT_TEST_SOURCES,
119                          'win/test_tls.S']
120
121 port_test_exe = env.ComponentProgram('port_test',
122                                      PORT_TEST_SOURCES,
123                                      EXTRA_LIBS=['platform','gio'])
124
125 node = env.CommandTest('port_test.out',
126                        [port_test_exe])
127
128 env.AddNodeToTestSuite(node,
129                        ['small_tests'],
130                        'run_platform_tests')
131
132
133 nacl_semaphore_test_exe = env.ComponentProgram('nacl_semaphore_test',
134                                                ['nacl_semaphore_test.c'],
135                                                EXTRA_LIBS=['platform',
136                                                            'gio'])
137 node = env.CommandTest('nacl_semaphore_test.out',
138                        command=[nacl_semaphore_test_exe])
139
140 env.AddNodeToTestSuite(node, ['small_tests'], 'run_nacl_semaphore_test')
141
142
143 nacl_host_dir_test_exe = env.ComponentProgram('nacl_host_dir_test',
144                                               ['nacl_host_dir_test.c'],
145                                               EXTRA_LIBS=['platform',
146                                                           'gio',
147                                                           'nrd_xfer',
148                                                           ])
149
150 # For -d, env.Dir does not work.  bradnelson@ says SCons's underlay
151 # works for Files, but possibly not for Dir -- and apparently it does
152 # not, since the path that results is OBJ_DIR relative.
153
154 node = env.CommandTest('nacl_host_dir_test.out',
155                        [nacl_host_dir_test_exe,
156                         '-f',
157                         env.File('testdata/sample_dir1_expected.txt'),
158                         '-d',
159                         env.MakeTempDir(prefix='tmp_platform')])
160 env.AddNodeToTestSuite(node, ['small_tests'], 'run_nacl_host_dir_test')
161
162
163 nacl_clock_test_exe = env.ComponentProgram('nacl_clock_test',
164                                            ['nacl_clock_test.c'],
165                                            EXTRA_LIBS=['platform'])
166
167 node = env.CommandTest('nacl_clock_test.out',
168                        [nacl_clock_test_exe] + time_slop_args)
169
170 env.AddNodeToTestSuite(node, ['small_tests'], 'run_nacl_clock_test')
171
172 node = env.CommandTest('nacl_clock_cputime_test.out',
173                         [nacl_clock_test_exe, '-c'],
174                         size='large')
175
176 env.AddNodeToTestSuite(node, ['large_tests'], 'run_nacl_clock_cputime_test',
177                        is_broken=not cputime_test_enabled)
178
179
180 nacl_sync_test_exe = env.ComponentProgram('nacl_sync_test',
181                                           ['nacl_sync_test.c'],
182                                           EXTRA_LIBS=['platform'])
183
184 for flavor in ['lock_lock', 'lock_trylock',
185                'trylock_lock', 'trylock_trylock']:
186   name = 'nacl_sync_' + flavor + '_test'
187   node = env.CommandTest(name + '.out',
188                          [nacl_sync_test_exe, '-T', flavor])
189
190   env.AddNodeToTestSuite(node, ['small_tests'], 'run_' + name)
191
192 nacl_host_desc_mmap_test_exe = env.ComponentProgram(
193     'nacl_host_desc_mmap_test',
194     ['nacl_host_desc_mmap_test.c'],
195     EXTRA_LIBS=['platform',
196                 'nrd_xfer'])  # nrd_xfer for NaClDescEffectorTrustedMem
197
198
199 node = env.CommandTest('nacl_host_desc_mmap_test.out',
200                        [nacl_host_desc_mmap_test_exe, '-t',
201                         env.MakeTempDir(prefix='tmp_platform')])
202
203 env.AddNodeToTestSuite(node, ['small_tests'], 'run_nacl_host_desc_mmap_test',
204                        is_broken=env.UsingEmulator())
205
206 if env.Bit('windows'):
207   nacl_host_desc_mmap_win_test_exe = env.ComponentProgram(
208     'nacl_host_desc_mmap_win_test',
209     ['win/nacl_host_desc_mmap_win_test.c'],
210     EXTRA_LIBS=['platform',
211                 'nrd_xfer'])
212
213   node = env.CommandTest('nacl_host_desc_mmap_win_test.out',
214                          [nacl_host_desc_mmap_win_test_exe,
215                           '-t', env.MakeTempDir(prefix='tmp_platform')])
216
217   env.AddNodeToTestSuite(node, ['small_tests'],
218                          'run_nacl_host_desc_mmap_win_test')
219
220 nacl_host_desc_pread_pwrite_test_exe = env.ComponentProgram(
221   'nacl_host_desc_pread_pwrite_test',
222   ['nacl_host_desc_pread_pwrite_test.c'],
223   EXTRA_LIBS=['platform', 'nrd_xfer'])
224
225 node = env.CommandTest('nacl_host_desc_pread_pwrite_test.out',
226                        [nacl_host_desc_pread_pwrite_test_exe,
227                         '-t', env.MakeTempDir(prefix='tmp_platform')])
228
229 env.AddNodeToTestSuite(node, ['small_tests'],
230                        'run_nacl_host_desc_pread_pwrite_test')
231
232 nacl_host_desc_big_file_nexe = env.ComponentProgram(
233   'nacl_host_desc_big_file_test',
234   ['nacl_host_desc_big_file_test.c'],
235   EXTRA_LIBS=['platform', 'nrd_xfer'])
236
237 d = os.path.join(str(env.Dir('${TARGET_ROOT}')), 'large_temporary_files')
238 try:
239   os.makedirs(d)  # if scons-out is missing, MakeTempDir would fail
240 except:
241   pass  # but the directory may already exist.
242
243 if env.Bit('mac') or env.Bit('windows'):
244   # OSX's HFS has no support for sparse files, so we generate a lot of
245   # disk I/O and this is expensive.  On Windows, NTFS support sparse
246   # files, but ReFs does not.  (We don't run on VFAT, so we can ignore
247   # that case.)  Whether this is an expensive test depends on the
248   # filesystem type, so we err on the side of caution.
249   test_size = 'huge'
250 else:
251   # On Linux, sparse file support at the filesystem level means that
252   # the test is fast -- cost is proportional to actual number of bytes
253   # written.
254   test_size = 'small'
255
256 node = env.CommandTest(
257   'nacl_host_desc_big_file_test.out',
258   [nacl_host_desc_big_file_nexe, '-t',
259    env.MakeTempDir(prefix='tmp_platform', dir=d)],
260   size=test_size)
261
262 env.AddNodeToTestSuite(node,
263                        [test_size + '_tests'],
264                        'run_nacl_host_desc_big_file_test',
265                        is_broken=env.UsingEmulator())
266 # Qemu appears to not honor big file support and fails the lseek w/ EINVAL
267
268 env.EnsureRequiredBuildWarnings()