mbligh | c6b01ed | 2006-10-13 17:03:26 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
mbligh | 006f230 | 2007-09-13 20:46:46 +0000 | [diff] [blame^] | 2 | import os, re, md5, sys |
mbligh | bb7b891 | 2006-10-08 03:59:02 +0000 | [diff] [blame] | 3 | |
| 4 | valid_users = r'(apw|mbligh|andyw|korgtest)' |
| 5 | build_stock = re.compile('build generic stock (2\.\S+)') |
mbligh | b85e6b0 | 2006-10-08 17:20:56 +0000 | [diff] [blame] | 6 | build_url = re.compile('build generic url \S*/linux-(2\.\d\.\d+(\.\d+)?(-rc\d+)?).tar') |
mbligh | 340c968 | 2006-10-08 18:26:08 +0000 | [diff] [blame] | 7 | valid_kernel= re.compile('2\.\d\.\d+(\.\d+)?(-rc\d+)?(-(git|bk))\d+') |
mbligh | b85e6b0 | 2006-10-08 17:20:56 +0000 | [diff] [blame] | 8 | |
mbligh | 006f230 | 2007-09-13 20:46:46 +0000 | [diff] [blame^] | 9 | debug = True |
| 10 | |
mbligh | b85e6b0 | 2006-10-08 17:20:56 +0000 | [diff] [blame] | 11 | def shorten_patch(long): |
mbligh | 340c968 | 2006-10-08 18:26:08 +0000 | [diff] [blame] | 12 | short = os.path.basename(long) |
mbligh | b85e6b0 | 2006-10-08 17:20:56 +0000 | [diff] [blame] | 13 | short = re.sub(r'^patch-', '', short) |
| 14 | short = re.sub(r'\.(bz2|gz)$', '', short) |
| 15 | short = re.sub(r'\.patch$', '', short) |
| 16 | short = re.sub(r'\+', '_', short) |
| 17 | return short |
| 18 | |
mbligh | bb7b891 | 2006-10-08 03:59:02 +0000 | [diff] [blame] | 19 | |
mbligh | 006f230 | 2007-09-13 20:46:46 +0000 | [diff] [blame^] | 20 | def dprint(info): |
| 21 | if debug: |
| 22 | sys.stderr.write(str(info) + '\n') |
| 23 | |
| 24 | |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 25 | class job: |
| 26 | def __init__(self, dir, type): |
| 27 | self.dir = dir |
mbligh | d5c33db | 2006-10-08 21:34:16 +0000 | [diff] [blame] | 28 | self.type = type |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 29 | self.control = os.path.join(dir, "control") |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 30 | self.status = os.path.join(dir, "status") |
mbligh | bb7b891 | 2006-10-08 03:59:02 +0000 | [diff] [blame] | 31 | self.variables = {} |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 32 | self.tests = [] |
mbligh | bb7b891 | 2006-10-08 03:59:02 +0000 | [diff] [blame] | 33 | self.kernel = None |
| 34 | |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 35 | if not os.path.exists(self.status): |
| 36 | return None |
| 37 | |
| 38 | # We should really replace this with sysinfo/hostname! |
| 39 | uname = os.path.join(dir, "sysinfo/uname_-a") |
| 40 | try: |
| 41 | self.machine = open(uname, 'r').readline().split()[1] |
| 42 | except: |
| 43 | return None |
| 44 | |
mbligh | 529f2f3 | 2007-08-30 11:22:50 +0000 | [diff] [blame] | 45 | self.grope_status() |
mbligh | bb7b891 | 2006-10-08 03:59:02 +0000 | [diff] [blame] | 46 | |
| 47 | |
mbligh | d5c33db | 2006-10-08 21:34:16 +0000 | [diff] [blame] | 48 | def grope_status(self): |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 49 | # HACK. we don't have proper build tags in the status file yet |
| 50 | # so we hardcode build/ and do it at the start of the job |
| 51 | build = os.path.join(self.dir, 'build') |
| 52 | if os.path.exists(build): |
| 53 | self.kernel = kernel(build) |
| 54 | |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 55 | for line in open(self.status, 'r').readlines(): |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 56 | (status, testname, reason) = line.rstrip().split(' ', 2) |
mbligh | 006f230 | 2007-09-13 20:46:46 +0000 | [diff] [blame^] | 57 | dprint('GROPE_STATUS: '+str((status, testname, reason))) |
| 58 | self.tests.append(test(testname, status, reason, self.kernel, self)) |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 59 | |
| 60 | |
| 61 | class kernel: |
| 62 | def __init__(self, builddir): |
| 63 | self.base = None |
| 64 | self.patches = [] |
| 65 | |
| 66 | log = os.path.join(builddir, 'debug/build_log') |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 67 | if not os.path.exists(log): |
| 68 | return |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 69 | patch_hashes = [] |
| 70 | for line in open(log, 'r'): |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 71 | print line |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 72 | (type, rest) = line.split(': ', 1) |
| 73 | words = rest.split() |
| 74 | if type == 'BUILD VERSION': |
| 75 | self.base = words[0] |
| 76 | if type == 'PATCH': |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 77 | print words |
| 78 | self.patches.append(patch(*words[0:])) |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 79 | # patch_hashes.append(words[2]) |
mbligh | 9bb92fe | 2007-09-12 15:54:23 +0000 | [diff] [blame] | 80 | self.kernel_hash = self.get_kver_hash(self.base, patch_hashes) |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 81 | |
| 82 | |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 83 | def get_kver_hash(self, base, patch_hashes): |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 84 | """\ |
| 85 | Calculate a hash representing the unique combination of |
| 86 | the kernel base version plus |
| 87 | """ |
| 88 | key_string = ','.join([base] + patch_hashes) |
| 89 | return md5.new(key_string).hexdigest() |
| 90 | |
| 91 | |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 92 | class patch: |
| 93 | def __init__(self, spec, reference=None, hash=None): |
| 94 | # NEITHER OF THE ABOVE SHOULD HAVE DEFAULTS!!!! HACK HACK |
| 95 | if not reference: |
| 96 | reference = spec |
| 97 | print 'PATCH::%s %s %s' % (spec, reference, hash) |
| 98 | self.spec = spec |
| 99 | self.reference = reference |
| 100 | self.hash = hash |
| 101 | |
| 102 | |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 103 | class test: |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 104 | def __init__(self, dir, status, reason, kernel, job): |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 105 | self.dir = dir |
| 106 | self.status = status |
| 107 | self.reason = reason |
| 108 | self.keyval = os.path.join(dir, 'results/keyval') |
| 109 | self.iterations = [] |
mbligh | 608c325 | 2007-08-31 13:53:00 +0000 | [diff] [blame] | 110 | self.testname = re.sub(r'\..*', '', self.dir) |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 111 | self.kernel = kernel |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 112 | self.machine = job.machine |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 113 | |
| 114 | if not os.path.exists(self.keyval): |
| 115 | self.keyval = None |
| 116 | return |
| 117 | count = 1 |
| 118 | lines = [] |
| 119 | for line in open(self.keyval, 'r').readlines(): |
| 120 | if not re.search('\S'): # blank line |
| 121 | self.iterations.append(iteration(count, lines)) |
| 122 | lines = [] |
| 123 | count += 1 |
| 124 | next |
| 125 | else: |
| 126 | lines.append(line) |
| 127 | if lines: |
| 128 | self.iterations.append(iteration(count, lines)) |
| 129 | |
| 130 | |
| 131 | class iteration: |
| 132 | def __init__(self, index, lines): |
| 133 | self.index = index |
| 134 | self.keyval = {} |
| 135 | |
| 136 | for line in lines: |
| 137 | (key, value) = line.split('=', 1) |
| 138 | self.keyval[key] = value |