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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
|
#!/usr/bin/python
"""
Selects all rows and columns that satisfy the condition specified
and draws the matrix. There is a seperate SQL query made for every (x,y)
in the matrix.
"""
print "Content-type: text/html\n"
import cgi, cgitb, re, datetime, query_lib
import sys, os
import urllib
tko = os.path.dirname(os.path.realpath(os.path.abspath(sys.argv[0])))
sys.path.insert(0, tko)
import display, frontend, db, query_lib
client_bin = os.path.abspath(os.path.join(tko, '../client/bin'))
sys.path.insert(0, client_bin)
import kernel_versions
html_header = """\
<form action="compose_query.cgi" method="get">
<table border="0">
<tr>
<td>Column: </td>
<td>Row: </td>
<td>Condition: </td>
<td align="center">
<a href="http://test.kernel.org/autotest/AutotestTKOCondition">Help</a>
</td>
</tr>
<tr>
<td>
<SELECT NAME="columns">
%s
</SELECT>
</td>
<td>
<SELECT NAME="rows">
%s
</SELECT>
</td>
<td>
<input type="text" name="condition" size="30" value="%s">
<input type="hidden" name="title" value="Report">
</td>
<td align="center"><input type="submit" value="Submit">
</td>
</tr>
</table>
</form>
"""
next_field = {
'machine_group': 'hostname',
'hostname': 'tag',
'tag': 'tag',
'kernel': 'test',
'test': 'label',
'label': 'tag',
'reason': 'tag',
'user': 'tag',
'status': 'tag',
'time': 'tag',
'time_daily': 'time',
}
def parse_field(form, form_field):
field_input = form[form_field].value.lower()
if field_input and field_input in frontend.test_view_field_dict:
return field_input
return ''
def parse_condition(form, form_field, field_default):
if not form_field in form:
return field_default
return form[form_field].value
form = cgi.FieldStorage()
try:
row = parse_field(form, 'rows')
column = parse_field(form, 'columns')
condition_field = parse_condition(form, 'condition','')
except KeyError:
## first time here
## to start faster, begin with records of last week only
cut_off = datetime.datetime.now() - datetime.timedelta(7)
cut_off = datetime.date(cut_off.year, cut_off.month, cut_off.day)
condition_field = parse_condition(form, 'condition',
"time > '%s'" % str(cut_off))
row = 'kernel'
column = 'machine_group'
## caller can specify rows and columns that shall be included into the report
## regardless of whether actual test data is available yet
force_row_field = parse_condition(form,'force_row','')
force_column_field = parse_condition(form,'force_column','')
def split_forced_fields(force_field):
if force_field:
return force_field.split()
else:
return []
force_row = split_forced_fields(force_row_field)
force_column = split_forced_fields(force_column_field)
cgitb.enable()
db_obj = db.db()
def construct_link(x, y):
next_row = row
next_column = column
condition_list = []
if condition_field != '':
condition_list.append(condition_field)
if y:
next_row = next_field[row]
condition_list.append("%s='%s'" % (row, y))
if x:
next_column = next_field[column]
condition_list.append("%s='%s'" % (column, x))
next_condition = '&'.join(condition_list)
return 'compose_query.cgi?' + urllib.urlencode({'columns': next_column,
'rows': next_row, 'condition': next_condition})
def create_select_options(selected_val):
ret = ""
for option in sorted(frontend.test_view_field_dict.keys()):
if selected_val == option:
selected = " SELECTED"
else:
selected = ""
ret += '<OPTION VALUE="%s"%s>%s</OPTION>\n' % \
(option, selected, option)
return ret
def map_kernel_base(kernel_name):
## insert <br> after each / in kernel name
## but spare consequtive //
kernel_name = kernel_name.replace('/','/<br>')
kernel_name = kernel_name.replace('/<br>/<br>','//')
return kernel_name
def header_tuneup(field_name, header):
## header tune up depends on particular field name and may include:
## - breaking header into several strings if it is long url
## - creating date from datetime stamp
## - possibly, expect more various refinements for different fields
if field_name == 'kernel':
return map_kernel_base(header)
else:
return header
# Kernel name mappings -- the kernels table 'printable' field is
# effectively a sortable identifier for the kernel It encodes the base
# release which is used for overall sorting, plus where patches are
# applied it adds an increasing pNNN patch combination identifier
# (actually the kernel_idx for the entry). This allows sorting
# as normal by the base kernel version and then sub-sorting by the
# "first time we saw" a patch combination which should keep them in
# approximatly date order. This patch identifier is not suitable
# for display, so we have to map it to a suitable html fragment for
# display. This contains the kernel base version plus the truncated
# names of all the patches,
#
# 2.6.24-mm1 p112
# +add-new-string-functions-
# +x86-amd-thermal-interrupt
#
# This mapping is produced when the first mapping is request, with
# a single query over the patches table; the result is then cached.
#
# Note: that we only count a base version as patched if it contains
# patches which are not already "expressed" in the base version.
# This includes both -gitN and -mmN kernels.
map_kernel_map = None
def map_kernel_init():
fields = ['base', 'k.kernel_idx', 'name', 'url']
map = {}
for (base, idx, name, url) in db_obj.select(','.join(fields),
'kernels k,patches p', 'k.kernel_idx=p.kernel_idx'):
match = re.match(r'.*(-mm[0-9]+|-git[0-9]+)\.(bz2|gz)$', url)
if match:
continue
key = base + ' p%d' % (idx)
if not map.has_key(key):
map[key] = map_kernel_base(base) + ' p%d' % (idx)
map[key] += '<br>+<span title="' + name + '">' + name[0:25] + '</span>'
return map
def map_kernel(name):
global map_kernel_map
if map_kernel_map == None:
map_kernel_map = map_kernel_init()
if map_kernel_map.has_key(name):
return map_kernel_map[name]
return map_kernel_base(name.split(' ')[0])
field_map = {
'kernel':map_kernel
}
def gen_matrix():
where = None
if condition_field.strip() != '':
try:
where = query_lib.parse_scrub_and_gen_condition(
condition_field, frontend.test_view_field_dict)
print "<!-- where clause: %s -->" % (where,)
except:
msg = "Unspecified error when parsing condition"
return [[display.box(msg)]]
try:
test_data = frontend.get_matrix_data(db_obj, column, row, where)
except db.MySQLTooManyRows, error:
return [[display.box(str(error))]]
for f_row in force_row:
if not f_row in test_data.y_values:
test_data.y_values.append(f_row)
for f_column in force_column:
if not f_column in test_data.x_values:
test_data.x_values.append(f_column)
if not test_data.y_values:
msg = "There are no results for this query (yet?)."
return [[display.box(msg)]]
dict_url = {'columns': row,
'rows': column, 'condition': condition_field}
link = 'compose_query.cgi?' + urllib.urlencode(dict_url)
header_row = [display.box("<center>(Flip Axis)</center>", link=link)]
for x in test_data.x_values:
dx = x
if field_map.has_key(column):
dx = field_map[column](x)
x_header = header_tuneup(column, dx)
link = construct_link(x, None)
header_row.append(display.box(x_header,header=True,link=link))
matrix = [header_row]
for y in test_data.y_values:
dy = y
if field_map.has_key(row):
dy = field_map[row](y)
y_header = header_tuneup(row, dy)
link = construct_link(None, y)
cur_row = [display.box(y_header, header=True, link=link)]
for x in test_data.x_values:
## next 2 lines: temporary, until non timestamped
## records are in the database
if x==datetime.datetime(1970,1,1): x = None
if y==datetime.datetime(1970,1,1): y = None
try:
box_data = test_data.data[x][y].status_count
except:
cur_row.append(display.box(None, None))
continue
job_tag = test_data.data[x][y].job_tag
if job_tag:
link = frontend.html_root + job_tag + '/'
if (row == 'test' and
not 'boot' in y and
not 'build' in y and
not 'install' in y ):
link += y + '/'
if (column == 'test' and
not 'boot' in x and
not 'build' in x and
not 'install' in x):
link += x + '/'
else:
link = construct_link(x, y)
cur_row.append(display.status_precounted_box(db_obj,
box_data,
link))
matrix.append(cur_row)
return matrix
def main():
# create the actual page
print '<html><head><title>'
print 'Filtered Autotest Results'
print '</title></head><body>'
display.print_main_header()
print html_header % (create_select_options(column),
create_select_options(row),
condition_field)
print display.color_keys_row()
display.print_table(gen_matrix())
print display.color_keys_row()
print '</body></html>'
main()
|