2014-10-12 20:49:36 +02:00
|
|
|
#!/usr/bin/env python2
|
|
|
|
#
|
|
|
|
# Parallel VM test case executor
|
|
|
|
# Copyright (c) 2014, Jouni Malinen <j@w1.fi>
|
|
|
|
#
|
|
|
|
# This software may be distributed under the terms of the BSD license.
|
|
|
|
# See README for more details.
|
|
|
|
|
2014-10-19 09:37:02 +02:00
|
|
|
import curses
|
2014-10-12 20:49:36 +02:00
|
|
|
import fcntl
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
2014-10-19 09:37:02 +02:00
|
|
|
def get_results():
|
|
|
|
global vm
|
|
|
|
started = []
|
|
|
|
passed = []
|
|
|
|
failed = []
|
|
|
|
skipped = []
|
|
|
|
for i in range(0, num_servers):
|
|
|
|
lines = vm[i]['out'].splitlines()
|
|
|
|
started += [ l for l in lines if l.startswith('START ') ]
|
|
|
|
passed += [ l for l in lines if l.startswith('PASS ') ]
|
|
|
|
failed += [ l for l in lines if l.startswith('FAIL ') ]
|
|
|
|
skipped += [ l for l in lines if l.startswith('SKIP ') ]
|
|
|
|
return (started, passed, failed, skipped)
|
2014-10-12 20:49:36 +02:00
|
|
|
|
2014-10-19 09:37:02 +02:00
|
|
|
def show_progress(scr):
|
|
|
|
global num_servers
|
|
|
|
global vm
|
2014-11-16 21:34:54 +01:00
|
|
|
global dir
|
|
|
|
global timestamp
|
2014-11-19 01:03:39 +01:00
|
|
|
global tests
|
|
|
|
|
|
|
|
total_tests = len(tests)
|
2014-10-19 09:37:02 +02:00
|
|
|
|
|
|
|
scr.leaveok(1)
|
|
|
|
scr.addstr(0, 0, "Parallel test execution status", curses.A_BOLD)
|
2014-10-12 20:49:36 +02:00
|
|
|
for i in range(0, num_servers):
|
2014-10-19 09:37:02 +02:00
|
|
|
scr.addstr(i + 1, 0, "VM %d:" % (i + 1), curses.A_BOLD)
|
2014-11-19 01:03:39 +01:00
|
|
|
scr.addstr(i + 1, 10, "starting VM")
|
2014-10-19 09:37:02 +02:00
|
|
|
scr.addstr(num_servers + 1, 0, "Total:", curses.A_BOLD)
|
2014-11-19 01:03:39 +01:00
|
|
|
scr.addstr(num_servers + 1, 20, "TOTAL={} STARTED=0 PASS=0 FAIL=0 SKIP=0".format(total_tests))
|
2014-10-19 09:37:02 +02:00
|
|
|
scr.refresh()
|
2014-10-12 20:49:36 +02:00
|
|
|
|
|
|
|
while True:
|
|
|
|
running = False
|
|
|
|
updated = False
|
|
|
|
for i in range(0, num_servers):
|
|
|
|
if not vm[i]['proc']:
|
|
|
|
continue
|
|
|
|
if vm[i]['proc'].poll() is not None:
|
|
|
|
vm[i]['proc'] = None
|
2014-10-19 09:37:02 +02:00
|
|
|
scr.move(i + 1, 10)
|
|
|
|
scr.clrtoeol()
|
2014-11-16 21:34:54 +01:00
|
|
|
log = '{}/{}.srv.{}/console'.format(dir, timestamp, i + 1)
|
|
|
|
with open(log, 'r') as f:
|
|
|
|
if "Kernel panic" in f.read():
|
|
|
|
scr.addstr("kernel panic")
|
|
|
|
else:
|
|
|
|
scr.addstr("completed run")
|
2014-10-19 09:37:02 +02:00
|
|
|
updated = True
|
2014-10-12 20:49:36 +02:00
|
|
|
continue
|
|
|
|
|
|
|
|
running = True
|
|
|
|
try:
|
|
|
|
err = vm[i]['proc'].stderr.read()
|
|
|
|
vm[i]['err'] += err
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
try:
|
|
|
|
out = vm[i]['proc'].stdout.read()
|
2014-11-19 01:03:39 +01:00
|
|
|
if "READY" in out or "PASS" in out or "FAIL" in out or "SKIP" in out:
|
|
|
|
if not tests:
|
|
|
|
vm[i]['proc'].stdin.write('\n')
|
|
|
|
else:
|
|
|
|
name = tests.pop(0)
|
|
|
|
vm[i]['proc'].stdin.write(name + '\n')
|
2014-10-12 20:49:36 +02:00
|
|
|
except:
|
|
|
|
continue
|
|
|
|
#print("VM {}: '{}'".format(i, out))
|
|
|
|
vm[i]['out'] += out
|
|
|
|
lines = vm[i]['out'].splitlines()
|
|
|
|
last = [ l for l in lines if l.startswith('START ') ]
|
|
|
|
if len(last) > 0:
|
|
|
|
try:
|
2014-10-19 09:37:02 +02:00
|
|
|
info = last[-1].split(' ')
|
|
|
|
scr.move(i + 1, 10)
|
|
|
|
scr.clrtoeol()
|
2014-11-19 01:03:39 +01:00
|
|
|
scr.addstr(info[1])
|
2014-10-12 20:49:36 +02:00
|
|
|
updated = True
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
if not running:
|
|
|
|
break
|
|
|
|
|
|
|
|
if updated:
|
2014-11-19 01:03:39 +01:00
|
|
|
(started, passed, failed, skipped) = get_results()
|
2014-10-19 09:37:02 +02:00
|
|
|
scr.move(num_servers + 1, 10)
|
|
|
|
scr.clrtoeol()
|
2014-11-19 01:03:39 +01:00
|
|
|
scr.addstr("{} %".format(int(100.0 * (len(passed) + len(failed) + len(skipped)) / total_tests)))
|
|
|
|
scr.addstr(num_servers + 1, 20, "TOTAL={} STARTED={} PASS={} FAIL={} SKIP={}".format(total_tests, len(started), len(passed), len(failed), len(skipped)))
|
2014-10-19 09:37:02 +02:00
|
|
|
if len(failed) > 0:
|
|
|
|
scr.move(num_servers + 2, 0)
|
|
|
|
scr.clrtoeol()
|
|
|
|
scr.addstr("Failed test cases: ")
|
|
|
|
for f in failed:
|
|
|
|
scr.addstr(f.split(' ')[1])
|
|
|
|
scr.addstr(' ')
|
|
|
|
scr.refresh()
|
2014-10-12 20:49:36 +02:00
|
|
|
|
2014-11-19 01:03:39 +01:00
|
|
|
time.sleep(0.5)
|
|
|
|
|
|
|
|
scr.refresh()
|
|
|
|
time.sleep(0.3)
|
2014-10-12 20:49:36 +02:00
|
|
|
|
2014-10-19 09:37:02 +02:00
|
|
|
def main():
|
|
|
|
global num_servers
|
|
|
|
global vm
|
2014-11-16 21:34:54 +01:00
|
|
|
global dir
|
|
|
|
global timestamp
|
2014-11-19 01:03:39 +01:00
|
|
|
global tests
|
2014-10-19 09:37:02 +02:00
|
|
|
|
|
|
|
if len(sys.argv) < 2:
|
|
|
|
sys.exit("Usage: %s <number of VMs> [params..]" % sys.argv[0])
|
|
|
|
num_servers = int(sys.argv[1])
|
|
|
|
if num_servers < 1:
|
|
|
|
sys.exit("Too small number of VMs")
|
|
|
|
|
2014-11-19 01:03:39 +01:00
|
|
|
tests = []
|
|
|
|
cmd = [ '../run-tests.py', '-L' ] + sys.argv[2:]
|
|
|
|
lst = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
|
|
|
for l in lst.stdout.readlines():
|
|
|
|
name = l.split(' ')[0]
|
|
|
|
tests.append(name)
|
|
|
|
if len(tests) == 0:
|
|
|
|
sys.exit("No test cases selected")
|
2014-12-07 14:31:38 +01:00
|
|
|
extra_args = [x for x in sys.argv[2:] if x not in tests]
|
2014-11-19 01:03:39 +01:00
|
|
|
|
2014-11-16 21:34:54 +01:00
|
|
|
dir = '/tmp/hwsim-test-logs'
|
|
|
|
try:
|
|
|
|
os.mkdir(dir)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2014-10-19 09:37:02 +02:00
|
|
|
timestamp = int(time.time())
|
|
|
|
vm = {}
|
|
|
|
for i in range(0, num_servers):
|
|
|
|
print("\rStarting virtual machine {}/{}".format(i + 1, num_servers)),
|
2014-11-16 21:24:18 +01:00
|
|
|
cmd = ['./vm-run.sh', '--timestamp', str(timestamp),
|
|
|
|
'--ext', 'srv.%d' % (i + 1),
|
2014-12-07 14:31:38 +01:00
|
|
|
'-i'] + extra_args
|
2014-10-19 09:37:02 +02:00
|
|
|
vm[i] = {}
|
|
|
|
vm[i]['proc'] = subprocess.Popen(cmd,
|
|
|
|
stdin=subprocess.PIPE,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE)
|
|
|
|
vm[i]['out'] = ""
|
|
|
|
vm[i]['err'] = ""
|
|
|
|
for stream in [ vm[i]['proc'].stdout, vm[i]['proc'].stderr ]:
|
|
|
|
fd = stream.fileno()
|
|
|
|
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
|
|
|
|
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
|
|
|
|
print
|
|
|
|
|
|
|
|
curses.wrapper(show_progress)
|
|
|
|
|
2014-10-12 20:49:36 +02:00
|
|
|
with open('{}/{}-parallel.log'.format(dir, timestamp), 'w') as f:
|
|
|
|
for i in range(0, num_servers):
|
|
|
|
f.write('VM {}\n{}\n{}\n'.format(i, vm[i]['out'], vm[i]['err']))
|
|
|
|
|
2014-10-19 09:37:02 +02:00
|
|
|
(started, passed, failed, skipped) = get_results()
|
2014-10-12 20:49:36 +02:00
|
|
|
|
|
|
|
if len(failed) > 0:
|
|
|
|
print "Failed test cases:"
|
|
|
|
for f in failed:
|
|
|
|
print f.split(' ')[1],
|
|
|
|
print
|
|
|
|
print("TOTAL={} PASS={} FAIL={} SKIP={}".format(len(started), len(passed), len(failed), len(skipped)))
|
2014-11-19 01:03:39 +01:00
|
|
|
print "Logs: " + dir + '/' + str(timestamp)
|
2014-10-12 20:49:36 +02:00
|
|
|
|
2014-11-16 21:34:54 +01:00
|
|
|
for i in range(0, num_servers):
|
|
|
|
log = '{}/{}.srv.{}/console'.format(dir, timestamp, i + 1)
|
|
|
|
with open(log, 'r') as f:
|
|
|
|
if "Kernel panic" in f.read():
|
|
|
|
print "Kernel panic in " + log
|
|
|
|
|
2014-10-12 20:49:36 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|