qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

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>

authored by

Robert Foley and committed by
Philippe Mathieu-Daudé
e56c4504 d5326a24

+27 -5
+4
tests/vm/Makefile.include
··· 41 41 @echo " J=[0..9]* - Override the -jN parameter for make commands" 42 42 @echo " DEBUG=1 - Enable verbose output on host and interactive debugging" 43 43 @echo " V=1 - Enable verbose ouput on host and guest commands" 44 + @echo " QEMU_LOCAL=1 - Use QEMU binary local to this build." 44 45 @echo " QEMU=/path/to/qemu - Change path to QEMU binary" 45 46 @echo " QEMU_IMG=/path/to/qemu-img - Change path to qemu-img tool" 46 47 ··· 57 58 $(PYTHON) $< \ 58 59 $(if $(V)$(DEBUG), --debug) \ 59 60 $(if $(GENISOIMAGE),--genisoimage $(GENISOIMAGE)) \ 61 + $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \ 60 62 --image "$@" \ 61 63 --force \ 62 64 --build-image $@, \ ··· 71 73 $(if $(DEBUG), --interactive) \ 72 74 $(if $(J),--jobs $(J)) \ 73 75 $(if $(V),--verbose) \ 76 + $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \ 74 77 --image "$<" \ 75 78 $(if $(BUILD_TARGET),--build-target $(BUILD_TARGET)) \ 76 79 --snapshot \ ··· 92 95 $(PYTHON) $(SRC_PATH)/tests/vm/$* \ 93 96 $(if $(J),--jobs $(J)) \ 94 97 $(if $(V)$(DEBUG), --debug) \ 98 + $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \ 95 99 --image "$<" \ 96 100 --interactive \ 97 101 false, \
+23 -5
tests/vm/basevm.py
··· 61 61 # 4 is arbitrary, but greater than 2, 62 62 # since we found we need to wait more than twice as long. 63 63 tcg_ssh_timeout_multiplier = 4 64 - def __init__(self, debug=False, vcpus=None, genisoimage=None): 64 + def __init__(self, debug=False, vcpus=None, genisoimage=None, 65 + build_path=None): 65 66 self._guest = None 66 67 self._genisoimage = genisoimage 68 + self._build_path = build_path 67 69 self._tmpdir = os.path.realpath(tempfile.mkdtemp(prefix="vm-test-", 68 70 suffix=".tmp", 69 71 dir=".")) ··· 184 186 "-device", "virtio-blk,drive=drive0,bootindex=0"] 185 187 args += self._data_args + extra_args 186 188 logging.debug("QEMU args: %s", " ".join(args)) 187 - qemu_bin = os.environ.get("QEMU", "qemu-system-" + self.arch) 188 - guest = QEMUMachine(binary=qemu_bin, args=args) 189 + qemu_path = get_qemu_path(self.arch, self._build_path) 190 + guest = QEMUMachine(binary=qemu_path, args=args) 189 191 guest.set_machine('pc') 190 192 guest.set_console() 191 193 try: 192 194 guest.launch() 193 195 except: 194 196 logging.error("Failed to launch QEMU, command line:") 195 - logging.error(" ".join([qemu_bin] + args)) 197 + logging.error(" ".join([qemu_path] + args)) 196 198 logging.error("Log:") 197 199 logging.error(guest.get_log()) 198 200 logging.error("QEMU version >= 2.10 is required") ··· 391 393 392 394 return os.path.join(cidir, "cloud-init.iso") 393 395 396 + def get_qemu_path(arch, build_path=None): 397 + """Fetch the path to the qemu binary.""" 398 + # If QEMU environment variable set, it takes precedence 399 + if "QEMU" in os.environ: 400 + qemu_path = os.environ["QEMU"] 401 + elif build_path: 402 + qemu_path = os.path.join(build_path, arch + "-softmmu") 403 + qemu_path = os.path.join(qemu_path, "qemu-system-" + arch) 404 + else: 405 + # Default is to use system path for qemu. 406 + qemu_path = "qemu-system-" + arch 407 + return qemu_path 408 + 394 409 def parse_args(vmcls): 395 410 396 411 def get_default_jobs(): ··· 421 436 help="build QEMU from source in guest") 422 437 parser.add_option("--build-target", 423 438 help="QEMU build target", default="check") 439 + parser.add_option("--build-path", default=None, 440 + help="Path of build directory, "\ 441 + "for using build tree QEMU binary. ") 424 442 parser.add_option("--interactive", "-I", action="store_true", 425 443 help="Interactively run command") 426 444 parser.add_option("--snapshot", "-s", action="store_true", ··· 439 457 logging.basicConfig(level=(logging.DEBUG if args.debug 440 458 else logging.WARN)) 441 459 vm = vmcls(debug=args.debug, vcpus=args.jobs, 442 - genisoimage=args.genisoimage) 460 + genisoimage=args.genisoimage, build_path=args.build_path) 443 461 if args.build_image: 444 462 if os.path.exists(args.image) and not args.force: 445 463 sys.stderr.writelines(["Image file exists: %s\n" % args.image,