blob: 5fef8b8f1b5af526a1d532936ce76e41b75379a1 [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"
mbligh2e4e5df2007-11-05 17:22:46 +000010
jadmanski22ab0692008-05-01 22:22:51 +000011import sys, os, urllib, cgi, cgitb, re, datetime, time
mbligh2e4e5df2007-11-05 17:22:46 +000012
jadmanski22ab0692008-05-01 22:22:51 +000013total_wall_time_start = time.time()
14
15import common
16from autotest_lib.tko import display, frontend, db, query_lib
17from autotest_lib.client.bin import kernel_versions
mbligh12eebfa2008-01-03 02:01:53 +000018
mbligh190a81d2007-11-05 20:40:38 +000019html_header = """\
20<form action="compose_query.cgi" method="get">
21<table border="0">
22<tr>
23 <td>Column: </td>
24 <td>Row: </td>
25 <td>Condition: </td>
mbligh44710b62008-03-07 00:25:43 +000026 <td align="center">
27 <a href="http://test.kernel.org/autotest/AutotestTKOCondition">Help</a>
28 </td>
mbligh190a81d2007-11-05 20:40:38 +000029</tr>
30<tr>
31 <td>
32 <SELECT NAME="columns">
33 %s
34 </SELECT>
35 </td>
36 <td>
37 <SELECT NAME="rows">
38 %s
39 </SELECT>
40 </td>
41 <td>
mbligh44710b62008-03-07 00:25:43 +000042 <input type="text" name="condition" size="30" value="%s">
mblighbe257452008-04-16 23:29:13 +000043 <input type="hidden" name="title" value="%s">
mbligh190a81d2007-11-05 20:40:38 +000044 </td>
45 <td align="center"><input type="submit" value="Submit">
46 </td>
47</tr>
48</table>
49</form>
50"""
51
mbligh12eebfa2008-01-03 02:01:53 +000052
mbligh5dd503b2008-01-03 16:35:27 +000053next_field = {
mbligh44710b62008-03-07 00:25:43 +000054 'machine_group': 'hostname',
55 'hostname': 'tag',
56 'tag': 'tag',
mbligh5dd503b2008-01-03 16:35:27 +000057
mbligh44710b62008-03-07 00:25:43 +000058 'kernel': 'test',
59 'test': 'label',
60 'label': 'tag',
mbligh5dd503b2008-01-03 16:35:27 +000061
mbligh44710b62008-03-07 00:25:43 +000062 'reason': 'tag',
63 'user': 'tag',
64 'status': 'tag',
65
mbligh5bb55862008-04-16 23:09:31 +000066 'time': 'tag',
67 'time_daily': 'time',
mbligh5dd503b2008-01-03 16:35:27 +000068}
69
70
mbligh11204f82008-04-16 23:30:07 +000071def parse_field(form, form_field, field_default):
72 if not form_field in form:
73 return field_default
mbligh12eebfa2008-01-03 02:01:53 +000074 field_input = form[form_field].value.lower()
mbligh2ba3e732008-01-16 01:30:19 +000075 if field_input and field_input in frontend.test_view_field_dict:
mbligh12eebfa2008-01-03 02:01:53 +000076 return field_input
mbligh11204f82008-04-16 23:30:07 +000077 return field_default
mbligh12eebfa2008-01-03 02:01:53 +000078
79
80def parse_condition(form, form_field, field_default):
81 if not form_field in form:
82 return field_default
83 return form[form_field].value
84
85
86form = cgi.FieldStorage()
mbligh3d7a5f52008-04-16 23:06:36 +000087
mblighbe257452008-04-16 23:29:13 +000088title_field = parse_condition(form, 'title', '')
mbligh9add5882008-04-16 23:32:01 +000089row = parse_field(form, 'rows', 'kernel')
90column = parse_field(form, 'columns', 'machine_group')
91condition_field = parse_condition(form, 'condition', '')
mbligh44710b62008-03-07 00:25:43 +000092
mbligh439661b2008-02-19 15:57:53 +000093## caller can specify rows and columns that shall be included into the report
94## regardless of whether actual test data is available yet
95force_row_field = parse_condition(form,'force_row','')
96force_column_field = parse_condition(form,'force_column','')
mbligh190a81d2007-11-05 20:40:38 +000097
mbligh9add5882008-04-16 23:32:01 +000098
mbligh439661b2008-02-19 15:57:53 +000099def split_forced_fields(force_field):
100 if force_field:
101 return force_field.split()
102 else:
103 return []
104
105force_row = split_forced_fields(force_row_field)
106force_column = split_forced_fields(force_column_field)
107
mbligh2e4e5df2007-11-05 17:22:46 +0000108cgitb.enable()
mblighaea09602008-04-16 22:59:37 +0000109db_obj = db.db()
mbligh2e4e5df2007-11-05 17:22:46 +0000110
mbligh12eebfa2008-01-03 02:01:53 +0000111
mbligh2ba3e732008-01-16 01:30:19 +0000112def construct_link(x, y):
113 next_row = row
114 next_column = column
mbligh5dd503b2008-01-03 16:35:27 +0000115 condition_list = []
116 if condition_field != '':
117 condition_list.append(condition_field)
mbligh2ba3e732008-01-16 01:30:19 +0000118 if y:
119 next_row = next_field[row]
120 condition_list.append("%s='%s'" % (row, y))
121 if x:
122 next_column = next_field[column]
123 condition_list.append("%s='%s'" % (column, x))
mblighb180f6c2008-01-04 20:24:41 +0000124 next_condition = '&'.join(condition_list)
mblighbe257452008-04-16 23:29:13 +0000125 link = 'compose_query.cgi?' + urllib.urlencode({'columns': next_column,
126 'rows': next_row, 'condition': next_condition,
127 'title': title_field})
128 return link
mbligh5dd503b2008-01-03 16:35:27 +0000129
130
mbligh38e9d782008-05-01 20:49:41 +0000131def construct_logs_link(x, y, job_tag):
132 job_path = frontend.html_root + job_tag + '/'
133 test = ''
134 if (row == 'test' and
135 not y.split('.')[0] in ('boot', 'build', 'install')):
136 test = y
137 if (column == 'test' and
138 not x.split('.')[0] in ('boot', 'build', 'install')):
139 test = x
140 return 'retrieve_logs.cgi?' + urllib.urlencode({'job' : job_path,
141 'test' : test})
142
143
mbligh12eebfa2008-01-03 02:01:53 +0000144def create_select_options(selected_val):
mbligh190a81d2007-11-05 20:40:38 +0000145 ret = ""
mbligh2ba3e732008-01-16 01:30:19 +0000146 for option in sorted(frontend.test_view_field_dict.keys()):
mbligh190a81d2007-11-05 20:40:38 +0000147 if selected_val == option:
148 selected = " SELECTED"
149 else:
150 selected = ""
151
mbligh2ba3e732008-01-16 01:30:19 +0000152 ret += '<OPTION VALUE="%s"%s>%s</OPTION>\n' % \
153 (option, selected, option)
mbligh190a81d2007-11-05 20:40:38 +0000154 return ret
155
156
apw7a7316b2008-02-21 17:42:05 +0000157def map_kernel_base(kernel_name):
mbligh439661b2008-02-19 15:57:53 +0000158 ## insert <br> after each / in kernel name
159 ## but spare consequtive //
mbligh8e7c78e2008-02-20 21:18:49 +0000160 kernel_name = kernel_name.replace('/','/<br>')
161 kernel_name = kernel_name.replace('/<br>/<br>','//')
mbligh439661b2008-02-19 15:57:53 +0000162 return kernel_name
163
164
mbligh44710b62008-03-07 00:25:43 +0000165def header_tuneup(field_name, header):
166 ## header tune up depends on particular field name and may include:
167 ## - breaking header into several strings if it is long url
168 ## - creating date from datetime stamp
169 ## - possibly, expect more various refinements for different fields
170 if field_name == 'kernel':
171 return map_kernel_base(header)
mbligh44710b62008-03-07 00:25:43 +0000172 else:
173 return header
174
175
apw7a7316b2008-02-21 17:42:05 +0000176# Kernel name mappings -- the kernels table 'printable' field is
177# effectively a sortable identifier for the kernel It encodes the base
178# release which is used for overall sorting, plus where patches are
179# applied it adds an increasing pNNN patch combination identifier
180# (actually the kernel_idx for the entry). This allows sorting
181# as normal by the base kernel version and then sub-sorting by the
182# "first time we saw" a patch combination which should keep them in
183# approximatly date order. This patch identifier is not suitable
184# for display, so we have to map it to a suitable html fragment for
185# display. This contains the kernel base version plus the truncated
186# names of all the patches,
187#
188# 2.6.24-mm1 p112
189# +add-new-string-functions-
190# +x86-amd-thermal-interrupt
191#
192# This mapping is produced when the first mapping is request, with
193# a single query over the patches table; the result is then cached.
194#
195# Note: that we only count a base version as patched if it contains
196# patches which are not already "expressed" in the base version.
197# This includes both -gitN and -mmN kernels.
198map_kernel_map = None
199
200
201def map_kernel_init():
202 fields = ['base', 'k.kernel_idx', 'name', 'url']
203 map = {}
mblighaea09602008-04-16 22:59:37 +0000204 for (base, idx, name, url) in db_obj.select(','.join(fields),
apw7a7316b2008-02-21 17:42:05 +0000205 'kernels k,patches p', 'k.kernel_idx=p.kernel_idx'):
206 match = re.match(r'.*(-mm[0-9]+|-git[0-9]+)\.(bz2|gz)$', url)
207 if match:
208 continue
209
210 key = base + ' p%d' % (idx)
211 if not map.has_key(key):
212 map[key] = map_kernel_base(base) + ' p%d' % (idx)
213 map[key] += '<br>+<span title="' + name + '">' + name[0:25] + '</span>'
214
215 return map
216
217
218def map_kernel(name):
219 global map_kernel_map
220 if map_kernel_map == None:
221 map_kernel_map = map_kernel_init()
222
223 if map_kernel_map.has_key(name):
224 return map_kernel_map[name]
225
226 return map_kernel_base(name.split(' ')[0])
227
228
229field_map = {
230 'kernel':map_kernel
231}
232
jadmanski36505a92008-05-01 22:07:02 +0000233sql_wall_time = 0
apw7a7316b2008-02-21 17:42:05 +0000234
mbligh12eebfa2008-01-03 02:01:53 +0000235def gen_matrix():
mbligh12eebfa2008-01-03 02:01:53 +0000236 where = None
237 if condition_field.strip() != '':
mbligh44710b62008-03-07 00:25:43 +0000238 try:
239 where = query_lib.parse_scrub_and_gen_condition(
240 condition_field, frontend.test_view_field_dict)
241 print "<!-- where clause: %s -->" % (where,)
242 except:
243 msg = "Unspecified error when parsing condition"
244 return [[display.box(msg)]]
mbligh2e4e5df2007-11-05 17:22:46 +0000245
jadmanski36505a92008-05-01 22:07:02 +0000246 wall_time_start = time.time()
mblighaea09602008-04-16 22:59:37 +0000247 try:
mbligh31260692008-04-16 23:12:12 +0000248 ## Unfortunately, we can not request reasons of failure always
249 ## because it may result in an inflated size of data transfer
250 ## (at the moment we fetch 500 bytes of reason descriptions into
251 ## each cell )
252 ## If 'status' in [row,column] then either width or height
253 ## of the table <=7, hence table is not really 2D, and
254 ## query_reason is relatively save.
255 ## At the same time view when either rows or columns grouped
256 ## by status is when users need reasons of failures the most.
257
258 ## TO DO: implement [Show/Hide reasons] button or link in
259 ## all views and make thorough performance testing
260 test_data = frontend.get_matrix_data(db_obj, column, row, where,
261 query_reasons = ('status' in [row,column])
262 )
jadmanski36505a92008-05-01 22:07:02 +0000263 global sql_wall_time
264 sql_wall_time = time.time() - wall_time_start
265
mblighaea09602008-04-16 22:59:37 +0000266 except db.MySQLTooManyRows, error:
267 return [[display.box(str(error))]]
mbligh44710b62008-03-07 00:25:43 +0000268
mbligh439661b2008-02-19 15:57:53 +0000269 for f_row in force_row:
270 if not f_row in test_data.y_values:
271 test_data.y_values.append(f_row)
272 for f_column in force_column:
273 if not f_column in test_data.x_values:
274 test_data.x_values.append(f_column)
mbligh2e4e5df2007-11-05 17:22:46 +0000275
mbligh2ba3e732008-01-16 01:30:19 +0000276 if not test_data.y_values:
mbligh12eebfa2008-01-03 02:01:53 +0000277 msg = "There are no results for this query (yet?)."
278 return [[display.box(msg)]]
mbligh2e4e5df2007-11-05 17:22:46 +0000279
mbligh456b4772008-03-25 23:54:45 +0000280 dict_url = {'columns': row,
mblighbe257452008-04-16 23:29:13 +0000281 'rows': column, 'condition': condition_field,
282 'title': title_field}
mbligh456b4772008-03-25 23:54:45 +0000283 link = 'compose_query.cgi?' + urllib.urlencode(dict_url)
mbligh5dd503b2008-01-03 16:35:27 +0000284 header_row = [display.box("<center>(Flip Axis)</center>", link=link)]
285
mbligh2ba3e732008-01-16 01:30:19 +0000286 for x in test_data.x_values:
apw7a7316b2008-02-21 17:42:05 +0000287 dx = x
288 if field_map.has_key(column):
289 dx = field_map[column](x)
mbligh44710b62008-03-07 00:25:43 +0000290 x_header = header_tuneup(column, dx)
291 link = construct_link(x, None)
292 header_row.append(display.box(x_header,header=True,link=link))
mbligh2e4e5df2007-11-05 17:22:46 +0000293
294 matrix = [header_row]
jadmanskif9fa4272008-05-02 15:43:33 +0000295 # For each row, we are looping horizontally over the columns.
mbligh2ba3e732008-01-16 01:30:19 +0000296 for y in test_data.y_values:
apw7a7316b2008-02-21 17:42:05 +0000297 dy = y
298 if field_map.has_key(row):
299 dy = field_map[row](y)
mbligh44710b62008-03-07 00:25:43 +0000300 y_header = header_tuneup(row, dy)
mbligh5bb55862008-04-16 23:09:31 +0000301 link = construct_link(None, y)
mbligh44710b62008-03-07 00:25:43 +0000302 cur_row = [display.box(y_header, header=True, link=link)]
mbligh2ba3e732008-01-16 01:30:19 +0000303 for x in test_data.x_values:
mbligh44710b62008-03-07 00:25:43 +0000304 ## next 2 lines: temporary, until non timestamped
305 ## records are in the database
306 if x==datetime.datetime(1970,1,1): x = None
307 if y==datetime.datetime(1970,1,1): y = None
mbligh12eebfa2008-01-03 02:01:53 +0000308 try:
mbligh31260692008-04-16 23:12:12 +0000309 box_data = test_data.data[x][y]
mbligh12eebfa2008-01-03 02:01:53 +0000310 except:
jadmanskif9fa4272008-05-02 15:43:33 +0000311 cur_row.append(display.box(None, None,
312 row_label=y, column_label=x))
mbligh12eebfa2008-01-03 02:01:53 +0000313 continue
mbligh2ba3e732008-01-16 01:30:19 +0000314 job_tag = test_data.data[x][y].job_tag
mbligh5dd503b2008-01-03 16:35:27 +0000315 if job_tag:
mbligh38e9d782008-05-01 20:49:41 +0000316 link = construct_logs_link(x, y, job_tag)
mbligh5dd503b2008-01-03 16:35:27 +0000317 else:
mbligh2ba3e732008-01-16 01:30:19 +0000318 link = construct_link(x, y)
jadmanskif9fa4272008-05-02 15:43:33 +0000319
mblighaea09602008-04-16 22:59:37 +0000320 cur_row.append(display.status_precounted_box(db_obj,
mbligh5dd503b2008-01-03 16:35:27 +0000321 box_data,
jadmanskif9fa4272008-05-02 15:43:33 +0000322 link, y, x))
mbligh12eebfa2008-01-03 02:01:53 +0000323 matrix.append(cur_row)
mbligh12eebfa2008-01-03 02:01:53 +0000324 return matrix
mbligh2b672532007-11-05 19:24:51 +0000325
mbligh2b672532007-11-05 19:24:51 +0000326
mbligh12eebfa2008-01-03 02:01:53 +0000327def main():
mbligh190a81d2007-11-05 20:40:38 +0000328 # create the actual page
mbligh190a81d2007-11-05 20:40:38 +0000329 print '<html><head><title>'
330 print 'Filtered Autotest Results'
331 print '</title></head><body>'
mbligh14671622008-01-11 16:49:54 +0000332 display.print_main_header()
mbligh2ba3e732008-01-16 01:30:19 +0000333 print html_header % (create_select_options(column),
334 create_select_options(row),
mblighbe257452008-04-16 23:29:13 +0000335 condition_field, title_field)
336 if title_field:
337 print '<h1> %s </h1>' % (title_field)
mbligh439661b2008-02-19 15:57:53 +0000338 print display.color_keys_row()
mbligh12eebfa2008-01-03 02:01:53 +0000339 display.print_table(gen_matrix())
mbligh439661b2008-02-19 15:57:53 +0000340 print display.color_keys_row()
jadmanski36505a92008-05-01 22:07:02 +0000341 total_wall_time = time.time() - total_wall_time_start
342 print '<p style="font-size:x-small;">sql access wall time = %s secs, \
343 total wall time = %s secs</p>' % (sql_wall_time, total_wall_time)
mbligh190a81d2007-11-05 20:40:38 +0000344 print '</body></html>'
mbligh2e4e5df2007-11-05 17:22:46 +0000345
mbligh2e4e5df2007-11-05 17:22:46 +0000346main()