Main motivation here is in the next patch: getting access to ConfigParser
for pulling extra options out of x86/unittests.cfg.

Drop the README bits about manually invoking qemu-kvm/qemu-system: the
runner spits out the generated CLI if you want to invoke it by hand,
and since some tests want specific options the docs weren't correct
to begin with.

This also fixes the script to have a consistent exit status regardless
of the version of qemu we invoke.
---
 README  |  21 ++++--------
 x86-run | 113 ++++++++++++++++++++++++++++++++++++++++++++++++----------------
 2 files changed, 93 insertions(+), 41 deletions(-)

diff --git a/README b/README
index db525e3..9a580b8 100644
--- a/README
+++ b/README
@@ -9,24 +9,17 @@ See file testdev.txt for more details.
 To create the tests' images just type 'make' in this directory.
 Tests' images created in ./<ARCH>/*.flat
 
-An example of a test invocation:
-Using qemu-kvm:
 
-qemu-kvm -device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out 
-serial stdio -kernel ./x86/msr.flat
-This invocation runs the msr test case. The test outputs to stdio.
+To launch a test, use the runner script:
 
-Using qemu (supported since qemu 1.3):
-qemu-system-x86_64 -enable-kvm -device pc-testdev -serial stdio -device 
isa-debug-exit,iobase=0xf4,iosize=0x4 -kernel ./x86/msr.flat
+  ./x86-run ./x86/msr.flat
 
-Or use a runner script to detect the correct invocation:
-./x86-run ./x86/msr.flat
-To select a specific qemu binary, specify the QEMU=<path> environment:
-QEMU=/tmp/qemu/x86_64-softmmu/qemu-system-x86_64 ./x86-run ./x86/msr.flat
+To select a specific qemu binary: specify the QEMU=<path> environment:
+
+  ./x86-run --qemu /path/to/x86_64-softmmu/qemu-system-x86_64 ./x86/msr.flat
+
+./x86-run returns 1 if any passed test fails, 0 otherwise.
 
-The exit status of the binary (and the script) is inconsistent: with
-qemu-system, after the unittest is done, the exit status of qemu is 1,
-different from the 'old style' qemu-kvm, whose exit status in successful
-completion is 0.
 
 Directory structure:
 .:  Makefile and config files for the tests
diff --git a/x86-run b/x86-run
index e395a70..ab9eed9 100755
--- a/x86-run
+++ b/x86-run
@@ -1,27 +1,86 @@
-#!/usr/bin/bash
-
-qemukvm="${QEMU:-qemu-kvm}"
-qemusystem="${QEMU:-qemu-system-x86_64}"
-if
-       ${qemukvm} -device '?' 2>&1 | fgrep -e \"testdev\" -e \"pc-testdev\" > 
/dev/null;
-then
-       qemu="${qemukvm}"
-else
-       if
-               ${qemsystem} -device '?' 2>&1 | fgrep -e \"testdev\" -e 
\"pc-testdev\" > /dev/null;
-       then
-               qemu="${qemusystem}"
-       else
-               echo QEMU binary ${QEMU} has no support for test device. 
Exiting.
-               exit 1
-       fi
-fi
-
-if
-       ${qemu} -device '?' 2>&1 | fgrep "pc-testdev" > /dev/null;
-then
-       command="${qemu} -enable-kvm -device pc-testdev -serial stdio -device 
isa-debug-exit,iobase=0xf4,iosize=0x4 -kernel"
-else
-       command="${qemu} -device testdev,chardev=testlog -chardev 
file,id=testlog,path=msr.out -serial stdio -kernel"
-fi
-exec ${command} "$@"
+#!/usr/bin/env python
+
+import glob
+import optparse
+import os
+import sys
+
+
+def fail(msg):
+    print >> sys.stderr, "ERROR: %s" % msg
+    sys.exit(1)
+
+def supports_testdev(qemu):
+    return os.system("%s -device ? 2>&1 | fgrep -q "
+                     "-e 'testdev' -e 'pc-testdev'" % qemu) == 0
+
+def check_qemu(binpath):
+    if binpath:
+        if not supports_testdev(binpath):
+            fail("%s does not support testdev" % binpath)
+    elif supports_testdev("qemu-kvm"):
+        binpath = "qemu-kvm"
+    elif supports_testdev("qemu-system-x86_64"):
+        binpath = "qemu-system-x86_64"
+    else:
+        fail("Could not find qemu binary that supports testdev")
+
+    cmd = "%s -enable-kvm -serial stdio " % binpath
+
+    if os.system("%s -device ? 2>&1 | fgrep -q 'pc-testdev'" % binpath) == 0:
+        devcmd = ("-device pc-testdev "
+                  "-device isa-debug-exit,iobase=0xf4,iosize=0x4")
+    else:
+        devcmd = ("-device testdev,chardev=testlog "
+                  "-chardev file,id=testlog,path=test.out")
+
+    return cmd + devcmd
+
+
+def parse_args():
+    parser = optparse.OptionParser(
+        usage="%prog x86/$TEST1.flat [x86/$TEST2.flat] ...",
+        description="Launch a test with the correct qemu args")
+
+    parser.add_option("--qemu-bin", dest="qemu",
+                      help="Path to qemu binary to use. If not specified, "
+                           "uses qemu-kvm or qemu-system-x86_64 from $PATH.")
+    parser.add_option("--all", action="store_true", help="Run all x86 tests")
+
+    options, args = parser.parse_args()
+    if options.all:
+        args = glob.glob("x86/*.flat")
+        if not args:
+            parser.error("Didn't find any .flat files in x86/")
+
+    elif not args:
+        parser.error("A .flat test file or --all must be specified")
+
+    return options.qemu, args
+
+
+def main():
+    qemu, testfiles = parse_args()
+    basecmd = check_qemu(qemu)
+    newstyle = "pc-testdev" in basecmd
+
+    ret = 0
+    for testfile in testfiles:
+        cmd = basecmd + " -kernel %s" % testfile
+        print cmd
+
+        cmdret = os.system(cmd) >> 8
+        print
+
+        if cmdret == 0 and not newstyle:
+            continue
+        if cmdret == 1 and newstyle:
+            continue
+        ret = 1
+
+
+    return ret
+
+
+if __name__ == '__main__':
+    sys.exit(main())
-- 
1.8.1.4

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to