summaryrefslogtreecommitdiffstats
path: root/tests/vm/basevm.py
diff options
context:
space:
mode:
authorRobert Foley2020-05-29 22:34:51 +0200
committerPhilippe Mathieu-Daudé2020-05-31 18:25:31 +0200
commite56c45047bd5bbcfdc36e3f4ed8b439c5d5c989a (patch)
tree9de4f1b60e8213c616572dbf88605e9f61c5043a /tests/vm/basevm.py
parenttests/vm: Pass --debug through for vm-boot-ssh (diff)
downloadqemu-e56c45047bd5bbcfdc36e3f4ed8b439c5d5c989a.tar.gz
qemu-e56c45047bd5bbcfdc36e3f4ed8b439c5d5c989a.tar.xz
qemu-e56c45047bd5bbcfdc36e3f4ed8b439c5d5c989a.zip
tests/vm: Add ability to select QEMU from current build
Added a new special variable QEMU_LOCAL=1, which will indicate to take the QEMU binary from the current build. Signed-off-by: Robert Foley <robert.foley@linaro.org> Reviewed-by: Peter Puhov <peter.puhov@linaro.org> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20200529203458.1038-6-robert.foley@linaro.org> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Diffstat (limited to 'tests/vm/basevm.py')
-rw-r--r--tests/vm/basevm.py28
1 files changed, 23 insertions, 5 deletions
diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py
index a2d4054d72..5a3ce42281 100644
--- a/tests/vm/basevm.py
+++ b/tests/vm/basevm.py
@@ -61,9 +61,11 @@ class BaseVM(object):
# 4 is arbitrary, but greater than 2,
# since we found we need to wait more than twice as long.
tcg_ssh_timeout_multiplier = 4
- def __init__(self, debug=False, vcpus=None, genisoimage=None):
+ def __init__(self, debug=False, vcpus=None, genisoimage=None,
+ build_path=None):
self._guest = None
self._genisoimage = genisoimage
+ self._build_path = build_path
self._tmpdir = os.path.realpath(tempfile.mkdtemp(prefix="vm-test-",
suffix=".tmp",
dir="."))
@@ -184,15 +186,15 @@ 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)
- guest = QEMUMachine(binary=qemu_bin, args=args)
+ qemu_path = get_qemu_path(self.arch, self._build_path)
+ guest = QEMUMachine(binary=qemu_path, args=args)
guest.set_machine('pc')
guest.set_console()
try:
guest.launch()
except:
logging.error("Failed to launch QEMU, command line:")
- logging.error(" ".join([qemu_bin] + args))
+ logging.error(" ".join([qemu_path] + args))
logging.error("Log:")
logging.error(guest.get_log())
logging.error("QEMU version >= 2.10 is required")
@@ -391,6 +393,19 @@ class BaseVM(object):
return os.path.join(cidir, "cloud-init.iso")
+def get_qemu_path(arch, build_path=None):
+ """Fetch the path to the qemu binary."""
+ # If QEMU environment variable set, it takes precedence
+ if "QEMU" in os.environ:
+ qemu_path = os.environ["QEMU"]
+ elif build_path:
+ qemu_path = os.path.join(build_path, arch + "-softmmu")
+ qemu_path = os.path.join(qemu_path, "qemu-system-" + arch)
+ else:
+ # Default is to use system path for qemu.
+ qemu_path = "qemu-system-" + arch
+ return qemu_path
+
def parse_args(vmcls):
def get_default_jobs():
@@ -421,6 +436,9 @@ 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-path", default=None,
+ help="Path of build directory, "\
+ "for using build tree QEMU binary. ")
parser.add_option("--interactive", "-I", action="store_true",
help="Interactively run command")
parser.add_option("--snapshot", "-s", action="store_true",
@@ -439,7 +457,7 @@ def main(vmcls):
logging.basicConfig(level=(logging.DEBUG if args.debug
else logging.WARN))
vm = vmcls(debug=args.debug, vcpus=args.jobs,
- genisoimage=args.genisoimage)
+ genisoimage=args.genisoimage, build_path=args.build_path)
if args.build_image:
if os.path.exists(args.image) and not args.force:
sys.stderr.writelines(["Image file exists: %s\n" % args.image,