Skip to content

Commit

Permalink
scripts: twister: Add TestCase status printing
Browse files Browse the repository at this point in the history
When at verbosity 1, we print out the status of TestInstances.
This makes it harder to notice changes at TestCase level,
which require perusing the logs.

This adds TestCase status and reason printing
if verbosity level is 2 or more.
Reason printing is suppressed if the reason is empty or None.

Signed-off-by: Lukasz Mrugala <[email protected]>
  • Loading branch information
LukaszMrugala committed Sep 17, 2024
1 parent ca09a4b commit 8a30029
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
7 changes: 7 additions & 0 deletions scripts/pylib/twister/twisterlib/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,13 @@ def report_out(self, results):
results.done, total_tests_width, total_to_do , instance.platform.name,
instance.testsuite.name, status, more_info))

if self.options.verbose > 1:
for tc in self.instance.testcases:
color = TwisterStatus.get_color(tc.status)
logger.info(f' {" ":<{total_tests_width+25+4}} {tc.name:<75} '
f'{color}{str.upper(tc.status.value):<12}{Fore.RESET}'
f'{" " + tc.reason if tc.reason else ""}')

if instance.status in [TwisterStatus.ERROR, TwisterStatus.FAIL]:
self.log_info_file(self.options.inline_logs)
else:
Expand Down
17 changes: 17 additions & 0 deletions scripts/pylib/twister/twisterlib/statuses.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"""
Status classes to be used instead of str statuses.
"""
from __future__ import annotations

from colorama import Fore
from enum import Enum


Expand All @@ -19,6 +21,21 @@ def _missing_(cls, value):
if value is None:
return TwisterStatus.NONE

@staticmethod
def get_color(status: TwisterStatus) -> str:
match(status):
case TwisterStatus.PASS:
color = Fore.GREEN
case TwisterStatus.SKIP | TwisterStatus.FILTER | TwisterStatus.BLOCK:
color = Fore.YELLOW
case TwisterStatus.FAIL | TwisterStatus.ERROR:
color = Fore.RED
case TwisterStatus.STARTED | TwisterStatus.NONE:
color = Fore.MAGENTA
case _:
color = Fore.RESET
return color

# All statuses below this comment can be used for TestCase
BLOCK = 'blocked'
STARTED = 'started'
Expand Down
10 changes: 7 additions & 3 deletions scripts/tests/twister/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2008,9 +2008,13 @@ def test_projectbuilder_report_out(
instance_mock.status = status
instance_mock.reason = 'dummy reason'
instance_mock.testsuite.name = 'dummy.testsuite.name'
instance_mock.testsuite.testcases = [mock.Mock() for _ in range(25)]
instance_mock.testcases = [mock.Mock() for _ in range(24)] + \
[mock.Mock(status=TwisterStatus.SKIP)]
skip_mock_tc = mock.Mock(status=TwisterStatus.SKIP, reason='?')
skip_mock_tc.name = '?'
unknown_mock_tc = mock.Mock(status=mock.Mock(value='?'), reason='?')
unknown_mock_tc.name = '?'
instance_mock.testsuite.testcases = [unknown_mock_tc for _ in range(25)]
instance_mock.testcases = [unknown_mock_tc for _ in range(24)] + \
[skip_mock_tc]
env_mock = mock.Mock()

pb = ProjectBuilder(instance_mock, env_mock, mocked_jobserver)
Expand Down

0 comments on commit 8a30029

Please sign in to comment.