Commit 147997af authored by Jakub Kicinski's avatar Jakub Kicinski

selftests: net: ksft: avoid continue when handling results

Exception handlers print the result and use continue
to skip the non-exception result printing. This makes
inserting common post-test code hard. Refactor to
avoid the continues and have only one ktap_result() call.
Reviewed-by: default avatarPetr Machata <petrm@nvidia.com>
Link: https://patch.msgid.link/20240627185502.3069139-2-kuba@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent bf7bb7b4
...@@ -130,29 +130,29 @@ def ksft_run(cases=None, globs=None, case_pfx=None, args=()): ...@@ -130,29 +130,29 @@ def ksft_run(cases=None, globs=None, case_pfx=None, args=()):
for case in cases: for case in cases:
KSFT_RESULT = True KSFT_RESULT = True
cnt += 1 cnt += 1
comment = ""
cnt_key = ""
try: try:
case(*args) case(*args)
except KsftSkipEx as e: except KsftSkipEx as e:
ktap_result(True, cnt, case, comment="SKIP " + str(e)) comment = "SKIP " + str(e)
totals['skip'] += 1 cnt_key = 'skip'
continue
except KsftXfailEx as e: except KsftXfailEx as e:
ktap_result(True, cnt, case, comment="XFAIL " + str(e)) comment = "XFAIL " + str(e)
totals['xfail'] += 1 cnt_key = 'xfail'
continue
except Exception as e: except Exception as e:
tb = traceback.format_exc() tb = traceback.format_exc()
for line in tb.strip().split('\n'): for line in tb.strip().split('\n'):
ksft_pr("Exception|", line) ksft_pr("Exception|", line)
ktap_result(False, cnt, case) KSFT_RESULT = False
totals['fail'] += 1 cnt_key = 'fail'
continue
if not cnt_key:
ktap_result(KSFT_RESULT, cnt, case) cnt_key = 'pass' if KSFT_RESULT else 'fail'
if KSFT_RESULT:
totals['pass'] += 1 ktap_result(KSFT_RESULT, cnt, case, comment=comment)
else: totals[cnt_key] += 1
totals['fail'] += 1
print( print(
f"# Totals: pass:{totals['pass']} fail:{totals['fail']} xfail:{totals['xfail']} xpass:0 skip:{totals['skip']} error:0" f"# Totals: pass:{totals['pass']} fail:{totals['fail']} xfail:{totals['xfail']} xpass:0 skip:{totals['skip']} error:0"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment