]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Provide more details of parallel testing with curses UI
authorJouni Malinen <j@w1.fi>
Sun, 19 Oct 2014 07:37:02 +0000 (10:37 +0300)
committerJouni Malinen <j@w1.fi>
Sun, 19 Oct 2014 08:19:49 +0000 (11:19 +0300)
This extends parallel-vm.py to show more details about testing progress
from each VM.

Signed-off-by: Jouni Malinen <j@w1.fi>
tests/hwsim/vm/parallel-vm.py

index bb79c44e69d9dcc78e36a4cbb6e42b2cefa3b277..42083f761cd67e3e421d5dc5ce467bff2fb12736 100755 (executable)
@@ -6,38 +6,38 @@
 # This software may be distributed under the terms of the BSD license.
 # See README for more details.
 
+import curses
 import fcntl
 import os
 import subprocess
 import sys
 import time
 
-def main():
-    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")
+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)
 
-    timestamp = int(time.time())
-    vm = {}
+def show_progress(scr):
+    global num_servers
+    global vm
+
+    scr.leaveok(1)
+    scr.addstr(0, 0, "Parallel test execution status", curses.A_BOLD)
     for i in range(0, num_servers):
-        print("\rStarting virtual machine {}/{}".format(i + 1, num_servers)),
-        cmd = ['./vm-run.sh', '--ext', 'srv.%d' % (i + 1),
-               '--split', '%d/%d' % (i + 1, num_servers)] + sys.argv[2:]
-        vm[i] = {}
-        vm[i]['proc'] = subprocess.Popen(cmd,
-                                         stdin=subprocess.PIPE,
-                                         stdout=subprocess.PIPE,
-                                         stderr=subprocess.PIPE)
-        vm[i]['out'] = ""
-        vm[i]['err'] = ""
-        vm[i]['pos'] = ""
-        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
+        scr.addstr(i + 1, 0, "VM %d:" % (i + 1), curses.A_BOLD)
+        scr.addstr(i + 1, 20, "starting VM")
+    scr.addstr(num_servers + 1, 0, "Total:", curses.A_BOLD)
+    scr.refresh()
 
     while True:
         running = False
@@ -47,6 +47,11 @@ def main():
                 continue
             if vm[i]['proc'].poll() is not None:
                 vm[i]['proc'] = None
+                vm[i]['done'] = vm[i]['total']
+                scr.move(i + 1, 10)
+                scr.clrtoeol()
+                scr.addstr("completed run")
+                updated = True
                 continue
 
             running = True
@@ -66,8 +71,17 @@ def main():
             last = [ l for l in lines if l.startswith('START ') ]
             if len(last) > 0:
                 try:
-                    pos = last[-1].split(' ')[2]
-                    vm[i]['pos'] = pos
+                    info = last[-1].split(' ')
+                    vm[i]['pos'] = info[2]
+                    pos = info[2].split('/')
+                    if int(pos[0]) > 0:
+                        vm[i]['done'] = int(pos[0]) - 1
+                    vm[i]['total'] = int(pos[1])
+                    p = float(pos[0]) / float(pos[1]) * 100.0
+                    scr.move(i + 1, 10)
+                    scr.clrtoeol()
+                    scr.addstr("{} %".format(int(p)))
+                    scr.addstr(i + 1, 20, info[1])
                     updated = True
                 except:
                     pass
@@ -75,19 +89,66 @@ def main():
                 vm[i]['pos'] = ''
 
         if not running:
-            print("All VMs completed")
             break
 
         if updated:
-            status = {}
+            done = 0
+            total = 0
             for i in range(0, num_servers):
-                if not vm[i]['proc']:
-                    continue
-                status[i] = vm[i]['pos']
-            print status
+                done += vm[i]['done']
+                total += vm[i]['total']
+            scr.move(num_servers + 1, 10)
+            scr.clrtoeol()
+            if total > 0:
+                scr.addstr("{} %".format(int(100.0 * done / total)))
+
+            (started, passed, failed, skipped) = get_results()
+            scr.addstr(num_servers + 1, 20, "TOTAL={} PASS={} FAIL={} SKIP={}".format(len(started), len(passed), len(failed), len(skipped)))
+            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()
 
         time.sleep(1)
 
+def main():
+    global num_servers
+    global vm
+
+    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")
+
+    timestamp = int(time.time())
+    vm = {}
+    for i in range(0, num_servers):
+        print("\rStarting virtual machine {}/{}".format(i + 1, num_servers)),
+        cmd = ['./vm-run.sh', '--ext', 'srv.%d' % (i + 1),
+               '--split', '%d/%d' % (i + 1, num_servers)] + sys.argv[2:]
+        vm[i] = {}
+        vm[i]['proc'] = subprocess.Popen(cmd,
+                                         stdin=subprocess.PIPE,
+                                         stdout=subprocess.PIPE,
+                                         stderr=subprocess.PIPE)
+        vm[i]['out'] = ""
+        vm[i]['err'] = ""
+        vm[i]['pos'] = ""
+        vm[i]['done'] = 0
+        vm[i]['total'] = 0
+        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)
+
     dir = '/tmp/hwsim-test-logs'
     try:
         os.mkdir(dir)
@@ -97,16 +158,7 @@ def main():
         for i in range(0, num_servers):
             f.write('VM {}\n{}\n{}\n'.format(i, vm[i]['out'], vm[i]['err']))
 
-    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 ') ]
+    (started, passed, failed, skipped) = get_results()
 
     if len(failed) > 0:
         print "Failed test cases:"