blob: 6de73ae2f28db377f6d36a56a54775c911d3da99 [file] [log] [blame]
mbligh9bb92fe2007-09-12 15:54:23 +00001#!/usr/bin/python
mbligh2aaeb672007-10-01 14:54:18 +00002import os, re, db, sys
mbligh9bb92fe2007-09-12 15:54:23 +00003
mbligh2aaeb672007-10-01 14:54:18 +00004tko = os.path.dirname(os.path.realpath(os.path.abspath(sys.argv[0])))
5root_url_file = os.path.join(tko, '.root_url')
6if os.path.exists(root_url_file):
7 html_root = open(root_url_file, 'r').readline().rstrip()
8else:
9 html_root = 'http://test.kernel.org/google/'
10
11
mblighcff2d212007-10-07 00:11:10 +000012class group:
13 @classmethod
14 def select(klass, db):
15 """Return all possible machine groups"""
16 rows = db.select('distinct machine_group', 'machines',
17 'machine_group is not null')
18 groupnames = sorted([row[0] for row in rows])
19 return [klass(db, groupname) for groupname in groupnames]
20
21
22 def __init__(self, db, name):
23 self.name = name
24 self.db = db
25
26
27 def machines(self):
28 return machine.select(self.db, { 'machine_group' : self.name })
29
30
31 def tests(self, where = {}):
32 values = [self.name]
33 sql = 't inner join machines m on m.machine_idx=t.machine_idx where m.machine_group=%s'
34 for key in where.keys():
35 sql += ' and %s=%%s' % key
36 values.append(where[key])
37 return test.select_sql(self.db, sql, values)
38
39
mbligh2aaeb672007-10-01 14:54:18 +000040class machine:
41 @classmethod
42 def select(klass, db, where = {}):
43 fields = ['machine_idx', 'hostname', 'machine_group', 'owner']
44 machines = []
45 for row in db.select(','.join(fields), 'machines', where):
46 machines.append(klass(db, *row))
47 return machines
48
49
50 def __init__(self, db, idx, hostname, group, owner):
51 self.db = db
52 self.idx = idx
53 self.hostname = hostname
54 self.group = group
55 self.owner = owner
56
mbligh250300e2007-09-18 00:50:57 +000057
mbligh9bb92fe2007-09-12 15:54:23 +000058class kernel:
mbligh8e1ab172007-09-13 17:29:56 +000059 @classmethod
60 def select(klass, db, where = {}):
61 fields = ['kernel_idx', 'kernel_hash', 'base', 'printable']
62 kernels = []
63 for row in db.select(','.join(fields), 'kernels', where):
64 kernels.append(klass(db, *row))
65 return kernels
mbligh9bb92fe2007-09-12 15:54:23 +000066
mbligh8e1ab172007-09-13 17:29:56 +000067
68 def __init__(self, db, idx, hash, base, printable):
mbligh9bb92fe2007-09-12 15:54:23 +000069 self.db = db
mbligh8e1ab172007-09-13 17:29:56 +000070 self.idx = idx
mbligh9bb92fe2007-09-12 15:54:23 +000071 self.hash = hash
mbligh8e1ab172007-09-13 17:29:56 +000072 self.base = base
73 self.printable = printable
74 self.patches = [] # THIS SHOULD PULL IN PATCHES!
mbligh9bb92fe2007-09-12 15:54:23 +000075
76
77class test:
mbligh8e1ab172007-09-13 17:29:56 +000078 @classmethod
mbligh31d29c42007-09-27 00:51:33 +000079 def select(klass, db, where = {}, distinct = False):
mbligh8e1ab172007-09-13 17:29:56 +000080 fields = ['test_idx', 'job_idx', 'test', 'subdir',
mbligh2aaeb672007-10-01 14:54:18 +000081 'kernel_idx', 'status', 'reason', 'machine_idx']
mbligh8e1ab172007-09-13 17:29:56 +000082 tests = []
mbligh31d29c42007-09-27 00:51:33 +000083 for row in db.select(','.join(fields), 'tests', where, distinct):
mbligh8e1ab172007-09-13 17:29:56 +000084 tests.append(klass(db, *row))
85 return tests
86
87
mbligh414c69e2007-10-05 15:13:06 +000088 @classmethod
89 def select_sql(klass, db, sql, values):
90 fields = ['test_idx', 'job_idx', 'test', 'subdir',
91 'kernel_idx', 'status', 'reason', 'machine_idx']
92 fields = ['t.'+field for field in fields]
93 rows = db.select_sql(','.join(fields), 'tests', sql, values)
94 return [klass(db, *row) for row in rows]
95
96
mbligh2aaeb672007-10-01 14:54:18 +000097 def __init__(self, db, test_idx, job_idx, testname, subdir, kernel_idx, status_num, reason, machine_idx):
mbligh8e1ab172007-09-13 17:29:56 +000098 self.idx = test_idx
mbligh250300e2007-09-18 00:50:57 +000099 self.job = job(db, job_idx)
mblighde7335d2007-09-26 16:53:20 +0000100 self.testname = testname
mbligh8e1ab172007-09-13 17:29:56 +0000101 self.subdir = subdir
mbligh50a25252007-09-27 15:26:17 +0000102 self.kernel_idx = kernel_idx
103 self.__kernel = None
104 self.__iterations = None
mbligh2aaeb672007-10-01 14:54:18 +0000105 self.machine_idx = machine_idx
106 self.__machine = None
mbligh8e1ab172007-09-13 17:29:56 +0000107 self.status_num = status_num
108 self.status_word = db.status_word[status_num]
mbligh9bb92fe2007-09-12 15:54:23 +0000109 self.reason = reason
mbligh50a25252007-09-27 15:26:17 +0000110 self.db = db
mblighde7335d2007-09-26 16:53:20 +0000111 if self.subdir:
112 self.url = html_root + self.job.tag + '/' + self.subdir
113 else:
mbligh676510c2007-09-28 01:28:12 +0000114 self.url = None
mbligh16ae9262007-09-21 00:53:08 +0000115
mbligh50a25252007-09-27 15:26:17 +0000116
117
118 def iterations(self):
119 """
120 Caching function for iterations
121 """
122 if not self.__iterations:
123 self.__iterations = {}
124 # A dictionary - dict{key} = [value1, value2, ....]
125 where = {'test_idx' : self.idx}
126 for i in iteration.select(self.db, where):
127 if self.__iterations.has_key(i.key):
128 self.__iterations[i.key].append(i.value)
129 else:
130 self.__iterations[i.key] = [i.value]
131 return self.__iterations
132
133
134 def kernel(self):
135 """
136 Caching function for kernels
137 """
138 if not self.__kernel:
139 where = {'kernel_idx' : self.kernel_idx}
140 self.__kernel = kernel.select(self.db, where)[0]
141 return self.__kernel
142
mbligh250300e2007-09-18 00:50:57 +0000143
mbligh2aaeb672007-10-01 14:54:18 +0000144 def machine(self):
145 """
146 Caching function for kernels
147 """
148 if not self.__machine:
149 where = {'machine_idx' : self.machine_idx}
150 self.__machine = machine.select(self.db, where)[0]
151 return self.__machine
152
153
mbligh250300e2007-09-18 00:50:57 +0000154class job:
155 def __init__(self, db, job_idx):
156 where = {'job_idx' : job_idx}
mbligh2aaeb672007-10-01 14:54:18 +0000157 rows = db.select('tag, machine_idx', 'jobs', where)
mbligh250300e2007-09-18 00:50:57 +0000158 if not rows:
159 return None
mbligh2aaeb672007-10-01 14:54:18 +0000160 (self.tag, self.machine_idx) = rows[0]
mbligh250300e2007-09-18 00:50:57 +0000161
mbligh8e1ab172007-09-13 17:29:56 +0000162
mbligh16ae9262007-09-21 00:53:08 +0000163class iteration:
164 @classmethod
165 def select(klass, db, where):
166 fields = ['iteration', 'attribute', 'value']
167 iterations = []
168 rows = db.select(','.join(fields), 'iteration_result', where)
169 for row in rows:
170 iterations.append(klass(*row))
171 return iterations
172
173
174 def __init__(self, iteration, key, value):
175 self.iteration = iteration
176 self.key = key
177 self.value = value
178
mbligh8e1ab172007-09-13 17:29:56 +0000179# class patch:
180# def __init__(self):
181# self.spec = None