aboutsummaryrefslogtreecommitdiff
path: root/piglit-summary.py
blob: 6f4c8316f61d70eda5911fdd4ec2ea26042db6c4 (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
#!/usr/bin/env python
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# This permission notice shall be included in all copies or
# substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHOR(S) BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
# OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

# Print a very simple summary of piglit results file(s).
# When multiple result files are specified, compare the results
# of each test run to look for differences/regressions.
#
# Brian Paul
# April 2013


from getopt import getopt, GetoptError
import os.path
import sys
import string

sys.path.append(os.path.dirname(os.path.realpath(sys.argv[0])))
import framework.core as core
import framework.summary


#############################################################################
##### Main program
#############################################################################
def usage():
	USAGE = """\
Usage: %(progName)s [options] resultsfile [...]

Print path/name of each test and the result.
When multiple files are specified, count the number of differences in results.
Tests are sorted by name.

Options:
  -h, --help            Show this message
  -s, --summary         Only display pass/fail summary
  -d, --diff            Only display the differences between multiple result files
  -l, --list=listfile   Use test results from a list file

Example list file:
 [
   [ 'test.result', { name: 'override-name' } ],
   [ 'other.result' ]
 ]
"""
	print USAGE % {'progName': sys.argv[0]}
	sys.exit(1)


def parse_listfile(filename):
	file = open(filename, "r")
	code = file.read()
	file.close()
	return eval(code)

def loadresult(descr):
	result = core.loadTestResults(descr[0])
	if len(descr) > 1:
		result.__dict__.update(descr[1])
	return result

def main():
	try:
		options, args = getopt(sys.argv[1:], "hsdl:", [ "help", "summary", "diff", "list" ])
	except GetoptError:
		usage()

	OptionList = []
	CountsOnly = False
	DiffOnly = False
	for name, value in options:
		if name == "-h" or name == "--help":
			usage()
		elif name == "-s" or name == "--summary":
			CountsOnly = True
		elif name == "-d" or name == "--diff":
			DiffOnly = True
		elif name == "-l" or name == "--list":
			OptionList += parse_listfile(value)

	OptionList += [[name] for name in args[0:]]

	if len(args) == 0 and len(OptionList) == 0:
		usage()

	# make list of results
	results = []
	for result_dir in OptionList:
		results.append(loadresult(result_dir))

	summary = framework.summary.Summary(results)

	# possible test outcomes
	possible_results = [ "pass", "fail", "crash", "skip", "warn" ]
	if len(OptionList) > 1:
			possible_results.append("changes")

	# init the summary counters
	counts = {}
	for result in possible_results:
			counts[result] = 0

	# get all results
	all = summary.allTests()

	# sort the results list by path
	all = sorted(all, key=lambda test: test.path)

	# loop over the tests
	for test in all:
		results = []
		anyChange = False
		# loop over the results for multiple runs
		for j in range(len(summary.testruns)):
			outcome = test.results[j]['result'] # 'pass', 'fail', etc.
			# check for different results between multiple runs
			if len(results) >= 1 and not outcome in results:
				# something changed
				counts["changes"] += 1
				anyChange = True
			results.append(outcome)

		# if all test runs had the same outcome:
		if not anyChange:
			counts[outcome] += 1

		# print the individual test result line
		if DiffOnly:
			if anyChange:
				print "%s: %s" % (test.path, string.join(results," "))
		elif not CountsOnly:
			print "%s: %s" % (test.path, string.join(results," "))

	# print the summary info
	print "summary:"
	total = 0
	for result in possible_results:
		print " %7s: %5d" % (result, counts[result])
		total += counts[result]
	print "   total: %5d" % total


if __name__ == "__main__":
	main()