blob: 11db9bed4ac53fe630bafc34561fb381ce86c381 [file] [log] [blame]
mbligh2e4e5df2007-11-05 17:22:46 +00001#!/usr/bin/python
2
3"""
4Selects all rows and columns that satisfy the condition specified
5and draws the matrix. There is a seperate SQL query made for every (x,y)
6in the matrix.
7"""
8
mbligh2e4e5df2007-11-05 17:22:46 +00009print "Content-type: text/html\n"
mbligh44710b62008-03-07 00:25:43 +000010import cgi, cgitb, re, datetime, query_lib
mbligha4266932007-11-05 18:12:16 +000011import sys, os
mblighb180f6c2008-01-04 20:24:41 +000012import urllib
mbligh2e4e5df2007-11-05 17:22:46 +000013
14tko = os.path.dirname(os.path.realpath(os.path.abspath(sys.argv[0])))
15sys.path.insert(0, tko)
16
mbligh2b672532007-11-05 19:24:51 +000017import display, frontend, db, query_lib
mbligh12eebfa2008-01-03 02:01:53 +000018client_bin = os.path.abspath(os.path.join(tko, '../client/bin'))
19sys.path.insert(0, client_bin)
20import kernel_versions
21
mbligh190a81d2007-11-05 20:40:38 +000022html_header = """\
23<form action="compose_query.cgi" method="get">
24<table border="0">
25<tr>
26 <td>Column: </td>
27 <td>Row: </td>
28 <td>Condition: </td>
mbligh44710b62008-03-07 00:25:43 +000029 <td align="center">
30 <a href="http://test.kernel.org/autotest/AutotestTKOCondition">Help</a>
31 </td>
mbligh190a81d2007-11-05 20:40:38 +000032</tr>
33<tr>
34 <td>
35 <SELECT NAME="columns">
36 %s
37 </SELECT>
38 </td>
39 <td>
40 <SELECT NAME="rows">
41 %s
42 </SELECT>
43 </td>
44 <td>
mbligh44710b62008-03-07 00:25:43 +000045 <input type="text" name="condition" size="30" value="%s">
mblighbe257452008-04-16 23:29:13 +000046 <input type="hidden" name="title" value="%s">
mbligh190a81d2007-11-05 20:40:38 +000047 </td>
48 <td align="center"><input type="submit" value="Submit">
49 </td>
50</tr>
51</table>
52</form>
53"""
54
mbligh12eebfa2008-01-03 02:01:53 +000055
mbligh5dd503b2008-01-03 16:35:27 +000056next_field = {
mbligh44710b62008-03-07 00:25:43 +000057 'machine_group': 'hostname',
58 'hostname': 'tag',
59 'tag': 'tag',
mbligh5dd503b2008-01-03 16:35:27 +000060
mbligh44710b62008-03-07 00:25:43 +000061 'kernel': 'test',
62 'test': 'label',
63 'label': 'tag',
mbligh5dd503b2008-01-03 16:35:27 +000064
mbligh44710b62008-03-07 00:25:43 +000065 'reason': 'tag',
66 'user': 'tag',
67 'status': 'tag',
68
mbligh5bb55862008-04-16 23:09:31 +000069 'time': 'tag',
70 'time_daily': 'time',
mbligh5dd503b2008-01-03 16:35:27 +000071}
72
73
mbligh3d7a5f52008-04-16 23:06:36 +000074def parse_field(form, form_field):
mbligh12eebfa2008-01-03 02:01:53 +000075 field_input = form[form_field].value.lower()
mbligh2ba3e732008-01-16 01:30:19 +000076 if field_input and field_input in frontend.test_view_field_dict:
mbligh12eebfa2008-01-03 02:01:53 +000077 return field_input
mbligh3d7a5f52008-04-16 23:06:36 +000078 return ''
mbligh12eebfa2008-01-03 02:01:53 +000079
80
81def parse_condition(form, form_field, field_default):
82 if not form_field in form:
83 return field_default
84 return form[form_field].value
85
86
87form = cgi.FieldStorage()
mbligh3d7a5f52008-04-16 23:06:36 +000088
mblighbe257452008-04-16 23:29:13 +000089title_field = parse_condition(form, 'title', '')
mbligh3d7a5f52008-04-16 23:06:36 +000090try:
91 row = parse_field(form, 'rows')
92 column = parse_field(form, 'columns')
93 condition_field = parse_condition(form, 'condition','')
mblighbe257452008-04-16 23:29:13 +000094
mbligh3d7a5f52008-04-16 23:06:36 +000095except KeyError:
96 ## first time here
97 ## to start faster, begin with records of last week only
98 cut_off = datetime.datetime.now() - datetime.timedelta(7)
99 cut_off = datetime.date(cut_off.year, cut_off.month, cut_off.day)
100 condition_field = parse_condition(form, 'condition',
101 "time > '%s'" % str(cut_off))
102 row = 'kernel'
103 column = 'machine_group'
104
mbligh44710b62008-03-07 00:25:43 +0000105
mbligh439661b2008-02-19 15:57:53 +0000106## caller can specify rows and columns that shall be included into the report
107## regardless of whether actual test data is available yet
108force_row_field = parse_condition(form,'force_row','')
109force_column_field = parse_condition(form,'force_column','')
mbligh190a81d2007-11-05 20:40:38 +0000110
mbligh439661b2008-02-19 15:57:53 +0000111def split_forced_fields(force_field):
112 if force_field:
113 return force_field.split()
114 else:
115 return []
116
117force_row = split_forced_fields(force_row_field)
118force_column = split_forced_fields(force_column_field)
119
mbligh2e4e5df2007-11-05 17:22:46 +0000120cgitb.enable()
mblighaea09602008-04-16 22:59:37 +0000121db_obj = db.db()
mbligh2e4e5df2007-11-05 17:22:46 +0000122
mbligh12eebfa2008-01-03 02:01:53 +0000123
mbligh2ba3e732008-01-16 01:30:19 +0000124def construct_link(x, y):
125 next_row = row
126 next_column = column
mbligh5dd503b2008-01-03 16:35:27 +0000127 condition_list = []
128 if condition_field != '':
129 condition_list.append(condition_field)
mbligh2ba3e732008-01-16 01:30:19 +0000130 if y:
131 next_row = next_field[row]
132 condition_list.append("%s='%s'" % (row, y))
133 if x:
134 next_column = next_field[column]
135 condition_list.append("%s='%s'" % (column, x))
mblighb180f6c2008-01-04 20:24:41 +0000136 next_condition = '&'.join(condition_list)
mblighbe257452008-04-16 23:29:13 +0000137 link = 'compose_query.cgi?' + urllib.urlencode({'columns': next_column,
138 'rows': next_row, 'condition': next_condition,
139 'title': title_field})
140 return link
mbligh5dd503b2008-01-03 16:35:27 +0000141
142
mbligh12eebfa2008-01-03 02:01:53 +0000143def create_select_options(selected_val):
mbligh190a81d2007-11-05 20:40:38 +0000144 ret = ""
mbligh2ba3e732008-01-16 01:30:19 +0000145 for option in sorted(frontend.test_view_field_dict.keys()):
mbligh190a81d2007-11-05 20:40:38 +0000146 if selected_val == option:
147 selected = " SELECTED"
148 else:
149 selected = ""
150
mbligh2ba3e732008-01-16 01:30:19 +0000151 ret += '<OPTION VALUE="%s"%s>%s</OPTION>\n' % \
152 (option, selected, option)
mbligh190a81d2007-11-05 20:40:38 +0000153 return ret
154
155
apw7a7316b2008-02-21 17:42:05 +0000156def map_kernel_base(kernel_name):
mbligh439661b2008-02-19 15:57:53 +0000157 ## insert <br> after each / in kernel name
158 ## but spare consequtive //
mbligh8e7c78e2008-02-20 21:18:49 +0000159 kernel_name = kernel_name.replace('/','/<br>')
160 kernel_name = kernel_name.replace('/<br>/<br>','//')
mbligh439661b2008-02-19 15:57:53 +0000161 return kernel_name
162
163
mbligh44710b62008-03-07 00:25:43 +0000164def header_tuneup(field_name, header):
165 ## header tune up depends on particular field name and may include:
166 ## - breaking header into several strings if it is long url
167 ## - creating date from datetime stamp
168 ## - possibly, expect more various refinements for different fields
169 if field_name == 'kernel':
170 return map_kernel_base(header)
mbligh44710b62008-03-07 00:25:43 +0000171 else:
172 return header
173
174
apw7a7316b2008-02-21 17:42:05 +0000175# Kernel name mappings -- the kernels table 'printable' field is
176# effectively a sortable identifier for the kernel It encodes the base
177# release which is used for overall sorting, plus where patches are
178# applied it adds an increasing pNNN patch combination identifier
179# (actually the kernel_idx for the entry). This allows sorting
180# as normal by the base kernel version and then sub-sorting by the
181# "first time we saw" a patch combination which should keep them in
182# approximatly date order. This patch identifier is not suitable
183# for display, so we have to map it to a suitable html fragment for
184# display. This contains the kernel base version plus the truncated
185# names of all the patches,
186#
187# 2.6.24-mm1 p112
188# +add-new-string-functions-
189# +x86-amd-thermal-interrupt
190#
191# This mapping is produced when the first mapping is request, with
192# a single query over the patches table; the result is then cached.
193#
194# Note: that we only count a base version as patched if it contains
195# patches which are not already "expressed" in the base version.
196# This includes both -gitN and -mmN kernels.
197map_kernel_map = None
198
199
200def map_kernel_init():
201 fields = ['base', 'k.kernel_idx', 'name', 'url']
202 map = {}
mblighaea09602008-04-16 22:59:37 +0000203 for (base, idx, name, url) in db_obj.select(','.join(fields),
apw7a7316b2008-02-21 17:42:05 +0000204 'kernels k,patches p', 'k.kernel_idx=p.kernel_idx'):
205 match = re.match(r'.*(-mm[0-9]+|-git[0-9]+)\.(bz2|gz)$', url)
206 if match:
207 continue
208
209 key = base + ' p%d' % (idx)
210 if not map.has_key(key):
211 map[key] = map_kernel_base(base) + ' p%d' % (idx)
212 map[key] += '<br>+<span title="' + name + '">' + name[0:25] + '</span>'
213
214 return map
215
216
217def map_kernel(name):
218 global map_kernel_map
219 if map_kernel_map == None:
220 map_kernel_map = map_kernel_init()
221
222 if map_kernel_map.has_key(name):
223 return map_kernel_map[name]
224
225 return map_kernel_base(name.split(' ')[0])
226
227
228field_map = {
229 'kernel':map_kernel
230}
231
232
mbligh12eebfa2008-01-03 02:01:53 +0000233def gen_matrix():
mbligh12eebfa2008-01-03 02:01:53 +0000234 where = None
235 if condition_field.strip() != '':
mbligh44710b62008-03-07 00:25:43 +0000236 try:
237 where = query_lib.parse_scrub_and_gen_condition(
238 condition_field, frontend.test_view_field_dict)
239 print "<!-- where clause: %s -->" % (where,)
240 except:
241 msg = "Unspecified error when parsing condition"
242 return [[display.box(msg)]]
mbligh2e4e5df2007-11-05 17:22:46 +0000243
mblighaea09602008-04-16 22:59:37 +0000244 try:
mbligh31260692008-04-16 23:12:12 +0000245 ## Unfortunately, we can not request reasons of failure always
246 ## because it may result in an inflated size of data transfer
247 ## (at the moment we fetch 500 bytes of reason descriptions into
248 ## each cell )
249 ## If 'status' in [row,column] then either width or height
250 ## of the table <=7, hence table is not really 2D, and
251 ## query_reason is relatively save.
252 ## At the same time view when either rows or columns grouped
253 ## by status is when users need reasons of failures the most.
254
255 ## TO DO: implement [Show/Hide reasons] button or link in
256 ## all views and make thorough performance testing
257 test_data = frontend.get_matrix_data(db_obj, column, row, where,
258 query_reasons = ('status' in [row,column])
259 )
mblighaea09602008-04-16 22:59:37 +0000260 except db.MySQLTooManyRows, error:
261 return [[display.box(str(error))]]
mbligh44710b62008-03-07 00:25:43 +0000262
mbligh439661b2008-02-19 15:57:53 +0000263 for f_row in force_row:
264 if not f_row in test_data.y_values:
265 test_data.y_values.append(f_row)
266 for f_column in force_column:
267 if not f_column in test_data.x_values:
268 test_data.x_values.append(f_column)
mbligh2e4e5df2007-11-05 17:22:46 +0000269
mbligh2ba3e732008-01-16 01:30:19 +0000270 if not test_data.y_values:
mbligh12eebfa2008-01-03 02:01:53 +0000271 msg = "There are no results for this query (yet?)."
272 return [[display.box(msg)]]
mbligh2e4e5df2007-11-05 17:22:46 +0000273
mbligh456b4772008-03-25 23:54:45 +0000274 dict_url = {'columns': row,
mblighbe257452008-04-16 23:29:13 +0000275 'rows': column, 'condition': condition_field,
276 'title': title_field}
mbligh456b4772008-03-25 23:54:45 +0000277 link = 'compose_query.cgi?' + urllib.urlencode(dict_url)
mbligh5dd503b2008-01-03 16:35:27 +0000278 header_row = [display.box("<center>(Flip Axis)</center>", link=link)]
279
mbligh2ba3e732008-01-16 01:30:19 +0000280 for x in test_data.x_values:
apw7a7316b2008-02-21 17:42:05 +0000281 dx = x
282 if field_map.has_key(column):
283 dx = field_map[column](x)
mbligh44710b62008-03-07 00:25:43 +0000284 x_header = header_tuneup(column, dx)
285 link = construct_link(x, None)
286 header_row.append(display.box(x_header,header=True,link=link))
mbligh2e4e5df2007-11-05 17:22:46 +0000287
288 matrix = [header_row]
mbligh2ba3e732008-01-16 01:30:19 +0000289 for y in test_data.y_values:
apw7a7316b2008-02-21 17:42:05 +0000290 dy = y
291 if field_map.has_key(row):
292 dy = field_map[row](y)
mbligh44710b62008-03-07 00:25:43 +0000293 y_header = header_tuneup(row, dy)
mbligh5bb55862008-04-16 23:09:31 +0000294 link = construct_link(None, y)
mbligh44710b62008-03-07 00:25:43 +0000295 cur_row = [display.box(y_header, header=True, link=link)]
mbligh2ba3e732008-01-16 01:30:19 +0000296 for x in test_data.x_values:
mbligh44710b62008-03-07 00:25:43 +0000297 ## next 2 lines: temporary, until non timestamped
298 ## records are in the database
299 if x==datetime.datetime(1970,1,1): x = None
300 if y==datetime.datetime(1970,1,1): y = None
mbligh12eebfa2008-01-03 02:01:53 +0000301 try:
mbligh31260692008-04-16 23:12:12 +0000302 box_data = test_data.data[x][y]
mbligh12eebfa2008-01-03 02:01:53 +0000303 except:
304 cur_row.append(display.box(None, None))
305 continue
mbligh2ba3e732008-01-16 01:30:19 +0000306 job_tag = test_data.data[x][y].job_tag
mbligh5dd503b2008-01-03 16:35:27 +0000307 if job_tag:
mblighe47ff2a2008-02-28 00:44:11 +0000308 link = frontend.html_root + job_tag + '/'
mbligh439661b2008-02-19 15:57:53 +0000309 if (row == 'test' and
310 not 'boot' in y and
311 not 'build' in y and
312 not 'install' in y ):
313 link += y + '/'
314 if (column == 'test' and
315 not 'boot' in x and
316 not 'build' in x and
317 not 'install' in x):
318 link += x + '/'
mbligh5dd503b2008-01-03 16:35:27 +0000319 else:
mbligh2ba3e732008-01-16 01:30:19 +0000320 link = construct_link(x, y)
mbligh44710b62008-03-07 00:25:43 +0000321
mblighaea09602008-04-16 22:59:37 +0000322 cur_row.append(display.status_precounted_box(db_obj,
mbligh5dd503b2008-01-03 16:35:27 +0000323 box_data,
324 link))
mbligh12eebfa2008-01-03 02:01:53 +0000325 matrix.append(cur_row)
mbligh12eebfa2008-01-03 02:01:53 +0000326 return matrix
mbligh2b672532007-11-05 19:24:51 +0000327
mbligh2b672532007-11-05 19:24:51 +0000328
mbligh12eebfa2008-01-03 02:01:53 +0000329def main():
mbligh190a81d2007-11-05 20:40:38 +0000330 # create the actual page
mbligh190a81d2007-11-05 20:40:38 +0000331 print '<html><head><title>'
332 print 'Filtered Autotest Results'
333 print '</title></head><body>'
mbligh14671622008-01-11 16:49:54 +0000334 display.print_main_header()
mbligh2ba3e732008-01-16 01:30:19 +0000335 print html_header % (create_select_options(column),
336 create_select_options(row),
mblighbe257452008-04-16 23:29:13 +0000337 condition_field, title_field)
338 if title_field:
339 print '<h1> %s </h1>' % (title_field)
mbligh439661b2008-02-19 15:57:53 +0000340 print display.color_keys_row()
mbligh12eebfa2008-01-03 02:01:53 +0000341 display.print_table(gen_matrix())
mbligh439661b2008-02-19 15:57:53 +0000342 print display.color_keys_row()
mbligh190a81d2007-11-05 20:40:38 +0000343 print '</body></html>'
mbligh2e4e5df2007-11-05 17:22:46 +0000344
345
346main()