mtest: move test_count and name_max_len to TestHarness class

Avoid passing them around as parameters; this will be useful when logging
is moved out of TestHarness, because individual loggers will call back
into TestHarness to do common formatting chores.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
pull/8001/head
Paolo Bonzini 4 years ago
parent 3f8c901245
commit 9d29bd0225
  1. 19
      mesonbuild/mtest.py

@ -870,13 +870,15 @@ class TestHarness:
self.success_count = 0 self.success_count = 0
self.skip_count = 0 self.skip_count = 0
self.timeout_count = 0 self.timeout_count = 0
self.test_count = 0
self.name_max_len = 0
self.is_run = False self.is_run = False
self.tests = None
self.results = [] # type: T.List[TestRun] self.results = [] # type: T.List[TestRun]
self.logfilename = None # type: T.Optional[str] self.logfilename = None # type: T.Optional[str]
self.logfile = None # type: T.Optional[T.TextIO] self.logfile = None # type: T.Optional[T.TextIO]
self.jsonlogfile = None # type: T.Optional[T.TextIO] self.jsonlogfile = None # type: T.Optional[T.TextIO]
self.junit = None # type: T.Optional[JunitBuilder] self.junit = None # type: T.Optional[JunitBuilder]
if self.options.benchmark: if self.options.benchmark:
self.tests = load_benchmarks(options.wd) self.tests = load_benchmarks(options.wd)
else: else:
@ -958,16 +960,15 @@ class TestHarness:
else: else:
sys.exit('Unknown test result encountered: {}'.format(result.res)) sys.exit('Unknown test result encountered: {}'.format(result.res))
def print_stats(self, test_count: int, name_max_len: int, def print_stats(self, result: TestRun) -> None:
result: TestRun) -> None:
ok_statuses = (TestResult.OK, TestResult.EXPECTEDFAIL) ok_statuses = (TestResult.OK, TestResult.EXPECTEDFAIL)
bad_statuses = (TestResult.FAIL, TestResult.TIMEOUT, TestResult.INTERRUPT, bad_statuses = (TestResult.FAIL, TestResult.TIMEOUT, TestResult.INTERRUPT,
TestResult.UNEXPECTEDPASS, TestResult.ERROR) TestResult.UNEXPECTEDPASS, TestResult.ERROR)
result_str = '{num:{numlen}}/{testcount} {name:{name_max_len}} {res:{reslen}} {dur:.2f}s'.format( result_str = '{num:{numlen}}/{testcount} {name:{name_max_len}} {res:{reslen}} {dur:.2f}s'.format(
numlen=len(str(test_count)), numlen=len(str(self.test_count)),
num=result.num, num=result.num,
testcount=test_count, testcount=self.test_count,
name_max_len=name_max_len, name_max_len=self.name_max_len,
name=result.name, name=result.name,
reslen=TestResult.maxlen(), reslen=TestResult.maxlen(),
res=result.res.value, res=result.res.value,
@ -1051,6 +1052,8 @@ class TestHarness:
# wrapper script. # wrapper script.
sys.exit(125) sys.exit(125)
self.test_count = len(tests)
self.name_max_len = max([len(self.get_pretty_suite(test)) for test in tests])
self.run_tests(tests) self.run_tests(tests)
return self.total_failure_count() return self.total_failure_count()
@ -1203,8 +1206,6 @@ class TestHarness:
semaphore = asyncio.Semaphore(self.options.num_processes) semaphore = asyncio.Semaphore(self.options.num_processes)
futures = deque() # type: T.Deque[asyncio.Future] futures = deque() # type: T.Deque[asyncio.Future]
running_tests = dict() # type: T.Dict[asyncio.Future, str] running_tests = dict() # type: T.Dict[asyncio.Future, str]
test_count = len(tests)
name_max_len = max([len(self.get_pretty_suite(test)) for test in tests])
self.open_log_files() self.open_log_files()
startdir = os.getcwd() startdir = os.getcwd()
if self.options.wd: if self.options.wd:
@ -1218,7 +1219,7 @@ class TestHarness:
return return
res = await test.run() res = await test.run()
self.process_test_result(res) self.process_test_result(res)
self.print_stats(test_count, name_max_len, res) self.print_stats(res)
def test_done(f: asyncio.Future) -> None: def test_done(f: asyncio.Future) -> None:
if not f.cancelled(): if not f.cancelled():

Loading…
Cancel
Save