From 3b8d10d270413a1f49ccce5563c1e4e96e10b6ef Mon Sep 17 00:00:00 2001 From: Guilherme Gallo Date: Tue, 21 Jun 2022 16:30:34 -0300 Subject: [PATCH] ci/lava: Improve result parsing regex LAVA job logs have an ongoing problem of message interleaving with kmsg. So any kernel dumps and LAVA signals (which are being printed in kmsg) will have a chance to clutter the pattern matching for `hwci: mesa: (pass|fail)` line. v2: - Add an 1 second sleep before exiting the test script, to give enough time to print the result message without conflicting with LAVA ENDTC signal from kmsg Closes: #6714 Signed-off-by: Guilherme Gallo Part-of: --- .gitlab-ci/common/init-stage2.sh | 4 ++ .gitlab-ci/lava/lava_job_submitter.py | 2 +- .gitlab-ci/tests/test_lava_job_submitter.py | 49 +++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci/common/init-stage2.sh b/.gitlab-ci/common/init-stage2.sh index 2f6f498c9d6..ff73ec8a06f 100755 --- a/.gitlab-ci/common/init-stage2.sh +++ b/.gitlab-ci/common/init-stage2.sh @@ -157,5 +157,9 @@ fi # We still need to echo the hwci: mesa message, as some scripts rely on it, such # as the python ones inside the bare-metal folder [ ${EXIT_CODE} -eq 0 ] && RESULT=pass + +set +x echo "hwci: mesa: $RESULT" +# Sleep a bit to avoid kernel dump message interleave from LAVA ENDTC signal +sleep 1 exit $EXIT_CODE diff --git a/.gitlab-ci/lava/lava_job_submitter.py b/.gitlab-ci/lava/lava_job_submitter.py index f9d4d89b893..9eba34c8820 100755 --- a/.gitlab-ci/lava/lava_job_submitter.py +++ b/.gitlab-ci/lava/lava_job_submitter.py @@ -313,7 +313,7 @@ class LAVAJob: """ log_lines = [l["msg"] for l in lava_lines if l["lvl"] == "target"] for line in log_lines: - if result := re.search(r"hwci: mesa: (\S*)", line): + if result := re.search(r"hwci: mesa: (pass|fail)", line): self.is_finished = True self.status = result.group(1) color = LAVAJob.color_status_map.get(self.status, CONSOLE_LOG_COLOR_RED) diff --git a/.gitlab-ci/tests/test_lava_job_submitter.py b/.gitlab-ci/tests/test_lava_job_submitter.py index 76a43c33eff..9e010b46b14 100644 --- a/.gitlab-ci/tests/test_lava_job_submitter.py +++ b/.gitlab-ci/tests/test_lava_job_submitter.py @@ -421,6 +421,7 @@ GITLAB_SECTION_MANGLED_SCENARIOS = { ), } + @pytest.mark.parametrize( "message, fixed_message", GITLAB_SECTION_MANGLED_SCENARIOS.values(), @@ -464,3 +465,51 @@ LAVA_DEBUG_SPAM_MESSAGES = { ) def test_filter_debug_messages(message, expectation): assert filter_debug_messages(message) == expectation + + +LAVA_RESULT_LOG_SCENARIOS = { + # the submitter should accept xtrace logs + "Bash xtrace echo with kmsg interleaving": ( + create_lava_yaml_msg( + msg="echo hwci: mesa: pass[ 737.673352] ", + lvl="target", + ), + "pass", + ), + # the submitter should accept xtrace logs + "kmsg result print": ( + create_lava_yaml_msg( + msg="[ 737.673352] hwci: mesa: pass", + lvl="target", + ), + "pass", + ), + # if the job result echo has a very bad luck, it still can be interleaved + # with kmsg + "echo output with kmsg interleaving": ( + create_lava_yaml_msg( + msg="hwci: mesa: pass[ 737.673352] ", + lvl="target", + ), + "pass", + ), + "fail case": ( + create_lava_yaml_msg( + msg="hwci: mesa: fail", + lvl="target", + ), + "fail", + ), +} + + +@pytest.mark.parametrize( + "message, expectation", + LAVA_RESULT_LOG_SCENARIOS.values(), + ids=LAVA_RESULT_LOG_SCENARIOS.keys(), +) +def test_filter_debug_messages(message, expectation, mock_proxy): + job = LAVAJob(mock_proxy(), "") + job.parse_job_result_from_log([message]) + + assert job.status == expectation