xref: /freebsd/sys/contrib/openzfs/.github/workflows/scripts/merge_summary.awk (revision b64c5a0ace59af62eff52bfe110a521dc73c937b)
1#!/bin/awk -f
2#
3# Merge multiple ZTS tests results summaries into a single summary.  This is
4# needed when you're running different parts of ZTS on different tests
5# runners or VMs.
6#
7# Usage:
8#
9#	./merge_summary.awk summary1.txt [summary2.txt] [summary3.txt] ...
10#
11#	or:
12#
13#	cat summary*.txt | ./merge_summary.awk
14#
15BEGIN {
16	i=-1
17	pass=0
18	fail=0
19	skip=0
20	state=""
21	cl=0
22	el=0
23	upl=0
24	ul=0
25
26	# Total seconds of tests runtime
27	total=0;
28}
29
30# Skip empty lines
31/^\s*$/{next}
32
33# Skip Configuration and Test lines
34/^Test:/{state=""; next}
35/Configuration/{state="";next}
36
37# When we see "test-runner.py" stop saving config lines, and
38# save test runner lines
39/test-runner.py/{state="testrunner"; runner=runner$0"\n"; next}
40
41# We need to differentiate the PASS counts from test result lines that start
42# with PASS, like:
43#
44#   PASS mv_files/setup
45#
46# Use state="pass_count" to differentiate
47#
48/Results Summary/{state="pass_count"; next}
49/PASS/{ if (state=="pass_count") {pass += $2}}
50/FAIL/{ if (state=="pass_count") {fail += $2}}
51/SKIP/{ if (state=="pass_count") {skip += $2}}
52/Running Time/{
53	state="";
54	running[i]=$3;
55	split($3, arr, ":")
56	total += arr[1] * 60 * 60;
57	total += arr[2] * 60;
58	total += arr[3]
59	next;
60}
61
62/Tests with results other than PASS that are expected/{state="expected_lines"; next}
63/Tests with result of PASS that are unexpected/{state="unexpected_pass_lines"; next}
64/Tests with results other than PASS that are unexpected/{state="unexpected_lines"; next}
65{
66	if (state == "expected_lines") {
67		expected_lines[el] = $0
68		el++
69	}
70
71	if (state == "unexpected_pass_lines") {
72		unexpected_pass_lines[upl] = $0
73		upl++
74	}
75	if (state == "unexpected_lines") {
76		unexpected_lines[ul] = $0
77		ul++
78	}
79}
80
81# Reproduce summary
82END {
83	print runner;
84	print "\nResults Summary"
85	print "PASS\t"pass
86	print "FAIL\t"fail
87	print "SKIP\t"skip
88	print ""
89	print "Running Time:\t"strftime("%T", total, 1)
90	if (pass+fail+skip > 0) {
91		percent_passed=(pass/(pass+fail+skip) * 100)
92	}
93	printf "Percent passed:\t%3.2f%", percent_passed
94
95	print "\n\nTests with results other than PASS that are expected:"
96	asort(expected_lines, sorted)
97	for (j in sorted)
98		print sorted[j]
99
100	print "\n\nTests with result of PASS that are unexpected:"
101	asort(unexpected_pass_lines, sorted)
102	for (j in sorted)
103		print sorted[j]
104
105	print "\n\nTests with results other than PASS that are unexpected:"
106	asort(unexpected_lines, sorted)
107	for (j in sorted)
108		print sorted[j]
109}
110