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