Skip to content

Commit

Permalink
test: add boot test on arm64 as well
Browse files Browse the repository at this point in the history
This commit enables an amd64 boot test when an image is generated
from macos.
  • Loading branch information
mvo5 committed Feb 26, 2024
1 parent 6bf69d2 commit d9e952c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
1 change: 0 additions & 1 deletion test/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ def test_image_is_generated(image_type):
f"content: {os.listdir(os.fspath(image_type.img_path))}"


@pytest.mark.skipif(platform.system() != "Linux", reason="boot test only runs on linux right now")
@pytest.mark.parametrize("image_type", gen_testcases("direct-boot"), indirect=["image_type"])
def test_image_boots(image_type):
with QEMU(image_type.img_path, arch=image_type.img_arch) as test_vm:
Expand Down
6 changes: 3 additions & 3 deletions test/testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ def gen_testcases(what):
]
# do a cross arch test too
if platform.machine() == "x86_64":
# todo: add fedora:eln
# todo: add fedora:eln(?)
test_cases.append(
f'{CONTAINERS_TO_TEST["centos"]},raw,arm64')
elif platform.machine() == "arm64":
# TODO: add arm64->x86_64 cross build test too
pass
test_cases.append(
f'{CONTAINERS_TO_TEST["centos"]},raw,amd64')
return test_cases
elif what == "all":
test_cases = []
Expand Down
21 changes: 18 additions & 3 deletions test/vm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import abc
import glob
import os
import pathlib
import platform
Expand Down Expand Up @@ -83,12 +84,18 @@ def __exit__(self, exc_type, exc_value, traceback):

# needed as each distro puts the OVMF.fd in a different location
def find_ovmf():
# linux
for p in [
"/usr/share/ovmf/OVMF.fd", # Debian
"/usr/share/OVMF/OVMF_CODE.fd", # Fedora
]:
if os.path.exists(p):
return p
# macos
p = "/opt/homebrew/Cellar/qemu/*/share/qemu/edk2-aarch64-code.fd"
m = glob.glob(p)
if len(m) > 0:
return m[0]
raise ValueError("cannot find a OVMF bios")


Expand Down Expand Up @@ -122,10 +129,18 @@ def _gen_qemu_cmdline(self, snapshot, use_ovmf):
elif self._arch in ("amd64", "x86_64"):
qemu_cmdline = [
"qemu-system-x86_64",
"-M", "accel=kvm",
# get "illegal instruction" inside the VM otherwise
"-cpu", "host",
]
if platform.machine() == "x86_64":
qemu_cmdline.append([
"-M", "accel=kvm",
# get "illegal instruction" inside the VM otherwise
"-cpu", "host",
])
elif platform.machine() == "arm64":
qemu_cmdline.append([
"-machine", "q35",
"-cpu", "SkyLake",
])
if use_ovmf:
qemu_cmdline.extend(["-bios", find_ovmf()])
else:
Expand Down

0 comments on commit d9e952c

Please sign in to comment.