diff --git a/.gitlab-ci/lava/lava_job_submitter.py b/.gitlab-ci/lava/lava_job_submitter.py index 8a1968b7eb9..68f2efdfa5a 100755 --- a/.gitlab-ci/lava/lava_job_submitter.py +++ b/.gitlab-ci/lava/lava_job_submitter.py @@ -381,6 +381,25 @@ def fix_lava_color_log(line): line["msg"] = re.sub(r"(\[\d{1,2}m)", "\x1b" + r"\1", line["msg"]) +def fix_lava_gitlab_section_log(line): + """This function is a temporary solution for the Gitlab section markers + mangling problem. Gitlab parses the following lines to define a collapsible + gitlab section in their log: + - \x1b[0Ksection_start:timestamp:section_id[collapsible=true/false]\r\x1b[0Ksection_header + - \x1b[0Ksection_end:timestamp:section_id\r\x1b[0K + There is some problem in message passing between the LAVA dispatcher and the + device under test (DUT), that digests \x1b and \r control characters + incorrectly. When this problem is fixed on the LAVA side, one should remove + this function. + """ + if match := re.match(r"\[0K(section_\w+):(\d+):(\S+)\[0K([\S ]+)?", line["msg"]): + marker, timestamp, id_collapsible, header = match.groups() + # The above regex serves for both section start and end lines. + # When the header is None, it means we are dealing with `section_end` line + header = header or "" + line["msg"] = f"\x1b[0K{marker}:{timestamp}:{id_collapsible}\r\x1b[0K{header}" + + def parse_lava_lines(new_lines) -> list[str]: parsed_lines: list[str] = [] for line in new_lines: diff --git a/.gitlab-ci/tests/test_lava_job_submitter.py b/.gitlab-ci/tests/test_lava_job_submitter.py index cfb670a9e68..975b1939ff2 100644 --- a/.gitlab-ci/tests/test_lava_job_submitter.py +++ b/.gitlab-ci/tests/test_lava_job_submitter.py @@ -38,6 +38,7 @@ from lava.lava_job_submitter import ( NUMBER_OF_RETRIES_TIMEOUT_DETECTION, LAVAJob, fix_lava_color_log, + fix_lava_gitlab_section_log, follow_job_execution, hide_sensitive_data, retriable_follow_job, @@ -375,3 +376,39 @@ def test_fix_lava_color_log(message, fixed_message): fix_lava_color_log(message) assert message["msg"] == fixed_message + + +GITLAB_SECTION_MANGLED_SCENARIOS = { + "Mangled section_start at target level": ( + create_lava_yaml_msg( + msg="[0Ksection_start:1652658415:deqp[collapsed=false][0Kdeqp-runner", + lvl="target", + ), + "\x1b[0Ksection_start:1652658415:deqp[collapsed=false]\r\x1b[0Kdeqp-runner", + ), + "Mangled section_start at target level with header with spaces": ( + create_lava_yaml_msg( + msg="[0Ksection_start:1652658415:deqp[collapsed=false][0Kdeqp runner stats", + lvl="target", + ), + "\x1b[0Ksection_start:1652658415:deqp[collapsed=false]\r\x1b[0Kdeqp runner stats", + ), + "Mangled section_end at target level": ( + create_lava_yaml_msg( + msg="[0Ksection_end:1652658415:test_setup[0K", + lvl="target", + ), + "\x1b[0Ksection_end:1652658415:test_setup\r\x1b[0K", + ), +} + + +@pytest.mark.parametrize( + "message, fixed_message", + GITLAB_SECTION_MANGLED_SCENARIOS.values(), + ids=GITLAB_SECTION_MANGLED_SCENARIOS.keys(), +) +def test_fix_lava_gitlab_section_log(message, fixed_message): + fix_lava_gitlab_section_log(message) + + assert message["msg"] == fixed_message