Work around bug in AIX 7.1 awk in report card tool
[dejagnu.git] / commands / report-card.awk
bloba88b5cb807be1fcc0d07b3b8ee0c777e5dd8a98b
1 # report-card.awk -- Test summary tool
2 # Copyright (C) 2018, 2021, 2024 Free Software Foundation, Inc.
4 # This file is part of DejaGnu.
6 # DejaGnu is free software: you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # DejaGnu is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with DejaGnu. If not, see <http://www.gnu.org/licenses/>.
19 # This file was written by Jacob Bachmeyer.
21 # ##help
22 # #Usage: dejagnu report card [ OPTION | TOOL | FILE ]...
23 # #Usage: dejagnu report-card [ OPTION | TOOL | FILE ]...
24 # # --verbose, -v Emit additional messages
25 # ##end
27 # Arrays storing lists in this program store items in numbered keys, with a
28 # count in the "C" key, similar to Awk's ARGV/ARGC.
30 # The Tools array stores a list of tools in 1..N.
32 # The Passes array stores a global list of passes seen, a per-tool list of
33 # passes seen, and a global index of passes seen if DejaGnu's multipass
34 # support is used.
35 # Key prefixes:
36 # "" -- global list: 1..N; "C"
37 # "t", <tool> -- per-tool list: 1..N; "C"
38 # Key patterns:
39 # "p", <pass> -- count of tools using <pass>
41 # The Totals array stores counts of test results, indexed by tool and pass.
42 # A summarization step adds per-tool, per-pass, and grand totals.
43 # Key patterns:
44 # "tp", <Tool>, <Pass>, <result>
45 # "t", <Tool>, <result>
46 # "p", <Pass>, <result>
47 # <result>
50 ## Get list of files to scan
52 BEGIN {
53 Tools["C"] = 1
54 Passes["", "C"] = 1
55 ToolWidth = 0
56 PassWidth = 0
57 Verbose = 0
58 # remove arguments from ARGV
59 for (i = 1; i < ARGC; i++) {
60 if (ARGV[i] ~ /^-/) {
61 if (ARGV[i] ~ /^--?v(erb.*)?$/)
62 Verbose++
63 else if (ARGV[i] == "--")
64 break
65 delete ARGV[i]
68 if (ARGV[i] == "--")
69 delete ARGV[i]
70 if (Verbose) print "Verbose level is "Verbose
71 # adjust filenames in ARGV
72 FileCount = 0
73 for (i = 1; i < ARGC; i++) {
74 if (i in ARGV) FileCount++
75 else continue
76 if (ARGV[i] ~ /\.sum$/) continue
77 else if (ARGV[i] ~ /\.log$/) sub(/\.log$/, ".sum", ARGV[i])
78 else if (ARGV[i] ~/\.$/) sub(/\.$/, ".sum", ARGV[i])
79 else ARGV[i] = (ARGV[i]".sum")
81 if (FileCount == 0) {
82 cmd_ls_files = "ls -1 *.sum"
83 while (cmd_ls_files | getline File) {
84 FileCount++
85 ARGV[ARGC++] = File
87 close(cmd_ls_files)
89 if (Verbose > 2) {
90 print "Reading "FileCount" file(s)"
91 for (i = 1; i < ARGC; i++)
92 if (i in ARGV)
93 print " "ARGV[i]
98 ## Read files and collect data
100 FNR == 1 {
101 if (Verbose)
102 print "Reading `"FILENAME"' ..."
103 Pass = ""
104 Tool = File = FILENAME
105 sub(/\.sum$/, "", Tool)
106 if (length(Tool) > ToolWidth)
107 ToolWidth = length(Tool)
108 Tools[Tools["C"]++] = Tool
109 Passes["t", Tool, "C"] = 1
110 Passes["t", Tool, 1] = "" # will be overwritten if multipass is used
113 /^Running pass `[^']*' .../ {
114 Pass = $3
115 sub(/^`/, "", Pass)
116 sub(/'$/, "", Pass)
117 if (("p", Pass) in Passes)
118 Passes["p", Pass]++
119 else {
120 if (length(Pass) > PassWidth)
121 PassWidth = length(Pass)
122 Passes["", Passes["", "C"]++] = Pass
123 Passes["p", Pass] = 1
125 Passes["t", Tool, Passes["t", Tool, "C"]++] = Pass
128 $1 ~ /:$/ { sub(/:$/, "", $1); Totals["tp", Tool, Pass, $1]++ }
131 ## Compute totals
133 END {
134 $0 = ("PASS FAIL KPASS KFAIL XPASS XFAIL UNSUPPORTED UNRESOLVED UNTESTED")
135 NF = 9 # work around bug in AIX 7.1 awk
136 for (i = 1; i in Tools; i++)
137 for (j = 1; ("t", Tools[i], j) in Passes; j++)
138 for (k = 1; k <= NF; k++) {
139 Totals[$k] \
140 += Totals["tp", Tools[i], Passes["t", Tools[i], j], $k]
141 Totals["t", Tools[i], $k] \
142 += Totals["tp", Tools[i], Passes["t", Tools[i], j], $k]
143 Totals["p", Passes["t", Tools[i], j], $k] \
144 += Totals["tp", Tools[i], Passes["t", Tools[i], j], $k]
149 ## Compute total name column width
151 END {
152 if (Passes["", "C"] > 1)
153 NameWidth = ToolWidth + 3 + PassWidth
154 else
155 NameWidth = ToolWidth
159 ## Emit header
161 END {
162 printf "%*s __________________________________________________\n", \
163 NameWidth, ""
164 printf "%*s / %6s %6s %6s %6s %6s %6s %6s\n", NameWidth, "", \
165 "PASS", "FAIL", "?PASS", "?FAIL", "UNSUP", "UNRES", "UNTEST"
166 printf "%*s |--------------------------------------------------\n", \
167 NameWidth, ""
171 ## Emit counts
173 END {
174 for (i = 1; i in Tools; i++) {
175 Tool = Tools[i]
176 for (j = 1; ("t", Tool, j) in Passes; j++) {
177 Pass = Passes["t", Tool, j]
178 if (Passes["t", Tool, "C"] > 1)
179 printf "%*s / %-*s | ", ToolWidth, Tool, PassWidth, Pass
180 else if (Passes["", "C"] > 1)
181 printf "%*s %*s | ", ToolWidth, Tool, PassWidth, ""
182 else
183 printf "%*s | ", NameWidth, Tool
184 # Passes["t", <tool>, 1] is a pass name or a null string if
185 # <tool> did not use multipass.
186 printf " %6d %6d %6d %6d %6d %6d %6d%s%s\n", \
187 Totals["tp", Tool, Pass, "PASS"], \
188 Totals["tp", Tool, Pass, "FAIL"], \
189 Totals["tp", Tool, Pass, "KPASS"] \
190 + Totals["tp", Tool, Pass, "XPASS"], \
191 Totals["tp", Tool, Pass, "KFAIL"] \
192 + Totals["tp", Tool, Pass, "XFAIL"], \
193 Totals["tp", Tool, Pass, "UNSUPPORTED"], \
194 Totals["tp", Tool, Pass, "UNRESOLVED"], \
195 Totals["tp", Tool, Pass, "UNTESTED"], \
196 (Totals["tp", Tool, Pass, "ERROR" ] > 0 ? " !E!" : ""), \
197 (Totals["tp", Tool, Pass, "WARNING"] > 0 ? " !W!" : "")
203 ## Emit pass totals
205 END {
206 if (Passes["", "C"] > 1) {
207 printf "%*s |--------------------------------------------------\n", \
208 NameWidth, ""
209 for (i = 1; ("", i) in Passes; i++)
210 printf "%*s %-*s | %6d %6d %6d %6d %6d %6d %6d\n", \
211 ToolWidth, "", PassWidth, Passes["", i], \
212 Totals["p", Passes["", i], "PASS"], \
213 Totals["p", Passes["", i], "FAIL"], \
214 Totals["p", Passes["", i], "KPASS"] \
215 + Totals["p", Passes["", i], "XPASS"], \
216 Totals["p", Passes["", i], "KFAIL"] \
217 + Totals["p", Passes["", i], "XFAIL"], \
218 Totals["p", Passes["", i], "UNSUPPORTED"], \
219 Totals["p", Passes["", i], "UNRESOLVED"], \
220 Totals["p", Passes["", i], "UNTESTED"]
225 ## Emit grand totals
227 END {
228 printf "%*s |--------------------------------------------------\n", \
229 NameWidth, ""
230 printf "%*s | %6d %6d %6d %6d %6d %6d %6d\n", NameWidth, "", \
231 Totals["PASS"], Totals["FAIL"], \
232 Totals["KPASS"] + Totals["XPASS"], Totals["KFAIL"] + Totals["XFAIL"], \
233 Totals["UNSUPPORTED"], Totals["UNRESOLVED"], Totals["UNTESTED"]
234 printf "%*s \\__________________________________________________\n", \
235 NameWidth, ""
238 #EOF