-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathprint_results.py
executable file
·113 lines (81 loc) · 2.89 KB
/
print_results.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python3
import argparse
import sys
import traceback
from typing import Optional
from ktoolbox import common
import tftbase
def print_flow_test_output(test_output: Optional[tftbase.FlowTestOutput]) -> None:
if test_output is None:
print("Test ID: Unknown test")
return
if not test_output.eval_success:
msg = f"failed: {test_output.eval_msg}"
else:
msg = "succeeded"
print(
f"Test ID: {test_output.tft_metadata.test_case_id.name}, "
f"Test Type: {test_output.tft_metadata.test_type.name}, "
f"Reverse: {common.bool_to_str(test_output.tft_metadata.reverse)}, "
f"TX Bitrate: {test_output.bitrate_gbps.tx} Gbps, "
f"RX Bitrate: {test_output.bitrate_gbps.rx} Gbps, "
f"{msg}"
)
def print_plugin_output(plugin_output: tftbase.PluginOutput) -> None:
msg = f"failed: {plugin_output.eval_msg}"
if not plugin_output.eval_success:
msg = f"failed: {plugin_output.eval_msg}"
else:
msg = "succeeded"
print(" " f"plugin {plugin_output.plugin_metadata.plugin_name}, " f"{msg}")
def print_tft_result(tft_result: tftbase.TftResult) -> None:
print_flow_test_output(tft_result.flow_test)
for plugin_output in tft_result.plugins:
print_plugin_output(plugin_output)
def print_tft_results(tft_results: tftbase.TftResults) -> None:
for tft_result in tft_results:
print_tft_result(tft_result)
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="Tool to prettify the TFT Flow test results"
)
parser.add_argument(
"result",
nargs="+",
help="The JSON result file(s) from TFT Flow test.",
)
common.log_argparse_add_argument_verbose(parser)
args = parser.parse_args()
common.log_config_logger(args.verbose, "tft", "ktoolbox")
return args
def process_file(result_file: str) -> bool:
tft_results = tftbase.TftResults.parse_from_file(result_file)
group_success, group_fail = tft_results.group_by_success()
print(
f"There are {len(group_success)} passing flows in {repr(result_file)}.{' Details:' if group_success else ''}"
)
print_tft_results(group_success)
print(
f"There are {len(group_fail)} failing flows in {repr(result_file)}.{' Details:' if group_fail else ''}"
)
print_tft_results(group_fail)
print()
return not group_fail
def main() -> None:
args = parse_args()
failed_files: list[str] = []
for result_file in args.result:
if not process_file(result_file):
failed_files.append(result_file)
print()
if failed_files:
print(f"Failures detected in {repr(failed_files)}")
sys.exit(1)
print("No failures detected in results")
sys.exit(0)
if __name__ == "__main__":
try:
main()
except Exception:
traceback.print_exc()
sys.exit(2)