mbligh | 5f1839e | 2008-03-28 14:32:36 +0000 | [diff] [blame] | 1 | import os, re, sys, frontend |
mbligh | bfec522 | 2007-09-14 16:58:57 +0000 | [diff] [blame] | 2 | |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 3 | color_map = { |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame] | 4 | 'header' : '#e5e5c0', # greyish yellow |
| 5 | 'blank' : '#ffffff', # white |
| 6 | 'plain_text' : '#e5e5c0', # greyish yellow |
| 7 | 'borders' : '#bbbbbb', # grey |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 8 | 'white' : '#ffffff', # white |
| 9 | 'green' : '#66ff66', # green |
| 10 | 'yellow' : '#fffc00', # yellow |
| 11 | 'red' : '#ff6666', # red |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 12 | |
| 13 | #### additional keys for shaded color of a box |
| 14 | #### depending on stats of GOOD/FAIL |
mbligh | 310b59e | 2008-03-25 23:53:55 +0000 | [diff] [blame] | 15 | '100pct' : '#80ff80', # green, 94% to 100% of success |
| 16 | '95pct' : '#c0ff80', # step twrds yellow, 88% to 94% of success |
| 17 | '90pct' : '#ffff80', # yellow, 82% to 88% |
| 18 | '85pct' : '#ffc040', # 76% to 82% |
| 19 | '75pct' : '#ff4040', # red, 1% to 76% |
| 20 | '0pct' : '#d080d0', # violet, <1% of success |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 21 | |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 22 | } |
mbligh | bfec522 | 2007-09-14 16:58:57 +0000 | [diff] [blame] | 23 | |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 24 | |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 25 | def color_keys_row(): |
| 26 | """ Returns one row table with samples of 'NNpct' colors |
| 27 | defined in the color_map |
| 28 | and numbers of corresponding %% |
| 29 | """ |
| 30 | ### This function does not require maintenance in case of |
| 31 | ### color_map augmenting - as long as |
| 32 | ### color keys for box shading have names that end with 'pct' |
| 33 | keys = filter(lambda key: key.endswith('pct'), color_map.keys()) |
| 34 | def num_pct(key): |
| 35 | return int(key.replace('pct','')) |
| 36 | keys.sort(key=num_pct) |
| 37 | html = '' |
| 38 | for key in keys: |
| 39 | html+= "\t\t\t<td bgcolor =%s> </td>\n"\ |
| 40 | % color_map[key] |
| 41 | hint = key.replace('pct',' %') |
| 42 | if hint[0]<>'0': ## anything but 0 % |
| 43 | hint = 'to ' + hint |
| 44 | html+= "\t\t\t<td> %s </td>\n" % hint |
| 45 | |
| 46 | html = """ |
| 47 | <table width = "500" border="0" cellpadding="2" cellspacing="2">\n |
| 48 | <tbody>\n |
| 49 | <tr>\n |
| 50 | %s |
| 51 | </tr>\n |
| 52 | </tbody> |
| 53 | </table><br> |
| 54 | """ % html |
| 55 | return html |
| 56 | |
| 57 | |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 58 | class box: |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 59 | def __init__(self, data, color_key = None, header = False, link = None, |
| 60 | tooltip = None ): |
mbligh | 835c0e4 | 2008-03-11 21:39:54 +0000 | [diff] [blame] | 61 | if data: |
| 62 | data = "<tt>%s</tt>" % data |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 63 | if link and tooltip: |
| 64 | self.data = '<a href="%s" title="%s">%s</a>' \ |
| 65 | % (link, tooltip, data) |
| 66 | elif tooltip: |
| 67 | self.data = '<a href="%s" title="%s">%s</a>' \ |
| 68 | % ('#', tooltip, data) |
| 69 | elif link: |
mbligh | f91b3f5 | 2007-10-07 00:47:04 +0000 | [diff] [blame] | 70 | self.data = '<a href="%s">%s</a>' % (link, data) |
| 71 | else: |
| 72 | self.data = data |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 73 | |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 74 | if color_map.has_key(color_key): |
| 75 | self.color = color_map[color_key] |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame] | 76 | elif header: |
| 77 | self.color = color_map['header'] |
| 78 | elif data: |
| 79 | self.color = color_map['plain_text'] |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 80 | else: |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame] | 81 | self.color = color_map['blank'] |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 82 | self.header = header |
| 83 | |
| 84 | |
mbligh | 38757e7 | 2007-09-30 22:32:13 +0000 | [diff] [blame] | 85 | def html(self): |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 86 | if self.data: |
| 87 | data = self.data |
| 88 | else: |
| 89 | data = ' ' |
| 90 | |
| 91 | if self.header: |
| 92 | box_html = 'th' |
| 93 | else: |
| 94 | box_html = 'td' |
| 95 | |
mbligh | 38757e7 | 2007-09-30 22:32:13 +0000 | [diff] [blame] | 96 | return "<%s bgcolor=%s>%s</%s>" % \ |
| 97 | (box_html, self.color, data, box_html) |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 98 | |
| 99 | |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 100 | def grade_from_status(status): |
| 101 | # % of goodness |
| 102 | # GOOD (6) -> 1 |
mbligh | 302482e | 2008-05-01 20:06:16 +0000 | [diff] [blame] | 103 | # TEST_NA (8) is not counted |
mbligh | 1b4780e | 2008-02-21 16:27:52 +0000 | [diff] [blame] | 104 | # ## If the test doesn't PASS, it FAILS |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 105 | # else -> 0 |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 106 | |
| 107 | if status == 6: |
| 108 | return 1.0 |
mbligh | 1b4780e | 2008-02-21 16:27:52 +0000 | [diff] [blame] | 109 | else: |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 110 | return 0.0 |
| 111 | |
| 112 | |
| 113 | def average_grade_from_status_count(status_count): |
| 114 | average_grade = 0 |
| 115 | total_count = 0 |
| 116 | for key in status_count.keys(): |
mbligh | 302482e | 2008-05-01 20:06:16 +0000 | [diff] [blame] | 117 | if key != 8: # TEST_NA status |
| 118 | average_grade += (grade_from_status(key) |
| 119 | * status_count[key]) |
| 120 | total_count += status_count[key] |
| 121 | if total_count != 0: |
| 122 | average_grade = average_grade / total_count |
| 123 | else: |
| 124 | average_grade = 0.0 |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 125 | return average_grade |
| 126 | |
| 127 | |
| 128 | def shade_from_status_count(status_count): |
| 129 | if not status_count: |
| 130 | return None |
| 131 | |
| 132 | ## average_grade defines a shade of the box |
| 133 | ## 0 -> violet |
| 134 | ## 0.76 -> red |
| 135 | ## 0.88-> yellow |
| 136 | ## 1.0 -> green |
| 137 | average_grade = average_grade_from_status_count(status_count) |
| 138 | |
| 139 | ## find appropiate keyword from color_map |
| 140 | if average_grade<0.01: |
| 141 | shade = '0pct' |
mbligh | 8e7c78e | 2008-02-20 21:18:49 +0000 | [diff] [blame] | 142 | elif average_grade<0.75: |
| 143 | shade = '75pct' |
| 144 | elif average_grade<0.85: |
| 145 | shade = '85pct' |
| 146 | elif average_grade<0.90: |
| 147 | shade = '90pct' |
| 148 | elif average_grade<0.95: |
| 149 | shade = '95pct' |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 150 | else: |
| 151 | shade = '100pct' |
| 152 | |
| 153 | return shade |
| 154 | |
| 155 | |
mbligh | 3126069 | 2008-04-16 23:12:12 +0000 | [diff] [blame] | 156 | def status_html(db, box_data, shade): |
mbligh | a997a34 | 2007-10-06 22:35:04 +0000 | [diff] [blame] | 157 | """ |
| 158 | status_count: dict mapping from status (integer key) to count |
| 159 | eg. { 'GOOD' : 4, 'FAIL' : 1 } |
| 160 | """ |
mbligh | 3126069 | 2008-04-16 23:12:12 +0000 | [diff] [blame] | 161 | status_count = box_data.status_count |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 162 | if 6 in status_count.keys(): |
mbligh | 8e7c78e | 2008-02-20 21:18:49 +0000 | [diff] [blame] | 163 | html = "%d / %d " \ |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 164 | %(status_count[6],sum(status_count.values())) |
| 165 | else: |
mbligh | 8e7c78e | 2008-02-20 21:18:49 +0000 | [diff] [blame] | 166 | html = "%d / %d " % \ |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 167 | (0, sum(status_count.values())) |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 168 | |
mbligh | 3126069 | 2008-04-16 23:12:12 +0000 | [diff] [blame] | 169 | if box_data.reasons_list: |
| 170 | box_data.reasons_list.sort() |
| 171 | for reason in box_data.reasons_list: |
| 172 | reason = reason.replace('<br>','\n') |
| 173 | reason = reason.replace('<','[').replace('>',']') |
| 174 | reason = reason.replace('|','\n').replace('&',' AND ') |
| 175 | reason = reason.replace('\n','<br>') |
| 176 | html += '<br>' + reason |
| 177 | |
| 178 | tooltip = "" |
mbligh | a997a34 | 2007-10-06 22:35:04 +0000 | [diff] [blame] | 179 | for status in sorted(status_count.keys(), reverse = True): |
| 180 | status_word = db.status_word[status] |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 181 | tooltip += "%d %s " % (status_count[status], status_word) |
| 182 | return (html,tooltip) |
mbligh | a997a34 | 2007-10-06 22:35:04 +0000 | [diff] [blame] | 183 | |
| 184 | |
| 185 | def status_count_box(db, tests, link = None): |
| 186 | """ |
mbligh | 835c0e4 | 2008-03-11 21:39:54 +0000 | [diff] [blame] | 187 | Display a ratio of total number of GOOD tests |
| 188 | to total number of all tests in the group of tests. |
| 189 | More info (e.g. 10 GOOD, 2 WARN, 3 FAIL) is in tooltips |
mbligh | a997a34 | 2007-10-06 22:35:04 +0000 | [diff] [blame] | 190 | """ |
| 191 | if not tests: |
| 192 | return box(None, None) |
| 193 | |
| 194 | status_count = {} |
| 195 | for test in tests: |
| 196 | count = status_count.get(test.status_num, 0) |
| 197 | status_count[test.status_num] = count + 1 |
mbligh | 83f63a0 | 2007-12-12 19:13:04 +0000 | [diff] [blame] | 198 | return status_precounted_box(db, status_count, link) |
| 199 | |
| 200 | |
mbligh | 3126069 | 2008-04-16 23:12:12 +0000 | [diff] [blame] | 201 | def status_precounted_box(db, box_data, link = None): |
mbligh | 83f63a0 | 2007-12-12 19:13:04 +0000 | [diff] [blame] | 202 | """ |
mbligh | 835c0e4 | 2008-03-11 21:39:54 +0000 | [diff] [blame] | 203 | Display a ratio of total number of GOOD tests |
| 204 | to total number of all tests in the group of tests. |
| 205 | More info (e.g. 10 GOOD, 2 WARN, 3 FAIL) is in tooltips |
mbligh | 3126069 | 2008-04-16 23:12:12 +0000 | [diff] [blame] | 206 | """ |
| 207 | status_count = box_data.status_count |
mbligh | 83f63a0 | 2007-12-12 19:13:04 +0000 | [diff] [blame] | 208 | if not status_count: |
| 209 | return box(None, None) |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 210 | |
| 211 | shade = shade_from_status_count(status_count) |
mbligh | 3126069 | 2008-04-16 23:12:12 +0000 | [diff] [blame] | 212 | html,tooltip = status_html(db, box_data, shade) |
mbligh | 439661b | 2008-02-19 15:57:53 +0000 | [diff] [blame] | 213 | precounted_box = box(html, shade, False, link, tooltip) |
| 214 | return precounted_box |
mbligh | a997a34 | 2007-10-06 22:35:04 +0000 | [diff] [blame] | 215 | |
mbligh | 3126069 | 2008-04-16 23:12:12 +0000 | [diff] [blame] | 216 | |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 217 | def print_table(matrix): |
| 218 | """ |
| 219 | matrix: list of lists of boxes, giving a matrix of data |
| 220 | Each of the inner lists is a row, not a column. |
| 221 | |
| 222 | Display the given matrix of data as a table. |
| 223 | """ |
| 224 | |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame] | 225 | print '<table bgcolor="%s" cellspacing="1" cellpadding="5">' % ( |
| 226 | color_map['borders']) |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 227 | for row in matrix: |
| 228 | print '<tr>' |
| 229 | for element in row: |
mbligh | 38757e7 | 2007-09-30 22:32:13 +0000 | [diff] [blame] | 230 | print element.html() |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 231 | print '</tr>' |
| 232 | print '</table>' |
| 233 | |
| 234 | |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 235 | def sort_tests(tests): |
| 236 | kernel_order = ['patch', 'config', 'build', 'mkinitrd', 'install'] |
| 237 | |
| 238 | results = [] |
| 239 | for kernel_op in kernel_order: |
| 240 | test = 'kernel.' + kernel_op |
| 241 | if tests.count(test): |
| 242 | results.append(test) |
| 243 | tests.remove(test) |
mbligh | 7a41a86 | 2007-11-30 17:44:24 +0000 | [diff] [blame] | 244 | if tests.count('boot'): |
| 245 | results.append('boot') |
| 246 | tests.remove('boot') |
mbligh | cfd2d01 | 2007-09-19 21:07:34 +0000 | [diff] [blame] | 247 | return results + sorted(tests) |
mbligh | bfec522 | 2007-09-14 16:58:57 +0000 | [diff] [blame] | 248 | |
mbligh | 0459875 | 2007-10-01 15:49:58 +0000 | [diff] [blame] | 249 | |
| 250 | def print_main_header(): |
mbligh | 1405f4e | 2007-11-05 19:26:23 +0000 | [diff] [blame] | 251 | print '<head><style type="text/css">' |
| 252 | print 'a { text-decoration: none }' |
| 253 | print '</style></head>' |
mbligh | 0459875 | 2007-10-01 15:49:58 +0000 | [diff] [blame] | 254 | print '<h2>' |
mbligh | dfeee94 | 2008-02-07 20:47:39 +0000 | [diff] [blame] | 255 | print '<a href="compose_query.cgi">Functional</a>' |
mbligh | 0459875 | 2007-10-01 15:49:58 +0000 | [diff] [blame] | 256 | print '   ' |
| 257 | print '<a href="machine_benchmark.cgi">Performance</a>' |
mbligh | cb0c38c | 2008-01-11 16:49:25 +0000 | [diff] [blame] | 258 | print '   ' |
| 259 | print '<a href="http://test.kernel.org/autotest">[about Autotest]</a>' |
mbligh | 0459875 | 2007-10-01 15:49:58 +0000 | [diff] [blame] | 260 | print '</h2><p>' |
mbligh | 7a41a86 | 2007-11-30 17:44:24 +0000 | [diff] [blame] | 261 | |
| 262 | |
| 263 | def group_name(group): |
| 264 | name = re.sub('_', '<br>', group.name) |
| 265 | if re.search('/', name): |
| 266 | (owner, machine) = name.split('/', 1) |
mbligh | 7a41a86 | 2007-11-30 17:44:24 +0000 | [diff] [blame] | 267 | name = owner + '<br>' + machine |
| 268 | return name |