forked from Linaro/test-definitions
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Showing
2 changed files
with
73 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env python3 | ||
import sys | ||
import re | ||
|
||
|
||
def parse_line(line): | ||
""" | ||
Parses a single line of input to extract the test result and description. | ||
Args: | ||
line (str): A single line of input. | ||
Returns: | ||
tuple: A tuple containing the result and description. | ||
""" | ||
|
||
if not line.startswith("ok") and not line.startswith("not ok"): | ||
return None, None | ||
|
||
parts = re.split(r" \d+ - ", line) | ||
if len(parts) < 2: | ||
raise ValueError(f"Invalid line format: {line}") | ||
|
||
result = "pass" if parts[0] == "ok" else "fail" | ||
description = parts[1].strip() | ||
|
||
if "# skip" in description.lower(): | ||
result = "skip" | ||
description = description.split("# skip")[0].strip() | ||
|
||
return result, description | ||
|
||
|
||
def sanitize_description(description): | ||
""" | ||
Sanitizes the description by replacing spaces with dashes, removing special characters, and avoiding double dashes. | ||
Args: | ||
description (str): The test description. | ||
Returns: | ||
str: The sanitized description. | ||
""" | ||
description = description.replace(" ", "-") | ||
description = re.sub(r"[^a-zA-Z0-9_-]+", "", description) # Slugify | ||
description = re.sub( | ||
r"-+", "-", description | ||
) # Replace multiple dashes with a single dash | ||
return description | ||
|
||
|
||
def main(): | ||
""" | ||
Main function to parse input, process each line, and output the results. | ||
""" | ||
lines = sys.stdin.readlines() | ||
|
||
for line in lines: | ||
result, description = parse_line(line) | ||
|
||
if not result or not description: | ||
continue | ||
|
||
print(f"{sanitize_description(description)} {result}") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |