qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] tests/vm: favour the locally built QEMU for bootstr


From: Alex Bennée
Subject: [Qemu-devel] [PATCH] tests/vm: favour the locally built QEMU for bootstrapping
Date: Fri, 7 Jun 2019 19:53:37 +0100

It turns out that relying on the system installed QEMU can result in
problems especially if it has been patched. Seeing as this is a
developer tool and we should be dogfooding we favour the locally built
binary if it exists. The developer always has the option of overriding
their locally broken build with the QEMU environment variable.

Signed-off-by: Alex Bennée <address@hidden>

---
This applies on top of my PR and will get rolled into v2 if people are
happy with it.
---
 tests/vm/Makefile.include |  1 +
 tests/vm/basevm.py        | 21 ++++++++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/tests/vm/Makefile.include b/tests/vm/Makefile.include
index 5e37063d32..b49e5e2f2c 100644
--- a/tests/vm/Makefile.include
+++ b/tests/vm/Makefile.include
@@ -48,6 +48,7 @@ $(IMAGES_DIR)/%.img:  $(SRC_PATH)/tests/vm/% \
        $(call quiet-command, \
                $(PYTHON) $< \
                $(if $(V)$(DEBUG), --debug) \
+               --build-dir $(BUILD_DIR) \
                --image "$@" \
                --force \
                --build-image $@, \
diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py
index d4b816be14..1a8850ba98 100755
--- a/tests/vm/basevm.py
+++ b/tests/vm/basevm.py
@@ -48,6 +48,9 @@ class BaseVM(object):
         "no_proxy",
     ]
 
+    # path for seaching for qemu
+    qemu_build_dir = None
+
     # The script to run in the guest that builds QEMU
     BUILD_SCRIPT = ""
     # The guest name, to be overridden by subclasses
@@ -155,6 +158,19 @@ class BaseVM(object):
                             "-device",
                             "virtio-blk,drive=%s,serial=%s,bootindex=1" % 
(name, name)]
 
+    def set_qemu_build_dir(self, build_dir):
+        self.qemu_build_dir = build_dir
+
+    def _find_best_qemu(self):
+        "Return a QEMU we should use. Use the locally built one if we can."
+        bin_name = "qemu-system-" + self.arch
+        if self.qemu_build_dir:
+            bin_path = "%s/%s-softmmu/%s" % (self.qemu_build_dir,
+                                             self.arch, bin_name)
+            if os.path.exists(bin_path):
+                return bin_path
+        return bin_name
+
     def boot(self, img, extra_args=[]):
         args = self._args + [
             "-device", "VGA",
@@ -162,7 +178,7 @@ class BaseVM(object):
             "-device", "virtio-blk,drive=drive0,bootindex=0"]
         args += self._data_args + extra_args
         logging.debug("QEMU args: %s", " ".join(args))
-        qemu_bin = os.environ.get("QEMU", "qemu-system-" + self.arch)
+        qemu_bin = os.environ.get("QEMU", self._find_best_qemu())
         guest = QEMUMachine(binary=qemu_bin, args=args)
         guest.set_machine('pc')
         guest.set_console()
@@ -327,6 +343,8 @@ def parse_args(vmcls):
                       help="build QEMU from source in guest")
     parser.add_option("--build-target",
                       help="QEMU build target", default="check")
+    parser.add_option("--build-dir", default="flibble",
+                      help="QEMU build directory", action="store")
     parser.add_option("--interactive", "-I", action="store_true",
                       help="Interactively run command")
     parser.add_option("--snapshot", "-s", action="store_true",
@@ -348,6 +366,7 @@ def main(vmcls):
                 sys.stderr.writelines(["Image file exists: %s\n" % args.image,
                                       "Use --force option to overwrite\n"])
                 return 1
+            vm.set_qemu_build_dir(args.build_dir)
             return vm.build_image(args.image)
         if args.build_qemu:
             vm.add_source_dir(args.build_qemu)
-- 
2.20.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]