blob: c68040323e29bc734ae54f803cac7cf851921b22 [file] [log] [blame]
#!/usr/bin/python
# testkernel <client> <control> <kernel> <config> <patches ...>
#
# Create a config that builds the kernel+patches specified,
# then runs the tests specified in the control file supplied.
#
# Run that control file on the comma-separated list of machines supplied
# by dumping a control file in $AUTOTEST_DIR/queue/machine.
import os, sys, time
if len(sys.argv) < 5:
print "Usage: testkernel <client> <control> <kernel> <config> <patches ...>"
sys.exit(1)
(client, control, kernel, config) = sys.argv[1:5]
if len(sys.argv) > 5:
patches = sys.argv[5:]
else:
patches = []
# Need to be careful to create the control file atomically, so don't end up
# executing half of it. Try to create it in the same filesystem, then move it.
queuedir = os.path.join(os.environ['AUTOTEST_DIR'], 'queue')
tmpfile = os.path.join(queuedir, 'tmp_control.%d' % os.getpid())
c = open(tmpfile, 'w')
print >> c, "def step_init():"
print >> c, "\t" + "job.next_step([step_test])"
print >> c, "\t" + "testkernel = job.kernel('%s')" % kernel
if patches:
patch_list = ', '.join(["'%s'" % x for x in patches])
print >> c, "\t" + "testkernel.patch(%s)" % patch_list
print >> c, "\t" + "testkernel.config('%s')" % config
print >> c, "\t" + "testkernel.build()"
print >> c, "\t" + "testkernel.boot()"
print >> c, ""
print >> c, "def step_test():"
for line in open(control, 'r'):
print >> c, "\t" + line,
c.close()
# This is pretty revolting, but will do as a hack for testing
jobname = os.path.basename(control) + '.' + os.path.basename(kernel)
output = os.path.join(queuedir, client, jobname)
if os.path.exists(output):
output += ".%d" % int(time.time())
os.rename(tmpfile, output)