-
Notifications
You must be signed in to change notification settings - Fork 7
/
SConstruct
executable file
·3860 lines (3256 loc) · 144 KB
/
SConstruct
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! -*- python -*-
# Copyright (c) 2012 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import atexit
import json
import os
import platform
import re
import subprocess
import sys
import zlib
sys.path.append("./common")
sys.path.append('../third_party')
from SCons.Errors import UserError
from SCons.Script import GetBuildFailures
import SCons.Warnings
import SCons.Util
SCons.Warnings.warningAsException()
sys.path.append("tools")
import command_tester
import test_lib
import pynacl.platform
# turning garbage collection off reduces startup time by 10%
import gc
gc.disable()
# REPORT
CMD_COUNTER = {}
ENV_COUNTER = {}
def PrintFinalReport():
"""This function is run just before scons exits and dumps various reports.
"""
# Note, these global declarations are not strictly necessary
global pre_base_env
global CMD_COUNTER
global ENV_COUNTER
if pre_base_env.Bit('target_stats'):
print
print '*' * 70
print 'COMMAND EXECUTION REPORT'
print '*' * 70
for k in sorted(CMD_COUNTER.keys()):
print "%4d %s" % (CMD_COUNTER[k], k)
print
print '*' * 70
print 'ENVIRONMENT USAGE REPORT'
print '*' * 70
for k in sorted(ENV_COUNTER.keys()):
print "%4d %s" % (ENV_COUNTER[k], k)
failures = []
for failure in GetBuildFailures():
for node in Flatten(failure.node):
failures.append({
# If this wasn't a test, "GetTestName" will return raw_name.
'test_name': GetTestName(node),
'raw_name': str(node.path),
'errstr': failure.errstr
})
json_path = ARGUMENTS.get('json_build_results_output_file')
if json_path:
with open(json_path, 'w') as f:
json.dump(failures, f, sort_keys=True, indent=2)
if not failures:
return
print
print '*' * 70
print 'ERROR REPORT: %d failures' % len(failures)
print '*' * 70
print
for failure in failures:
test_name = failure['test_name']
if test_name != failure['raw_name']:
test_name = '%s (%s)' % (test_name, failure['raw_name'])
print "%s failed: %s\n" % (test_name, failure['errstr'])
def VerboseConfigInfo(env):
"Should we print verbose config information useful for bug reports"
if '--help' in sys.argv: return False
if env.Bit('prebuilt') or env.Bit('built_elsewhere'): return False
return env.Bit('sysinfo')
# SANITY CHECKS
# NOTE BitFromArgument(...) implicitly defines additional ACCEPTABLE_ARGUMENTS.
ACCEPTABLE_ARGUMENTS = set([
# TODO: add comments what these mean
# TODO: check which ones are obsolete
#### ASCII SORTED ####
# Use a destination directory other than the default "scons-out".
'DESTINATION_ROOT',
'MODE',
'SILENT',
# Limit bandwidth of browser tester
'browser_tester_bw',
# Location to download Chromium binaries to and/or read them from.
'chrome_binaries_dir',
# used for chrome_browser_tests: path to the browser
'chrome_browser_path',
# A comma-separated list of test names to disable by excluding the
# tests from a test suite. For example, 'small_tests
# disable_tests=run_hello_world_test' will run small_tests without
# including hello_world_test. Note that if a test listed here
# does not exist you will not get an error or a warning.
'disable_tests',
# used for chrome_browser_tests: path to a pre-built browser plugin.
'force_ppapi_plugin',
# force emulator use by tests
'force_emulator',
# force sel_ldr use by tests
'force_sel_ldr',
# force nacl_helper_bootstrap used by tests
'force_bootstrap',
# force irt image used by tests
'force_irt',
# generate_ninja=FILE enables a Ninja backend for SCons. This writes a
# .ninja build file to FILE describing all of SCons' build targets.
'generate_ninja',
# Path to a JSON file for machine-readable output.
'json_build_results_output_file',
# Replacement memcheck command for overriding the DEPS-in memcheck
# script. May have commas to separate separate shell args. There
# is no quoting, so this implies that this mechanism will fail if
# the args actually need to have commas. See
# http://code.google.com/p/nativeclient/issues/detail?id=3158 for
# the discussion of why this argument is needed.
'memcheck_command',
# If the replacement memcheck command only works for trusted code,
# set memcheck_trusted_only to non-zero.
'memcheck_trusted_only',
# When building with MSan, this can be set to values 0 (fastest, least
# useful reports) through 2 (slowest, most useful reports). Default is 1.
'msan_track_origins',
# colon-separated list of linker flags, e.g. "-lfoo:-Wl,-u,bar".
'nacl_linkflags',
# prefix to add in-front of perf tracking trace labels.
'perf_prefix',
# colon-separated list of pnacl bcld flags, e.g. "-lfoo:-Wl,-u,bar".
# Not using nacl_linkflags since that gets clobbered in some tests.
'pnacl_bcldflags',
'platform',
# Run tests under this tool (e.g. valgrind, tsan, strace, etc).
# If the tool has options, pass them after comma: 'tool,--opt1,--opt2'.
# NB: no way to use tools the names or the args of
# which contains a comma.
'run_under',
# More args for the tool.
'run_under_extra_args',
# Multiply timeout values by this number.
'scale_timeout',
# test_wrapper specifies a wrapper program such as
# tools/run_test_via_ssh.py, which runs tests on a remote host
# using rsync and SSH. Example usage:
# ./scons run_hello_world_test platform=arm force_emulator= \
# test_wrapper="./tools/run_test_via_ssh.py --host=armbox --subdir=tmp"
'test_wrapper',
# Replacement tsan command for overriding the DEPS-in tsan
# script. May have commas to separate separate shell args. There
# is no quoting, so this implies that this mechanism will fail if
# the args actually need to have commas. See
# http://code.google.com/p/nativeclient/issues/detail?id=3158 for
# the discussion of why this argument is needed.
'tsan_command',
# Run browser tests under this tool. See
# tools/browser_tester/browsertester/browserlauncher.py for tool names.
'browser_test_tool',
# Where to install header files for public consumption.
'includedir',
# Where to install libraries for public consumption.
'libdir',
# Where to install trusted-code binaries for public (SDK) consumption.
'bindir',
# Where a Breakpad build output directory is for optional Breakpad testing.
'breakpad_tools_dir',
# Allows overriding of the nacl newlib toolchain directory.
'nacl_newlib_dir',
# Allows override of the nacl glibc toolchain directory.
'nacl_glibc_dir',
# Allows override of the pnacl newlib toolchain directory.
'pnacl_newlib_dir',
# Allows overriding the version number in the toolchain's
# FEATURE_VERSION file. This is used for PNaCl ABI compatibility
# testing.
'toolchain_feature_version',
])
# Overly general to provide compatibility with existing build bots, etc.
# In the future it might be worth restricting the values that are accepted.
_TRUE_STRINGS = set(['1', 'true', 'yes'])
_FALSE_STRINGS = set(['0', 'false', 'no'])
# Converts a string representing a Boolean value, of some sort, into an actual
# Boolean value. Python's built in type coercion does not work because
# bool('False') == True
def StringValueToBoolean(value):
# ExpandArguments may stick non-string values in ARGUMENTS. Be accommodating.
if isinstance(value, bool):
return value
if not isinstance(value, basestring):
raise Exception("Expecting a string but got a %s" % repr(type(value)))
if value.lower() in _TRUE_STRINGS:
return True
elif value.lower() in _FALSE_STRINGS:
return False
else:
raise Exception("Cannot convert '%s' to a Boolean value" % value)
def GetBinaryArgumentValue(arg_name, default):
if not isinstance(default, bool):
raise Exception("Default value for '%s' must be a Boolean" % arg_name)
if arg_name not in ARGUMENTS:
return default
return StringValueToBoolean(ARGUMENTS[arg_name])
# name is the name of the bit
# arg_name is the name of the command-line argument, if it differs from the bit
def BitFromArgument(env, name, default, desc, arg_name=None):
# In most cases the bit name matches the argument name
if arg_name is None:
arg_name = name
DeclareBit(name, desc)
assert arg_name not in ACCEPTABLE_ARGUMENTS, repr(arg_name)
ACCEPTABLE_ARGUMENTS.add(arg_name)
if GetBinaryArgumentValue(arg_name, default):
env.SetBits(name)
else:
env.ClearBits(name)
# SetUpArgumentBits declares binary command-line arguments and converts them to
# bits. For example, one of the existing declarations would result in the
# argument "bitcode=1" causing env.Bit('bitcode') to evaluate to true.
# NOTE Command-line arguments are a SCons-ism that is separate from
# command-line options. Options are prefixed by "-" or "--" whereas arguments
# are not. The function SetBitFromOption can be used for options.
# NOTE This function must be called before the bits are used
# NOTE This function must be called after all modifications of ARGUMENTS have
# been performed. See: ExpandArguments
def SetUpArgumentBits(env):
BitFromArgument(env, 'bitcode', default=False,
desc='We are building bitcode')
BitFromArgument(env, 'pnacl_native_clang_driver', default=False,
desc='Use the (experimental) native PNaCl Clang driver')
BitFromArgument(env, 'nacl_clang', default=(not env.Bit('bitcode') and
not env.Bit('nacl_glibc')),
desc='Use the native nacl-clang newlib compiler instead of nacl-gcc')
BitFromArgument(env, 'translate_fast', default=False,
desc='When using pnacl TC (bitcode=1) use accelerated translation step')
BitFromArgument(env, 'use_sz', default=False,
desc='When using pnacl TC (bitcode=1) use Subzero for fast translation')
BitFromArgument(env, 'built_elsewhere', default=False,
desc='The programs have already been built by another system')
BitFromArgument(env, 'skip_trusted_tests', default=False,
desc='Only run untrusted tests - useful for translator testing'
' (also skips tests of the IRT itself')
BitFromArgument(env, 'nacl_pic', default=False,
desc='generate position indepent code for (P)NaCl modules')
BitFromArgument(env, 'nacl_static_link', default=not env.Bit('nacl_glibc'),
desc='Whether to use static linking instead of dynamic linking '
'for building NaCl executables during tests. '
'For nacl-newlib, the default is 1 (static linking). '
'For nacl-glibc, the default is 0 (dynamic linking).')
BitFromArgument(env, 'nacl_disable_shared', default=not env.Bit('nacl_glibc'),
desc='Do not build shared versions of libraries. '
'For nacl-newlib, the default is 1 (static libraries only). '
'For nacl-glibc, the default is 0 (both static and shared libraries).')
# Defaults on when --verbose is specified.
# --verbose sets 'brief_comstr' to False, so this looks a little strange
BitFromArgument(env, 'target_stats', default=not GetOption('brief_comstr'),
desc='Collect and display information about which commands are executed '
'during the build process')
BitFromArgument(env, 'werror', default=True,
desc='Treat warnings as errors (-Werror)')
BitFromArgument(env, 'disable_nosys_linker_warnings', default=False,
desc='Disable warning mechanism in src/untrusted/nosys/warning.h')
BitFromArgument(env, 'naclsdk_validate', default=True,
desc='Verify the presence of the SDK')
# TODO(mseaborn): Remove this, since this is always False -- Valgrind is
# no longer supported. This will require removing some Chromium-side
# references.
BitFromArgument(env, 'running_on_valgrind', default=False,
desc='Compile and test using valgrind')
BitFromArgument(env, 'pp', default=False,
desc='Enable pretty printing')
# Defaults on when --verbose is specified
# --verbose sets 'brief_comstr' to False, so this looks a little strange
BitFromArgument(env, 'sysinfo', default=not GetOption('brief_comstr'),
desc='Print verbose system information')
BitFromArgument(env, 'disable_flaky_tests', default=False,
desc='Do not run potentially flaky tests - used on Chrome bots')
BitFromArgument(env, 'use_sandboxed_translator', default=False,
desc='use pnacl sandboxed translator for linking (not available for arm)')
BitFromArgument(env, 'pnacl_generate_pexe', default=env.Bit('bitcode'),
desc='use pnacl to generate pexes and translate in a separate step')
BitFromArgument(env, 'translate_in_build_step', default=True,
desc='Run translation during build phase (e.g. if do_not_run_tests=1)')
BitFromArgument(env, 'pnacl_unsandboxed', default=False,
desc='Translate pexe to an unsandboxed, host executable')
BitFromArgument(env, 'nonsfi_nacl', default=False,
desc='Use Non-SFI Mode instead of the original SFI Mode. This uses '
'nonsfi_loader instead of sel_ldr, and it tells the PNaCl toolchain '
'to translate pexes to Non-SFI nexes.')
BitFromArgument(env, 'use_newlib_nonsfi_loader', default=True,
desc='Test nonsfi_loader linked against NaCl newlib instead of the one '
'linked against host libc. This flag makes sense only with '
'nonsfi_nacl=1.')
BitFromArgument(env, 'browser_headless', default=False,
desc='Where possible, set up a dummy display to run the browser on '
'when running browser tests. On Linux, this runs the browser through '
'xvfb-run. This Scons does not need to be run with an X11 display '
'and we do not open a browser window on the user\'s desktop. '
'Unfortunately there is no equivalent on Mac OS X.')
BitFromArgument(env, 'disable_crash_dialog', default=True,
desc='Disable Windows\' crash dialog box, which Windows pops up when a '
'process exits with an unhandled fault. Windows enables this by '
'default for processes launched from the command line or from the '
'GUI. Our default is to disable it, because the dialog turns crashes '
'into hangs on Buildbot, and our test suite includes various crash '
'tests.')
BitFromArgument(env, 'do_not_run_tests', default=False,
desc='Prevents tests from running. This lets SCons build the files needed '
'to run the specified test(s) without actually running them. This '
'argument is a counterpart to built_elsewhere.')
BitFromArgument(env, 'no_gdb_tests', default=False,
desc='Prevents GDB tests from running. If GDB is not available, you can '
'test everything else by specifying this flag.')
# TODO(shcherbina): add support for other golden-based tests, not only
# run_x86_*_validator_testdata_tests.
BitFromArgument(env, 'regenerate_golden', default=False,
desc='When running golden-based tests, instead of comparing results '
'save actual output as golden data.')
BitFromArgument(env, 'x86_64_zero_based_sandbox', default=False,
desc='Use the zero-address-based x86-64 sandbox model instead of '
'the r15-based model.')
BitFromArgument(env, 'android', default=False,
desc='Build for Android target')
BitFromArgument(env, 'skip_nonstable_bitcode', default=False,
desc='Skip tests involving non-stable bitcode')
#########################################################################
# EXPERIMENTAL
# This is for generating a testing library for use within private test
# enuminsts, where we want to compare and test different validators.
#
BitFromArgument(env, 'ncval_testing', default=False,
desc='EXPERIMENTAL: Compile validator code for testing within enuminsts')
# PNaCl sanity checks
if not env.Bit('bitcode'):
pnacl_only_flags = ('nonsfi_nacl',
'pnacl_generate_pexe',
'pnacl_unsandboxed',
'skip_nonstable_bitcode',
'translate_fast',
'use_sz',
'use_sandboxed_translator')
for flag_name in pnacl_only_flags:
if env.Bit(flag_name):
raise UserError('The option %r only makes sense when using the '
'PNaCl toolchain (i.e. with bitcode=1)'
% flag_name)
else:
pnacl_incompatible_flags = ('nacl_clang',
'nacl_glibc')
for flag_name in pnacl_incompatible_flags:
if env.Bit(flag_name):
raise UserError('The option %r cannot be used when building with '
'PNaCl (i.e. with bitcode=1)' % flag_name)
def CheckArguments():
for key in ARGUMENTS:
if key not in ACCEPTABLE_ARGUMENTS:
raise UserError('bad argument: %s' % key)
def GetTargetPlatform():
return pynacl.platform.GetArch3264(ARGUMENTS.get('platform', 'x86-32'))
def GetBuildPlatform():
return pynacl.platform.GetArch3264()
environment_list = []
# Base environment for both nacl and non-nacl variants.
kwargs = {}
if ARGUMENTS.get('DESTINATION_ROOT') is not None:
kwargs['DESTINATION_ROOT'] = ARGUMENTS.get('DESTINATION_ROOT')
pre_base_env = Environment(
# Use the environment that scons was run in to run scons invoked commands.
# This allows in things like externally provided PATH, PYTHONPATH.
ENV = os.environ.copy(),
tools = ['component_setup'],
# SOURCE_ROOT is one leave above the native_client directory.
SOURCE_ROOT = Dir('#/..').abspath,
# Publish dlls as final products (to staging).
COMPONENT_LIBRARY_PUBLISH = True,
# Use workaround in special scons version.
LIBS_STRICT = True,
LIBS_DO_SUBST = True,
# Select where to find coverage tools.
COVERAGE_MCOV = '../third_party/lcov/bin/mcov',
COVERAGE_GENHTML = '../third_party/lcov/bin/genhtml',
**kwargs
)
if 'generate_ninja' in ARGUMENTS:
import pynacl.scons_to_ninja
pynacl.scons_to_ninja.GenerateNinjaFile(
pre_base_env, dest_file=ARGUMENTS['generate_ninja'])
breakpad_tools_dir = ARGUMENTS.get('breakpad_tools_dir')
if breakpad_tools_dir is not None:
pre_base_env['BREAKPAD_TOOLS_DIR'] = pre_base_env.Dir(
os.path.abspath(breakpad_tools_dir))
# CLANG
DeclareBit('clang', 'Use clang to build trusted code')
pre_base_env.SetBitFromOption('clang', False)
DeclareBit('asan',
'Use AddressSanitizer to build trusted code (implies --clang)')
pre_base_env.SetBitFromOption('asan', False)
if pre_base_env.Bit('asan'):
pre_base_env.SetBits('clang')
DeclareBit('msan',
'Use MemorySanitizer to build trusted code (implies --clang)')
pre_base_env.SetBitFromOption('msan', False)
if pre_base_env.Bit('msan'):
pre_base_env.SetBits('clang')
# CODE COVERAGE
DeclareBit('coverage_enabled', 'The build should be instrumented to generate'
'coverage information')
# If the environment variable BUILDBOT_BUILDERNAME is set, we can determine
# if we are running in a VM by the lack of a '-bare-' (aka bare metal) in the
# bot name. Otherwise if the builder name is not set, then assume real HW.
DeclareBit('running_on_vm', 'Returns true when environment is running in a VM')
builder = os.environ.get('BUILDBOT_BUILDERNAME')
if builder and builder.find('-bare-') == -1:
pre_base_env.SetBits('running_on_vm')
else:
pre_base_env.ClearBits('running_on_vm')
DeclareBit('nacl_glibc', 'Use nacl-glibc for building untrusted code')
pre_base_env.SetBitFromOption('nacl_glibc', False)
# This function should be called ASAP after the environment is created, but
# after ExpandArguments.
SetUpArgumentBits(pre_base_env)
# Register PrintFinalReport only after SetUpArgumentBits since it references
# bits that get declared in SetUpArgumentBits
atexit.register(PrintFinalReport)
def DisableCrashDialog():
if sys.platform == 'win32':
import win32api
import win32con
# The double call is to preserve existing flags, as discussed at
# http://blogs.msdn.com/oldnewthing/archive/2004/07/27/198410.aspx
new_flags = win32con.SEM_NOGPFAULTERRORBOX
existing_flags = win32api.SetErrorMode(new_flags)
win32api.SetErrorMode(existing_flags | new_flags)
if pre_base_env.Bit('disable_crash_dialog'):
DisableCrashDialog()
# We want to pull CYGWIN setup in our environment or at least set flag
# nodosfilewarning. It does not do anything when CYGWIN is not involved
# so let's do it in all cases.
pre_base_env['ENV']['CYGWIN'] = os.environ.get('CYGWIN', 'nodosfilewarning')
# Note: QEMU_PREFIX_HOOK may influence test runs and sb translator invocations
pre_base_env['ENV']['QEMU_PREFIX_HOOK'] = os.environ.get('QEMU_PREFIX_HOOK', '')
# Allow the zero-based sandbox model to run insecurely.
# TODO(arbenson): remove this once binutils bug is fixed (see
# src/trusted/service_runtime/arch/x86_64/sel_addrspace_posix_x86_64.c)
if pre_base_env.Bit('x86_64_zero_based_sandbox'):
pre_base_env['ENV']['NACL_ENABLE_INSECURE_ZERO_BASED_SANDBOX'] = 1
if pre_base_env.Bit('werror'):
werror_flags = ['-Werror']
else:
werror_flags = []
# Allow variadic macros
werror_flags = werror_flags + ['-Wno-variadic-macros']
if pre_base_env.Bit('clang'):
# Allow 'default' label in switch even when all enumeration cases
# have been covered.
werror_flags += ['-Wno-covered-switch-default']
# Allow C++11 extensions (for "override")
werror_flags += ['-Wno-c++11-extensions']
# Method to make sure -pedantic, etc, are not stripped from the
# default env, since occasionally an engineer will be tempted down the
# dark -- but wide and well-trodden -- path of expediency and stray
# from the path of correctness.
def EnsureRequiredBuildWarnings(env):
if (env.Bit('linux') or env.Bit('mac')) and not env.Bit('android'):
required_env_flags = set(['-pedantic', '-Wall'] + werror_flags)
ccflags = set(env.get('CCFLAGS'))
if not required_env_flags.issubset(ccflags):
raise UserError('required build flags missing: '
+ ' '.join(required_env_flags.difference(ccflags)))
else:
# windows get a pass for now
pass
pre_base_env.AddMethod(EnsureRequiredBuildWarnings)
# Expose MakeTempDir and MakeTempFile to scons scripts
def MakeEmptyFile(env, **kwargs):
fd, path = test_lib.MakeTempFile(env, **kwargs)
os.close(fd)
return path
pre_base_env.AddMethod(test_lib.MakeTempDir)
pre_base_env.AddMethod(MakeEmptyFile)
# Method to add target suffix to name.
def NaClTargetArchSuffix(env, name):
return name + '_' + env['TARGET_FULLARCH'].replace('-', '_')
pre_base_env.AddMethod(NaClTargetArchSuffix)
# Generic Test Wrapper
# Add list of Flaky or Bad tests to skip per platform. A
# platform is defined as build type
# <BUILD_TYPE>-<SUBARCH>
bad_build_lists = {
'arm': [],
}
# This is a list of tests that do not yet pass when using nacl-glibc.
# TODO(mseaborn): Enable more of these tests!
nacl_glibc_skiplist = set([
# Struct layouts differ.
'run_abi_test',
# Syscall wrappers not implemented yet.
'run_sysbasic_test',
'run_sysbrk_test',
# Fails because clock() is not hooked up.
'run_timefuncs_test',
# Needs further investigation.
'sdk_minimal_test',
# This test fails with nacl-glibc: glibc reports an internal
# sanity check failure in free().
# TODO(robertm): This needs further investigation.
'run_ppapi_event_test',
'run_ppapi_geturl_valid_test',
'run_ppapi_geturl_invalid_test',
# http://code.google.com/p/chromium/issues/detail?id=108131
# we would need to list all of the glibc components as
# web accessible resources in the extensions's manifest.json,
# not just the nexe and nmf file.
'run_ppapi_extension_mime_handler_browser_test',
])
nacl_glibc_skiplist.update(['%s_irt' % test for test in nacl_glibc_skiplist])
# Whitelist of tests to run for Non-SFI Mode. Note that typos here will
# not be caught automatically!
# TODO(mseaborn): Eventually we should run all of small_tests instead of
# this whitelist.
nonsfi_test_whitelist = set([
'run_arm_float_abi_test',
'run_clock_get_test',
'run_clone_test',
'run_directory_test',
'run_dup_test',
'run_example_irt_caller_test',
'run_exception_test',
'run_fcntl_test',
'run_file_descriptor_test',
'run_float_test',
'run_fork_test',
'run_getpid_test',
'run_hello_world_test',
'run_icache_test',
'run_irt_futex_test',
'run_malloc_realloc_calloc_free_test',
'run_mmap_test',
'run_nanosleep_test',
'run_nonsfi_syscall_test',
'run_prctl_test',
'run_printf_test',
'run_pwrite_test',
'run_random_test',
'run_rlimit_test',
'run_sigaction_test',
'run_signal_sigbus_test',
'run_signal_test',
'run_socket_test',
'run_stack_alignment_asm_test',
'run_stack_alignment_test',
'run_syscall_test',
'run_thread_test',
'run_user_async_signal_test',
])
# If a test is not in one of these suites, it will probally not be run on a
# regular basis. These are the suites that will be run by the try bot or that
# a large number of users may run by hand.
MAJOR_TEST_SUITES = set([
'small_tests',
'medium_tests',
'large_tests',
# Tests using the pepper plugin, only run with chrome
# TODO(ncbray): migrate pepper_browser_tests to chrome_browser_tests
'pepper_browser_tests',
# Lightweight browser tests
'chrome_browser_tests',
'huge_tests',
'memcheck_bot_tests',
'tsan_bot_tests',
# Special testing environment for testing comparing x86 validators.
'ncval_testing',
# Environment for validator difference testing
'validator_diff_tests',
# Subset of tests enabled for Non-SFI Mode.
'nonsfi_tests',
])
# These are the test suites we know exist, but aren't run on a regular basis.
# These test suites are essentially shortcuts that run a specific subset of the
# test cases.
ACCEPTABLE_TEST_SUITES = set([
'barebones_tests',
'dynamic_load_tests',
'eh_tests', # Tests for C++ exception handling
'exception_tests', # Tests for hardware exception handling
'exit_status_tests',
'gdb_tests',
'mmap_race_tests',
'nonpexe_tests',
'pnacl_abi_tests',
'sel_ldr_sled_tests',
'sel_ldr_tests',
'toolchain_tests',
'validator_modeling',
'validator_tests',
# Special testing of the decoder for the ARM validator.
'arm_decoder_tests',
])
# Under --mode=nacl_irt_test we build variants of numerous tests normally
# built under --mode=nacl. The test names and suite names for these
# variants are set (in IrtTestAddNodeToTestSuite, below) by appending _irt
# to the names used for the --mode=nacl version of the same tests.
MAJOR_TEST_SUITES |= set([name + '_irt'
for name in MAJOR_TEST_SUITES])
ACCEPTABLE_TEST_SUITES |= set([name + '_irt'
for name in ACCEPTABLE_TEST_SUITES])
# The major test suites are also acceptable names. Suite names are checked
# against this set in order to catch typos.
ACCEPTABLE_TEST_SUITES.update(MAJOR_TEST_SUITES)
def ValidateTestSuiteNames(suite_name, node_name):
if node_name is None:
node_name = '<unknown>'
# Prevent a silent failiure - strings are iterable!
if not isinstance(suite_name, (list, tuple)):
raise Exception("Test suites for %s should be specified as a list, "
"not as a %s: %s" % (node_name, type(suite_name).__name__,
repr(suite_name)))
if not suite_name:
raise Exception("No test suites are specified for %s. Set the 'broken' "
"parameter on AddNodeToTestSuite in the cases where there's a known "
"issue and you don't want the test to run" % (node_name,))
# Make sure each test is in at least one test suite we know will run
major_suites = set(suite_name).intersection(MAJOR_TEST_SUITES)
if not major_suites:
raise Exception("None of the test suites %s for %s are run on a "
"regular basis" % (repr(suite_name), node_name))
# Make sure a wierd test suite hasn't been inadvertantly specified
for s in suite_name:
if s not in ACCEPTABLE_TEST_SUITES:
raise Exception("\"%s\" is not a known test suite. Either this is "
"a typo for %s, or it should be added to ACCEPTABLE_TEST_SUITES in "
"SConstruct" % (s, node_name))
BROKEN_TEST_COUNT = 0
def GetPlatformString(env):
build = env['BUILD_TYPE']
# If we are testing 'NACL' we really need the trusted info
if build=='nacl' and 'TRUSTED_ENV' in env:
trusted_env = env['TRUSTED_ENV']
build = trusted_env['BUILD_TYPE']
subarch = trusted_env['BUILD_SUBARCH']
else:
subarch = env['BUILD_SUBARCH']
# Build the test platform string
return build + '-' + subarch
pre_base_env.AddMethod(GetPlatformString)
tests_to_disable_qemu = set([
# These tests do not work under QEMU but do work on ARM hardware.
#
# You should use the is_broken argument in preference to adding
# tests to this list.
#
# See: http://code.google.com/p/nativeclient/issues/detail?id=2437
# Note, for now these tests disable both the irt and non-irt variants
'run_egyptian_cotton_test',
'run_many_threads_sequential_test',
# subprocess needs to also have qemu prefix, which isn't supported
'run_subprocess_test',
'run_thread_suspension_test',
'run_dynamic_modify_test',
])
tests_to_disable = set()
if ARGUMENTS.get('disable_tests', '') != '':
tests_to_disable.update(ARGUMENTS['disable_tests'].split(','))
def ShouldSkipTest(env, node_name):
if (env.Bit('skip_trusted_tests')
and (env['NACL_BUILD_FAMILY'] == 'TRUSTED'
or env['NACL_BUILD_FAMILY'] == 'UNTRUSTED_IRT')):
return True
if env.Bit('do_not_run_tests'):
# This hack is used for pnacl testing where we might build tests
# without running them on one bot and then transfer and run them on another.
# The skip logic only takes the first bot into account e.g. qemu
# restrictions, while it really should be skipping based on the second
# bot. By simply disabling the skipping completely we work around this.
return False
# There are no known-to-fail tests any more, but this code is left
# in so that if/when we port to a new architecture or add a test
# that is known to fail on some platform(s), we can continue to have
# a central location to disable tests from running. NB: tests that
# don't *build* on some platforms need to be omitted in another way.
if node_name in tests_to_disable:
return True
if env.UsingEmulator():
if node_name in tests_to_disable_qemu:
return True
# For now also disable the irt variant
if node_name.endswith('_irt') and node_name[:-4] in tests_to_disable_qemu:
return True
# Retrieve list of tests to skip on this platform
skiplist = bad_build_lists.get(env.GetPlatformString(), [])
if node_name in skiplist:
return True
if env.Bit('nacl_glibc') and node_name in nacl_glibc_skiplist:
return True
return False
pre_base_env.AddMethod(ShouldSkipTest)
def AddImplicitTestSuites(suite_list, node_name):
if node_name in nonsfi_test_whitelist:
suite_list = suite_list + ['nonsfi_tests']
return suite_list
def AddNodeToTestSuite(env, node, suite_name, node_name, is_broken=False,
is_flaky=False):
global BROKEN_TEST_COUNT
# CommandTest can return an empty list when it silently discards a test
if not node:
return
assert node_name is not None
test_name_regex = r'run_.*_(unit)?test.*$'
assert re.match(test_name_regex, node_name), (
'test %r does not match "run_..._test" naming convention '
'(precise regex is %s)' % (node_name, test_name_regex))
suite_name = AddImplicitTestSuites(suite_name, node_name)
ValidateTestSuiteNames(suite_name, node_name)
AlwaysBuild(node)
if is_broken or is_flaky and env.Bit('disable_flaky_tests'):
# Only print if --verbose is specified
if not GetOption('brief_comstr'):
print '*** BROKEN ', node_name
BROKEN_TEST_COUNT += 1
env.Alias('broken_tests', node)
elif env.ShouldSkipTest(node_name):
print '*** SKIPPING ', env.GetPlatformString(), ':', node_name
env.Alias('broken_tests', node)
else:
env.Alias('all_tests', node)
for s in suite_name:
env.Alias(s, node)
if node_name:
env.ComponentTestOutput(node_name, node)
test_name = node_name
else:
# This is rather shady, but the tests need a name without dots so they match
# what gtest does.
# TODO(ncbray) node_name should not be optional.
test_name = os.path.basename(str(node[0].path))
if test_name.endswith('.out'):
test_name = test_name[:-4]
test_name = test_name.replace('.', '_')
SetTestName(node, test_name)
pre_base_env.AddMethod(AddNodeToTestSuite)
def TestBindsFixedTcpPort(env, node):
# This tells Scons that tests that bind a fixed TCP port should not
# run concurrently, because they would interfere with each other.
# These tests are typically tests for NaCl's GDB debug stub. The
# dummy filename used below is an arbitrary token that just has to
# match across the tests.
SideEffect(env.File('${SCONSTRUCT_DIR}/test_binds_fixed_tcp_port'), node)
pre_base_env.AddMethod(TestBindsFixedTcpPort)
# Convenient testing aliases
# NOTE: work around for scons non-determinism in the following two lines
Alias('sel_ldr_sled_tests', [])
Alias('small_tests', [])
Alias('medium_tests', [])
Alias('large_tests', [])
Alias('small_tests_irt', [])
Alias('medium_tests_irt', [])
Alias('large_tests_irt', [])
Alias('pepper_browser_tests', [])
Alias('chrome_browser_tests', [])
Alias('unit_tests', 'small_tests')
Alias('smoke_tests', ['small_tests', 'medium_tests'])
if pre_base_env.Bit('nacl_glibc'):
Alias('memcheck_bot_tests', ['small_tests'])
Alias('tsan_bot_tests', ['small_tests'])
else:
Alias('memcheck_bot_tests', ['small_tests', 'medium_tests', 'large_tests'])
Alias('tsan_bot_tests', [])
def Banner(text):
print '=' * 70
print text
print '=' * 70
pre_base_env.AddMethod(Banner)
# PLATFORM LOGIC
# Define the platforms, and use them to define the path for the
# scons-out directory (aka TARGET_ROOT)
#
# Various variables in the scons environment are related to this, e.g.
#
# BUILD_ARCH: (arm, mips, x86)
# BUILD_SUBARCH: (32, 64)
#
DeclareBit('build_x86_32', 'Building binaries for the x86-32 architecture',
exclusive_groups='build_arch')
DeclareBit('build_x86_64', 'Building binaries for the x86-64 architecture',
exclusive_groups='build_arch')
DeclareBit('build_mips32', 'Building binaries for the MIPS architecture',
exclusive_groups='build_arch')
DeclareBit('build_arm_arm', 'Building binaries for the ARM architecture',
exclusive_groups='build_arch')
# Shorthand for either the 32 or 64 bit version of x86.
DeclareBit('build_x86', 'Building binaries for the x86 architecture')
DeclareBit('build_arm', 'Building binaries for the arm architecture')
def MakeArchSpecificEnv(platform=None):
env = pre_base_env.Clone()
if platform is None:
platform = GetTargetPlatform()
arch = pynacl.platform.GetArch(platform)
if pynacl.platform.IsArch64Bit(platform):
subarch = '64'
else:
subarch = '32'
env.Replace(BUILD_FULLARCH=platform)
env.Replace(BUILD_ARCHITECTURE=arch)
env.Replace(BUILD_SUBARCH=subarch)
env.Replace(TARGET_FULLARCH=platform)
env.Replace(TARGET_ARCHITECTURE=arch)
env.Replace(TARGET_SUBARCH=subarch)
env.SetBits('build_%s' % platform.replace('-', '_'))
if env.Bit('build_x86_32') or env.Bit('build_x86_64'):
env.SetBits('build_x86')
if env.Bit('build_arm_arm'):
env.SetBits('build_arm')
env.Replace(BUILD_ISA_NAME=platform)
# Determine where the object files go
env.Replace(BUILD_TARGET_NAME=platform)
# This may be changed later; see target_variant_map, below.
env.Replace(TARGET_VARIANT='')
env.Replace(TARGET_ROOT=