Skip to content

Commit 14a72b5

Browse files
LukaszMrugalacarlescufi
authored andcommitted
scripts: Plug TwisterStatus type gaps
Some dict.get() calls did not use a TwisterStatus as a default value, thus using a NoneType where TwisterStatus should appear. Signed-off-by: Lukasz Mrugala <[email protected]>
1 parent 788d1a9 commit 14a72b5

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed

scripts/ci/test_plan.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
sys.path.append(os.path.join(zephyr_base, 'scripts'))
3838
import list_boards
3939

40+
from pylib.twister.twisterlib.statuses import TwisterStatus
41+
4042

4143
def _get_match_fn(globs, regexes):
4244
# Constructs a single regex that tests for matches against the globs in
@@ -469,12 +471,12 @@ def parse_args():
469471
dup_free_set = set()
470472
logging.info(f'Total tests gathered: {len(f.all_tests)}')
471473
for ts in f.all_tests:
472-
if ts.get('status') == 'filtered':
474+
if TwisterStatus(ts.get('status')) == TwisterStatus.FILTER:
473475
continue
474476
n = ts.get("name")
475477
a = ts.get("arch")
476478
p = ts.get("platform")
477-
if ts.get('status') == 'error':
479+
if TwisterStatus(ts.get('status')) == TwisterStatus.ERROR:
478480
logging.info(f"Error found: {n} on {p} ({ts.get('reason')})")
479481
errors += 1
480482
if (n, a, p,) not in dup_free_set:

scripts/pylib/twister/twisterlib/reports.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def process_log(log_file):
6565

6666

6767
@staticmethod
68-
def xunit_testcase(eleTestsuite, name, classname, status, ts_status, reason, duration, runnable, stats, log, build_only_as_skip):
68+
def xunit_testcase(eleTestsuite, name, classname, status: TwisterStatus, ts_status: TwisterStatus, reason, duration, runnable, stats, log, build_only_as_skip):
6969
fails, passes, errors, skips = stats
7070

7171
if status in [TwisterStatus.SKIP, TwisterStatus.FILTER]:
@@ -127,7 +127,7 @@ def xunit_report_suites(self, json_file, filename):
127127
suites_to_report = all_suites
128128
# do not create entry if everything is filtered out
129129
if not self.env.options.detailed_skipped_report:
130-
suites_to_report = list(filter(lambda d: d.get('status') != TwisterStatus.FILTER, all_suites))
130+
suites_to_report = list(filter(lambda d: TwisterStatus(d.get('status')) != TwisterStatus.FILTER, all_suites))
131131

132132
for suite in suites_to_report:
133133
duration = 0
@@ -149,9 +149,9 @@ def xunit_report_suites(self, json_file, filename):
149149
handler_time = suite.get('execution_time', 0)
150150
runnable = suite.get('runnable', 0)
151151
duration += float(handler_time)
152-
ts_status = suite.get('status')
152+
ts_status = TwisterStatus(suite.get('status'))
153153
for tc in suite.get("testcases", []):
154-
status = tc.get('status')
154+
status = TwisterStatus(tc.get('status'))
155155
reason = tc.get('reason', suite.get('reason', 'Unknown'))
156156
log = tc.get("log", suite.get("log"))
157157

@@ -197,7 +197,7 @@ def xunit_report(self, json_file, filename, selected_platform=None, full_report=
197197
suites = list(filter(lambda d: d['platform'] == platform, all_suites))
198198
# do not create entry if everything is filtered out
199199
if not self.env.options.detailed_skipped_report:
200-
non_filtered = list(filter(lambda d: d.get('status') != TwisterStatus.FILTER, suites))
200+
non_filtered = list(filter(lambda d: TwisterStatus(d.get('status')) != TwisterStatus.FILTER, suites))
201201
if not non_filtered:
202202
continue
203203

@@ -221,13 +221,13 @@ def xunit_report(self, json_file, filename, selected_platform=None, full_report=
221221
runnable = ts.get('runnable', 0)
222222
duration += float(handler_time)
223223

224-
ts_status = ts.get('status')
224+
ts_status = TwisterStatus(ts.get('status'))
225225
# Do not report filtered testcases
226226
if ts_status == TwisterStatus.FILTER and not self.env.options.detailed_skipped_report:
227227
continue
228228
if full_report:
229229
for tc in ts.get("testcases", []):
230-
status = tc.get('status')
230+
status = TwisterStatus(tc.get('status'))
231231
reason = tc.get('reason', ts.get('reason', 'Unknown'))
232232
log = tc.get("log", ts.get("log"))
233233

scripts/pylib/twister/twisterlib/statuses.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ class TwisterStatus(str, Enum):
1313
def __str__(self):
1414
return str(self.value)
1515

16+
@classmethod
17+
def _missing_(cls, value):
18+
super()._missing_(value)
19+
if value is None:
20+
return TwisterStatus.NONE
21+
1622
# All statuses below this comment can be used for TestCase
1723
BLOCK = 'blocked'
1824
STARTED = 'started'

scripts/pylib/twister/twisterlib/testplan.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,7 @@ def load_from_file(self, file, filter_platform=[]):
624624
instance.metrics['available_ram'] = ts.get('available_ram', 0)
625625
instance.metrics['available_rom'] = ts.get('available_rom', 0)
626626

627-
status = ts.get('status')
628-
status = TwisterStatus(status) if status else TwisterStatus.NONE
627+
status = TwisterStatus(ts.get('status'))
629628
reason = ts.get("reason", "Unknown")
630629
if status in [TwisterStatus.ERROR, TwisterStatus.FAIL]:
631630
if self.options.report_summary is not None:
@@ -649,8 +648,7 @@ def load_from_file(self, file, filter_platform=[]):
649648

650649
for tc in ts.get('testcases', []):
651650
identifier = tc['identifier']
652-
tc_status = tc.get('status')
653-
tc_status = TwisterStatus(tc_status) if tc_status else TwisterStatus.NONE
651+
tc_status = TwisterStatus(tc.get('status'))
654652
tc_reason = None
655653
# we set reason only if status is valid, it might have been
656654
# reset above...

scripts/tests/twister_blackbox/test_report.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
# pylint: disable=no-name-in-module
2121
from conftest import TEST_DATA, ZEPHYR_BASE, testsuite_filename_mock, clear_log_in_test
22+
from twisterlib.statuses import TwisterStatus
2223
from twisterlib.testplan import TestPlan
2324

2425

@@ -414,7 +415,7 @@ def test_report_filtered(self, out_path, test_path, report_filtered, expected_fi
414415

415416
testsuites = j.get('testsuites')
416417
assert testsuites, 'No testsuites found.'
417-
statuses = [testsuite.get('status') for testsuite in testsuites]
418+
statuses = [TwisterStatus(testsuite.get('status')) for testsuite in testsuites]
418419
filtered_status_count = statuses.count("filtered")
419420
assert filtered_status_count == expected_filtered_count, \
420421
f'Expected {expected_filtered_count} filtered statuses, got {filtered_status_count}.'

0 commit comments

Comments
 (0)