qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] tests/vm: favour the locally built QEMU for bootstrapping
@ 2019-06-07 18:53 Alex Bennée
  0 siblings, 0 replies; only message in thread
From: Alex Bennée @ 2019-06-07 18:53 UTC (permalink / raw)
  To: peter.maydell
  Cc: Fam Zheng, Philippe Mathieu-Daudé, Alex Bennée, qemu-devel

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 <alex.bennee@linaro.org>

---
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



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2019-06-07 20:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-07 18:53 [Qemu-devel] [PATCH] tests/vm: favour the locally built QEMU for bootstrapping Alex Bennée

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).