Skip to contentSkip to conversation

tests/vm: Improvements when KVM is not available

PATCH Superseded Philippe Mathieu-Daudé 2 participants 7 messages Jul 17, 2018

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover tests/vm: Improvements when KVM is not available

Hi Fam,

Few patches I added while testing the VM tests without KVM access. I doubt many people want to suffer using TCG for VM testing, but it was handy to debug/support aarch64 VM tests.

Also this could be a useful TCG stress test...?

Regards,

Phil.

Philippe Mathieu-Daudé (5):
tests/vm: Extract the kvm_available() handy function tests/vm: Use 'host' cpu when KVM is available, else default to 'max' tests/vm: Do not abuse parallelism when KVM is not available tests/vm: Display remaining seconds to wait for a VM to start tests/vm: When using TCG, wait longer for a VM to start

 tests/vm/basevm.py | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
Signature · 1 line
2.18.0
#1 lore raw

PATCH 1/5 tests/vm: Extract the kvm_available() handy function

---
 tests/vm/basevm.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tests/vm/basevm.py +6 -1
index 3643117816..04089cd545 100755
@@ -33,6 +33,11 @@ SSH_KEY = open(os.path.join(os.path.dirname(__file__),
 SSH_PUB_KEY = open(os.path.join(os.path.dirname(__file__),
                    "..", "keys", "id_rsa.pub")).read()
 
+
+def kvm_available():
+    return os.access("/dev/kvm", os.R_OK | os.W_OK)
+
+
 class BaseVM(object):
     GUEST_USER = "qemu"
     GUEST_PASS = "qemupass"
@@ -72,7 +77,7 @@ class BaseVM(object):
             "-serial", "file:%s" % os.path.join(self._tmpdir, "serial.out")]
         if vcpus:
             self._args += ["-smp", str(vcpus)]
-        if os.access("/dev/kvm", os.R_OK | os.W_OK):
+        if kvm_available():
             self._args += ["-enable-kvm"]
         else:
             logging.info("KVM not available, not using -enable-kvm")
Signature · 1 line
2.18.0
#2 lore raw

PATCH 2/5 tests/vm: Use 'host' cpu when KVM is available, else default to 'max'

In reply to Philippe Mathieu-Daudé
---
 tests/vm/basevm.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tests/vm/basevm.py +2 -1
index 04089cd545..1f4ad04c32 100755
@@ -70,7 +70,6 @@ class BaseVM(object):
             self._stdout = self._devnull
         self._args = [ \
             "-nodefaults", "-m", "2G",
-            "-cpu", "host",
             "-netdev", "user,id=vnet,hostfwd=:127.0.0.1:0-:22",
             "-device", "virtio-net-pci,netdev=vnet",
             "-vnc", "127.0.0.1:0,to=20",
@@ -79,8 +78,10 @@ class BaseVM(object):
             self._args += ["-smp", str(vcpus)]
         if kvm_available():
             self._args += ["-enable-kvm"]
+            self._args += ["-cpu", "host"]
         else:
             logging.info("KVM not available, not using -enable-kvm")
+            self._args += ["-cpu", "max"]
         self._data_args = []
 
     def _download_with_cache(self, url, sha256sum=None):
Signature · 1 line
2.18.0
#3 lore raw

PATCH 3/5 tests/vm: Do not abuse parallelism when KVM is not available

In reply to Philippe Mathieu-Daudé
---
 tests/vm/basevm.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tests/vm/basevm.py +2 -2
index 1f4ad04c32..715e433142 100755
@@ -233,7 +233,7 @@ def main(vmcls):
             return 1
         logging.basicConfig(level=(logging.DEBUG if args.debug
                                    else logging.WARN))
-        vm = vmcls(debug=args.debug, vcpus=args.jobs)
+        vm = vmcls(debug=args.debug, vcpus=args.jobs if kvm_available() else 0)
         if args.build_image:
             if os.path.exists(args.image) and not args.force:
                 sys.stderr.writelines(["Image file exists: %s\n" % args.image,
@@ -244,7 +244,7 @@ def main(vmcls):
             vm.add_source_dir(args.build_qemu)
             cmd = [vm.BUILD_SCRIPT.format(
                    configure_opts = " ".join(argv),
-                   jobs=args.jobs)]
+                   jobs=args.jobs if kvm_available() else 1)]
         else:
             cmd = argv
         vm.boot(args.image + ",snapshot=on")
Signature · 1 line
2.18.0
#4 lore raw

Re: [Qemu-devel] [PATCH 3/5] tests/vm: Do not abuse parallelism when KVM is not available

Quoted 30 lines · Philippe Mathieu-Daudé
---
 tests/vm/basevm.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tests/vm/basevm.py +2 -2
index 1f4ad04c32..715e433142 100755
@@ -233,7 +233,7 @@ def main(vmcls):
             return 1
         logging.basicConfig(level=(logging.DEBUG if args.debug
                                    else logging.WARN))
-        vm = vmcls(debug=args.debug, vcpus=args.jobs)
+        vm = vmcls(debug=args.debug, vcpus=args.jobs if kvm_available() else 0)
         if args.build_image:
             if os.path.exists(args.image) and not args.force:
                 sys.stderr.writelines(["Image file exists: %s\n" % args.image,
@@ -244,7 +244,7 @@ def main(vmcls):
             vm.add_source_dir(args.build_qemu)
             cmd = [vm.BUILD_SCRIPT.format(
                    configure_opts = " ".join(argv),
-                   jobs=args.jobs)]
+                   jobs=args.jobs if kvm_available() else 1)]
         else:
             cmd = argv
         vm.boot(args.image + ",snapshot=on")
Signature · 1 line
2.18.0

Could you instead change this line

parser.add_option("--jobs", type=int, default=multiprocessing.cpu_count() / 2,
help="number of virtual CPUs")

to use kvm_available()? With another helper function to contain the line width, probably:

    ..., default=get_default_jobs(), help=...

and

    def get_default_jobs():
        if kvm_available():
            return ...
        else:
            return ...

Fam

#5 lore raw

RFC PATCH 4/5 tests/vm: Display remaining seconds to wait for a VM to start

In reply to Philippe Mathieu-Daudé
---
 tests/vm/basevm.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tests/vm/basevm.py +4 -1
index 715e433142..7575c36f0b 100755
@@ -183,12 +183,15 @@ class BaseVM(object):
 
     def wait_ssh(self, seconds=120):
         starttime = datetime.datetime.now()
+        endtime = starttime + datetime.timedelta(seconds=seconds)
         guest_up = False
-        while (datetime.datetime.now() - starttime).total_seconds() < seconds:
+        while datetime.datetime.now() < endtime:
             if self.ssh("exit 0") == 0:
                 guest_up = True
                 break
             time.sleep(1)
+            seconds = (endtime - datetime.datetime.now()).total_seconds()
+            logging.debug("%ds before timeout", seconds)
         if not guest_up:
             raise Exception("Timeout while waiting for guest ssh")
 
Signature · 1 line
2.18.0
#6 lore raw

RFC PATCH 5/5 tests/vm: When using TCG, wait longer for a VM to start

In reply to Philippe Mathieu-Daudé

---
4 is random (but more than 1).

---
 tests/vm/basevm.py | 2 ++
 1 file changed, 2 insertions(+)
tests/vm/basevm.py +2 -0
index 7575c36f0b..50785a64df 100755
@@ -182,6 +182,8 @@ class BaseVM(object):
                             usernet_info)
 
     def wait_ssh(self, seconds=120):
+        if not kvm_available():
+            seconds *= 4
         starttime = datetime.datetime.now()
         endtime = starttime + datetime.timedelta(seconds=seconds)
         guest_up = False
Signature · 1 line
2.18.0