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