summaryrefslogtreecommitdiff
path: root/framework/summary.py
blob: 08dd13b629f238c2058c60c141111f981188061a (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
#!/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.

import core


#############################################################################
##### Vector indicating the number of subtests that have passed/failed/etc.
#############################################################################
class PassVector:
	def __init__(self, p, w, f, s):
		self.passnr = p
		self.warnnr = w
		self.failnr = f
		self.skipnr = s

	def add(self, o):
		self.passnr += o.passnr
		self.warnnr += o.warnnr
		self.failnr += o.failnr
		self.skipnr += o.skipnr


#############################################################################
##### TestSummary: Summarize the results for one test across a
##### number of testruns
#############################################################################
class TestSummary:
	def __init__(self, summary, path, name, results):
		"""\
summary is the root summary object
path is the path to the group (e.g. shaders/glean-fragProg1)
name is the display name of the group (e.g. glean-fragProg1)
results is an array of TestResult instances, one per testrun
"""
		self.summary = summary
		self.path = path
		self.name = name
		self.results = results[:]

		for j in range(len(self.results)):
			result = self.results[j]
			result.testrun = self.summary.testruns[j]
			result.status = ''
			if 'result' in result:
				result.status = result['result']

			vectormap = {
				'pass': PassVector(1,0,0,0),
				'warn': PassVector(0,1,0,0),
				'fail': PassVector(0,0,1,0),
				'skip': PassVector(0,0,0,1)
			}

			if result.status not in vectormap:
				result.status = 'warn'

			result.passvector = vectormap[result.status]

		stati = set([result.status for result in results])
		self.changes = len(stati) > 1
		self.problems = len(stati - set(['pass', 'skip'])) > 0

	def allTests(self):
		return [self]

#############################################################################
##### GroupSummary: Summarize a group of tests
#############################################################################
class GroupSummary:
	def __init__(self, summary, path, name, results):
		"""\
summary is the root summary object
path is the path to the group (e.g. shaders/glean-fragProg1)
name is the display name of the group (e.g. glean-fragProg1)
results is an array of GroupResult instances, one per testrun
"""
		self.summary = summary
		self.path = path
		self.name = name
		self.results = results[:]
		self.changes = False
		self.problems = False
		self.children = {}

		# Perform some initial annotations
		for j in range(len(self.results)):
			result = self.results[j]
			result.passvector = PassVector(0, 0, 0, 0)
			result.testrun = self.summary.testruns[j]

		# Collect, create and annotate children
		for result in self.results:
			for name in result:
				if name in self.children:
					continue

				childpath = name
				if len(self.path) > 0:
					childpath = self.path + '/' + childpath

				if isinstance(result[name], core.GroupResult):
					childresults = [r.get(name, core.GroupResult())
							for r in self.results]

					self.children[name] = GroupSummary(
						summary,
						childpath,
						name,
						childresults
					)
				else:
					childresults = [r.get(name, core.TestResult({}, { 'result': 'skip' }))
							for r in self.results]

					self.children[name] = TestSummary(
						summary,
						childpath,
						name,
						childresults
					)

				for j in range(len(self.results)):
					self.results[j].passvector.add(childresults[j].passvector)

				self.changes = self.changes or self.children[name].changes
				self.problems = self.problems or self.children[name].problems

	def allTests(self):
		"""\
Returns an array of all child TestSummary instances.
"""
		return [t for name in self.children for t in self.children[name].allTests()]

#############################################################################
##### Summary: Summarize an array of testruns
#############################################################################
class Summary:
	def __init__(self, testruns):
		"""\
testruns is an array of TestrunResult instances
"""
		self.testruns = testruns
		self.root = GroupSummary(self, '', 'All', [tr.results for tr in testruns])

	def allTests(self):
		"""\
Returns an array of all child TestSummary instances.
"""
		return self.root.allTests()