66from __future__ import print_function
77from functools import reduce
88
9- from collections import OrderedDict
9+ from collections import OrderedDict , namedtuple
1010import json
1111import multiprocessing
1212import optparse
116116]
117117
118118
119- class ModeConfig (object ):
120- def __init__ (self , flags , timeout_scalefactor , status_mode , execution_mode ):
121- self .flags = flags
122- self .timeout_scalefactor = timeout_scalefactor
123- self .status_mode = status_mode
124- self .execution_mode = execution_mode
125-
119+ ModeConfig = namedtuple (
120+ 'ModeConfig' , 'label flags timeout_scalefactor status_mode' )
126121
127122DEBUG_FLAGS = ["--nohard-abort" , "--enable-slow-asserts" , "--verify-heap" ]
128123RELEASE_FLAGS = ["--nohard-abort" ]
129- MODES = {
130- "debug" : ModeConfig (
131- flags = DEBUG_FLAGS ,
132- timeout_scalefactor = 4 ,
133- status_mode = "debug" ,
134- execution_mode = "debug" ,
135- ),
136- "optdebug" : ModeConfig (
124+
125+ DEBUG_MODE = ModeConfig (
126+ label = 'debug' ,
137127 flags = DEBUG_FLAGS ,
138128 timeout_scalefactor = 4 ,
139129 status_mode = "debug" ,
140- execution_mode = "debug" ,
141- ),
142- "release" : ModeConfig (
130+ )
131+
132+ RELEASE_MODE = ModeConfig (
133+ label = 'release' ,
143134 flags = RELEASE_FLAGS ,
144135 timeout_scalefactor = 1 ,
145136 status_mode = "release" ,
146- execution_mode = "release" ,
147- ),
148- # Normal trybot release configuration. There, dchecks are always on which
149- # implies debug is set. Hence, the status file needs to assume debug-like
150- # behavior/timeouts.
151- "tryrelease" : ModeConfig (
137+ )
138+
139+ # Normal trybot release configuration. There, dchecks are always on which
140+ # implies debug is set. Hence, the status file needs to assume debug-like
141+ # behavior/timeouts.
142+ TRY_RELEASE_MODE = ModeConfig (
143+ label = 'release+dchecks' ,
152144 flags = RELEASE_FLAGS ,
153- timeout_scalefactor = 1 ,
154- status_mode = "debug" ,
155- execution_mode = "release" ,
156- ),
157- # This mode requires v8 to be compiled with dchecks and slow dchecks.
158- "slowrelease" : ModeConfig (
159- flags = RELEASE_FLAGS + ["--enable-slow-asserts" ],
160- timeout_scalefactor = 2 ,
145+ timeout_scalefactor = 4 ,
161146 status_mode = "debug" ,
162- execution_mode = "release" ,
163- ),
164- }
147+ )
165148
166149PROGRESS_INDICATORS = {
167150 'verbose' : progress .VerboseProgressIndicator ,
@@ -242,12 +225,29 @@ def __str__(self):
242225 return '\n ' .join (detected_options )
243226
244227
228+ def _do_load_build_config (outdir , verbose = False ):
229+ build_config_path = os .path .join (outdir , "v8_build_config.json" )
230+ if not os .path .exists (build_config_path ):
231+ if verbose :
232+ print ("Didn't find build config: %s" % build_config_path )
233+ raise TestRunnerError ()
234+
235+ with open (build_config_path ) as f :
236+ try :
237+ build_config_json = json .load (f )
238+ except Exception : # pragma: no cover
239+ print ("%s exists but contains invalid json. Is your build up-to-date?"
240+ % build_config_path )
241+ raise TestRunnerError ()
242+
243+ return BuildConfig (build_config_json )
244+
245+
245246class BaseTestRunner (object ):
246247 def __init__ (self , basedir = None ):
247248 self .basedir = basedir or BASE_DIR
248249 self .outdir = None
249250 self .build_config = None
250- self .mode_name = None
251251 self .mode_options = None
252252 self .target_os = None
253253
@@ -284,7 +284,7 @@ def execute(self, sys_args=None):
284284 tests = self ._load_testsuite_generators (args , options )
285285 self ._setup_env ()
286286 print (">>> Running tests for %s.%s" % (self .build_config .arch ,
287- self .mode_name ))
287+ self .mode_options . label ))
288288 exit_code = self ._do_execute (tests , args , options )
289289 if exit_code == utils .EXIT_CODE_FAILURES and options .json_test_results :
290290 print ("Force exit code 0 after failures. Json test results file "
@@ -318,9 +318,6 @@ def _add_parser_default_options(self, parser):
318318 default = "out" )
319319 parser .add_option ("--arch" ,
320320 help = "The architecture to run tests for" )
321- parser .add_option ("-m" , "--mode" ,
322- help = "The test mode in which to run (uppercase for builds"
323- " in CI): %s" % MODES .keys ())
324321 parser .add_option ("--shell-dir" , help = "DEPRECATED! Executables from build "
325322 "directory will be used" )
326323 parser .add_option ("--test-root" , help = "Root directory of the test suites" ,
@@ -402,17 +399,21 @@ def _add_parser_options(self, parser):
402399 def _parse_args (self , parser , sys_args ):
403400 options , args = parser .parse_args (sys_args )
404401
405- if any (map (lambda v : v and ',' in v ,
406- [options .arch , options .mode ])): # pragma: no cover
407- print ('Multiple arch/mode are deprecated' )
402+ if options .arch and ',' in options .arch : # pragma: no cover
403+ print ('Multiple architectures are deprecated' )
408404 raise TestRunnerError ()
409405
410406 return options , args
411407
412408 def _load_build_config (self , options ):
413409 for outdir in self ._possible_outdirs (options ):
414410 try :
415- self .build_config = self ._do_load_build_config (outdir , options .verbose )
411+ self .build_config = _do_load_build_config (outdir , options .verbose )
412+
413+ # In auto-detect mode the outdir is always where we found the build config.
414+ # This ensures that we'll also take the build products from there.
415+ self .outdir = outdir
416+ break
416417 except TestRunnerError :
417418 pass
418419
@@ -435,26 +436,21 @@ def _load_build_config(self, options):
435436 # Returns possible build paths in order:
436437 # gn
437438 # outdir
438- # outdir/arch.mode
439- # Each path is provided in two versions: <path> and <path>/mode for bots.
439+ # outdir on bots
440440 def _possible_outdirs (self , options ):
441441 def outdirs ():
442442 if options .gn :
443443 yield self ._get_gn_outdir ()
444444 return
445445
446446 yield options .outdir
447- if options . arch and options . mode :
448- yield os .path .join (options .outdir ,
449- '%s.%s' % (options .arch , options . mode ) )
447+
448+ if os .path .basename (options .outdir ) != 'build' :
449+ yield os . path . join (options .outdir , 'build' )
450450
451451 for outdir in outdirs ():
452452 yield os .path .join (self .basedir , outdir )
453453
454- # bot option
455- if options .mode :
456- yield os .path .join (self .basedir , outdir , options .mode )
457-
458454 def _get_gn_outdir (self ):
459455 gn_out_dir = os .path .join (self .basedir , DEFAULT_OUT_GN )
460456 latest_timestamp = - 1
@@ -470,51 +466,13 @@ def _get_gn_outdir(self):
470466 print (">>> Latest GN build found: %s" % latest_config )
471467 return os .path .join (DEFAULT_OUT_GN , latest_config )
472468
473- def _do_load_build_config (self , outdir , verbose = False ):
474- build_config_path = os .path .join (outdir , "v8_build_config.json" )
475- if not os .path .exists (build_config_path ):
476- if verbose :
477- print ("Didn't find build config: %s" % build_config_path )
478- raise TestRunnerError ()
479-
480- with open (build_config_path ) as f :
481- try :
482- build_config_json = json .load (f )
483- except Exception : # pragma: no cover
484- print ("%s exists but contains invalid json. Is your build up-to-date?"
485- % build_config_path )
486- raise TestRunnerError ()
487-
488- # In auto-detect mode the outdir is always where we found the build config.
489- # This ensures that we'll also take the build products from there.
490- self .outdir = os .path .dirname (build_config_path )
491-
492- return BuildConfig (build_config_json )
493-
494469 def _process_default_options (self , options ):
495- # We don't use the mode for more path-magic.
496- # Therefore transform the bot mode here to fix build_config value.
497- if options .mode :
498- options .mode = self ._bot_to_v8_mode (options .mode )
499-
500- build_config_mode = 'debug' if self .build_config .is_debug else 'release'
501- if options .mode :
502- if options .mode not in MODES : # pragma: no cover
503- print ('%s mode is invalid' % options .mode )
504- raise TestRunnerError ()
505- if MODES [options .mode ].execution_mode != build_config_mode :
506- print ('execution mode (%s) for %s is inconsistent with build config '
507- '(%s)' % (
508- MODES [options .mode ].execution_mode ,
509- options .mode ,
510- build_config_mode ))
511- raise TestRunnerError ()
512-
513- self .mode_name = options .mode
470+ if self .build_config .is_debug :
471+ self .mode_options = DEBUG_MODE
472+ elif self .build_config .dcheck_always_on :
473+ self .mode_options = TRY_RELEASE_MODE
514474 else :
515- self .mode_name = build_config_mode
516-
517- self .mode_options = MODES [self .mode_name ]
475+ self .mode_options = RELEASE_MODE
518476
519477 if options .arch and options .arch != self .build_config .arch :
520478 print ('--arch value (%s) inconsistent with build config (%s).' % (
@@ -535,15 +493,6 @@ def _process_default_options(self, options):
535493 options .command_prefix = shlex .split (options .command_prefix )
536494 options .extra_flags = sum (map (shlex .split , options .extra_flags ), [])
537495
538- def _bot_to_v8_mode (self , config ):
539- """Convert build configs from bots to configs understood by the v8 runner.
540-
541- V8 configs are always lower case and without the additional _x64 suffix
542- for 64 bit builds on windows with ninja.
543- """
544- mode = config [:- 4 ] if config .endswith ('_x64' ) else config
545- return mode .lower ()
546-
547496 def _process_options (self , options ):
548497 pass
549498
@@ -692,9 +641,7 @@ def _get_statusfile_variables(self, options):
692641 "is_clang" : self .build_config .is_clang ,
693642 "is_full_debug" : self .build_config .is_full_debug ,
694643 "mips_arch_variant" : mips_arch_variant ,
695- "mode" : self .mode_options .status_mode
696- if not self .build_config .dcheck_always_on
697- else "debug" ,
644+ "mode" : self .mode_options .status_mode ,
698645 "msan" : self .build_config .msan ,
699646 "no_harness" : options .no_harness ,
700647 "no_i18n" : self .build_config .no_i18n ,
@@ -804,10 +751,7 @@ def _get_shard_info(self, options):
804751 def _create_progress_indicators (self , test_count , options ):
805752 procs = [PROGRESS_INDICATORS [options .progress ]()]
806753 if options .json_test_results :
807- procs .append (progress .JsonTestProgressIndicator (
808- self .framework_name ,
809- self .build_config .arch ,
810- self .mode_options .execution_mode ))
754+ procs .append (progress .JsonTestProgressIndicator (self .framework_name ))
811755
812756 for proc in procs :
813757 proc .configure (options )
0 commit comments