twister: add setting skip reason

When testcase written in ztest is skipped by ztest_test_skip() function,
then "SKIP" information is printed in output data. This "SKIP" result is
set as result of performed testcase, but the information about reason is
still "Unknown". This patch fix this problem and if all test scenario
has state "passed" (so testcases have result "PASS" or "SKIP"), reason
is still set as "Unknown" and if any of testcase has result "SKIP" then
set reason as "ztest skip".

Fixes #42414

Signed-off-by: Piotr Golyzniak <piotr.golyzniak@nordicsemi.no>
This commit is contained in:
Piotr Golyzniak 2022-02-02 16:37:05 +01:00 committed by Anas Nashif
commit c8862db1d9

View file

@ -453,6 +453,21 @@ class Handler:
if c not in harness.tests:
harness.tests[c] = "BLOCK"
def _set_skip_reason(self, harness_state):
"""
If testcase written in ztest framework is skipped by "ztest_test_skip()"
function, then such testcase is marked in instance.results dict as
"SKIP", but reason of this sipping still "Unknown". This method pick up
this situation and complete the instance.reason properly.
"""
harness_state_pass = "passed"
harness_testcase_result_skip = "SKIP"
instance_reason_unknown = "Unknown"
if harness_state == harness_state_pass and \
self.instance.reason == instance_reason_unknown and \
harness_testcase_result_skip in self.instance.results.values():
self.instance.reason = "ztest skip"
class BinaryHandler(Handler):
def __init__(self, instance, type_str):
@ -609,6 +624,8 @@ class BinaryHandler(Handler):
self.instance.reason = "Timeout"
self.add_missing_testscases(harness)
self._set_skip_reason(harness.state)
self.record(harness)
@ -905,6 +922,8 @@ class DeviceHandler(Handler):
else:
self.set_state(out_state, handler_time)
self._set_skip_reason(harness.state)
if post_script:
self.run_custom_script(post_script, 30)
@ -1173,6 +1192,8 @@ class QEMUHandler(Handler):
self.instance.reason = "Exited with {}".format(self.returncode)
self.add_missing_testscases(harness)
self._set_skip_reason(harness.state)
def get_fifo(self):
return self.fifo_fn