Skip to content

Commit 067126a

Browse files
golowanowkartben
authored andcommitted
twister: harness: fix Ztest case summary pattern
Fix missing match on Ztest test case summary log entries, so even if the test case 'END' log entry is missed or corrupted, its status will be updated from the Ztest summary log entries, if present. Signed-off-by: Dmitrii Golovanov <[email protected]>
1 parent 11b9eba commit 067126a

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

scripts/pylib/twister/twisterlib/harness.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,9 @@ def _check_result(self, line):
785785
class Test(Harness):
786786
__test__ = False # for pytest to skip this class when collects tests
787787

788+
# Ztest log patterns don't require to match the line start exactly: there are platforms
789+
# where there is some logging prefix at each console line whereas on other platforms
790+
# without prefixes the leading space is stripped.
788791
test_suite_start_pattern = re.compile(r"Running TESTSUITE (?P<suite_name>\S*)")
789792
test_suite_end_pattern = re.compile(
790793
r"TESTSUITE (?P<suite_name>\S*)\s+(?P<suite_status>succeeded|failed)"
@@ -798,7 +801,7 @@ class Test(Harness):
798801
r" .* duration = (\d*[.,]?\d*) seconds"
799802
)
800803
test_case_summary_pattern = re.compile(
801-
r" - (PASS|FAIL|SKIP) - \[([^\.]*).(test_)?(\S*)\] duration = (\d*[.,]?\d*) seconds"
804+
r".*- (PASS|FAIL|SKIP) - \[([^\.]*).(test_)?(\S*)\] duration = (\d*[.,]?\d*) seconds"
802805
)
803806

804807

@@ -896,17 +899,16 @@ def end_case(self, tc_name, phase='TC_END'):
896899
elif phase != 'TS_SUM':
897900
logger.warning(f"{phase}: END case '{tc_name}' without START detected")
898901

899-
900902
def handle(self, line):
901903
testcase_match = None
902904
if self._match:
903905
self.testcase_output += line + "\n"
904-
905906
if test_suite_start_match := re.search(self.test_suite_start_pattern, line):
906907
self.start_suite(test_suite_start_match.group("suite_name"))
907908
elif test_suite_end_match := re.search(self.test_suite_end_pattern, line):
908909
suite_name=test_suite_end_match.group("suite_name")
909910
self.end_suite(suite_name)
911+
self.ztest = True
910912
elif testcase_match := re.search(self.test_case_start_pattern, line):
911913
tc_name = testcase_match.group(2)
912914
tc = self.get_testcase(tc_name, 'TC_START')
@@ -947,6 +949,11 @@ def handle(self, line):
947949
tc_name = test_case_summary_match.group(4)
948950
tc = self.get_testcase(tc_name, 'TS_SUM', suite_name)
949951
self.end_case(tc.name, 'TS_SUM')
952+
if tc.status not in [TwisterStatus.NONE, TwisterStatus[matched_status]]:
953+
# TestCase miss its END log entry, so its status is from the Suite summary.
954+
logger.warning(
955+
f"TS_SUM: {tc.name} force status: {tc.status}->{TwisterStatus[matched_status]}"
956+
)
950957
tc.status = TwisterStatus[matched_status]
951958
if tc.status == TwisterStatus.SKIP:
952959
tc.reason = "ztest skip"
@@ -960,7 +967,7 @@ def handle(self, line):
960967
self.process_test(line)
961968

962969
if not self.ztest and self.status != TwisterStatus.NONE:
963-
logger.debug(f"not a ztest and no state for {self.id}")
970+
logger.debug(f"{self.id} is not a Ztest, status:{self.status}")
964971
tc = self.instance.get_case_or_create(self.id)
965972
if self.status == TwisterStatus.PASS:
966973
tc.status = TwisterStatus.PASS

scripts/tests/twister/test_harness.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ def test_get_harness(name):
734734
),
735735
(
736736
True,
737-
"not a ztest and no state for dummy.test_id",
737+
"dummy.test_id is not a Ztest, status:passed",
738738
"START - test_testcase",
739739
[],
740740
{},
@@ -745,7 +745,7 @@ def test_get_harness(name):
745745
),
746746
(
747747
False,
748-
"not a ztest and no state for dummy.test_id",
748+
"dummy.test_id is not a Ztest, status:passed",
749749
"START - test_testcase",
750750
[],
751751
{},
@@ -756,7 +756,7 @@ def test_get_harness(name):
756756
),
757757
(
758758
True,
759-
"not a ztest and no state for dummy.test_id",
759+
"dummy.test_id is not a Ztest, status:failed",
760760
"START - test_testcase",
761761
[],
762762
{},

0 commit comments

Comments
 (0)