mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 15:23:53 -06:00
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>
This commit is contained in:
parent
d5326a2437
commit
e56c45047b
2 changed files with 27 additions and 5 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue