mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | """ |
| 4 | Selects all rows and columns that satisfy the condition specified |
| 5 | and draws the matrix. There is a seperate SQL query made for every (x,y) |
| 6 | in the matrix. |
| 7 | """ |
| 8 | |
| 9 | |
| 10 | print "Content-type: text/html\n" |
| 11 | import cgi, cgitb, re |
mbligh | a426693 | 2007-11-05 18:12:16 +0000 | [diff] [blame] | 12 | import sys, os |
mbligh | b180f6c | 2008-01-04 20:24:41 +0000 | [diff] [blame] | 13 | import urllib |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 14 | |
| 15 | tko = os.path.dirname(os.path.realpath(os.path.abspath(sys.argv[0]))) |
| 16 | sys.path.insert(0, tko) |
| 17 | |
mbligh | 2b67253 | 2007-11-05 19:24:51 +0000 | [diff] [blame] | 18 | import display, frontend, db, query_lib |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 19 | client_bin = os.path.abspath(os.path.join(tko, '../client/bin')) |
| 20 | sys.path.insert(0, client_bin) |
| 21 | import kernel_versions |
| 22 | |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 23 | |
mbligh | 190a81d | 2007-11-05 20:40:38 +0000 | [diff] [blame] | 24 | html_header = """\ |
| 25 | <form action="compose_query.cgi" method="get"> |
| 26 | <table border="0"> |
| 27 | <tr> |
| 28 | <td>Column: </td> |
| 29 | <td>Row: </td> |
| 30 | <td>Condition: </td> |
| 31 | <td align="center"><a href="index.html">Help</a></td> |
| 32 | </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> |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 45 | <input type="text" name="condition" size="30" maxlength="200" value="%s"> |
mbligh | 190a81d | 2007-11-05 20:40:38 +0000 | [diff] [blame] | 46 | <input type="hidden" name="title" value="Report"> |
| 47 | </td> |
| 48 | <td align="center"><input type="submit" value="Submit"> |
| 49 | </td> |
| 50 | </tr> |
| 51 | </table> |
| 52 | </form> |
| 53 | """ |
| 54 | |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 55 | |
mbligh | 5dd503b | 2008-01-03 16:35:27 +0000 | [diff] [blame] | 56 | next_field = { |
| 57 | 'machine_group': 'hostname', |
| 58 | 'hostname': 'tag', |
| 59 | 'tag': 'tag', |
| 60 | |
| 61 | 'kernel': 'test', |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 62 | 'test': 'test', |
mbligh | 5dd503b | 2008-01-03 16:35:27 +0000 | [diff] [blame] | 63 | 'label': 'label', |
| 64 | |
| 65 | 'reason': 'reason', |
| 66 | 'user': 'user', |
| 67 | 'status': 'status', |
| 68 | } |
| 69 | |
| 70 | |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 71 | |
| 72 | def parse_field(form, form_field, field_default): |
| 73 | if not form_field in form: |
| 74 | return field_default |
| 75 | field_input = form[form_field].value.lower() |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 76 | if field_input and field_input in frontend.test_view_field_dict: |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 77 | return field_input |
| 78 | return field_default |
| 79 | |
| 80 | |
| 81 | def 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 | |
| 87 | form = cgi.FieldStorage() |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 88 | row = parse_field(form, 'rows', 'kernel') |
| 89 | column = parse_field(form, 'columns', 'machine_group') |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 90 | condition_field = parse_condition(form, 'condition', '') |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 91 | ## caller can specify rows and columns that shall be included into the report |
| 92 | ## regardless of whether actual test data is available yet |
| 93 | force_row_field = parse_condition(form,'force_row','') |
| 94 | force_column_field = parse_condition(form,'force_column','') |
mbligh | 190a81d | 2007-11-05 20:40:38 +0000 | [diff] [blame] | 95 | |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 96 | def split_forced_fields(force_field): |
| 97 | if force_field: |
| 98 | return force_field.split() |
| 99 | else: |
| 100 | return [] |
| 101 | |
| 102 | force_row = split_forced_fields(force_row_field) |
| 103 | force_column = split_forced_fields(force_column_field) |
| 104 | |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 105 | cgitb.enable() |
| 106 | db = db.db() |
| 107 | |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 108 | |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 109 | def construct_link(x, y): |
| 110 | next_row = row |
| 111 | next_column = column |
mbligh | 5dd503b | 2008-01-03 16:35:27 +0000 | [diff] [blame] | 112 | condition_list = [] |
| 113 | if condition_field != '': |
| 114 | condition_list.append(condition_field) |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 115 | if y: |
| 116 | next_row = next_field[row] |
| 117 | condition_list.append("%s='%s'" % (row, y)) |
| 118 | if x: |
| 119 | next_column = next_field[column] |
| 120 | condition_list.append("%s='%s'" % (column, x)) |
mbligh | b180f6c | 2008-01-04 20:24:41 +0000 | [diff] [blame] | 121 | next_condition = '&'.join(condition_list) |
| 122 | return 'compose_query.cgi?' + urllib.urlencode({'columns': next_column, |
| 123 | 'rows': next_row, 'condition': next_condition}) |
mbligh | 5dd503b | 2008-01-03 16:35:27 +0000 | [diff] [blame] | 124 | |
| 125 | |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 126 | def create_select_options(selected_val): |
mbligh | 190a81d | 2007-11-05 20:40:38 +0000 | [diff] [blame] | 127 | ret = "" |
mbligh | 190a81d | 2007-11-05 20:40:38 +0000 | [diff] [blame] | 128 | |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 129 | for option in sorted(frontend.test_view_field_dict.keys()): |
mbligh | 190a81d | 2007-11-05 20:40:38 +0000 | [diff] [blame] | 130 | if selected_val == option: |
| 131 | selected = " SELECTED" |
| 132 | else: |
| 133 | selected = "" |
| 134 | |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 135 | ret += '<OPTION VALUE="%s"%s>%s</OPTION>\n' % \ |
| 136 | (option, selected, option) |
mbligh | 190a81d | 2007-11-05 20:40:38 +0000 | [diff] [blame] | 137 | |
| 138 | return ret |
| 139 | |
| 140 | |
apw | 7a7316b | 2008-02-21 17:42:05 +0000 | [diff] [blame] | 141 | def map_kernel_base(kernel_name): |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 142 | ## insert <br> after each / in kernel name |
| 143 | ## but spare consequtive // |
mbligh | 8e7c78e | 2008-02-20 21:18:49 +0000 | [diff] [blame] | 144 | kernel_name = kernel_name.replace('/','/<br>') |
| 145 | kernel_name = kernel_name.replace('/<br>/<br>','//') |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 146 | return kernel_name |
| 147 | |
| 148 | |
apw | 7a7316b | 2008-02-21 17:42:05 +0000 | [diff] [blame] | 149 | # Kernel name mappings -- the kernels table 'printable' field is |
| 150 | # effectively a sortable identifier for the kernel It encodes the base |
| 151 | # release which is used for overall sorting, plus where patches are |
| 152 | # applied it adds an increasing pNNN patch combination identifier |
| 153 | # (actually the kernel_idx for the entry). This allows sorting |
| 154 | # as normal by the base kernel version and then sub-sorting by the |
| 155 | # "first time we saw" a patch combination which should keep them in |
| 156 | # approximatly date order. This patch identifier is not suitable |
| 157 | # for display, so we have to map it to a suitable html fragment for |
| 158 | # display. This contains the kernel base version plus the truncated |
| 159 | # names of all the patches, |
| 160 | # |
| 161 | # 2.6.24-mm1 p112 |
| 162 | # +add-new-string-functions- |
| 163 | # +x86-amd-thermal-interrupt |
| 164 | # |
| 165 | # This mapping is produced when the first mapping is request, with |
| 166 | # a single query over the patches table; the result is then cached. |
| 167 | # |
| 168 | # Note: that we only count a base version as patched if it contains |
| 169 | # patches which are not already "expressed" in the base version. |
| 170 | # This includes both -gitN and -mmN kernels. |
| 171 | map_kernel_map = None |
| 172 | |
| 173 | |
| 174 | def map_kernel_init(): |
| 175 | fields = ['base', 'k.kernel_idx', 'name', 'url'] |
| 176 | map = {} |
| 177 | for (base, idx, name, url) in db.select(','.join(fields), |
| 178 | 'kernels k,patches p', 'k.kernel_idx=p.kernel_idx'): |
| 179 | match = re.match(r'.*(-mm[0-9]+|-git[0-9]+)\.(bz2|gz)$', url) |
| 180 | if match: |
| 181 | continue |
| 182 | |
| 183 | key = base + ' p%d' % (idx) |
| 184 | if not map.has_key(key): |
| 185 | map[key] = map_kernel_base(base) + ' p%d' % (idx) |
| 186 | map[key] += '<br>+<span title="' + name + '">' + name[0:25] + '</span>' |
| 187 | |
| 188 | return map |
| 189 | |
| 190 | |
| 191 | def map_kernel(name): |
| 192 | global map_kernel_map |
| 193 | if map_kernel_map == None: |
| 194 | map_kernel_map = map_kernel_init() |
| 195 | |
| 196 | if map_kernel_map.has_key(name): |
| 197 | return map_kernel_map[name] |
| 198 | |
| 199 | return map_kernel_base(name.split(' ')[0]) |
| 200 | |
| 201 | |
| 202 | field_map = { |
| 203 | 'kernel':map_kernel |
| 204 | } |
| 205 | |
| 206 | |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 207 | def gen_matrix(): |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 208 | where = None |
| 209 | if condition_field.strip() != '': |
| 210 | where = query_lib.parse_scrub_and_gen_condition( |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 211 | condition_field, frontend.test_view_field_dict) |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 212 | print "<!-- where clause: %s -->" % (where,) |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 213 | |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 214 | test_data = frontend.get_matrix_data(db, column, row, where) |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 215 | |
| 216 | for f_row in force_row: |
| 217 | if not f_row in test_data.y_values: |
| 218 | test_data.y_values.append(f_row) |
| 219 | for f_column in force_column: |
| 220 | if not f_column in test_data.x_values: |
| 221 | test_data.x_values.append(f_column) |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 222 | |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 223 | if not test_data.y_values: |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 224 | msg = "There are no results for this query (yet?)." |
| 225 | return [[display.box(msg)]] |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 226 | |
mbligh | 5dd503b | 2008-01-03 16:35:27 +0000 | [diff] [blame] | 227 | link = 'compose_query.cgi?columns=%s&rows=%s&condition=%s' % ( |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 228 | row, column, condition_field) |
mbligh | 5dd503b | 2008-01-03 16:35:27 +0000 | [diff] [blame] | 229 | header_row = [display.box("<center>(Flip Axis)</center>", link=link)] |
| 230 | |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 231 | for x in test_data.x_values: |
| 232 | link = construct_link(x, None) |
apw | 7a7316b | 2008-02-21 17:42:05 +0000 | [diff] [blame] | 233 | dx = x |
| 234 | if field_map.has_key(column): |
| 235 | dx = field_map[column](x) |
| 236 | header_row.append(display.box(dx, header=True, link=link)) |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 237 | |
| 238 | matrix = [header_row] |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 239 | for y in test_data.y_values: |
| 240 | link = construct_link(None, y) |
apw | 7a7316b | 2008-02-21 17:42:05 +0000 | [diff] [blame] | 241 | dy = y |
| 242 | if field_map.has_key(row): |
| 243 | dy = field_map[row](y) |
| 244 | cur_row = [display.box(dy, header=True, link=link)] |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 245 | for x in test_data.x_values: |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 246 | try: |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 247 | box_data = test_data.data[x][y].status_count |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 248 | except: |
| 249 | cur_row.append(display.box(None, None)) |
| 250 | continue |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 251 | job_tag = test_data.data[x][y].job_tag |
mbligh | 5dd503b | 2008-01-03 16:35:27 +0000 | [diff] [blame] | 252 | if job_tag: |
mbligh | e47ff2a | 2008-02-28 00:44:11 +0000 | [diff] [blame] | 253 | link = frontend.html_root + job_tag + '/' |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 254 | if (row == 'test' and |
| 255 | not 'boot' in y and |
| 256 | not 'build' in y and |
| 257 | not 'install' in y ): |
| 258 | link += y + '/' |
| 259 | if (column == 'test' and |
| 260 | not 'boot' in x and |
| 261 | not 'build' in x and |
| 262 | not 'install' in x): |
| 263 | link += x + '/' |
mbligh | 5dd503b | 2008-01-03 16:35:27 +0000 | [diff] [blame] | 264 | else: |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 265 | link = construct_link(x, y) |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 266 | cur_row.append(display.status_precounted_box(db, |
mbligh | 5dd503b | 2008-01-03 16:35:27 +0000 | [diff] [blame] | 267 | box_data, |
| 268 | link)) |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 269 | matrix.append(cur_row) |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 270 | |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 271 | return matrix |
mbligh | 2b67253 | 2007-11-05 19:24:51 +0000 | [diff] [blame] | 272 | |
mbligh | 2b67253 | 2007-11-05 19:24:51 +0000 | [diff] [blame] | 273 | |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 274 | def main(): |
mbligh | 190a81d | 2007-11-05 20:40:38 +0000 | [diff] [blame] | 275 | # create the actual page |
mbligh | 190a81d | 2007-11-05 20:40:38 +0000 | [diff] [blame] | 276 | print '<html><head><title>' |
| 277 | print 'Filtered Autotest Results' |
| 278 | print '</title></head><body>' |
mbligh | 1467162 | 2008-01-11 16:49:54 +0000 | [diff] [blame] | 279 | display.print_main_header() |
mbligh | 2ba3e73 | 2008-01-16 01:30:19 +0000 | [diff] [blame] | 280 | print html_header % (create_select_options(column), |
| 281 | create_select_options(row), |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 282 | condition_field) |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 283 | print display.color_keys_row() |
mbligh | 12eebfa | 2008-01-03 02:01:53 +0000 | [diff] [blame] | 284 | display.print_table(gen_matrix()) |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 285 | print display.color_keys_row() |
mbligh | 190a81d | 2007-11-05 20:40:38 +0000 | [diff] [blame] | 286 | print '</body></html>' |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 287 | |
| 288 | |
| 289 | main() |