blob: 42b2443066cf9c3252d54f34f6ec4cbddd46a88b [file] [log] [blame]
mblighc6b01ed2006-10-13 17:03:26 +00001#!/usr/bin/python
mbligh006f2302007-09-13 20:46:46 +00002import os, re, md5, sys
mblighbb7b8912006-10-08 03:59:02 +00003
4valid_users = r'(apw|mbligh|andyw|korgtest)'
5build_stock = re.compile('build generic stock (2\.\S+)')
mblighb85e6b02006-10-08 17:20:56 +00006build_url = re.compile('build generic url \S*/linux-(2\.\d\.\d+(\.\d+)?(-rc\d+)?).tar')
mbligh340c9682006-10-08 18:26:08 +00007valid_kernel= re.compile('2\.\d\.\d+(\.\d+)?(-rc\d+)?(-(git|bk))\d+')
mblighb85e6b02006-10-08 17:20:56 +00008
mbligh006f2302007-09-13 20:46:46 +00009debug = True
10
mblighb85e6b02006-10-08 17:20:56 +000011def shorten_patch(long):
mbligh340c9682006-10-08 18:26:08 +000012 short = os.path.basename(long)
mblighb85e6b02006-10-08 17:20:56 +000013 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
mblighbb7b8912006-10-08 03:59:02 +000019
mbligh006f2302007-09-13 20:46:46 +000020def dprint(info):
21 if debug:
22 sys.stderr.write(str(info) + '\n')
23
24
mblighe9cf9d42007-08-31 08:56:00 +000025class job:
26 def __init__(self, dir, type):
27 self.dir = dir
mblighd5c33db2006-10-08 21:34:16 +000028 self.type = type
mblighe9cf9d42007-08-31 08:56:00 +000029 self.control = os.path.join(dir, "control")
mbligh237bed32007-09-05 13:05:57 +000030 self.status = os.path.join(dir, "status")
mblighbb7b8912006-10-08 03:59:02 +000031 self.variables = {}
mblighe9cf9d42007-08-31 08:56:00 +000032 self.tests = []
mblighbb7b8912006-10-08 03:59:02 +000033 self.kernel = None
34
mbligh8e1ab172007-09-13 17:29:56 +000035 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
mbligh529f2f32007-08-30 11:22:50 +000045 self.grope_status()
mblighbb7b8912006-10-08 03:59:02 +000046
47
mblighd5c33db2006-10-08 21:34:16 +000048 def grope_status(self):
mbligh237bed32007-09-05 13:05:57 +000049 # 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
mbligh237bed32007-09-05 13:05:57 +000055 for line in open(self.status, 'r').readlines():
mblighe9cf9d42007-08-31 08:56:00 +000056 (status, testname, reason) = line.rstrip().split(' ', 2)
mbligh006f2302007-09-13 20:46:46 +000057 dprint('GROPE_STATUS: '+str((status, testname, reason)))
58 self.tests.append(test(testname, status, reason, self.kernel, self))
mblighe9cf9d42007-08-31 08:56:00 +000059
60
61class kernel:
62 def __init__(self, builddir):
63 self.base = None
64 self.patches = []
65
66 log = os.path.join(builddir, 'debug/build_log')
mbligh237bed32007-09-05 13:05:57 +000067 if not os.path.exists(log):
68 return
mblighe9cf9d42007-08-31 08:56:00 +000069 patch_hashes = []
70 for line in open(log, 'r'):
mbligh237bed32007-09-05 13:05:57 +000071 print line
mblighe9cf9d42007-08-31 08:56:00 +000072 (type, rest) = line.split(': ', 1)
73 words = rest.split()
74 if type == 'BUILD VERSION':
75 self.base = words[0]
76 if type == 'PATCH':
mbligh237bed32007-09-05 13:05:57 +000077 print words
78 self.patches.append(patch(*words[0:]))
mblighe9cf9d42007-08-31 08:56:00 +000079 # patch_hashes.append(words[2])
mbligh9bb92fe2007-09-12 15:54:23 +000080 self.kernel_hash = self.get_kver_hash(self.base, patch_hashes)
mblighe9cf9d42007-08-31 08:56:00 +000081
82
mbligh237bed32007-09-05 13:05:57 +000083 def get_kver_hash(self, base, patch_hashes):
mblighe9cf9d42007-08-31 08:56:00 +000084 """\
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
mbligh237bed32007-09-05 13:05:57 +000092class 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
mblighe9cf9d42007-08-31 08:56:00 +0000103class test:
mbligh8e1ab172007-09-13 17:29:56 +0000104 def __init__(self, dir, status, reason, kernel, job):
mblighe9cf9d42007-08-31 08:56:00 +0000105 self.dir = dir
106 self.status = status
107 self.reason = reason
108 self.keyval = os.path.join(dir, 'results/keyval')
109 self.iterations = []
mbligh608c3252007-08-31 13:53:00 +0000110 self.testname = re.sub(r'\..*', '', self.dir)
mbligh237bed32007-09-05 13:05:57 +0000111 self.kernel = kernel
mbligh8e1ab172007-09-13 17:29:56 +0000112 self.machine = job.machine
mblighe9cf9d42007-08-31 08:56:00 +0000113
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
131class 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