tests: Add run-tests.py -i to control execution from stdin
authorJouni Malinen <j@w1.fi>
Wed, 19 Nov 2014 00:01:27 +0000 (02:01 +0200)
committerJouni Malinen <j@w1.fi>
Wed, 19 Nov 2014 13:20:53 +0000 (15:20 +0200)
The new -i command line argument can be used to control test case
execution from stdin to run-tests.py and vm-run.sh. This can be used,
e.g., to run multiple repeated test sequences in a virtual machine
without havign to restart the VM between each iteration.

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

index b267228..481b785 100755 (executable)
@@ -204,6 +204,8 @@ def main():
                         type=str, choices=[[]] + test_modules, nargs='+')
     parser.add_argument('-l', metavar='<modules file>', dest='mfile',
                         help='test modules file name')
+    parser.add_argument('-i', action='store_true', dest='stdin_ctrl',
+                        help='stdin-controlled test case execution')
     parser.add_argument('tests', metavar='<test>', nargs='*', type=str,
                         help='tests to run (only valid without -f)',
                         choices=[[]] + test_names)
@@ -339,7 +341,34 @@ def main():
         shuffle(tests_to_run)
 
     count = 0
-    for t in tests_to_run:
+    if args.stdin_ctrl:
+        print "READY"
+        sys.stdout.flush()
+    else:
+        remaining_tests = tests_to_run
+    while True:
+        if args.stdin_ctrl:
+            test = sys.stdin.readline()
+            if not test:
+                break
+            test = test.splitlines()[0]
+            if test == '':
+                break
+            t = None
+            for tt in tests:
+                name = tt.__name__.replace('test_', '', 1)
+                if name == test:
+                    t = tt
+                    break
+            if not t:
+                print "NOT-FOUND"
+                sys.stdout.flush()
+                continue
+        else:
+            if len(remaining_tests) == 0:
+                break
+            t = remaining_tests.pop(0)
+
         name = t.__name__.replace('test_', '', 1)
         if log_handler:
             log_handler.stream.close()