182 lines
7.5 KiB
Python
182 lines
7.5 KiB
Python
"""Colorize xfstests.zsh output."""
|
|
import sys
|
|
import re
|
|
import termcolor
|
|
|
|
|
|
PROTO_COLORS = {"tcp": "white", "rdma": "yellow"}
|
|
STATUS_COLORS = {"Ran": "cyan", "Not run": "magenta", "Failures": "red"}
|
|
VERS_COLORS = {"v3": "red", "v4.0": "green", "v4.1": "blue", "v4.2": "yellow"}
|
|
|
|
PROTO = sys.argv[1]
|
|
VERS = f"v{sys.argv[2]}"
|
|
COLOR = VERS_COLORS[VERS]
|
|
PROTO_COLOR = PROTO_COLORS[PROTO]
|
|
CONFIG = []
|
|
|
|
PREFIX = termcolor.colored("[", "white", attrs=["bold"])
|
|
PREFIX += termcolor.colored(PROTO.rjust(4), PROTO_COLOR, attrs=["dark"])
|
|
PREFIX += termcolor.colored(",", "white", attrs=["bold"])
|
|
PREFIX += termcolor.colored(VERS.ljust(4), COLOR, attrs=["bold"])
|
|
PREFIX += termcolor.colored("] ", "white", attrs=["bold"])
|
|
|
|
|
|
def add_config(line: str) -> None:
|
|
"""Format a configuration entry and add it to the CONFIG list."""
|
|
[key, val] = [s.strip() for s in re.split("--", line)]
|
|
if key == "MKFS_OPTIONS":
|
|
return
|
|
elif key == "MOUNT_OPTIONS" and val[:2] != "-o":
|
|
return
|
|
|
|
parts = [PREFIX]
|
|
parts.append(termcolor.colored(key.ljust(14), COLOR, attrs=["bold"]))
|
|
parts.append(termcolor.colored("-- ", "white", attrs=["dark"]))
|
|
parts.append(termcolor.colored(val, "white", attrs=["bold"]))
|
|
CONFIG.append("".join(parts))
|
|
|
|
|
|
def print_config() -> None:
|
|
"""Print out the collected configuration entries and clear the list."""
|
|
if len(CONFIG) > 0:
|
|
print("\n".join(CONFIG), end="\n\n")
|
|
CONFIG.clear()
|
|
|
|
|
|
def print_test(match: re.Match) -> None:
|
|
"""Format and print a single testcase."""
|
|
parts = [PREFIX]
|
|
parts.append(termcolor.colored(match.group(1), COLOR, attrs=["bold"]))
|
|
|
|
if m := re.match(r"(\[not run\])(.*?\n)", match.group(2)):
|
|
return
|
|
parts.append(termcolor.colored(m.group(1), "yellow"))
|
|
parts.append(termcolor.colored(m.group(2), "white", attrs=["bold"]))
|
|
elif m := re.match(r"(\d+s)( ... +)(\d+s\n)", match.group(2)):
|
|
parts.append(termcolor.colored(m.group(1), "green"))
|
|
parts.append(termcolor.colored(m.group(2), "white", attrs=["dark"]))
|
|
parts.append(termcolor.colored(m.group(3), "green"))
|
|
elif re.match(r"\d+s\n", match.group(2)):
|
|
parts.append(termcolor.colored(match.group(2), "green"))
|
|
else: # Test failed
|
|
line = re.sub(r"\]-", r"\] -", match.group(2))
|
|
parts.append(termcolor.colored(line, "magenta", attrs=["bold"]))
|
|
|
|
print("".join(parts), end="")
|
|
|
|
|
|
def print_diff(line: str) -> None:
|
|
"""Format and print out a single line of a failing test diff."""
|
|
print(PREFIX, end="")
|
|
if re.match(r" +@@.*?@@\n", line):
|
|
termcolor.cprint(line, color="yellow", attrs=["dark"], end="")
|
|
elif re.match(r" +-", line):
|
|
termcolor.cprint(line, color="magenta", attrs=["dark"], end="")
|
|
elif re.match(r" +\+", line):
|
|
termcolor.cprint(line, color="cyan", attrs=["dark"], end="")
|
|
elif re.match(r" +\(Run", line):
|
|
termcolor.cprint(line, color="magenta", attrs=["bold"], end="")
|
|
else:
|
|
termcolor.cprint(line, color="white", attrs=["dark"], end="")
|
|
|
|
|
|
def print_test_list(status: str, line: str) -> None:
|
|
"""Format and print the list of tests that ran, failed, or were skipped."""
|
|
tests = dict()
|
|
_tmp = [t.split("/") for t in line[len(status)+1:].split()]
|
|
[tests.setdefault(t[0], []).append(t[1]) for t in _tmp]
|
|
|
|
for key in sorted(tests.keys()):
|
|
parts = [PREFIX]
|
|
parts.append(termcolor.colored(status, STATUS_COLORS[status],
|
|
attrs=["bold"]))
|
|
parts.append(termcolor.colored(": ", "white", attrs=["bold"]))
|
|
parts.append(termcolor.colored(key, color=COLOR, attrs=["bold"]))
|
|
parts.append(termcolor.colored(": [", "white", attrs=["bold"]))
|
|
for i, test_num in enumerate(sorted(tests[key])):
|
|
sep = termcolor.colored(", ", attrs=["bold"] if i > 0 else "")
|
|
if i != 0:
|
|
parts.append(sep)
|
|
attr = ["bold", "dark"] if i % 2 else ["bold"]
|
|
parts.append(termcolor.colored(test_num, STATUS_COLORS[status],
|
|
attrs=attr))
|
|
parts.append(termcolor.colored("]", "white", attrs=["bold"]))
|
|
print("".join(parts))
|
|
|
|
|
|
def print_failed(match: re.Match) -> None:
|
|
"""Format and print the number of failing tests."""
|
|
parts = [PREFIX]
|
|
parts.append(termcolor.colored("Failed ", "red", attrs=["bold"]))
|
|
parts.append(termcolor.colored(match.group(1), COLOR, attrs=["bold"]))
|
|
parts.append(termcolor.colored(" of ", "red", attrs=["bold"]))
|
|
parts.append(termcolor.colored(match.group(2), COLOR, attrs=["bold"]))
|
|
parts.append(termcolor.colored(" tests", "red", attrs=["bold"]))
|
|
print("".join(parts))
|
|
|
|
|
|
def print_all_passed(match: re.Match) -> None:
|
|
"""Format and print a status line if all tests pass."""
|
|
parts = [PREFIX]
|
|
parts.append(termcolor.colored("Passed all ", "green", attrs=["bold"]))
|
|
parts.append(termcolor.colored(match.group(1), COLOR, attrs=["bold"]))
|
|
parts.append(termcolor.colored(" tests", "green", attrs=["bold"]))
|
|
print("".join(parts))
|
|
|
|
|
|
def print_xunit(match: re.Match) -> None:
|
|
"""Format and print the xunit file location."""
|
|
parts = [PREFIX]
|
|
parts.append(termcolor.colored(match.group(1), PROTO_COLOR,
|
|
attrs=["dark", "bold"]))
|
|
parts.append(termcolor.colored(": ", "white", attrs=["bold"]))
|
|
parts.append(termcolor.colored(match.group(2), COLOR, attrs=["bold"]))
|
|
print("".join(parts))
|
|
|
|
|
|
def print_xfstestsdb(match: re.Match) -> None:
|
|
"""Format and print the xfstestsdb xunit-add line."""
|
|
parts = [PREFIX]
|
|
parts.append(termcolor.colored(match.group(1).title(), PROTO_COLOR,
|
|
attrs=["dark", "bold"]))
|
|
parts.append(termcolor.colored(" '", "white", attrs=["bold"]))
|
|
parts.append(termcolor.colored(match.group(2), COLOR,
|
|
attrs=["bold"]))
|
|
parts.append(termcolor.colored("' ", "white", attrs=["bold"]))
|
|
parts.append(termcolor.colored(match.group(3), PROTO_COLOR,
|
|
attrs=["dark", "bold"]))
|
|
parts.append(termcolor.colored(match.group(4), COLOR, attrs=["bold"]))
|
|
parts.append(termcolor.colored(match.group(5), PROTO_COLOR,
|
|
attrs=["dark", "bold"]))
|
|
parts.append(termcolor.colored(" #", "white", attrs=["bold"]))
|
|
parts.append(termcolor.colored(match.group(6), COLOR,
|
|
attrs=["bold"]))
|
|
print("".join(parts))
|
|
|
|
|
|
for line in sys.stdin:
|
|
if line == "\n":
|
|
print_config()
|
|
elif re.match("^[A-Z_]+[ ]+-- .*?\n", line):
|
|
if match := re.match("(^PLATFORM(.*?)PREEMPT.*?) (.*?\n)", line):
|
|
add_config(match.group(1))
|
|
line = f"COMPILED -- {match.group(3)}"
|
|
add_config(line)
|
|
elif match := re.match(r"(^[a-z]+/\d+[ | ]+)(.*?\n)", line):
|
|
print_test(match)
|
|
elif match := re.match("^ (.*?)\n", line):
|
|
print_diff(line)
|
|
elif match := re.match(r"^(Ran|Not run|Failures):([ a-z]+/\d+)+\n", line):
|
|
print_test_list(match.group(1), line)
|
|
elif match := re.match(r"^Failed (\d+) of (\d+) tests\n", line):
|
|
print_failed(match)
|
|
elif match := re.match(r"^Passed all (\d+) tests\n", line):
|
|
print_all_passed(match)
|
|
elif match := re.match(r"(^Xunit report): (.*?.xml)\n", line):
|
|
print_xunit(match)
|
|
elif match := re.match(r"(^added) '(.*?)' (with )"
|
|
r"(\d+)( testcases to run) #(\d+)\n", line):
|
|
print_xfstestsdb(match)
|
|
else:
|
|
print(PREFIX + line, end="")
|