mbligh | c6b01ed | 2006-10-13 17:03:26 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
mbligh | 26b992b | 2008-02-19 15:46:21 +0000 | [diff] [blame] | 2 | import os, re, md5, sys, email.Message, smtplib, datetime |
mbligh | c251454 | 2008-02-19 15:54:26 +0000 | [diff] [blame] | 3 | |
mbligh | 532cb27 | 2007-11-26 18:54:20 +0000 | [diff] [blame] | 4 | client_bin = os.path.join(os.path.dirname(__file__), '../client/bin') |
| 5 | sys.path.insert(0, os.path.abspath(client_bin)) |
| 6 | from autotest_utils import read_keyval |
mbligh | bb7b891 | 2006-10-08 03:59:02 +0000 | [diff] [blame] | 7 | |
mbligh | b10a60f | 2007-10-17 00:03:32 +0000 | [diff] [blame] | 8 | user = re.compile(r'user(\s*)=') |
| 9 | label = re.compile(r'label(\s*)=') |
mbligh | b85e6b0 | 2006-10-08 17:20:56 +0000 | [diff] [blame] | 10 | |
mbligh | 006f230 | 2007-09-13 20:46:46 +0000 | [diff] [blame] | 11 | debug = True |
| 12 | |
mbligh | 74fc046 | 2007-11-05 20:24:17 +0000 | [diff] [blame] | 13 | # XXX: these mail bits came almost verbatim from mirror/mirror and this should |
| 14 | # probably be refactored into another file and used by both. |
| 15 | def mail(from_address, to_addresses, cc_addresses, subject, message_text): |
mbligh | 08415d8 | 2007-11-24 19:23:34 +0000 | [diff] [blame] | 16 | # if passed a string for the to_addresses convert it to a tuple |
| 17 | if type(to_addresses) is str: |
| 18 | to_addresses = (to_addresses,) |
mbligh | 74fc046 | 2007-11-05 20:24:17 +0000 | [diff] [blame] | 19 | |
mbligh | 08415d8 | 2007-11-24 19:23:34 +0000 | [diff] [blame] | 20 | message = email.Message.Message() |
| 21 | message["To"] = ", ".join(to_addresses) |
| 22 | message["Cc"] = ", ".join(cc_addresses) |
| 23 | message["From"] = from_address |
| 24 | message["Subject"] = subject |
| 25 | message.set_payload(message_text) |
mbligh | 74fc046 | 2007-11-05 20:24:17 +0000 | [diff] [blame] | 26 | |
mbligh | 08415d8 | 2007-11-24 19:23:34 +0000 | [diff] [blame] | 27 | try: |
| 28 | sendmail(message.as_string()) |
| 29 | except SendmailException, e: |
| 30 | server = smtplib.SMTP("localhost") |
| 31 | server.sendmail(from_address, to_addresses, cc_addresses, message.as_string()) |
| 32 | server.quit() |
mbligh | 74fc046 | 2007-11-05 20:24:17 +0000 | [diff] [blame] | 33 | |
| 34 | |
| 35 | MAIL = "sendmail" |
| 36 | |
| 37 | class SendmailException(Exception): |
mbligh | 08415d8 | 2007-11-24 19:23:34 +0000 | [diff] [blame] | 38 | pass |
mbligh | 74fc046 | 2007-11-05 20:24:17 +0000 | [diff] [blame] | 39 | |
| 40 | def sendmail(message): |
mbligh | 08415d8 | 2007-11-24 19:23:34 +0000 | [diff] [blame] | 41 | """Send an email using sendmail""" |
| 42 | # open a pipe to the mail program and |
| 43 | # write the data to the pipe |
| 44 | p = os.popen("%s -t" % MAIL, 'w') |
| 45 | p.write(message) |
| 46 | exitcode = p.close() |
| 47 | if exitcode: |
| 48 | raise SendmailException("Exit code: %s" % exitcode) |
mbligh | 74fc046 | 2007-11-05 20:24:17 +0000 | [diff] [blame] | 49 | |
| 50 | # XXX: End of code from mirror/mirror |
| 51 | |
| 52 | |
mbligh | b85e6b0 | 2006-10-08 17:20:56 +0000 | [diff] [blame] | 53 | def shorten_patch(long): |
mbligh | 340c968 | 2006-10-08 18:26:08 +0000 | [diff] [blame] | 54 | short = os.path.basename(long) |
mbligh | b85e6b0 | 2006-10-08 17:20:56 +0000 | [diff] [blame] | 55 | short = re.sub(r'^patch-', '', short) |
| 56 | short = re.sub(r'\.(bz2|gz)$', '', short) |
| 57 | short = re.sub(r'\.patch$', '', short) |
| 58 | short = re.sub(r'\+', '_', short) |
| 59 | return short |
| 60 | |
mbligh | bb7b891 | 2006-10-08 03:59:02 +0000 | [diff] [blame] | 61 | |
mbligh | 006f230 | 2007-09-13 20:46:46 +0000 | [diff] [blame] | 62 | def dprint(info): |
| 63 | if debug: |
| 64 | sys.stderr.write(str(info) + '\n') |
| 65 | |
| 66 | |
mbligh | c251454 | 2008-02-19 15:54:26 +0000 | [diff] [blame] | 67 | def get_timestamp(mapping, field): |
| 68 | val = mapping.get(field, None) |
mbligh | 26b992b | 2008-02-19 15:46:21 +0000 | [diff] [blame] | 69 | if val is not None: |
| 70 | val = datetime.datetime.fromtimestamp(int(val)) |
| 71 | return val |
| 72 | |
| 73 | |
mbligh | 71d340d | 2008-03-05 15:51:16 +0000 | [diff] [blame^] | 74 | class status_stack: |
| 75 | def __init__(self, job): |
| 76 | self.job = job |
| 77 | self.status_stack = [self.job.statuses[-1]] |
| 78 | |
| 79 | |
| 80 | def current_status(self): |
| 81 | return self.status_stack[-1] |
| 82 | |
| 83 | |
| 84 | def update(self, new_status): |
| 85 | if new_status not in self.job.statuses: |
| 86 | return |
| 87 | old = self.job.statuses.index(self.current_status()) |
| 88 | new = self.job.statuses.index(new_status) |
| 89 | if new < old: |
| 90 | self.status_stack[-1] = new_status |
| 91 | |
| 92 | |
| 93 | def start(self): |
| 94 | self.status_stack.append(self.job.statuses[-1]) |
| 95 | |
| 96 | |
| 97 | def end(self): |
| 98 | result = self.status_stack.pop() |
| 99 | if len(self.status_stack) == 0: |
| 100 | self.status_stack.append(self.job.statuses[-1]) |
| 101 | return result |
| 102 | |
| 103 | |
| 104 | |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 105 | class job: |
mbligh | 71d340d | 2008-03-05 15:51:16 +0000 | [diff] [blame^] | 106 | statuses = ['NOSTATUS', 'ERROR', 'ABORT', 'FAIL', 'WARN', 'GOOD', |
| 107 | 'ALERT'] |
| 108 | |
mbligh | 532cb27 | 2007-11-26 18:54:20 +0000 | [diff] [blame] | 109 | def __init__(self, dir): |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 110 | self.dir = dir |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 111 | self.control = os.path.join(dir, "control") |
mbligh | e8b37a9 | 2007-12-19 15:54:11 +0000 | [diff] [blame] | 112 | self.status = os.path.join(dir, "status.log") |
| 113 | if not os.path.exists(self.status): |
| 114 | self.status = os.path.join(dir, "status") |
mbligh | bb7b891 | 2006-10-08 03:59:02 +0000 | [diff] [blame] | 115 | self.variables = {} |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 116 | self.tests = [] |
mbligh | bb7b891 | 2006-10-08 03:59:02 +0000 | [diff] [blame] | 117 | self.kernel = None |
| 118 | |
mbligh | b10a60f | 2007-10-17 00:03:32 +0000 | [diff] [blame] | 119 | # Get the user + tag info from the keyval file. |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 120 | try: |
mbligh | 532cb27 | 2007-11-26 18:54:20 +0000 | [diff] [blame] | 121 | keyval = read_keyval(dir) |
| 122 | print keyval |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 123 | except: |
mbligh | 532cb27 | 2007-11-26 18:54:20 +0000 | [diff] [blame] | 124 | keyval = {} |
| 125 | self.user = keyval.get('user', None) |
| 126 | self.label = keyval.get('label', None) |
| 127 | self.machine = keyval.get('hostname', None) |
mbligh | e8b37a9 | 2007-12-19 15:54:11 +0000 | [diff] [blame] | 128 | if self.machine: |
| 129 | assert ',' not in self.machine |
mbligh | c251454 | 2008-02-19 15:54:26 +0000 | [diff] [blame] | 130 | self.queued_time = get_timestamp(keyval, 'job_queued') |
| 131 | self.started_time = get_timestamp(keyval, 'job_started') |
| 132 | self.finished_time = get_timestamp(keyval, 'job_finished') |
mbligh | 7a41a86 | 2007-11-30 17:44:24 +0000 | [diff] [blame] | 133 | self.machine_owner = keyval.get('owner', None) |
mbligh | 532cb27 | 2007-11-26 18:54:20 +0000 | [diff] [blame] | 134 | |
| 135 | if not self.machine: |
| 136 | self.get_machine() |
| 137 | |
| 138 | print 'MACHINE NAME: ' + self.machine |
| 139 | if not os.path.exists(self.status): |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 140 | return None |
| 141 | |
mbligh | 529f2f3 | 2007-08-30 11:22:50 +0000 | [diff] [blame] | 142 | self.grope_status() |
mbligh | bb7b891 | 2006-10-08 03:59:02 +0000 | [diff] [blame] | 143 | |
| 144 | |
mbligh | 532cb27 | 2007-11-26 18:54:20 +0000 | [diff] [blame] | 145 | def get_machine(self): |
| 146 | try: |
mbligh | 7a41a86 | 2007-11-30 17:44:24 +0000 | [diff] [blame] | 147 | hostname = os.path.join(self.dir, "sysinfo/hostname") |
mbligh | 532cb27 | 2007-11-26 18:54:20 +0000 | [diff] [blame] | 148 | self.machine = open(hostname, 'r').readline().rstrip() |
| 149 | return |
| 150 | except: |
| 151 | pass |
| 152 | try: |
mbligh | 7a41a86 | 2007-11-30 17:44:24 +0000 | [diff] [blame] | 153 | uname = os.path.join(self.dir, "sysinfo/uname_-a") |
mbligh | 532cb27 | 2007-11-26 18:54:20 +0000 | [diff] [blame] | 154 | self.machine = open(uname, 'r').readline().split()[1] |
| 155 | return |
| 156 | except: |
| 157 | pass |
mbligh | 215a166 | 2007-11-29 19:16:58 +0000 | [diff] [blame] | 158 | raise "Could not figure out machine name" |
mbligh | 71d340d | 2008-03-05 15:51:16 +0000 | [diff] [blame^] | 159 | |
mbligh | 532cb27 | 2007-11-26 18:54:20 +0000 | [diff] [blame] | 160 | |
mbligh | d5c33db | 2006-10-08 21:34:16 +0000 | [diff] [blame] | 161 | def grope_status(self): |
mbligh | 215a166 | 2007-11-29 19:16:58 +0000 | [diff] [blame] | 162 | """ |
| 163 | Note that what we're looking for here is level 1 groups |
| 164 | (ie end markers with 1 tab in front) |
| 165 | |
| 166 | For back-compatiblity, we also count level 0 groups that |
| 167 | are not job-level events, if there's no start/end job level |
| 168 | markers: "START ---- ----" |
| 169 | """ |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 170 | dprint('=====================================================') |
| 171 | dprint(self.dir) |
| 172 | dprint('=====================================================') |
mbligh | 049f5e6 | 2007-09-30 02:00:14 +0000 | [diff] [blame] | 173 | self.kernel = kernel(self.dir) |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 174 | |
mbligh | 40d021b | 2007-12-03 17:35:51 +0000 | [diff] [blame] | 175 | reboot_inprogress = 0 # Saw reboot start and not finish |
mbligh | 9bcfef7 | 2008-02-12 20:55:34 +0000 | [diff] [blame] | 176 | boot_count = 0 |
apw | 569f478 | 2007-12-13 19:32:53 +0000 | [diff] [blame] | 177 | alert_pending = None # Saw an ALERT for this test |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 178 | group_subdir = None |
mbligh | 71d340d | 2008-03-05 15:51:16 +0000 | [diff] [blame^] | 179 | group_status = status_stack(self) |
mbligh | 215a166 | 2007-11-29 19:16:58 +0000 | [diff] [blame] | 180 | sought_level = 0 # we log events at indent level 0 |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 181 | for line in open(self.status, 'r').readlines(): |
mbligh | 215a166 | 2007-11-29 19:16:58 +0000 | [diff] [blame] | 182 | dprint('\nSTATUS: ' + line.rstrip()) |
| 183 | if not re.search(r'^\t*\S', line): |
| 184 | dprint('Continuation line, ignoring') |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 185 | continue # ignore continuation lines |
mbligh | 215a166 | 2007-11-29 19:16:58 +0000 | [diff] [blame] | 186 | if re.search(r'^START\t----\t----', line): |
| 187 | sought_level = 1 |
| 188 | # we now log events at indent level 1 |
| 189 | dprint('Found job level start marker. Looking for level 1 groups now') |
| 190 | continue |
| 191 | indent = re.search('^(\t*)', line).group(0).count('\t') |
mbligh | c251454 | 2008-02-19 15:54:26 +0000 | [diff] [blame] | 192 | line = line.lstrip() |
| 193 | line = line.rstrip('\n') |
mbligh | 215a166 | 2007-11-29 19:16:58 +0000 | [diff] [blame] | 194 | if line.startswith('START\t'): |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 195 | group_subdir = None |
mbligh | 71d340d | 2008-03-05 15:51:16 +0000 | [diff] [blame^] | 196 | group_status.start() |
mbligh | 215a166 | 2007-11-29 19:16:58 +0000 | [diff] [blame] | 197 | dprint('start line, ignoring') |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 198 | continue # ignore start lines |
| 199 | reason = None |
mbligh | c251454 | 2008-02-19 15:54:26 +0000 | [diff] [blame] | 200 | if line.startswith('END '): |
| 201 | elements = line.split('\t') |
| 202 | elements[0] = elements[0][4:] # remove 'END ' |
mbligh | bafa6ef | 2008-01-10 16:36:52 +0000 | [diff] [blame] | 203 | end = True |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 204 | else: |
mbligh | c251454 | 2008-02-19 15:54:26 +0000 | [diff] [blame] | 205 | elements = line.split('\t') |
mbligh | bafa6ef | 2008-01-10 16:36:52 +0000 | [diff] [blame] | 206 | end = False |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 207 | (status, subdir, testname, reason) = elements[0:4] |
mbligh | c251454 | 2008-02-19 15:54:26 +0000 | [diff] [blame] | 208 | status, subdir, testname = elements[:3] |
| 209 | reason = elements[-1] |
| 210 | optional_fields = dict(element.split('=', 1) |
| 211 | for element in elements[3:-1]) |
mbligh | 71d340d | 2008-03-05 15:51:16 +0000 | [diff] [blame^] | 212 | group_status.update(status) |
mbligh | c251454 | 2008-02-19 15:54:26 +0000 | [diff] [blame] | 213 | dprint('GROPE_STATUS: ' + |
mbligh | 71d340d | 2008-03-05 15:51:16 +0000 | [diff] [blame^] | 214 | str([group_status.current_status(), status, |
| 215 | subdir, testname, reason])) |
apw | 569f478 | 2007-12-13 19:32:53 +0000 | [diff] [blame] | 216 | if status == 'ALERT': |
| 217 | dprint('job level alert, recording') |
| 218 | alert_pending = reason |
| 219 | continue |
mbligh | bafa6ef | 2008-01-10 16:36:52 +0000 | [diff] [blame] | 220 | if testname == 'Autotest.install' and status == 'GOOD': |
| 221 | dprint('Sucessful autotest install, ignoring') |
mbligh | 59a479f | 2007-11-24 19:24:05 +0000 | [diff] [blame] | 222 | continue |
mbligh | bafa6ef | 2008-01-10 16:36:52 +0000 | [diff] [blame] | 223 | if testname == '----': |
| 224 | if status == 'ABORT' and not end: |
| 225 | testname = 'JOB' |
| 226 | else: |
| 227 | dprint('job level event, ignoring') |
| 228 | # This is a job level event, not a test |
| 229 | continue |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 230 | ################################################ |
| 231 | # REMOVE THIS SECTION ONCE OLD FORMAT JOBS ARE GONE |
| 232 | ################################################ |
mbligh | 215a166 | 2007-11-29 19:16:58 +0000 | [diff] [blame] | 233 | if re.search(r'^(GOOD|FAIL|WARN) ', line): |
mbligh | 71d340d | 2008-03-05 15:51:16 +0000 | [diff] [blame^] | 234 | status, testname, reason = line.split(None, 2) |
| 235 | |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 236 | if testname.startswith('kernel.'): |
| 237 | subdir = 'build' |
| 238 | else: |
| 239 | subdir = testname |
| 240 | if testname.startswith('completed'): |
| 241 | raise 'testname is crap' |
| 242 | ################################################ |
| 243 | if subdir == '----': |
| 244 | subdir = None |
| 245 | if line.startswith('END'): |
| 246 | subdir = group_subdir |
mbligh | bafa6ef | 2008-01-10 16:36:52 +0000 | [diff] [blame] | 247 | if indent != sought_level and status != 'ABORT': |
| 248 | # we're in a block group |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 249 | if subdir: |
mbligh | 215a166 | 2007-11-29 19:16:58 +0000 | [diff] [blame] | 250 | dprint('set group_subdir: %s' % subdir) |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 251 | group_subdir = subdir |
mbligh | 215a166 | 2007-11-29 19:16:58 +0000 | [diff] [blame] | 252 | dprint('incorrect indent level %d != %d, ignoring' % (indent, sought_level)) |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 253 | continue |
mbligh | e096846 | 2008-02-27 16:29:31 +0000 | [diff] [blame] | 254 | if not re.search(r'^(boot(\.\d+)?$|kernel\.)', testname): |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 255 | # This is a real test |
| 256 | if subdir and subdir.count('.'): |
| 257 | # eg dbench.ext3 |
| 258 | testname = subdir |
mbligh | 0e21c87 | 2008-01-03 16:36:56 +0000 | [diff] [blame] | 259 | if testname == 'reboot.start': |
| 260 | dprint('reboot start event, ignoring') |
| 261 | reboot_inprogress = 1 |
| 262 | continue |
mbligh | 215a166 | 2007-11-29 19:16:58 +0000 | [diff] [blame] | 263 | if testname == 'reboot.verify': |
mbligh | 9bcfef7 | 2008-02-12 20:55:34 +0000 | [diff] [blame] | 264 | testname = 'boot.%d' % boot_count |
mbligh | 0e21c87 | 2008-01-03 16:36:56 +0000 | [diff] [blame] | 265 | dprint('reboot verified') |
mbligh | 40d021b | 2007-12-03 17:35:51 +0000 | [diff] [blame] | 266 | reboot_inprogress = 0 |
mbligh | 9bcfef7 | 2008-02-12 20:55:34 +0000 | [diff] [blame] | 267 | boot_count += 1 |
apw | 569f478 | 2007-12-13 19:32:53 +0000 | [diff] [blame] | 268 | if alert_pending: |
| 269 | status = 'ALERT' |
| 270 | reason = alert_pending |
| 271 | alert_pending = None |
mbligh | 71d340d | 2008-03-05 15:51:16 +0000 | [diff] [blame^] | 272 | if status in self.statuses: |
| 273 | dprint('Adding: %s\nSubdir:%s\nTestname:%s\n%s' |
| 274 | % (group_status.current_status(), |
| 275 | subdir, testname, reason)) |
mbligh | 05d8121 | 2008-01-10 16:37:35 +0000 | [diff] [blame] | 276 | else: |
| 277 | dprint('WARNING: Invalid status code. Ignoring') |
| 278 | continue |
mbligh | c251454 | 2008-02-19 15:54:26 +0000 | [diff] [blame] | 279 | |
| 280 | finished_time = get_timestamp(optional_fields, |
| 281 | 'timestamp') |
mbligh | 71d340d | 2008-03-05 15:51:16 +0000 | [diff] [blame^] | 282 | test_status = group_status.end() |
| 283 | self.tests.append(test(subdir, testname, test_status, |
mbligh | c251454 | 2008-02-19 15:54:26 +0000 | [diff] [blame] | 284 | reason, self.kernel, self, |
| 285 | finished_time)) |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 286 | dprint('') |
mbligh | 05d8121 | 2008-01-10 16:37:35 +0000 | [diff] [blame] | 287 | |
mbligh | 40d021b | 2007-12-03 17:35:51 +0000 | [diff] [blame] | 288 | if reboot_inprogress: |
mbligh | 02ec1ba | 2008-02-21 16:15:09 +0000 | [diff] [blame] | 289 | testname = 'boot.%d' % boot_count |
mbligh | 40d021b | 2007-12-03 17:35:51 +0000 | [diff] [blame] | 290 | dprint('Adding: %s\nSubdir:%s\nTestname:%s\n%s' % |
mbligh | 02ec1ba | 2008-02-21 16:15:09 +0000 | [diff] [blame] | 291 | ('----', subdir, testname, reason)) |
| 292 | self.tests.append(test('----', testname, 'ABORT', |
mbligh | 40d021b | 2007-12-03 17:35:51 +0000 | [diff] [blame] | 293 | 'machine did not return from reboot', |
| 294 | self.kernel, self)) |
| 295 | dprint('') |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 296 | |
| 297 | |
| 298 | class kernel: |
mbligh | 049f5e6 | 2007-09-30 02:00:14 +0000 | [diff] [blame] | 299 | def __init__(self, topdir): |
mbligh | e8b37a9 | 2007-12-19 15:54:11 +0000 | [diff] [blame] | 300 | self.base = 'UNKNOWN' |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 301 | self.patches = [] |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 302 | patch_hashes = [] |
mbligh | 049f5e6 | 2007-09-30 02:00:14 +0000 | [diff] [blame] | 303 | # HACK. we don't have proper build tags in the status file yet |
| 304 | # so we hardcode build/ and do it at the start of the job |
mbligh | 9c39d15 | 2007-11-24 19:11:58 +0000 | [diff] [blame] | 305 | build_log = os.path.join(topdir, 'build/debug/build_log') |
mbligh | 049f5e6 | 2007-09-30 02:00:14 +0000 | [diff] [blame] | 306 | |
mbligh | 9c39d15 | 2007-11-24 19:11:58 +0000 | [diff] [blame] | 307 | if os.path.exists(build_log): |
| 308 | for line in open(build_log, 'r'): |
mbligh | 049f5e6 | 2007-09-30 02:00:14 +0000 | [diff] [blame] | 309 | print line |
| 310 | (type, rest) = line.split(': ', 1) |
| 311 | words = rest.split() |
| 312 | if type == 'BASE': |
| 313 | self.base = words[0] |
| 314 | if type == 'PATCH': |
| 315 | print words |
| 316 | self.patches.append(patch(*words[0:])) |
apw | 7a7316b | 2008-02-21 17:42:05 +0000 | [diff] [blame] | 317 | patch_hashes.append(words[2]) |
mbligh | 9c39d15 | 2007-11-24 19:11:58 +0000 | [diff] [blame] | 318 | else: |
| 319 | for sysinfo in ['sysinfo/reboot1', 'sysinfo']: |
| 320 | uname_file = os.path.join(topdir, sysinfo, 'uname_-a') |
| 321 | if not os.path.exists(uname_file): |
| 322 | continue |
| 323 | uname = open(uname_file, 'r').readline().split() |
| 324 | self.base = uname[2] |
mbligh | 215a166 | 2007-11-29 19:16:58 +0000 | [diff] [blame] | 325 | re.sub(r'-autotest$', '', self.base) |
mbligh | 9c39d15 | 2007-11-24 19:11:58 +0000 | [diff] [blame] | 326 | break |
| 327 | print 'kernel.__init__() found kernel version %s' % self.base |
mbligh | e8b37a9 | 2007-12-19 15:54:11 +0000 | [diff] [blame] | 328 | if self.base == 'UNKNOWN': |
| 329 | self.kernel_hash = 'UNKNOWN' |
| 330 | else: |
mbligh | 52f9744 | 2007-09-14 17:43:28 +0000 | [diff] [blame] | 331 | self.kernel_hash = self.get_kver_hash(self.base, patch_hashes) |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 332 | |
| 333 | |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 334 | def get_kver_hash(self, base, patch_hashes): |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 335 | """\ |
| 336 | Calculate a hash representing the unique combination of |
| 337 | the kernel base version plus |
| 338 | """ |
| 339 | key_string = ','.join([base] + patch_hashes) |
| 340 | return md5.new(key_string).hexdigest() |
| 341 | |
| 342 | |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 343 | class patch: |
| 344 | def __init__(self, spec, reference=None, hash=None): |
| 345 | # NEITHER OF THE ABOVE SHOULD HAVE DEFAULTS!!!! HACK HACK |
| 346 | if not reference: |
| 347 | reference = spec |
| 348 | print 'PATCH::%s %s %s' % (spec, reference, hash) |
| 349 | self.spec = spec |
| 350 | self.reference = reference |
| 351 | self.hash = hash |
| 352 | |
| 353 | |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 354 | class test: |
mbligh | c251454 | 2008-02-19 15:54:26 +0000 | [diff] [blame] | 355 | def __init__(self, subdir, testname, status, reason, kernel, job, |
| 356 | finished_time=None): |
mbligh | de94094 | 2007-11-05 17:25:56 +0000 | [diff] [blame] | 357 | # NOTE: subdir may be none here for lines that aren't an |
| 358 | # actual test |
mbligh | 2bd4887 | 2007-09-20 18:32:25 +0000 | [diff] [blame] | 359 | self.subdir = subdir |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 360 | self.testname = testname |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 361 | self.status = status |
| 362 | self.reason = reason |
mbligh | de94094 | 2007-11-05 17:25:56 +0000 | [diff] [blame] | 363 | self.version = None |
| 364 | self.keyval = None |
mbligh | 994a23d | 2007-10-25 15:28:58 +0000 | [diff] [blame] | 365 | |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 366 | if subdir: |
mbligh | de94094 | 2007-11-05 17:25:56 +0000 | [diff] [blame] | 367 | keyval = os.path.join(job.dir, subdir, 'results/keyval') |
| 368 | if os.path.exists(keyval): |
| 369 | self.keyval = keyval |
| 370 | keyval2 = os.path.join(job.dir, subdir, 'keyval') |
| 371 | if os.path.exists(keyval2): |
| 372 | self.version = open(keyval2, 'r').readline().split('=')[1] |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 373 | else: |
| 374 | self.keyval = None |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 375 | self.iterations = [] |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 376 | self.kernel = kernel |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 377 | self.machine = job.machine |
mbligh | c251454 | 2008-02-19 15:54:26 +0000 | [diff] [blame] | 378 | self.finished_time = finished_time |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 379 | |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 380 | dprint("PARSING TEST %s %s %s" % (subdir, testname, self.keyval)) |
mbligh | 994a23d | 2007-10-25 15:28:58 +0000 | [diff] [blame] | 381 | |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 382 | if not self.keyval: |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 383 | return |
| 384 | count = 1 |
| 385 | lines = [] |
| 386 | for line in open(self.keyval, 'r').readlines(): |
mbligh | 2bd4887 | 2007-09-20 18:32:25 +0000 | [diff] [blame] | 387 | if not re.search('\S', line): # blank line |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 388 | self.iterations.append(iteration(count, lines)) |
| 389 | lines = [] |
| 390 | count += 1 |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 391 | else: |
| 392 | lines.append(line) |
| 393 | if lines: |
| 394 | self.iterations.append(iteration(count, lines)) |
| 395 | |
| 396 | |
| 397 | class iteration: |
| 398 | def __init__(self, index, lines): |
| 399 | self.index = index |
| 400 | self.keyval = {} |
| 401 | |
mbligh | 2bd4887 | 2007-09-20 18:32:25 +0000 | [diff] [blame] | 402 | dprint("ADDING ITERATION %d" % index) |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 403 | for line in lines: |
mbligh | 4921b98 | 2007-12-03 17:47:45 +0000 | [diff] [blame] | 404 | line = line.rstrip(); |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 405 | (key, value) = line.split('=', 1) |
| 406 | self.keyval[key] = value |