Skip to content

Commit

Permalink
tests/vm: python3 fixes
Browse files Browse the repository at this point in the history
Add proper unicode handling when processing strings.
Also need to explicitly say we want int not float.

Signed-off-by: Gerd Hoffmann <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Tested-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <[email protected]>
[AJB: fix conflicts with tests/vm: Port basevm to Python 3]
Signed-off-by: Alex Bennée <[email protected]>
  • Loading branch information
kraxel authored and stsquad committed Jun 12, 2019
1 parent 8fc7617 commit 3ace9be
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions tests/vm/basevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(self, debug=False, vcpus=None):
"-vnc", "127.0.0.1:0,to=20",
"-serial", "file:%s" % os.path.join(self._tmpdir, "serial.out")]
if vcpus and vcpus > 1:
self._args += ["-smp", str(vcpus)]
self._args += ["-smp", "%d" % vcpus]
if kvm_available(self.arch):
self._args += ["-enable-kvm"]
else:
Expand All @@ -85,12 +85,13 @@ def check_sha256sum(fname):
if not sha256sum:
return True
checksum = subprocess.check_output(["sha256sum", fname]).split()[0]
return sha256sum == checksum.decode()
return sha256sum == checksum.decode("utf-8")

cache_dir = os.path.expanduser("~/.cache/qemu-vm/download")
if not os.path.exists(cache_dir):
os.makedirs(cache_dir)
fname = os.path.join(cache_dir, hashlib.sha1(url.encode()).hexdigest())
fname = os.path.join(cache_dir,
hashlib.sha1(url.encode("utf-8")).hexdigest())
if os.path.exists(fname) and check_sha256sum(fname):
return fname
logging.debug("Downloading %s to %s...", url, fname)
Expand Down Expand Up @@ -134,7 +135,7 @@ def build_image(self, img):
raise NotImplementedError

def add_source_dir(self, src_dir):
name = "data-" + hashlib.sha1(src_dir.encode()).hexdigest()[:5]
name = "data-" + hashlib.sha1(src_dir.encode("utf-8")).hexdigest()[:5]
tarfile = os.path.join(self._tmpdir, name + ".tar")
logging.debug("Creating archive %s for src_dir dir: %s", tarfile, src_dir)
subprocess.check_call(["./scripts/archive-source.sh", tarfile],
Expand Down Expand Up @@ -256,7 +257,7 @@ def main(vmcls):
vm.add_source_dir(args.build_qemu)
cmd = [vm.BUILD_SCRIPT.format(
configure_opts = " ".join(argv),
jobs=args.jobs,
jobs=int(args.jobs),
target=args.build_target,
verbose = "V=1" if args.verbose else "")]
else:
Expand Down

0 comments on commit 3ace9be

Please sign in to comment.