Skip to content

Commit

Permalink
contest: kunit: make more resilient against failures
Browse files Browse the repository at this point in the history
If build fails return a fail, don't crash.

Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
kuba-moo committed Jan 8, 2024
1 parent a48e024 commit 7b6771a
Showing 1 changed file with 32 additions and 13 deletions.
45 changes: 32 additions & 13 deletions contest/remote/kunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
"""


class InfraFail(Exception):
pass


str_to_code = {
'pass': 0,
'PASS': 0,
Expand Down Expand Up @@ -110,27 +114,42 @@ def test(binfo, rinfo, config):
rinfo['run-cookie'])
os.makedirs(results_path)

link = config.get('www', 'url') + '/' + \
config.get('local', 'results_path') + '/' + \
rinfo['run-cookie']

with open(os.path.join(results_path, 'stdout'), 'w') as fp:
fp.write(stdout)
with open(os.path.join(results_path, 'stderr'), 'w') as fp:
fp.write(stderr)

results_json = stdout_get_json(stdout)
expected = load_expected(config)
bad_tests, res = summary_result(expected, results_json)

if bad_tests:
with open(os.path.join(results_path, 'bad_tests'), 'w') as fp:
fp.write('\n'.join(bad_tests))
try:
if process.returncode:
raise InfraFail(f'retcode {process.returncode}')

results_json = stdout_get_json(stdout)
if results_json is None:
raise InfraFail('no JSON')
expected = load_expected(config)
bad_tests, res = summary_result(expected, results_json)

if bad_tests:
with open(os.path.join(results_path, 'bad_tests'), 'w') as fp:
fp.write('\n'.join(bad_tests))

cases = [{'test': config.get('executor', 'test'),
'group': config.get('executor', 'group'),
'result': res, 'link': link}]
except InfraFail as e:
with open(os.path.join(results_path, 'infra_fail'), 'w') as fp:
fp.write(e.args[0])
cases = [{'test': config.get('executor', 'test'),
'group': config.get('executor', 'group'),
'result': 'fail', 'link': link}]

link = config.get('www', 'url') + '/' + \
config.get('local', 'results_path') + '/' + \
rinfo['run-cookie']
print("Done at", datetime.datetime.now())

return [{'test': config.get('executor', 'test'),
'group': config.get('executor', 'group'),
'result': res, 'link': link}]
return cases


def main() -> None:
Expand Down

0 comments on commit 7b6771a

Please sign in to comment.