linux: gpiod: add a parser

update the log parser for gpiod to produce LAVA pass/fail output.

from:
ok <number> <testcase>

To:
<testcase> pass

Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
diff --git a/automated/linux/gpiod/gpiod.sh b/automated/linux/gpiod/gpiod.sh
index 9b1d0bd..6a87571 100755
--- a/automated/linux/gpiod/gpiod.sh
+++ b/automated/linux/gpiod/gpiod.sh
@@ -2,6 +2,8 @@
 
 . ../../lib/sh-test-lib
 GPIOD_PATH=${1:-"/opt/libgpiod/bin/"}
+LOGFILE=tmp.txt
+RESULT_FILE=result.txt
 
 export PATH="${GPIOD_PATH}:$PATH"
 
@@ -11,9 +13,4 @@
 mount_debugfs
 
 gpiod-test 2>&1| tee tmp.txt
-sed 's/\[[0-9;]*m//g'  tmp.txt \
-	| grep '\[TEST\]' \
-	| sed 's/\[TEST\]//' \
-	| sed -r "s/'//g; s/^ *//; s/-//; s/[^a-zA-Z0-9]/-/g; s/--+/-/g; s/-PASS/ pass/; s/-FAIL/ fail/; s/-SKIP/ skip/; s/-//;" 2>&1 \
-	| tee -a result.txt
-rm tmp.txt
+./parse-output.py < "${LOGFILE}" | tee -a "${RESULT_FILE}"
diff --git a/automated/linux/gpiod/parse-output.py b/automated/linux/gpiod/parse-output.py
new file mode 100755
index 0000000..d7761bb
--- /dev/null
+++ b/automated/linux/gpiod/parse-output.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python3
+import sys
+import re
+
+
+def slugify(line):
+    non_ascii_pattern = r"[^A-Za-z0-9_-]+"
+    line = re.sub(r"\[\d{1,5}\]", "", line)
+    line = re.sub(r"^_", "", line)
+    return re.sub(
+        r"_-", "_", re.sub(r"(^_|_$)", "", re.sub(non_ascii_pattern, "_", line))
+    )
+
+
+tests = ""
+for line in sys.stdin:
+    if re.search(r"^.*?not ok \d{1,5} ", line):
+        match = re.match(r"^.*?not ok [0-9]+ (.*?)$", line)
+        ascii_test_line = slugify(re.sub("# .*$", "", match.group(1)))
+        output = f"{tests}_{ascii_test_line} fail"
+        print(f"{output}")
+    elif re.search(r"^ok \d{1,5} ", line):
+        match = re.match(r"^.*?ok [0-9]+ (.*?)$", line)
+        ascii_test_line = slugify(match.group(1))
+        output = f"{tests}_{ascii_test_line} pass"
+        print(f"{output}")