test-gdb and test-userland: print time of each test

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-01-22 00:00:00 +00:00
parent 928b01f458
commit c02d52267f
3 changed files with 34 additions and 12 deletions

View File

@@ -9,6 +9,7 @@ import glob
import imp import imp
import inspect import inspect
import json import json
import math
import multiprocessing import multiprocessing
import os import os
import re import re
@@ -365,7 +366,7 @@ Valid emulators: {}
) )
self._is_common = False self._is_common = False
def __call__(self, **kwargs): def __call__(self, *args, **kwargs):
''' '''
For Python code calls, in addition to base: For Python code calls, in addition to base:
@@ -770,11 +771,14 @@ Valid emulators: {}
def import_path_main(self, path): def import_path_main(self, path):
return self.import_path(path).Main() return self.import_path(path).Main()
@staticmethod def log_error(self, msg):
def log_error(msg): print('error: {}'.format(msg), file=sys.stdout)
print('error: {}'.format(msg), file=sys.stderr)
def main(self, **kwargs): def log_info(self, msg, **kwargs):
if not self.env['quiet']:
print('{}'.format(msg), **kwargs)
def main(self, *args, **kwargs):
''' '''
Time the main of the derived class. Time the main of the derived class.
''' '''
@@ -811,7 +815,8 @@ Valid emulators: {}
ret = self.timed_main() ret = self.timed_main()
if not env['dry_run']: if not env['dry_run']:
end_time = time.time() end_time = time.time()
self._print_time(end_time - start_time) self.ellapsed_seconds = end_time - start_time
self.print_time(self.ellapsed_seconds)
if ret is not None and ret != 0: if ret is not None and ret != 0:
return ret return ret
elif not real_all_archs: elif not real_all_archs:
@@ -841,11 +846,23 @@ Valid emulators: {}
return True return True
return False return False
def _print_time(self, ellapsed_seconds): def seconds_to_hms(self, seconds):
'''
Seconds to hour:minute:seconds
:ptype seconds: float
:rtype: str
https://stackoverflow.com/questions/775049/how-do-i-convert-seconds-to-hours-minutes-and-seconds
'''
frac, whole = math.modf(seconds)
hours, rem = divmod(whole, 3600)
minutes, seconds = divmod(rem, 60)
return '{:02}:{:02}:{:02}'.format(int(hours), int(minutes), int(seconds))
def print_time(self, ellapsed_seconds):
if self.env['print_time'] and not self.env['quiet']: if self.env['print_time'] and not self.env['quiet']:
hours, rem = divmod(ellapsed_seconds, 3600) print('time {}'.format(self.seconds_to_hms(ellapsed_seconds)))
minutes, seconds = divmod(rem, 60)
print('time {:02}:{:02}:{:02}'.format(int(hours), int(minutes), int(seconds)))
def raw_to_qcow2(self, prebuilt=False, reverse=False): def raw_to_qcow2(self, prebuilt=False, reverse=False):
if prebuilt or not os.path.exists(self.env['qemu_img_executable']): if prebuilt or not os.path.exists(self.env['qemu_img_executable']):
@@ -918,8 +935,11 @@ Valid emulators: {}
if not self.env['verbose']: if not self.env['verbose']:
test_env['quiet'] = True test_env['quiet'] = True
test_id_string = '{} {} {}'.format(self.env['emulator'], self.env['arch'], source) test_id_string = '{} {} {}'.format(self.env['emulator'], self.env['arch'], source)
if not self.env['quiet']: if self.env['verbose']:
print(test_id_string) end = '\n'
else:
end = ' '
self.log_info(test_id_string, end=end)
return test_id_string return test_id_string
def timed_main(self): def timed_main(self):

View File

@@ -54,6 +54,7 @@ found by searching for the Python test files.
gdb_args['test'] = True gdb_args['test'] = True
run_gdb(**gdb_args) run_gdb(**gdb_args)
run_thread.join() run_thread.join()
self.log_info(self.seconds_to_hms(run.ellapsed_seconds))
if __name__ == '__main__': if __name__ == '__main__':
Main().cli() Main().cli()

View File

@@ -52,6 +52,7 @@ If given, run only the given tests. Otherwise, run all tests.
test_id_string = self.test_setup(run_args, source) test_id_string = self.test_setup(run_args, source)
run_args['background'] = True run_args['background'] = True
exit_status = run(**run_args) exit_status = run(**run_args)
self.log_info(self.seconds_to_hms(run.ellapsed_seconds))
# TODO forward all args attempt. In particular, --dry-run. # TODO forward all args attempt. In particular, --dry-run.
#new_env = self.env.copy() #new_env = self.env.copy()
#new_env['userland'] = source #new_env['userland'] = source