Mesa (main): ci/lava: Add support for more complex color codes

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jun 15 19:42:23 UTC 2022


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

Author: Guilherme Gallo <guilherme.gallo at collabora.com>
Date:   Tue Jun 14 23:39:22 2022 -0300

ci/lava: Add support for more complex color codes

Currently, the LAVA job submitter is employing a temporary solution for
the bash escape code mangling in the LAVA jobs. Until the issue is not
fixed on the LAVA side, the submitter will replace the wrong characters
with the fixed ones.

This commit improves the regex pattern to comprehend the scenarios of
color codes with font formatting and background color information, such
as: `echo -e "\e[1;41;39mRed background with white bold text color\e[0m"`

Fixes: #5503

Signed-off-by: Guilherme Gallo <guilherme.gallo at collabora.com>
Reviewed-by: David Heidelberg <david.heidelberg at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17046>

---

 .gitlab-ci/lava/lava_job_submitter.py       |  8 +++++---
 .gitlab-ci/tests/test_lava_job_submitter.py | 18 ++++++++++++++++++
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/.gitlab-ci/lava/lava_job_submitter.py b/.gitlab-ci/lava/lava_job_submitter.py
index 68f2efdfa5a..3c53c440d47 100755
--- a/.gitlab-ci/lava/lava_job_submitter.py
+++ b/.gitlab-ci/lava/lava_job_submitter.py
@@ -375,10 +375,12 @@ def fix_lava_color_log(line):
     """This function is a temporary solution for the color escape codes mangling
     problem. There is some problem in message passing between the LAVA
     dispatcher and the device under test (DUT). Here \x1b character is missing
-    before `[:digit::digit:?m` ANSI TTY color codes. When this problem is fixed
-    on the LAVA side, one should remove this function.
+    before `[:digit::digit:?:digit:?m` ANSI TTY color codes, or the more
+    complicated ones with number values for text format before background and
+    foreground colors.
+    When this problem is fixed on the LAVA side, one should remove this function.
     """
-    line["msg"] = re.sub(r"(\[\d{1,2}m)", "\x1b" + r"\1", line["msg"])
+    line["msg"] = re.sub(r"(\[(\d+;){0,2}\d{1,3}m)", "\x1b" + r"\1", line["msg"])
 
 
 def fix_lava_gitlab_section_log(line):
diff --git a/.gitlab-ci/tests/test_lava_job_submitter.py b/.gitlab-ci/tests/test_lava_job_submitter.py
index 975b1939ff2..def946c1ac9 100644
--- a/.gitlab-ci/tests/test_lava_job_submitter.py
+++ b/.gitlab-ci/tests/test_lava_job_submitter.py
@@ -364,6 +364,24 @@ COLOR_MANGLED_SCENARIOS = {
         ),
         "\x1b[0mPass: 26718, ExpectedFail: 95, Skip: 25187, Duration: 8:18, Remaining: 13",
     ),
+    "Mangled error message with bold formatting at target level": (
+        create_lava_yaml_msg(msg="[1;31mReview the image changes...", lvl="target"),
+        "\x1b[1;31mReview the image changes...",
+    ),
+    "Mangled error message with high intensity background at target level": (
+        create_lava_yaml_msg(msg="[100mReview the image changes...", lvl="target"),
+        "\x1b[100mReview the image changes...",
+    ),
+    "Mangled error message with underline+bg color+fg color at target level": (
+        create_lava_yaml_msg(msg="[4;41;97mReview the image changes...", lvl="target"),
+        "\x1b[4;41;97mReview the image changes...",
+    ),
+    "Bad input for color code.": (
+        create_lava_yaml_msg(
+            msg="[4;97 This message is missing the `m`.", lvl="target"
+        ),
+        "[4;97 This message is missing the `m`.",
+    ),
 }
 
 



More information about the mesa-commit mailing list