Skip to content

Commit 140f9f2

Browse files
Naresh Kambojuroxell
Naresh Kamboju
authored andcommitted
kvm-unit-tests: output test results in TAP13 format
This patch introduces TAP13 results format of kvm-unit-tests by adding flag '-t|--tap13' to kvm-unit-tests run_tests.sh script, it menas that the test results output in a TAP13 format. The new script, parse-output.py, to handle the parsing of kvm-unit-tests outputs. The script reads input from the standard input, processes each line to determine the test results as the LAVA understand. e.g. <test-name> <pass|fail|skip> Signed-off-by: Naresh Kamboju <naresh.kamboju@linaro.org>
1 parent c44e2c1 commit 140f9f2

File tree

2 files changed

+73
-16
lines changed

2 files changed

+73
-16
lines changed

automated/linux/kvm-unit-tests/kvm-unit-tests.sh

+5-16
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,16 @@ while getopts "s:m:g:h" o; do
2727
done
2828

2929
parse_output() {
30-
# Parse each type of results
31-
# A note on the sed line used below to strip color codes:
32-
# busybox's sed does not implement e.g. '\x1b', and so the literal
33-
# control code is used below. Do not copy/paste it, or it will lose
34-
# its magic.
35-
grep -e PASS -e SKIP -e FAIL "${RESULT_LOG}" | \
36-
sed 's/\[[0-9]*m//g' | \
37-
sed -e 's/PASS/pass/g' \
38-
-e 's/SKIP/skip/g' \
39-
-e 's/FAIL/fail/g' | \
40-
awk '{print $2" "$1}' >> "${RESULT_FILE}"
41-
cat "${RESULT_FILE}"
30+
# Parse input test names and results log to results file
31+
./parse-output.py < "${RESULT_LOG}" | tee -a "${RESULT_FILE}"
4232
}
4333

4434
kvm_unit_tests_run_test() {
4535
info_msg "running kvm unit tests ..."
4636
if [ "${SMP}" = "false" ]; then
47-
taskset -c 0 ./run_tests.sh -a -v | tee -a "${RESULT_LOG}"
37+
taskset -c 0 ./run_tests.sh -a -t -v | tee -a "${RESULT_LOG}"
4838
else
49-
./run_tests.sh -a -v | tee -a "${RESULT_LOG}"
39+
./run_tests.sh -a -t -v | tee -a "${RESULT_LOG}"
5040
fi
5141
}
5242

@@ -84,8 +74,6 @@ install() {
8474
# Test run.
8575
! check_root && error_msg "This script must be run as root"
8676
create_out_dir "${OUTPUT}"
87-
# shellcheck disable=SC2164
88-
cd "${OUTPUT}"
8977

9078
info_msg "About to run kvm unit tests ..."
9179
info_msg "Output directory: ${OUTPUT}"
@@ -107,6 +95,7 @@ fi
10795

10896
# Run kvm unit tests
10997
kvm_unit_tests_run_test
98+
cd - || exit 1
11099

111100
# Parse and print kvm unit tests results
112101
parse_output
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env python3
2+
import sys
3+
import re
4+
5+
6+
def parse_line(line):
7+
"""
8+
Parses a single line of input to extract the test result and description.
9+
10+
Args:
11+
line (str): A single line of input.
12+
13+
Returns:
14+
tuple: A tuple containing the result and description.
15+
"""
16+
17+
if not line.startswith("ok") and not line.startswith("not ok"):
18+
return None, None
19+
20+
parts = re.split(r" \d+ - ", line)
21+
if len(parts) < 2:
22+
raise ValueError(f"Invalid line format: {line}")
23+
24+
result = "pass" if parts[0] == "ok" else "fail"
25+
description = parts[1].strip()
26+
27+
if "# skip" in description.lower():
28+
result = "skip"
29+
description = description.split("# skip")[0].strip()
30+
31+
return result, description
32+
33+
34+
def sanitize_description(description):
35+
"""
36+
Sanitizes the description by replacing spaces with dashes, removing special characters, and avoiding double dashes.
37+
38+
Args:
39+
description (str): The test description.
40+
41+
Returns:
42+
str: The sanitized description.
43+
"""
44+
description = description.replace(" ", "-")
45+
description = re.sub(r"[^a-zA-Z0-9_-]+", "", description) # Slugify
46+
description = re.sub(
47+
r"-+", "-", description
48+
) # Replace multiple dashes with a single dash
49+
return description
50+
51+
52+
def main():
53+
"""
54+
Main function to parse input, process each line, and output the results.
55+
"""
56+
lines = sys.stdin.readlines()
57+
58+
for line in lines:
59+
result, description = parse_line(line)
60+
61+
if not result or not description:
62+
continue
63+
64+
print(f"{sanitize_description(description)} {result}")
65+
66+
67+
if __name__ == "__main__":
68+
main()

0 commit comments

Comments
 (0)