Mesa (main): ci/lava: Fix Gitlab Section markers

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon May 23 17:25:47 UTC 2022


Module: Mesa
Branch: main
Commit: ee2278de654853f1d6107e6ef6fc8537a668866e
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=ee2278de654853f1d6107e6ef6fc8537a668866e

Author: Guilherme Gallo <guilherme.gallo at collabora.com>
Date:   Sun May 15 21:44:48 2022 -0300

ci/lava: Fix Gitlab Section markers

LAVA is mangling the escape codes from ANSI during log fetching from the
target device, making the gitlab section markers from deqp, for example,
to not work, inputting noise into the log.

This commit makes the simplest fix which is to replace the mangled
characters to the fixed ones.

This approach is error-prone, since it may unwittingly replace a genuine
log that resembles the mangled escape code. But this solution should
suffice until we get a proper fix from LAVA team itself.

Signed-off-by: Guilherme Gallo <guilherme.gallo at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16520>

---

 .gitlab-ci/lava/lava_job_submitter.py       | 19 +++++++++++++++
 .gitlab-ci/tests/test_lava_job_submitter.py | 37 +++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+)

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",
+    ),
+}
+
+
+ at 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



More information about the mesa-commit mailing list