mirror of https://github.com/xemu-project/xemu.git
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
|
@ -41,6 +41,7 @@ endif
|
||||||
@echo " J=[0..9]* - Override the -jN parameter for make commands"
|
@echo " J=[0..9]* - Override the -jN parameter for make commands"
|
||||||
@echo " DEBUG=1 - Enable verbose output on host and interactive debugging"
|
@echo " DEBUG=1 - Enable verbose output on host and interactive debugging"
|
||||||
@echo " V=1 - Enable verbose ouput on host and guest commands"
|
@echo " V=1 - Enable verbose ouput on host and guest commands"
|
||||||
|
@echo " QEMU_LOCAL=1 - Use QEMU binary local to this build."
|
||||||
@echo " QEMU=/path/to/qemu - Change path to QEMU binary"
|
@echo " QEMU=/path/to/qemu - Change path to QEMU binary"
|
||||||
@echo " QEMU_IMG=/path/to/qemu-img - Change path to qemu-img tool"
|
@echo " QEMU_IMG=/path/to/qemu-img - Change path to qemu-img tool"
|
||||||
|
|
||||||
|
@ -57,6 +58,7 @@ $(IMAGES_DIR)/%.img: $(SRC_PATH)/tests/vm/% \
|
||||||
$(PYTHON) $< \
|
$(PYTHON) $< \
|
||||||
$(if $(V)$(DEBUG), --debug) \
|
$(if $(V)$(DEBUG), --debug) \
|
||||||
$(if $(GENISOIMAGE),--genisoimage $(GENISOIMAGE)) \
|
$(if $(GENISOIMAGE),--genisoimage $(GENISOIMAGE)) \
|
||||||
|
$(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
|
||||||
--image "$@" \
|
--image "$@" \
|
||||||
--force \
|
--force \
|
||||||
--build-image $@, \
|
--build-image $@, \
|
||||||
|
@ -71,6 +73,7 @@ vm-build-%: $(IMAGES_DIR)/%.img
|
||||||
$(if $(DEBUG), --interactive) \
|
$(if $(DEBUG), --interactive) \
|
||||||
$(if $(J),--jobs $(J)) \
|
$(if $(J),--jobs $(J)) \
|
||||||
$(if $(V),--verbose) \
|
$(if $(V),--verbose) \
|
||||||
|
$(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
|
||||||
--image "$<" \
|
--image "$<" \
|
||||||
$(if $(BUILD_TARGET),--build-target $(BUILD_TARGET)) \
|
$(if $(BUILD_TARGET),--build-target $(BUILD_TARGET)) \
|
||||||
--snapshot \
|
--snapshot \
|
||||||
|
@ -92,6 +95,7 @@ vm-boot-ssh-%: $(IMAGES_DIR)/%.img
|
||||||
$(PYTHON) $(SRC_PATH)/tests/vm/$* \
|
$(PYTHON) $(SRC_PATH)/tests/vm/$* \
|
||||||
$(if $(J),--jobs $(J)) \
|
$(if $(J),--jobs $(J)) \
|
||||||
$(if $(V)$(DEBUG), --debug) \
|
$(if $(V)$(DEBUG), --debug) \
|
||||||
|
$(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
|
||||||
--image "$<" \
|
--image "$<" \
|
||||||
--interactive \
|
--interactive \
|
||||||
false, \
|
false, \
|
||||||
|
|
|
@ -61,9 +61,11 @@ class BaseVM(object):
|
||||||
# 4 is arbitrary, but greater than 2,
|
# 4 is arbitrary, but greater than 2,
|
||||||
# since we found we need to wait more than twice as long.
|
# since we found we need to wait more than twice as long.
|
||||||
tcg_ssh_timeout_multiplier = 4
|
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._guest = None
|
||||||
self._genisoimage = genisoimage
|
self._genisoimage = genisoimage
|
||||||
|
self._build_path = build_path
|
||||||
self._tmpdir = os.path.realpath(tempfile.mkdtemp(prefix="vm-test-",
|
self._tmpdir = os.path.realpath(tempfile.mkdtemp(prefix="vm-test-",
|
||||||
suffix=".tmp",
|
suffix=".tmp",
|
||||||
dir="."))
|
dir="."))
|
||||||
|
@ -184,15 +186,15 @@ class BaseVM(object):
|
||||||
"-device", "virtio-blk,drive=drive0,bootindex=0"]
|
"-device", "virtio-blk,drive=drive0,bootindex=0"]
|
||||||
args += self._data_args + extra_args
|
args += self._data_args + extra_args
|
||||||
logging.debug("QEMU args: %s", " ".join(args))
|
logging.debug("QEMU args: %s", " ".join(args))
|
||||||
qemu_bin = os.environ.get("QEMU", "qemu-system-" + self.arch)
|
qemu_path = get_qemu_path(self.arch, self._build_path)
|
||||||
guest = QEMUMachine(binary=qemu_bin, args=args)
|
guest = QEMUMachine(binary=qemu_path, args=args)
|
||||||
guest.set_machine('pc')
|
guest.set_machine('pc')
|
||||||
guest.set_console()
|
guest.set_console()
|
||||||
try:
|
try:
|
||||||
guest.launch()
|
guest.launch()
|
||||||
except:
|
except:
|
||||||
logging.error("Failed to launch QEMU, command line:")
|
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("Log:")
|
||||||
logging.error(guest.get_log())
|
logging.error(guest.get_log())
|
||||||
logging.error("QEMU version >= 2.10 is required")
|
logging.error("QEMU version >= 2.10 is required")
|
||||||
|
@ -391,6 +393,19 @@ class BaseVM(object):
|
||||||
|
|
||||||
return os.path.join(cidir, "cloud-init.iso")
|
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 parse_args(vmcls):
|
||||||
|
|
||||||
def get_default_jobs():
|
def get_default_jobs():
|
||||||
|
@ -421,6 +436,9 @@ def parse_args(vmcls):
|
||||||
help="build QEMU from source in guest")
|
help="build QEMU from source in guest")
|
||||||
parser.add_option("--build-target",
|
parser.add_option("--build-target",
|
||||||
help="QEMU build target", default="check")
|
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",
|
parser.add_option("--interactive", "-I", action="store_true",
|
||||||
help="Interactively run command")
|
help="Interactively run command")
|
||||||
parser.add_option("--snapshot", "-s", action="store_true",
|
parser.add_option("--snapshot", "-s", action="store_true",
|
||||||
|
@ -439,7 +457,7 @@ def main(vmcls):
|
||||||
logging.basicConfig(level=(logging.DEBUG if args.debug
|
logging.basicConfig(level=(logging.DEBUG if args.debug
|
||||||
else logging.WARN))
|
else logging.WARN))
|
||||||
vm = vmcls(debug=args.debug, vcpus=args.jobs,
|
vm = vmcls(debug=args.debug, vcpus=args.jobs,
|
||||||
genisoimage=args.genisoimage)
|
genisoimage=args.genisoimage, build_path=args.build_path)
|
||||||
if args.build_image:
|
if args.build_image:
|
||||||
if os.path.exists(args.image) and not args.force:
|
if os.path.exists(args.image) and not args.force:
|
||||||
sys.stderr.writelines(["Image file exists: %s\n" % args.image,
|
sys.stderr.writelines(["Image file exists: %s\n" % args.image,
|
||||||
|
|
Loading…
Reference in New Issue