mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 1 | """The main job wrapper |
mbligh | a250805 | 2006-05-28 21:29:53 +0000 | [diff] [blame] | 2 | |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 3 | This is the core infrastructure. |
| 4 | """ |
| 5 | |
| 6 | __author__ = """Copyright Andy Whitcroft, Martin J. Bligh 2006""" |
mbligh | a250805 | 2006-05-28 21:29:53 +0000 | [diff] [blame] | 7 | |
mbligh | 8f243ec | 2006-10-10 05:55:49 +0000 | [diff] [blame] | 8 | # standard stuff |
apw | 8fef4ac | 2006-10-10 22:53:37 +0000 | [diff] [blame] | 9 | import os, sys, re, pickle, shutil |
mbligh | 8f243ec | 2006-10-10 05:55:49 +0000 | [diff] [blame] | 10 | # autotest stuff |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 11 | from autotest_utils import * |
apw | 8fef4ac | 2006-10-10 22:53:37 +0000 | [diff] [blame] | 12 | from parallel import * |
mbligh | 9c5ac32 | 2007-10-31 18:01:59 +0000 | [diff] [blame^] | 13 | from error import * |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 14 | import kernel, xen, test, profilers, barrier, filesystem, fd_stack, boottool |
apw | 059e1b1 | 2006-10-12 17:18:26 +0000 | [diff] [blame] | 15 | import harness, config |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 16 | |
| 17 | class job: |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 18 | """The actual job against which we do everything. |
| 19 | |
| 20 | Properties: |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 21 | autodir |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 22 | The top level autotest directory (/usr/local/autotest). |
| 23 | Comes from os.environ['AUTODIR']. |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 24 | bindir |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 25 | <autodir>/bin/ |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 26 | testdir |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 27 | <autodir>/tests/ |
| 28 | profdir |
| 29 | <autodir>/profilers/ |
| 30 | tmpdir |
| 31 | <autodir>/tmp/ |
| 32 | resultdir |
| 33 | <autodir>/results/<jobtag> |
| 34 | stdout |
| 35 | fd_stack object for stdout |
| 36 | stderr |
| 37 | fd_stack object for stderr |
| 38 | profilers |
| 39 | the profilers object for this job |
apw | 504a7dd | 2006-10-12 17:18:37 +0000 | [diff] [blame] | 40 | harness |
| 41 | the server harness object for this job |
apw | 059e1b1 | 2006-10-12 17:18:26 +0000 | [diff] [blame] | 42 | config |
| 43 | the job configuration for this job |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 44 | """ |
| 45 | |
mbligh | 362ab3d | 2007-08-30 11:24:04 +0000 | [diff] [blame] | 46 | def __init__(self, control, jobtag, cont, harness_type=None): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 47 | """ |
| 48 | control |
| 49 | The control file (pathname of) |
| 50 | jobtag |
| 51 | The job tag string (eg "default") |
apw | 96da1a4 | 2006-11-02 00:23:18 +0000 | [diff] [blame] | 52 | cont |
| 53 | If this is the continuation of this job |
apw | e68a713 | 2006-12-01 11:21:37 +0000 | [diff] [blame] | 54 | harness_type |
| 55 | An alternative server harness |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 56 | """ |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 57 | self.autodir = os.environ['AUTODIR'] |
apw | 870988b | 2007-09-25 16:50:53 +0000 | [diff] [blame] | 58 | self.bindir = os.path.join(self.autodir, 'bin') |
| 59 | self.testdir = os.path.join(self.autodir, 'tests') |
| 60 | self.profdir = os.path.join(self.autodir, 'profilers') |
| 61 | self.tmpdir = os.path.join(self.autodir, 'tmp') |
| 62 | self.resultdir = os.path.join(self.autodir, 'results', jobtag) |
mbligh | a250805 | 2006-05-28 21:29:53 +0000 | [diff] [blame] | 63 | |
apw | 96da1a4 | 2006-11-02 00:23:18 +0000 | [diff] [blame] | 64 | if not cont: |
| 65 | if os.path.exists(self.tmpdir): |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 66 | system('umount -f %s > /dev/null 2> /dev/null'%\ |
| 67 | self.tmpdir, ignorestatus=True) |
apw | 96da1a4 | 2006-11-02 00:23:18 +0000 | [diff] [blame] | 68 | system('rm -rf ' + self.tmpdir) |
| 69 | os.mkdir(self.tmpdir) |
| 70 | |
apw | 870988b | 2007-09-25 16:50:53 +0000 | [diff] [blame] | 71 | results = os.path.join(self.autodir, 'results') |
| 72 | if not os.path.exists(results): |
| 73 | os.mkdir(results) |
mbligh | fbfb77d | 2007-02-15 18:54:03 +0000 | [diff] [blame] | 74 | |
apw | f3d2862 | 2007-09-25 16:49:17 +0000 | [diff] [blame] | 75 | download = os.path.join(self.testdir, 'download') |
| 76 | if os.path.exists(download): |
| 77 | system('rm -rf ' + download) |
| 78 | os.mkdir(download) |
| 79 | |
apw | 96da1a4 | 2006-11-02 00:23:18 +0000 | [diff] [blame] | 80 | if os.path.exists(self.resultdir): |
| 81 | system('rm -rf ' + self.resultdir) |
| 82 | os.mkdir(self.resultdir) |
| 83 | |
apw | 870988b | 2007-09-25 16:50:53 +0000 | [diff] [blame] | 84 | os.mkdir(os.path.join(self.resultdir, 'debug')) |
| 85 | os.mkdir(os.path.join(self.resultdir, 'analysis')) |
| 86 | os.mkdir(os.path.join(self.resultdir, 'sysinfo')) |
| 87 | |
| 88 | shutil.copyfile(control, os.path.join(self.resultdir, 'control')) |
mbligh | 4b08966 | 2006-06-14 22:34:58 +0000 | [diff] [blame] | 89 | |
apw | ecf41b7 | 2006-03-31 14:00:55 +0000 | [diff] [blame] | 90 | self.control = control |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 91 | self.jobtab = jobtag |
| 92 | |
mbligh | 56f1fbb | 2006-10-01 15:10:56 +0000 | [diff] [blame] | 93 | self.stdout = fd_stack.fd_stack(1, sys.stdout) |
| 94 | self.stderr = fd_stack.fd_stack(2, sys.stderr) |
mbligh | 88ab90f | 2007-08-29 15:52:49 +0000 | [diff] [blame] | 95 | self.record_prefix = '' |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 96 | |
apw | 059e1b1 | 2006-10-12 17:18:26 +0000 | [diff] [blame] | 97 | self.config = config.config(self) |
| 98 | |
apw | d27e55f | 2006-12-01 11:22:08 +0000 | [diff] [blame] | 99 | self.harness = harness.select(harness_type, self) |
| 100 | |
mbligh | a35553b | 2006-04-23 15:52:25 +0000 | [diff] [blame] | 101 | self.profilers = profilers.profilers(self) |
mbligh | 7290556 | 2006-05-25 01:30:49 +0000 | [diff] [blame] | 102 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 103 | try: |
apw | 90154af | 2006-12-01 11:23:36 +0000 | [diff] [blame] | 104 | tool = self.config_get('boottool.executable') |
| 105 | self.bootloader = boottool.boottool(tool) |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 106 | except: |
| 107 | pass |
| 108 | |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 109 | pwd = os.getcwd() |
apw | 870988b | 2007-09-25 16:50:53 +0000 | [diff] [blame] | 110 | os.chdir(os.path.join(self.resultdir, 'sysinfo')) |
| 111 | system(os.path.join(self.bindir, 'sysinfo.py')) |
mbligh | afb6390 | 2007-10-23 00:10:34 +0000 | [diff] [blame] | 112 | system('dmesg -c > dmesg 2> /dev/null', ignorestatus=1) |
mbligh | 0674377 | 2006-05-18 21:30:19 +0000 | [diff] [blame] | 113 | os.chdir(pwd) |
mbligh | 3a6d6ca | 2006-04-23 15:50:24 +0000 | [diff] [blame] | 114 | |
apw | 357f50f | 2006-12-01 11:22:39 +0000 | [diff] [blame] | 115 | self.harness.run_start() |
| 116 | |
mbligh | 0692e47 | 2007-08-30 16:07:53 +0000 | [diff] [blame] | 117 | |
| 118 | def relative_path(self, path): |
| 119 | """\ |
| 120 | Return a patch relative to the job results directory |
| 121 | """ |
mbligh | 1c250ca | 2007-08-30 16:31:38 +0000 | [diff] [blame] | 122 | head = len(self.resultdir) + 1 # remove the / inbetween |
| 123 | return path[head:] |
mbligh | 0692e47 | 2007-08-30 16:07:53 +0000 | [diff] [blame] | 124 | |
| 125 | |
mbligh | 362ab3d | 2007-08-30 11:24:04 +0000 | [diff] [blame] | 126 | def control_get(self): |
| 127 | return self.control |
| 128 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 129 | |
apw | de1503a | 2006-10-10 08:34:21 +0000 | [diff] [blame] | 130 | def harness_select(self, which): |
| 131 | self.harness = harness.select(which, self) |
| 132 | |
| 133 | |
apw | 059e1b1 | 2006-10-12 17:18:26 +0000 | [diff] [blame] | 134 | def config_set(self, name, value): |
| 135 | self.config.set(name, value) |
| 136 | |
| 137 | |
| 138 | def config_get(self, name): |
| 139 | return self.config.get(name) |
| 140 | |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 141 | def setup_dirs(self, results_dir, tmp_dir): |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame] | 142 | if not tmp_dir: |
apw | 870988b | 2007-09-25 16:50:53 +0000 | [diff] [blame] | 143 | tmp_dir = os.path.join(self.tmpdir, 'build') |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame] | 144 | if not os.path.exists(tmp_dir): |
| 145 | os.mkdir(tmp_dir) |
| 146 | if not os.path.isdir(tmp_dir): |
| 147 | raise "Temp dir (%s) is not a dir - args backwards?" \ |
| 148 | % self.tmpdir |
| 149 | |
| 150 | # We label the first build "build" and then subsequent ones |
| 151 | # as "build.2", "build.3", etc. Whilst this is a little bit |
| 152 | # inconsistent, 99.9% of jobs will only have one build |
| 153 | # (that's not done as kernbench, sparse, or buildtest), |
| 154 | # so it works out much cleaner. One of life's comprimises. |
| 155 | if not results_dir: |
| 156 | results_dir = os.path.join(self.resultdir, 'build') |
| 157 | i = 2 |
| 158 | while os.path.exists(results_dir): |
| 159 | results_dir = os.path.join(self.resultdir, 'build.%d' % i) |
mbligh | d9223fc | 2006-11-26 17:19:54 +0000 | [diff] [blame] | 160 | i += 1 |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame] | 161 | if not os.path.exists(results_dir): |
| 162 | os.mkdir(results_dir) |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 163 | |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 164 | return (results_dir, tmp_dir) |
| 165 | |
| 166 | |
| 167 | def xen(self, base_tree, results_dir = '', tmp_dir = '', leave = False, \ |
| 168 | kjob = None ): |
| 169 | """Summon a xen object""" |
| 170 | (results_dir, tmp_dir) = self.setup_dirs(results_dir, tmp_dir) |
| 171 | build_dir = 'xen' |
| 172 | return xen.xen(self, base_tree, results_dir, tmp_dir, build_dir, leave, kjob) |
| 173 | |
| 174 | |
| 175 | def kernel(self, base_tree, results_dir = '', tmp_dir = '', leave = False): |
| 176 | """Summon a kernel object""" |
mbligh | 736adc9 | 2007-10-18 03:23:22 +0000 | [diff] [blame] | 177 | if base_tree.endswith('.rpm'): |
| 178 | return kernel.rpm_kernel(self, base_tree, results_dir) |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 179 | (results_dir, tmp_dir) = self.setup_dirs(results_dir, tmp_dir) |
| 180 | build_dir = 'linux' |
| 181 | return kernel.kernel(self, base_tree, results_dir, tmp_dir, build_dir, leave) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 182 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 183 | |
mbligh | fadca20 | 2006-09-23 04:40:01 +0000 | [diff] [blame] | 184 | def barrier(self, *args): |
| 185 | """Create a barrier object""" |
| 186 | return barrier.barrier(*args) |
| 187 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 188 | |
mbligh | 4b08966 | 2006-06-14 22:34:58 +0000 | [diff] [blame] | 189 | def setup_dep(self, deps): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 190 | """Set up the dependencies for this test. |
| 191 | |
| 192 | deps is a list of libraries required for this test. |
| 193 | """ |
mbligh | 4b08966 | 2006-06-14 22:34:58 +0000 | [diff] [blame] | 194 | for dep in deps: |
| 195 | try: |
apw | 870988b | 2007-09-25 16:50:53 +0000 | [diff] [blame] | 196 | os.chdir(os.path.join(self.autodir, 'deps', dep)) |
mbligh | 4b08966 | 2006-06-14 22:34:58 +0000 | [diff] [blame] | 197 | system('./' + dep + '.py') |
| 198 | except: |
| 199 | error = "setting up dependency " + dep + "\n" |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 200 | raise UnhandledError(error) |
mbligh | 4b08966 | 2006-06-14 22:34:58 +0000 | [diff] [blame] | 201 | |
| 202 | |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 203 | def __runtest(self, url, tag, args, dargs): |
| 204 | try: |
mbligh | 53c4150 | 2007-10-23 20:45:04 +0000 | [diff] [blame] | 205 | l = lambda : test.runtest(self, url, tag, args, dargs) |
| 206 | pid = fork_start(self.resultdir, l) |
| 207 | fork_waitfor(self.resultdir, pid) |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 208 | except AutotestError: |
| 209 | raise |
| 210 | except: |
| 211 | raise UnhandledError('running test ' + \ |
| 212 | self.__class__.__name__ + "\n") |
apw | f1a8116 | 2006-04-25 10:10:29 +0000 | [diff] [blame] | 213 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 214 | |
mbligh | d016ecc | 2006-11-25 21:41:07 +0000 | [diff] [blame] | 215 | def run_test(self, url, *args, **dargs): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 216 | """Summon a test object and run it. |
| 217 | |
| 218 | tag |
| 219 | tag to add to testname |
mbligh | 12a7df7 | 2006-10-06 03:54:33 +0000 | [diff] [blame] | 220 | url |
| 221 | url of the test to run |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 222 | """ |
mbligh | 12a7df7 | 2006-10-06 03:54:33 +0000 | [diff] [blame] | 223 | |
mbligh | d016ecc | 2006-11-25 21:41:07 +0000 | [diff] [blame] | 224 | if not url: |
| 225 | raise "Test name is invalid. Switched arguments?" |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 226 | (group, testname) = test.testname(url) |
mbligh | d016ecc | 2006-11-25 21:41:07 +0000 | [diff] [blame] | 227 | tag = None |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 228 | subdir = testname |
mbligh | d016ecc | 2006-11-25 21:41:07 +0000 | [diff] [blame] | 229 | if dargs.has_key('tag'): |
| 230 | tag = dargs['tag'] |
| 231 | del dargs['tag'] |
apw | 5a7335c | 2007-03-12 20:32:40 +0000 | [diff] [blame] | 232 | if tag: |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 233 | subdir += '.' + tag |
apw | f1a8116 | 2006-04-25 10:10:29 +0000 | [diff] [blame] | 234 | try: |
| 235 | try: |
mbligh | d016ecc | 2006-11-25 21:41:07 +0000 | [diff] [blame] | 236 | self.__runtest(url, tag, args, dargs) |
apw | f1a8116 | 2006-04-25 10:10:29 +0000 | [diff] [blame] | 237 | except Exception, detail: |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 238 | self.record('FAIL', subdir, testname, \ |
| 239 | detail.__str__()) |
apw | f1a8116 | 2006-04-25 10:10:29 +0000 | [diff] [blame] | 240 | |
| 241 | raise |
| 242 | else: |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 243 | self.record('GOOD', subdir, testname, \ |
| 244 | 'completed successfully') |
apw | f1a8116 | 2006-04-25 10:10:29 +0000 | [diff] [blame] | 245 | except TestError: |
mbligh | a730c12 | 2007-10-02 19:20:45 +0000 | [diff] [blame] | 246 | return 0 |
apw | f1a8116 | 2006-04-25 10:10:29 +0000 | [diff] [blame] | 247 | except: |
| 248 | raise |
| 249 | else: |
| 250 | return 1 |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 251 | |
mbligh | d7fb4a6 | 2006-10-01 00:57:53 +0000 | [diff] [blame] | 252 | |
apw | 1da244b | 2007-09-27 17:18:01 +0000 | [diff] [blame] | 253 | def run_group(self, function, *args, **dargs): |
mbligh | 88ab90f | 2007-08-29 15:52:49 +0000 | [diff] [blame] | 254 | """\ |
| 255 | function: |
| 256 | subroutine to run |
| 257 | *args: |
| 258 | arguments for the function |
| 259 | """ |
| 260 | |
apw | 08403ca | 2007-09-27 17:17:22 +0000 | [diff] [blame] | 261 | result = None |
mbligh | 88ab90f | 2007-08-29 15:52:49 +0000 | [diff] [blame] | 262 | name = function.__name__ |
apw | 1da244b | 2007-09-27 17:18:01 +0000 | [diff] [blame] | 263 | |
| 264 | # Allow the tag for the group to be specified. |
| 265 | if dargs.has_key('tag'): |
| 266 | tag = dargs['tag'] |
| 267 | del dargs['tag'] |
| 268 | if tag: |
| 269 | name = tag |
| 270 | |
mbligh | 88ab90f | 2007-08-29 15:52:49 +0000 | [diff] [blame] | 271 | # if tag: |
| 272 | # name += '.' + tag |
| 273 | old_record_prefix = self.record_prefix |
| 274 | try: |
| 275 | try: |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 276 | self.record('START', None, name) |
mbligh | 88ab90f | 2007-08-29 15:52:49 +0000 | [diff] [blame] | 277 | self.record_prefix += '\t' |
apw | 1da244b | 2007-09-27 17:18:01 +0000 | [diff] [blame] | 278 | result = function(*args, **dargs) |
mbligh | 88ab90f | 2007-08-29 15:52:49 +0000 | [diff] [blame] | 279 | self.record_prefix = old_record_prefix |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 280 | self.record('END GOOD', None, name) |
mbligh | 88ab90f | 2007-08-29 15:52:49 +0000 | [diff] [blame] | 281 | except: |
| 282 | self.record_prefix = old_record_prefix |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 283 | self.record('END FAIL', None, name, format_error()) |
mbligh | 88ab90f | 2007-08-29 15:52:49 +0000 | [diff] [blame] | 284 | # We don't want to raise up an error higher if it's just |
| 285 | # a TestError - we want to carry on to other tests. Hence |
| 286 | # this outer try/except block. |
| 287 | except TestError: |
| 288 | pass |
| 289 | except: |
| 290 | raise TestError(name + ' failed\n' + format_error()) |
| 291 | |
apw | 08403ca | 2007-09-27 17:17:22 +0000 | [diff] [blame] | 292 | return result |
| 293 | |
mbligh | 88ab90f | 2007-08-29 15:52:49 +0000 | [diff] [blame] | 294 | |
apw | ce73d89 | 2007-09-25 16:53:05 +0000 | [diff] [blame] | 295 | # Check the passed kernel identifier against the command line |
| 296 | # and the running kernel, abort the job on missmatch. |
mbligh | da0311e | 2007-10-25 16:03:33 +0000 | [diff] [blame] | 297 | def kernel_check_ident(self, expected_when, expected_id, expected_cl, subdir, type = 'src'): |
| 298 | print "POST BOOT: checking booted kernel mark=%d identity='%s' changelist=%s type='%s'" \ |
| 299 | % (expected_when, expected_id, expected_cl, type) |
apw | ce73d89 | 2007-09-25 16:53:05 +0000 | [diff] [blame] | 300 | |
| 301 | running_id = running_os_ident() |
| 302 | |
| 303 | cmdline = read_one_line("/proc/cmdline") |
| 304 | |
| 305 | find_sum = re.compile(r'.*IDENT=(\d+)') |
| 306 | m = find_sum.match(cmdline) |
| 307 | cmdline_when = -1 |
| 308 | if m: |
| 309 | cmdline_when = int(m.groups()[0]) |
| 310 | |
mbligh | da0311e | 2007-10-25 16:03:33 +0000 | [diff] [blame] | 311 | cl_re = re.compile(r'\d{7,}') |
| 312 | cl_match = cl_re.search(system_output('uname -v').split()[1]) |
| 313 | if cl_match: |
| 314 | current_cl = cl_match.group() |
| 315 | else: |
| 316 | current_cl = None |
| 317 | |
apw | ce73d89 | 2007-09-25 16:53:05 +0000 | [diff] [blame] | 318 | # We have all the facts, see if they indicate we |
| 319 | # booted the requested kernel or not. |
| 320 | bad = False |
mbligh | da0311e | 2007-10-25 16:03:33 +0000 | [diff] [blame] | 321 | if (type == 'src' and expected_id != running_id or |
| 322 | type == 'rpm' and not running_id.startswith(expected_id + '::')): |
apw | ce73d89 | 2007-09-25 16:53:05 +0000 | [diff] [blame] | 323 | print "check_kernel_ident: kernel identifier mismatch" |
| 324 | bad = True |
| 325 | if expected_when != cmdline_when: |
| 326 | print "check_kernel_ident: kernel command line mismatch" |
| 327 | bad = True |
mbligh | da0311e | 2007-10-25 16:03:33 +0000 | [diff] [blame] | 328 | if expected_cl and current_cl and str(expected_cl) != current_cl: |
| 329 | print 'check_kernel_ident: kernel changelist mismatch' |
| 330 | bad = True |
apw | ce73d89 | 2007-09-25 16:53:05 +0000 | [diff] [blame] | 331 | |
| 332 | if bad: |
| 333 | print " Expected Ident: " + expected_id |
| 334 | print " Running Ident: " + running_id |
| 335 | print " Expected Mark: %d" % (expected_when) |
| 336 | print "Command Line Mark: %d" % (cmdline_when) |
mbligh | da0311e | 2007-10-25 16:03:33 +0000 | [diff] [blame] | 337 | print " Expected P4 CL: %s" % expected_cl |
| 338 | print " P4 CL: %s" % current_cl |
apw | ce73d89 | 2007-09-25 16:53:05 +0000 | [diff] [blame] | 339 | print " Command Line: " + cmdline |
| 340 | |
| 341 | raise JobError("boot failure") |
| 342 | |
| 343 | self.record('GOOD', subdir, 'boot', 'boot successful') |
| 344 | |
| 345 | |
mbligh | c235985 | 2007-08-28 18:11:48 +0000 | [diff] [blame] | 346 | def filesystem(self, device, mountpoint = None, loop_size = 0): |
mbligh | d7fb4a6 | 2006-10-01 00:57:53 +0000 | [diff] [blame] | 347 | if not mountpoint: |
| 348 | mountpoint = self.tmpdir |
mbligh | c235985 | 2007-08-28 18:11:48 +0000 | [diff] [blame] | 349 | return filesystem.filesystem(self, device, mountpoint,loop_size) |
mbligh | d7fb4a6 | 2006-10-01 00:57:53 +0000 | [diff] [blame] | 350 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 351 | |
| 352 | def reboot(self, tag='autotest'): |
apw | de1503a | 2006-10-10 08:34:21 +0000 | [diff] [blame] | 353 | self.harness.run_reboot() |
apw | 11985b7 | 2007-10-04 15:44:47 +0000 | [diff] [blame] | 354 | default = self.config_get('boot.set_default') |
| 355 | if default: |
| 356 | self.bootloader.set_default(tag) |
| 357 | else: |
| 358 | self.bootloader.boot_once(tag) |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 359 | system("reboot") |
apw | 0778a2f | 2006-10-06 03:11:40 +0000 | [diff] [blame] | 360 | self.quit() |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 361 | |
| 362 | |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 363 | def noop(self, text): |
| 364 | print "job: noop: " + text |
| 365 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 366 | |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 367 | # Job control primatives. |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 368 | |
apw | 8fef4ac | 2006-10-10 22:53:37 +0000 | [diff] [blame] | 369 | def __parallel_execute(self, func, *args): |
| 370 | func(*args) |
| 371 | |
| 372 | |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 373 | def parallel(self, *tasklist): |
| 374 | """Run tasks in parallel""" |
apw | 8fef4ac | 2006-10-10 22:53:37 +0000 | [diff] [blame] | 375 | |
| 376 | pids = [] |
| 377 | for task in tasklist: |
| 378 | pids.append(fork_start(self.resultdir, |
| 379 | lambda: self.__parallel_execute(*task))) |
| 380 | for pid in pids: |
| 381 | fork_waitfor(self.resultdir, pid) |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 382 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 383 | |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 384 | def quit(self): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 385 | # XXX: should have a better name. |
apw | de1503a | 2006-10-10 08:34:21 +0000 | [diff] [blame] | 386 | self.harness.run_pause() |
apw | f2c6660 | 2006-04-27 14:11:25 +0000 | [diff] [blame] | 387 | raise JobContinue("more to come") |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 388 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 389 | |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 390 | def complete(self, status): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 391 | """Clean up and exit""" |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 392 | # We are about to exit 'complete' so clean up the control file. |
| 393 | try: |
apw | ecf41b7 | 2006-03-31 14:00:55 +0000 | [diff] [blame] | 394 | os.unlink(self.control + '.state') |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 395 | except: |
| 396 | pass |
mbligh | 61a6c1a | 2006-12-25 01:26:38 +0000 | [diff] [blame] | 397 | self.harness.run_complete() |
apw | 1b02190 | 2006-04-03 17:02:56 +0000 | [diff] [blame] | 398 | sys.exit(status) |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 399 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 400 | |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 401 | steps = [] |
| 402 | def next_step(self, step): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 403 | """Define the next step""" |
apw | ce73d89 | 2007-09-25 16:53:05 +0000 | [diff] [blame] | 404 | if not isinstance(step[0], basestring): |
| 405 | step[0] = step[0].__name__ |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 406 | self.steps.append(step) |
apw | ecf41b7 | 2006-03-31 14:00:55 +0000 | [diff] [blame] | 407 | pickle.dump(self.steps, open(self.control + '.state', 'w')) |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 408 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 409 | |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 410 | def next_step_prepend(self, step): |
| 411 | """Insert a new step, executing first""" |
apw | ce73d89 | 2007-09-25 16:53:05 +0000 | [diff] [blame] | 412 | if not isinstance(step[0], basestring): |
| 413 | step[0] = step[0].__name__ |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 414 | self.steps.insert(0, step) |
| 415 | pickle.dump(self.steps, open(self.control + '.state', 'w')) |
| 416 | |
| 417 | |
apw | 83f8d77 | 2006-04-27 14:12:56 +0000 | [diff] [blame] | 418 | def step_engine(self): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 419 | """the stepping engine -- if the control file defines |
| 420 | step_init we will be using this engine to drive multiple runs. |
| 421 | """ |
| 422 | """Do the next step""" |
apw | 83f8d77 | 2006-04-27 14:12:56 +0000 | [diff] [blame] | 423 | lcl = dict({'job': self}) |
| 424 | |
| 425 | str = """ |
| 426 | from error import * |
| 427 | from autotest_utils import * |
| 428 | """ |
| 429 | exec(str, lcl, lcl) |
| 430 | execfile(self.control, lcl, lcl) |
| 431 | |
mbligh | d9223fc | 2006-11-26 17:19:54 +0000 | [diff] [blame] | 432 | state = self.control + '.state' |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 433 | # If there is a mid-job state file load that in and continue |
| 434 | # where it indicates. Otherwise start stepping at the passed |
| 435 | # entry. |
| 436 | try: |
mbligh | d9223fc | 2006-11-26 17:19:54 +0000 | [diff] [blame] | 437 | self.steps = pickle.load(open(state, 'r')) |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 438 | except: |
apw | 83f8d77 | 2006-04-27 14:12:56 +0000 | [diff] [blame] | 439 | if lcl.has_key('step_init'): |
| 440 | self.next_step([lcl['step_init']]) |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 441 | |
| 442 | # Run the step list. |
| 443 | while len(self.steps) > 0: |
apw | fd922bb | 2006-04-04 07:47:00 +0000 | [diff] [blame] | 444 | step = self.steps.pop(0) |
mbligh | d9223fc | 2006-11-26 17:19:54 +0000 | [diff] [blame] | 445 | pickle.dump(self.steps, open(state, 'w')) |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 446 | |
| 447 | cmd = step.pop(0) |
apw | 83f8d77 | 2006-04-27 14:12:56 +0000 | [diff] [blame] | 448 | lcl['__args'] = step |
apw | ce73d89 | 2007-09-25 16:53:05 +0000 | [diff] [blame] | 449 | exec(cmd + "(*__args)", lcl, lcl) |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 450 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 451 | |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 452 | def record(self, status_code, subdir, operation, status = ''): |
| 453 | """ |
| 454 | Record job-level status |
apw | 7db8d0b | 2006-10-09 08:10:25 +0000 | [diff] [blame] | 455 | |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 456 | The intent is to make this file both machine parseable and |
| 457 | human readable. That involves a little more complexity, but |
| 458 | really isn't all that bad ;-) |
| 459 | |
| 460 | Format is <status code>\t<subdir>\t<operation>\t<status> |
| 461 | |
| 462 | status code: (GOOD|WARN|FAIL|ABORT) |
| 463 | or START |
| 464 | or END (GOOD|WARN|FAIL|ABORT) |
| 465 | |
| 466 | subdir: MUST be a relevant subdirectory in the results, |
| 467 | or None, which will be represented as '----' |
| 468 | |
| 469 | operation: description of what you ran (e.g. "dbench", or |
| 470 | "mkfs -t foobar /dev/sda9") |
| 471 | |
| 472 | status: error message or "completed sucessfully" |
| 473 | |
| 474 | ------------------------------------------------------------ |
| 475 | |
| 476 | Initial tabs indicate indent levels for grouping, and is |
| 477 | governed by self.record_prefix |
| 478 | |
| 479 | multiline messages have secondary lines prefaced by a double |
| 480 | space (' ') |
| 481 | """ |
| 482 | |
mbligh | b0570ad | 2007-09-19 18:18:11 +0000 | [diff] [blame] | 483 | if subdir: |
| 484 | if re.match(r'[\n\t]', subdir): |
| 485 | raise "Invalid character in subdir string" |
| 486 | substr = subdir |
| 487 | else: |
| 488 | substr = '----' |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 489 | |
| 490 | if not re.match(r'(START|(END )?(GOOD|WARN|FAIL|ABORT))$', \ |
| 491 | status_code): |
| 492 | raise "Invalid status code supplied: %s" % status_code |
mbligh | 9c5ac32 | 2007-10-31 18:01:59 +0000 | [diff] [blame^] | 493 | if not operation: |
| 494 | operation = '----' |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 495 | if re.match(r'[\n\t]', operation): |
| 496 | raise "Invalid character in operation string" |
| 497 | operation = operation.rstrip() |
| 498 | status = status.rstrip() |
| 499 | status = re.sub(r"\t", " ", status) |
apw | 7db8d0b | 2006-10-09 08:10:25 +0000 | [diff] [blame] | 500 | # Ensure any continuation lines are marked so we can |
| 501 | # detect them in the status file to ensure it is parsable. |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 502 | status = re.sub(r"\n", "\n" + self.record_prefix + " ", status) |
| 503 | |
mbligh | b0570ad | 2007-09-19 18:18:11 +0000 | [diff] [blame] | 504 | msg = '%s\t%s\t%s\t%s' %(status_code, substr, operation, status) |
apw | 7db8d0b | 2006-10-09 08:10:25 +0000 | [diff] [blame] | 505 | |
apw | 4b2e4fb | 2007-09-25 16:52:30 +0000 | [diff] [blame] | 506 | self.harness.test_status_detail(status_code, substr, |
| 507 | operation, status) |
apw | de1503a | 2006-10-10 08:34:21 +0000 | [diff] [blame] | 508 | self.harness.test_status(msg) |
apw | f1a8116 | 2006-04-25 10:10:29 +0000 | [diff] [blame] | 509 | print msg |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 510 | status_file = os.path.join(self.resultdir, 'status') |
mbligh | b0570ad | 2007-09-19 18:18:11 +0000 | [diff] [blame] | 511 | open(status_file, "a").write(self.record_prefix + msg + "\n") |
| 512 | if subdir: |
| 513 | status_file = os.path.join(self.resultdir, subdir, 'status') |
| 514 | open(status_file, "a").write(msg + "\n") |
apw | ce9abe9 | 2006-04-27 14:14:04 +0000 | [diff] [blame] | 515 | |
| 516 | |
mbligh | 570e93e | 2006-11-26 05:15:56 +0000 | [diff] [blame] | 517 | def runjob(control, cont = False, tag = "default", harness_type = ''): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 518 | """The main interface to this module |
| 519 | |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 520 | control |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 521 | The control file to use for this job. |
| 522 | cont |
| 523 | Whether this is the continuation of a previously started job |
| 524 | """ |
mbligh | b4eef24 | 2007-07-23 18:22:49 +0000 | [diff] [blame] | 525 | control = os.path.abspath(control) |
apw | ce9abe9 | 2006-04-27 14:14:04 +0000 | [diff] [blame] | 526 | state = control + '.state' |
| 527 | |
| 528 | # instantiate the job object ready for the control file. |
| 529 | myjob = None |
| 530 | try: |
| 531 | # Check that the control file is valid |
| 532 | if not os.path.exists(control): |
| 533 | raise JobError(control + ": control file not found") |
| 534 | |
| 535 | # When continuing, the job is complete when there is no |
| 536 | # state file, ensure we don't try and continue. |
mbligh | f3fef46 | 2006-09-13 16:05:05 +0000 | [diff] [blame] | 537 | if cont and not os.path.exists(state): |
apw | ce9abe9 | 2006-04-27 14:14:04 +0000 | [diff] [blame] | 538 | sys.exit(1) |
mbligh | f3fef46 | 2006-09-13 16:05:05 +0000 | [diff] [blame] | 539 | if cont == False and os.path.exists(state): |
apw | ce9abe9 | 2006-04-27 14:14:04 +0000 | [diff] [blame] | 540 | os.unlink(state) |
| 541 | |
mbligh | 570e93e | 2006-11-26 05:15:56 +0000 | [diff] [blame] | 542 | myjob = job(control, tag, cont, harness_type) |
apw | ce9abe9 | 2006-04-27 14:14:04 +0000 | [diff] [blame] | 543 | |
| 544 | # Load in the users control file, may do any one of: |
| 545 | # 1) execute in toto |
| 546 | # 2) define steps, and select the first via next_step() |
| 547 | myjob.step_engine() |
| 548 | |
apw | ce9abe9 | 2006-04-27 14:14:04 +0000 | [diff] [blame] | 549 | except JobContinue: |
| 550 | sys.exit(5) |
| 551 | |
| 552 | except JobError, instance: |
| 553 | print "JOB ERROR: " + instance.args[0] |
mbligh | 9c5ac32 | 2007-10-31 18:01:59 +0000 | [diff] [blame^] | 554 | if myjob: |
| 555 | myjob.record('ABORT', None, None, instance.args[0]) |
apw | ce9abe9 | 2006-04-27 14:14:04 +0000 | [diff] [blame] | 556 | myjob.complete(1) |
mbligh | 9c5ac32 | 2007-10-31 18:01:59 +0000 | [diff] [blame^] | 557 | |
apw | ce9abe9 | 2006-04-27 14:14:04 +0000 | [diff] [blame] | 558 | |
| 559 | except: |
mbligh | 9c5ac32 | 2007-10-31 18:01:59 +0000 | [diff] [blame^] | 560 | print "JOB ERROR: " + format_error() |
mbligh | fbfb77d | 2007-02-15 18:54:03 +0000 | [diff] [blame] | 561 | if myjob: |
mbligh | 9c5ac32 | 2007-10-31 18:01:59 +0000 | [diff] [blame^] | 562 | myjob.record('ABORT', None, None, format_error()) |
| 563 | myjob.complete(1) |
mbligh | 892d37f | 2007-03-01 17:03:25 +0000 | [diff] [blame] | 564 | |
| 565 | # If we get here, then we assume the job is complete and good. |
mbligh | 9c5ac32 | 2007-10-31 18:01:59 +0000 | [diff] [blame^] | 566 | myjob.record('GOOD', None, None, 'job completed sucessfully') |
mbligh | 892d37f | 2007-03-01 17:03:25 +0000 | [diff] [blame] | 567 | myjob.complete(0) |
| 568 | |