From 7b6771aea9283884ef733a27f00e1a802a5b5ee4 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Mon, 8 Jan 2024 06:55:52 -0800 Subject: [PATCH] contest: kunit: make more resilient against failures If build fails return a fail, don't crash. Signed-off-by: Jakub Kicinski --- contest/remote/kunit.py | 45 +++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/contest/remote/kunit.py b/contest/remote/kunit.py index 90ede72..db74a70 100755 --- a/contest/remote/kunit.py +++ b/contest/remote/kunit.py @@ -35,6 +35,10 @@ """ +class InfraFail(Exception): + pass + + str_to_code = { 'pass': 0, 'PASS': 0, @@ -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: