Skip to content

Commit 582f2e3

Browse files
committed
T8065: Dehardcode qemu settings to allow run tests on arch arm64
1 parent 88897ba commit 582f2e3

File tree

2 files changed

+48
-15
lines changed

2 files changed

+48
-15
lines changed

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ SHELL := /bin/bash
22

33
build_dir := build
44

5+
arch ?= $(shell dpkg --print-architecture 2>/dev/null || echo amd64)
6+
57
.PHONY: all
68
all:
79
@echo "Make what specifically?"
@@ -13,8 +15,8 @@ all:
1315
.PHONY: checkiso
1416
.ONESHELL:
1517
checkiso:
16-
if [ ! -f build/live-image-amd64.hybrid.iso ]; then
17-
echo "Could not find build/live-image-amd64.hybrid.iso"
18+
if [ ! -f build/live-image-$(arch).hybrid.iso ]; then
19+
echo "Could not find build/live-image-$(arch).hybrid.iso"
1820
exit 1
1921
fi
2022

@@ -31,7 +33,7 @@ test-no-interfaces: checkiso
3133
.PHONY: test-no-interfaces-no-vpp
3234
.ONESHELL:
3335
test-no-interfaces-no-vpp: checkiso
34-
scripts/check-qemu-install --debug --configd --smoketest --uefi --no-interfaces --no-vpp build/live-image-amd64.hybrid.iso
36+
scripts/check-qemu-install --debug --configd --smoketest --uefi --no-interfaces --no-vpp --arch $(arch) build/live-image-$(arch).hybrid.iso
3537

3638
.PHONY: test-interfaces
3739
.ONESHELL:

scripts/check-qemu-install

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@ now = datetime.now()
5454
tpm_folder = '/tmp/vyos_tpm_test'
5555
qemu_name = 'VyOS-QEMU'
5656

57+
# Map QEMU arch
58+
QEMU_CONFIG = {
59+
"amd64": {
60+
"bin": "qemu-system-x86_64",
61+
"cpu": "host",
62+
"machine": "pc",
63+
"bios": "/usr/share/OVMF/OVMF_CODE.fd",
64+
},
65+
"arm64": {
66+
"bin": "qemu-system-aarch64",
67+
"cpu": "cortex-a57",
68+
"machine": "virt",
69+
"bios": "/usr/share/qemu-efi-aarch64/QEMU_EFI.fd",
70+
},
71+
}
72+
5773
# getch.py
5874
KEY_F2 = chr(27) + chr(91) + chr(49) + chr(50) + chr(126)
5975
KEY_F10 = chr(27) + chr(91) + chr(50) + chr(49) + chr(126)
@@ -103,6 +119,7 @@ parser.add_argument('--no-vpp', help='Execute testsuite without VPP tests',
103119
action='store_true', default=False)
104120
parser.add_argument('--huge-page-size', help='Huge page size (e.g., 2M, 1G)', type=str)
105121
parser.add_argument('--huge-page-count', help='Number of huge pages to allocate', type=int)
122+
parser.add_argument('--arch', help='Architecture')
106123

107124
args = parser.parse_args()
108125

@@ -145,18 +162,31 @@ OVMF_VARS_TMP = args.disk.replace('.img', '.efivars')
145162
if args.sbtest:
146163
shutil.copy('/usr/share/OVMF/OVMF_VARS_4M.ms.fd', OVMF_VARS_TMP)
147164

165+
166+
def _kvm_exists():
167+
return os.path.exists("/dev/kvm")
168+
169+
148170
def get_qemu_cmd(name, enable_uefi, disk_img, raid=None, iso_img=None, tpm=False, vnc_enabled=False, secure_boot=False):
149171
uefi = ""
150172
uuid = "f48b60b2-e6ad-49ef-9d09-4245d0585e52"
151-
machine = 'pc'
173+
arch = getattr(args, 'arch', 'amd64')
174+
qemu_arch_config = QEMU_CONFIG.get(arch, QEMU_CONFIG["amd64"])
175+
qemu_bin = qemu_arch_config['bin']
176+
bios = qemu_arch_config['bios']
177+
cpu = qemu_arch_config['cpu']
178+
machine = qemu_arch_config['machine']
179+
accel = ',accel=kvm' if _kvm_exists() else ''
180+
enable_kvm = '-enable-kvm' if _kvm_exists() else ''
152181
vga = '-vga none'
153182
vnc = ''
183+
154184
if vnc_enabled:
155185
vga = '-vga virtio'
156186
vnc = '-vnc :0'
157187

158188
if enable_uefi:
159-
uefi = '-bios /usr/share/OVMF/OVMF_CODE.fd'
189+
uefi = f'-bios {bios}'
160190
name = f'{name}-UEFI'
161191

162192
if secure_boot:
@@ -170,26 +200,25 @@ def get_qemu_cmd(name, enable_uefi, disk_img, raid=None, iso_img=None, tpm=False
170200

171201
cdrom = ""
172202
if iso_img:
173-
cdrom = f' -drive file={iso_img},format=raw,if=none,media=cdrom,id=drive-cd1,readonly=on' \
174-
f' -device ahci,id=achi0' \
175-
f' -device ide-cd,bus=achi0.0,drive=drive-cd1,id=cd1,bootindex=10'
203+
cdrom = (
204+
f' -drive file={iso_img},format=raw,if=none,media=cdrom,id=drive-cd1,readonly=on'
205+
f' -device scsi-cd,bus=scsi0.0,drive=drive-cd1,id=cd1,bootindex=10'
206+
)
176207

177208
# RFC7042 section 2.1.2 MAC addresses used for documentation
178209
macbase = '00:00:5E:00:53'
179-
cmd = f'qemu-system-x86_64 \
210+
cmd = f'{qemu_bin} \
180211
-name "{name}" \
181212
-smp {args.cpu},sockets=1,cores={args.cpu},threads=1 \
182-
-cpu host \
183-
-machine {machine},accel=kvm \
213+
-cpu {cpu} \
214+
-machine {machine}{accel} \
184215
{uefi} \
185216
-m {args.memory}G \
186217
-vga none \
187218
-nographic \
188219
{vga} {vnc}\
189220
-uuid {uuid} \
190-
-cpu host \
191-
{cdrom} \
192-
-enable-kvm \
221+
{enable_kvm} \
193222
-monitor unix:/tmp/qemu-monitor-socket-{disk_img},server,nowait \
194223
-netdev user,id=n0,net=192.0.2.0/24,dhcpstart=192.0.2.101,dns=192.0.2.10 -device virtio-net-pci,netdev=n0,mac={macbase}:00,romfile="",host_mtu=1500 \
195224
-netdev user,id=n1 -device virtio-net-pci,netdev=n1,mac={macbase}:01,romfile="",host_mtu=1500 \
@@ -200,6 +229,7 @@ def get_qemu_cmd(name, enable_uefi, disk_img, raid=None, iso_img=None, tpm=False
200229
-netdev user,id=n6 -device virtio-net-pci,netdev=n6,mac={macbase}:06,romfile="" \
201230
-netdev user,id=n7 -device virtio-net-pci,netdev=n7,mac={macbase}:07,romfile="" \
202231
-device virtio-scsi-pci,id=scsi0 \
232+
{cdrom} \
203233
-drive format=raw,file={disk_img},if=none,media=disk,id=drive-hd1,readonly=off \
204234
-device scsi-hd,bus=scsi0.0,drive=drive-hd1,id=hd1,bootindex=1'
205235

@@ -282,7 +312,8 @@ if not os.path.isfile(args.iso):
282312

283313
if not os.path.exists('/dev/kvm'):
284314
log.error('KVM not enabled on host, proceeding with software emulation')
285-
sys.exit(1)
315+
# Some arm platforms do not have kvm, for example Mac arm devices
316+
# sys.exit(1)
286317

287318
# Creating diskimage!!
288319
diskname_raid = None

0 commit comments

Comments
 (0)