Skip to content

Commit 9dc0af5

Browse files
LukaszMrugalammahadevan108
authored andcommitted
scripts: twister: Fix NOTRUN in test_only
When using the --build-only into --test-only Twister setup, NOTRUN statuses were not properly rerun. Now they are properly run again if runnable. Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
1 parent 1e5a537 commit 9dc0af5

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

scripts/pylib/twister/twisterlib/reports.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,12 @@ def json_report(self, filename, version="NA", platform=None, filters=None):
354354
elif instance.status == TwisterStatus.SKIP:
355355
suite["status"] = TwisterStatus.SKIP
356356
suite["reason"] = instance.reason
357+
elif instance.status == TwisterStatus.NOTRUN:
358+
suite["status"] = TwisterStatus.NOTRUN
359+
suite["reason"] = instance.reason
360+
else:
361+
suite["status"] = TwisterStatus.NONE
362+
suite["reason"] = 'Unknown Instance status.'
357363

358364
if instance.status != TwisterStatus.NONE:
359365
suite["execution_time"] = f"{float(handler_time):.2f}"

scripts/pylib/twister/twisterlib/testplan.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,9 @@ def load_from_file(self, file, filter_platform=[]):
659659
self.hwm
660660
)
661661

662+
if self.options.test_only and not instance.run:
663+
continue
664+
662665
instance.metrics['handler_time'] = ts.get('execution_time', 0)
663666
instance.metrics['used_ram'] = ts.get("used_ram", 0)
664667
instance.metrics['used_rom'] = ts.get("used_rom",0)
@@ -676,9 +679,9 @@ def load_from_file(self, file, filter_platform=[]):
676679
instance.status = TwisterStatus.NONE
677680
instance.reason = None
678681
instance.retries += 1
679-
# test marked as passed (built only) but can run when
680-
# --test-only is used. Reset status to capture new results.
681-
elif status == TwisterStatus.PASS and instance.run and self.options.test_only:
682+
# test marked as built only can run when --test-only is used.
683+
# Reset status to capture new results.
684+
elif status == TwisterStatus.NOTRUN and instance.run and self.options.test_only:
682685
instance.status = TwisterStatus.NONE
683686
instance.reason = None
684687
else:

scripts/tests/twister/test_testplan.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,7 @@ def test_testplan_load(
766766
testplan.apply_filters = mock.Mock()
767767

768768
with mock.patch('twisterlib.testinstance.TestInstance.create_overlay', mock.Mock()), \
769+
mock.patch('twisterlib.testinstance.TestInstance.check_runnable', return_value=True), \
769770
pytest.raises(exception) if exception else nullcontext():
770771
testplan.load()
771772

@@ -1600,7 +1601,7 @@ def get_platform(name):
16001601
'testcases': {
16011602
'TS1.tc1': {
16021603
'status': TwisterStatus.PASS,
1603-
'reason': None,
1604+
'reason': 'passed',
16041605
'duration': 60.0,
16051606
'output': ''
16061607
}

scripts/tests/twister_blackbox/test_footprint.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
# pylint: disable=no-name-in-module
1818
from conftest import ZEPHYR_BASE, TEST_DATA, testsuite_filename_mock, clear_log_in_test
19+
from twisterlib.statuses import TwisterStatus
1920
from twisterlib.testplan import TestPlan
2021

2122

@@ -76,9 +77,10 @@ def test_compare_report(self, caplog, out_path, old_ram_multiplier, expect_delta
7677
with open(os.path.join(out_path, 'twister.json')) as f:
7778
j = json.load(f)
7879
for ts in j['testsuites']:
79-
if 'reason' not in ts:
80+
if TwisterStatus(ts.get('status')) == TwisterStatus.NOTRUN:
8081
# We assume positive RAM usage.
8182
ts[self.RAM_KEY] *= old_ram_multiplier
83+
8284
with open(os.path.join(out_path, 'twister.json'), 'w') as f:
8385
f.write(json.dumps(j, indent=4))
8486

@@ -137,7 +139,7 @@ def test_footprint_from_buildlog(self, out_path):
137139
with open(os.path.join(out_path, 'twister.json')) as f:
138140
j = json.load(f)
139141
for ts in j['testsuites']:
140-
if 'reason' not in ts:
142+
if TwisterStatus(ts.get('status')) == TwisterStatus.NOTRUN:
141143
assert self.RAM_KEY in ts
142144
old_values += [ts[self.RAM_KEY]]
143145

@@ -162,7 +164,7 @@ def test_footprint_from_buildlog(self, out_path):
162164
with open(os.path.join(out_path, 'twister.json')) as f:
163165
j = json.load(f)
164166
for ts in j['testsuites']:
165-
if 'reason' not in ts:
167+
if TwisterStatus(ts.get('status')) == TwisterStatus.NOTRUN:
166168
assert self.RAM_KEY in ts
167169
new_values += [ts[self.RAM_KEY]]
168170

@@ -202,7 +204,7 @@ def test_footprint_threshold(self, caplog, out_path, old_ram_multiplier,
202204
with open(os.path.join(out_path, 'twister.json')) as f:
203205
j = json.load(f)
204206
for ts in j['testsuites']:
205-
if 'reason' not in ts:
207+
if TwisterStatus(ts.get('status')) == TwisterStatus.NOTRUN:
206208
# We assume positive RAM usage.
207209
ts[self.RAM_KEY] *= old_ram_multiplier
208210
with open(os.path.join(out_path, 'twister.json'), 'w') as f:
@@ -271,7 +273,7 @@ def test_show_footprint(self, caplog, out_path, flags, old_ram_multiplier, expec
271273
with open(os.path.join(out_path, 'twister.json')) as f:
272274
j = json.load(f)
273275
for ts in j['testsuites']:
274-
if 'reason' not in ts:
276+
if TwisterStatus(ts.get('status')) == TwisterStatus.NOTRUN:
275277
# We assume positive RAM usage.
276278
ts[self.RAM_KEY] *= old_ram_multiplier
277279
with open(os.path.join(out_path, 'twister.json'), 'w') as f:
@@ -344,7 +346,7 @@ def test_last_metrics(self, caplog, out_path, old_ram_multiplier, expect_delta_l
344346
with open(os.path.join(out_path, 'twister.json')) as f:
345347
j = json.load(f)
346348
for ts in j['testsuites']:
347-
if 'reason' not in ts:
349+
if TwisterStatus(ts.get('status')) == TwisterStatus.NOTRUN:
348350
# We assume positive RAM usage.
349351
ts[self.RAM_KEY] *= old_ram_multiplier
350352
with open(os.path.join(out_path, 'twister.json'), 'w') as f:
@@ -441,7 +443,7 @@ def test_all_deltas(self, caplog, out_path, old_ram_multiplier, expect_delta_log
441443
with open(os.path.join(out_path, 'twister.json')) as f:
442444
j = json.load(f)
443445
for ts in j['testsuites']:
444-
if 'reason' not in ts:
446+
if TwisterStatus(ts.get('status')) == TwisterStatus.NOTRUN:
445447
# We assume positive RAM usage.
446448
ts[self.RAM_KEY] *= old_ram_multiplier
447449
with open(os.path.join(out_path, 'twister.json'), 'w') as f:

scripts/tests/twister_blackbox/test_runner.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,19 @@ class TestRunner:
4646
['qemu_x86/atom', 'qemu_x86_64/atom', 'intel_adl_crb/alder_lake'],
4747
{
4848
'selected_test_scenarios': 3,
49-
'selected_test_instances': 6,
49+
'selected_test_instances': 4,
5050
'skipped_configurations': 0,
5151
'skipped_by_static_filter': 0,
5252
'skipped_at_runtime': 0,
5353
'passed_configurations': 4,
54-
'built_configurations': 2,
54+
'built_configurations': 0,
5555
'failed_configurations': 0,
5656
'errored_configurations': 0,
5757
'executed_test_cases': 8,
5858
'skipped_test_cases': 0,
5959
'platform_count': 0,
6060
'executed_on_platform': 4,
61-
'only_built': 2
61+
'only_built': 0
6262
}
6363
)
6464
]

0 commit comments

Comments
 (0)