aboutsummaryrefslogtreecommitdiff
path: root/commands/report-card.awk
blob: dc5c4e91374158417e0323632d27c6c4d797d34d (plain)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# report-card.awk -- Test summary tool
# Copyright (C) 2018, 2021 Free Software Foundation, Inc.
#
# This file is part of DejaGnu.
#
# DejaGnu is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# DejaGnu is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with DejaGnu; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.

# This file was written by Jacob Bachmeyer.

# ##help
# #Usage: dejagnu report card [ OPTION | TOOL | FILE ]...
# #Usage: dejagnu report-card [ OPTION | TOOL | FILE ]...
# #	--verbose, -v		Emit additional messages
# ##end

# Arrays storing lists in this program store items in numbered keys, with a
# count in the "C" key, similar to Awk's ARGV/ARGC.

# The Tools array stores a list of tools in 1..N.

# The Passes array stores a global list of passes seen, a per-tool list of
# passes seen, and a global index of passes seen if DejaGnu's multipass
# support is used.
# Key prefixes:
#  ""		-- global list:    1..N; "C"
#  "t", <tool>	-- per-tool list:  1..N; "C"
# Key patterns:
#  "p", <pass>	-- count of tools using <pass>

# The Totals array stores counts of test results, indexed by tool and pass.
# A summarization step adds per-tool, per-pass, and grand totals.
# Key patterns:
#  "tp", <Tool>, <Pass>, <result>
#  "t", <Tool>, <result>
#  "p", <Pass>, <result>
#  <result>

##
## Get list of files to scan

BEGIN {
    Tools["C"] = 1
    Passes["", "C"] = 1
    ToolWidth = 0
    PassWidth = 0
    Verbose = 0
    # remove arguments from ARGV
    for (i = 1; i < ARGC; i++) {
	if (ARGV[i] ~ /^-/) {
	    if (ARGV[i] ~ /^--?v(erb.*)?$/)
		Verbose++
	    else if (ARGV[i] == "--")
		break
	    delete ARGV[i]
	}
    }
    if (ARGV[i] == "--")
	delete ARGV[i]
    if (Verbose) print "Verbose level is "Verbose
    # adjust filenames in ARGV
    FileCount = 0
    for (i = 1; i < ARGC; i++) {
	if (i in ARGV) FileCount++
	else continue
	if (ARGV[i] ~ /\.sum$/) continue
	else if (ARGV[i] ~ /\.log$/) sub(/\.log$/, ".sum", ARGV[i])
	else if (ARGV[i] ~/\.$/) sub(/\.$/, ".sum", ARGV[i])
	else ARGV[i] = (ARGV[i]".sum")
    }
    if (FileCount == 0) {
	cmd_ls_files = "ls -1 *.sum"
	while (cmd_ls_files | getline File) {
	    FileCount++
	    ARGV[ARGC++] = File
	}
	close(cmd_ls_files)
    }
    if (Verbose > 2) {
	print "Reading "FileCount" file(s)"
	for (i = 1; i < ARGC; i++)
	    if (i in ARGV)
		print "  "ARGV[i]
    }
}

##
## Read files and collect data

FNR == 1 {
    if (Verbose)
	print "Reading `"FILENAME"' ..."
    Pass = ""
    Tool = File = FILENAME
    sub(/\.sum$/, "", Tool)
    if (length(Tool) > ToolWidth)
	ToolWidth = length(Tool)
    Tools[Tools["C"]++] = Tool
    Passes["t", Tool, "C"] = 1
    Passes["t", Tool, 1] = "" # will be overwritten if multipass is used
}

/^Running pass `[^']*' .../ {
    Pass = $3
    sub(/^`/, "", Pass)
    sub(/'$/, "", Pass)
    if (("p", Pass) in Passes)
	Passes["p", Pass]++
    else {
	if (length(Pass) > PassWidth)
	    PassWidth = length(Pass)
	Passes["", Passes["", "C"]++] = Pass
	Passes["p", Pass] = 1
    }
    Passes["t", Tool, Passes["t", Tool, "C"]++] = Pass
}

$1 ~ /:$/ { sub(/:$/, "", $1); Totals["tp", Tool, Pass, $1]++ }

##
## Compute totals

END {
    $0 = ("PASS FAIL KPASS KFAIL XPASS XFAIL UNSUPPORTED UNRESOLVED UNTESTED")
    for (i = 1; i in Tools; i++)
	for (j = 1; ("t", Tools[i], j) in Passes; j++)
	    for (k = 1; k <= NF; k++) {
		Totals[$k]						\
		    += Totals["tp", Tools[i], Passes["t", Tools[i], j], $k]
		Totals["t", Tools[i], $k]				\
		    += Totals["tp", Tools[i], Passes["t", Tools[i], j], $k]
		Totals["p", Passes["t", Tools[i], j], $k]		\
		    += Totals["tp", Tools[i], Passes["t", Tools[i], j], $k]
	    }
}

##
## Compute total name column width

END {
    if (Passes["", "C"] > 1)
	NameWidth = ToolWidth + 3 + PassWidth
    else
	NameWidth = ToolWidth
}

##
## Emit header

END {
    printf "%*s   __________________________________________________\n", \
	NameWidth, ""
    printf "%*s  /  %6s %6s %6s %6s %6s %6s %6s\n", NameWidth, "",	\
	"PASS", "FAIL", "?PASS", "?FAIL", "UNSUP", "UNRES", "UNTEST"
    printf "%*s  |--------------------------------------------------\n", \
	NameWidth, ""
}

##
## Emit counts

END {
    for (i = 1; i in Tools; i++) {
	Tool = Tools[i]
	for (j = 1; ("t", Tool, j) in Passes; j++) {
	    Pass = Passes["t", Tool, j]
	    if (Passes["t", Tool, "C"] > 1)
		printf "%*s / %-*s  | ", ToolWidth, Tool, PassWidth, Pass
	    else if (Passes["", "C"] > 1)
		printf "%*s   %*s  | ", ToolWidth, Tool, PassWidth, ""
	    else
		printf "%*s  | ", NameWidth, Tool
	    # Passes["t", <tool>, 1] is a pass name or a null string if
	    #  <tool> did not use multipass.
	    printf " %6d %6d %6d %6d %6d %6d %6d%s%s\n",		\
		Totals["tp", Tool, Pass, "PASS"],			\
		Totals["tp", Tool, Pass, "FAIL"],			\
		Totals["tp", Tool, Pass, "KPASS"]			\
		+ Totals["tp", Tool, Pass, "XPASS"],			\
		Totals["tp", Tool, Pass, "KFAIL"]			\
		+ Totals["tp", Tool, Pass, "XFAIL"],			\
		Totals["tp", Tool, Pass, "UNSUPPORTED"],		\
		Totals["tp", Tool, Pass, "UNRESOLVED"],			\
		Totals["tp", Tool, Pass, "UNTESTED"],			\
		(Totals["tp", Tool, Pass, "ERROR"  ] > 0 ? " !E!" : ""), \
		(Totals["tp", Tool, Pass, "WARNING"] > 0 ? " !W!" : "")
	}
    }
}

##
## Emit pass totals

END {
    if (Passes["", "C"] > 1) {
	printf "%*s  |--------------------------------------------------\n", \
	    NameWidth, ""
	for (i = 1; ("", i) in Passes; i++)
	    printf "%*s   %-*s  |  %6d %6d %6d %6d %6d %6d %6d\n",	\
		ToolWidth, "", PassWidth, Passes["", i],		\
		Totals["p", Passes["", i], "PASS"],			\
		Totals["p", Passes["", i], "FAIL"],			\
		Totals["p", Passes["", i], "KPASS"]			\
		+ Totals["p", Passes["", i], "XPASS"],			\
		Totals["p", Passes["", i], "KFAIL"]			\
		+ Totals["p", Passes["", i], "XFAIL"],			\
		Totals["p", Passes["", i], "UNSUPPORTED"],		\
		Totals["p", Passes["", i], "UNRESOLVED"],		\
		Totals["p", Passes["", i], "UNTESTED"]
    }
}

##
## Emit grand totals

END {
    printf "%*s  |--------------------------------------------------\n", \
	NameWidth, ""
    printf "%*s  |  %6d %6d %6d %6d %6d %6d %6d\n", NameWidth, "",	\
	Totals["PASS"], Totals["FAIL"],					\
	Totals["KPASS"] + Totals["XPASS"], Totals["KFAIL"] + Totals["XFAIL"], \
	Totals["UNSUPPORTED"], Totals["UNRESOLVED"], Totals["UNTESTED"]
    printf "%*s  \\__________________________________________________\n", \
	NameWidth, ""
}

#EOF