5050 help = 'exclude tests with given tags' )
5151parser .add_argument ('--timeout' , type = int , default = 60 ,
5252 help = 'test timeout (default 60 seconds)' )
53+ parser .add_argument ('-l' , '--logfile' , metavar = 'logfile' , help = 'file to log results to' , default = None )
5354parser .add_argument ('--x86' , action = 'store_true' , help = 'use x86 build' )
5455parser .add_argument ('--x64' , action = 'store_true' , help = 'use x64 build' )
5556args = parser .parse_args ()
109110not_compile_flags = set (['-serialized' , '-simdjs' ]) \
110111 if sys .platform != 'win32' else None
111112
113+ class LogFile (object ):
114+ def __init__ (self , log_file_path = None ):
115+ self .file = None
116+
117+ if log_file_path is None :
118+ # Set up the log file paths
119+ # Make sure the right directory exists and the log file doesn't
120+ log_file_name = "testrun.{0}{1}.log" .format (arch , flavor )
121+ log_file_directory = os .path .join (repo_root , "test" , "logs" )
122+
123+ if not os .path .exists (log_file_directory ):
124+ os .mkdir (log_file_directory )
125+
126+ self .log_file_path = os .path .join (log_file_directory , log_file_name )
127+
128+ if os .path .exists (self .log_file_path ):
129+ os .remove (self .log_file_path )
130+ else :
131+ self .log_file_path = log_file_path
132+
133+ self .file = open (self .log_file_path , "w" )
134+
135+ def log (self , args ):
136+ self .file .write (args )
137+
138+ def __del__ (self ):
139+ if not (self .file is None ):
140+ self .file .close ()
141+
142+ log_file = LogFile (args .logfile )
143+
144+ def log_message (msg = "" ):
145+ log_file .log (msg + "\n " )
146+
147+ def print_and_log (msg = "" ):
148+ print (msg )
149+ log_message (msg )
150+
112151# records pass_count/fail_count
113152class PassFailCount (object ):
114153 def __init__ (self ):
@@ -200,9 +239,10 @@ def _process_msg(self, msg):
200239 self ._short_name (filename ))
201240 padding = self ._last_len - len (line )
202241 print (line + ' ' * padding , end = '\n ' if fail else '\r ' )
242+ log_message (line )
203243 self ._last_len = len (line ) if not fail else 0
204244 if len (output ) > 0 :
205- print (output )
245+ print_and_log (output )
206246
207247 # get a shorter test file path for display only
208248 def _short_name (self , filename ):
@@ -333,13 +373,13 @@ def timeout_func(timeout_data):
333373
334374 # run tests under this variant, using given multiprocessing Pool
335375 def run (self , tests , pool ):
336- print ('\n ############# Starting {} variant #############' .format (
376+ print_and_log ('\n ############# Starting {} variant #############' .format (
337377 self .name ))
338378 if self .tags :
339- print (' tags: {}' .format (self .tags ))
379+ print_and_log (' tags: {}' .format (self .tags ))
340380 for x in self .not_tags :
341- print (' exclude: {}' .format (x ))
342- print ()
381+ print_and_log (' exclude: {}' .format (x ))
382+ print_and_log ()
343383
344384 # filter tests to run
345385 tests = [x for x in tests if self ._should_test (x [1 ])]
@@ -353,11 +393,11 @@ def run(self, tests, pool):
353393
354394 # print test result summary
355395 def print_summary (self ):
356- print ('\n ######## Logs for {} variant ########' .format (self .name ))
396+ print_and_log ('\n ######## Logs for {} variant ########' .format (self .name ))
357397 for folder , result in sorted (self .test_result .folders .items ()):
358- print ('{}: {}' .format (folder , result ))
359- print ("----------------------------" )
360- print ('Total: {}' .format (self .test_result ))
398+ print_and_log ('{}: {}' .format (folder , result ))
399+ print_and_log ("----------------------------" )
400+ print_and_log ('Total: {}' .format (self .test_result ))
361401
362402# global run one test function for multiprocessing, used by TestVariant
363403def run_one (data ):
@@ -374,7 +414,7 @@ def __init__(self):
374414 try :
375415 xml = ET .parse (xmlpath ).getroot ()
376416 except IOError :
377- print ('ERROR: failed to read {}' .format (xmlpath ))
417+ print_and_log ('ERROR: failed to read {}' .format (xmlpath ))
378418 exit (- 1 )
379419
380420 self ._folder_tags = {}
0 commit comments