blob: 6a48ad94b5512a4d40037b81f6dce5e98d0bf233 [file] [log] [blame]
mblighf4c35322006-03-13 01:01:10 +00001from autotest_utils import *
apw0865f482006-03-30 18:50:19 +00002import os, sys, kernel, test, pickle, threading
mblighf4c35322006-03-13 01:01:10 +00003
apw0865f482006-03-30 18:50:19 +00004# Parallel run interface.
5class AsyncRun(threading.Thread):
6 def __init__(self, cmd):
7 threading.Thread.__init__(self)
8 self.cmd = cmd
9 def run(self):
10 x = self.cmd.pop(0)
11 x(*self.cmd)
12
13# JOB: the actual job against which we do everything.
mblighf4c35322006-03-13 01:01:10 +000014class job:
apwecf41b72006-03-31 14:00:55 +000015 def __init__(self, control, jobtag='default'):
mblighf4c35322006-03-13 01:01:10 +000016 self.autodir = os.environ['AUTODIR']
mbligh82641862006-04-23 06:21:36 +000017 self.testdir = self.autodir + '/tests'
mblighedf430c2006-04-23 06:52:09 +000018 self.profdir = self.autodir + '/profilers'
mblighf4c35322006-03-13 01:01:10 +000019 self.tmpdir = self.autodir + '/tmp'
mbligha66742f2006-04-02 19:54:27 +000020 if os.path.exists(self.tmpdir):
mbligha975fb62006-04-22 19:56:25 +000021 system('rm -rf ' + self.tmpdir)
mbligha66742f2006-04-02 19:54:27 +000022 os.mkdir(self.tmpdir)
mbligh24f7da02006-04-23 06:32:18 +000023 self.resultdir = self.autodir + '/results/' + jobtag
mblighf4c35322006-03-13 01:01:10 +000024 if os.path.exists(self.resultdir):
mbligha975fb62006-04-22 19:56:25 +000025 system('rm -rf ' + self.resultdir)
mblighf4c35322006-03-13 01:01:10 +000026 os.mkdir(self.resultdir)
27 os.mkdir(self.resultdir + "/debug")
28 os.mkdir(self.resultdir + "/analysis")
29
apwecf41b72006-03-31 14:00:55 +000030 self.control = control
mblighf4c35322006-03-13 01:01:10 +000031 self.jobtab = jobtag
32
33 self.stdout = fd_stack(1, sys.stdout)
34 self.stderr = fd_stack(2, sys.stderr)
35
36 def kernel(self, topdir, base_tree):
37 return kernel.kernel(self, topdir, base_tree)
38
apw5a78eef2006-04-03 14:16:59 +000039 def runtest(self, tag, testname, *test_args):
mbligh82641862006-04-23 06:21:36 +000040 sys.path.insert(0, self.testdir + '/' + testname)
apw5a78eef2006-04-03 14:16:59 +000041 exec "import %s" % testname
42 exec "mytest = %s.%s(self, testname + '.' + tag)" % (testname, testname)
mbligh82641862006-04-23 06:21:36 +000043 mytest.bindir = self.testdir + '/' + testname
44 mytest.srcdir = mytest.bindir + '/' + testname
45 if os.path.exists(mytest.srcdir):
46 # Bad idea, as it'll always rebuild, but will do for now
47 system('rm -rf ' + mytest.srcdir)
48 mytest.tmpdir = self.tmpdir + '/' + testname
49 os.mkdir(mytest.tmpdir)
mblighf4c35322006-03-13 01:01:10 +000050 mytest.run(testname, test_args)
apw0865f482006-03-30 18:50:19 +000051
52 def noop(self, text):
53 print "job: noop: " + text
54
55 # Job control primatives.
56 def parallel(self, *l):
57 tasks = []
58 for t in l:
59 task = AsyncRun(t)
60 tasks.append(task)
61 task.start()
62 for t in tasks:
63 t.join()
64
65 # XXX: should have a better name.
66 def quit(self):
67 sys.exit(5)
68
69 def complete(self, status):
70 # We are about to exit 'complete' so clean up the control file.
71 try:
apwecf41b72006-03-31 14:00:55 +000072 os.unlink(self.control + '.state')
apw0865f482006-03-30 18:50:19 +000073 except:
74 pass
mbligha66742f2006-04-02 19:54:27 +000075 if os.path.exists(self.control):
76 os.rename(self.control, self.control + '.complete')
apw1b021902006-04-03 17:02:56 +000077 sys.exit(status)
apw0865f482006-03-30 18:50:19 +000078
79 # STEPS: the stepping engine -- if the control file defines
80 # step_init we will be using this engine to drive multiple
81 # runs.
82 steps = []
83 def next_step(self, step):
84 self.steps.append(step)
apwecf41b72006-03-31 14:00:55 +000085 pickle.dump(self.steps, open(self.control + '.state', 'w'))
apw0865f482006-03-30 18:50:19 +000086
87 def step_engine(self, init):
88 # If there is a mid-job state file load that in and continue
89 # where it indicates. Otherwise start stepping at the passed
90 # entry.
91 try:
apwecf41b72006-03-31 14:00:55 +000092 self.steps = pickle.load(open(self.control + '.state',
93 'r'))
apw0865f482006-03-30 18:50:19 +000094 except:
95 self.next_step(init)
96
97 # Run the step list.
98 while len(self.steps) > 0:
apwfd922bb2006-04-04 07:47:00 +000099 step = self.steps.pop(0)
apwecf41b72006-03-31 14:00:55 +0000100 pickle.dump(self.steps, open(self.control + '.state',
101 'w'))
apw0865f482006-03-30 18:50:19 +0000102
103 cmd = step.pop(0)
104 cmd(*step)
105
106 # all done, clean up and exit.
107 self.complete(0)
108