summaryrefslogtreecommitdiff
path: root/programs/report.py
blob: 7ded68a90060fcdae73ea4491588abd955f9aeb4 (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
#!/usr/bin/env python3
#
# Copyright © 2012 Intel Corporation
#
# 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:
#
# The above copyright notice and this permission notice (including the next
# paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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.
#

from argparse import ArgumentParser
import os
import os.path as path
import re
import sys

from framework.database import ResultDatabase


#############################################################################
##### Helper functions
#############################################################################

filename_char_re = re.compile(r'[^a-zA-Z_]+')
def escape(s):
        return filename_char_re.sub('', s.replace('/', '__'))

#############################################################################
##### Summary page generation
#############################################################################

class StackEntry:
    def __init__(self, num_runs, group_name):
        self.name = group_name
        #self.results = [PassVector(0,0,0,0,0,0,0) for i in range(num_runs)]
        self.name_html = ''
        self.column_html = ['' for i in range(num_runs)]

def buildTable(run_names, results):
    # If the test list is empty, just return now.
	if not results:
		return ('', [''])

    num_runs = len(run_names)

	last_group = ''
	stack = []

	def openGroup(name):
		stack.append(StackEntry(num_runs, name))

	def closeGroup():
		group = stack.pop()

		stack[-1].name_html += ''.join(['<div class="group"><div class="head">', group.name, '</div><div class="groupbody">', group.name_html, '</div></div>'])

		for i in range(num_runs):
			stack[-1].results[i].add(group.results[i])
			stack[-1].column_html[i] += ''.join(['<div class="group">', buildGroupResultHeader(group.results[i]), group.column_html[i], '</div>'])

	openGroup('fake')
	openGroup('All')

	for full_test in results.keys():
		group, test = path.split(full_test) # or full_test.rpartition('/')

		if group != last_group:
			# We're in a different group now.  Close the old ones
			# and open the new ones.
			for x in path.relpath(group, last_group).split('/'):
				if x == '..':
					closeGroup()
				else:
					openGroup(x)

			last_group = group

		# Add the current test
		stack[-1].name_html += '<div>' + test + '</div>\n';
		for i in range(num_runs):
			passv, html = testResult(summary, summary.testruns[i], full_test, summary.results[full_test][i])
			stack[-1].results[i].add(passv)
			stack[-1].column_html[i] += html

	# Close any remaining groups
	while len(stack) > 1:
		closeGroup()

	assert(len(stack) == 1)

	return (stack[0].name_html, stack[0].column_html)

def writeSummaryHtml():
    names, columns = buildTable(...)

    #def makeColumn(name, contents):
        #return ''.join(['<div class="resultColumn"><div class="title"><b>%s</b><br/>(<a href="%s/index.html">info</a>)</div>' % (name, escape(name)), contents, '</div>'])

    #column_html = ''.join([makeColumn(name, contents) for name, contents in zip(run_names, columns)])

#############################################################################
##### Main program
#############################################################################

def parseArguments(argv, config):
    p = ArgumentParser(prog='robyn report', description='A GPU test runner')
    p.add_argument('-o', '--output', default='summary',
                   metavar='<directory to write HTML reports to>')
    p.add_argument('runs', nargs='+', metavar='<run name>')

    # XXX: alternate database (pending refactoring)
    return p.parse_args(argv)

def main(argv, config):
    args = parseArguments(argv, config)

    db = ResultDatabase(config)

    reportDir = args.output
    if not path.exists(reportDir):
        os.makedirs(reportDir)

    run_names = list(args.runs)
    results = db.getResults(run_names)

    # XXX: write detail pages

    print(results)
    #os.link(path.join(templateDir, 'index.css'),
            #path.join(reportDir, 'index.css'))
	writeSummaryHtml()


if __name__ == "__main__":
	main()