Skip to content

Commit 16b0ef3

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

File tree

2 files changed

+59
-15
lines changed

2 files changed

+59
-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: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,26 @@ 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+
"cdrom": {"bus": "ide", "controller": "ahci", "device": "ide-cd"},
65+
"disk": {"bus": "ide", "controller": "ahci", "device": "ide-hd"},
66+
},
67+
"arm64": {
68+
"bin": "qemu-system-aarch64",
69+
"cpu": "cortex-a57",
70+
"machine": "virt",
71+
"bios": "/usr/share/qemu-efi-aarch64/QEMU_EFI.fd",
72+
"cdrom": {"bus": "scsi", "controller": "virtio-scsi-pci", "device": "scsi-cd"},
73+
"disk": {"bus": "scsi", "controller": "virtio-scsi-pci", "device": "scsi-hd"},
74+
},
75+
}
76+
5777
# getch.py
5878
KEY_F2 = chr(27) + chr(91) + chr(49) + chr(50) + chr(126)
5979
KEY_F10 = chr(27) + chr(91) + chr(50) + chr(49) + chr(126)
@@ -103,6 +123,7 @@ parser.add_argument('--no-vpp', help='Execute testsuite without VPP tests',
103123
action='store_true', default=False)
104124
parser.add_argument('--huge-page-size', help='Huge page size (e.g., 2M, 1G)', type=str)
105125
parser.add_argument('--huge-page-count', help='Number of huge pages to allocate', type=int)
126+
parser.add_argument('--arch', help='Architecture')
106127

107128
args = parser.parse_args()
108129

@@ -145,18 +166,36 @@ OVMF_VARS_TMP = args.disk.replace('.img', '.efivars')
145166
if args.sbtest:
146167
shutil.copy('/usr/share/OVMF/OVMF_VARS_4M.ms.fd', OVMF_VARS_TMP)
147168

169+
170+
def _kvm_exists():
171+
return os.path.exists("/dev/kvm")
172+
173+
148174
def get_qemu_cmd(name, enable_uefi, disk_img, raid=None, iso_img=None, tpm=False, vnc_enabled=False, secure_boot=False):
149175
uefi = ""
150176
uuid = "f48b60b2-e6ad-49ef-9d09-4245d0585e52"
151-
machine = 'pc'
177+
arch = getattr(args, 'arch', 'amd64')
178+
qemu_arch_config = QEMU_CONFIG.get(arch, QEMU_CONFIG["amd64"])
179+
qemu_bin = qemu_arch_config['bin']
180+
bios = qemu_arch_config['bios']
181+
cpu = qemu_arch_config['cpu']
182+
machine = qemu_arch_config['machine']
183+
accel = ',accel=kvm' if _kvm_exists() else ''
184+
enable_kvm = '-enable-kvm' if _kvm_exists() else ''
152185
vga = '-vga none'
153186
vnc = ''
187+
# Controller
188+
if qemu_arch_config['disk']['bus'] == 'scsi':
189+
scsi_controller = f"-device {qemu_arch_config['disk']['controller']},id=scsi0,romfile=\"\""
190+
else:
191+
scsi_controller = f"-device {qemu_arch_config['disk']['controller']},id=achi0"
192+
154193
if vnc_enabled:
155194
vga = '-vga virtio'
156195
vnc = '-vnc :0'
157196

158197
if enable_uefi:
159-
uefi = '-bios /usr/share/OVMF/OVMF_CODE.fd'
198+
uefi = f'-bios {bios}'
160199
name = f'{name}-UEFI'
161200

162201
if secure_boot:
@@ -170,26 +209,29 @@ def get_qemu_cmd(name, enable_uefi, disk_img, raid=None, iso_img=None, tpm=False
170209

171210
cdrom = ""
172211
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'
212+
if qemu_arch_config['cdrom']['bus'] == 'scsi':
213+
cdrom = f'-drive file={iso_img},if=none,id=cdrom,media=cdrom,readonly=on ' \
214+
f'-device {qemu_arch_config["cdrom"]["device"]},drive=cdrom,bootindex=10'
215+
else:
216+
cdrom = f'-drive file={iso_img},format=raw,if=none,media=cdrom,id=drive-cd1,readonly=on ' \
217+
f'-device {qemu_arch_config["cdrom"]["device"]},bus=achi0.0,drive=drive-cd1,id=cd1,bootindex=10'
176218

177219
# RFC7042 section 2.1.2 MAC addresses used for documentation
178220
macbase = '00:00:5E:00:53'
179-
cmd = f'qemu-system-x86_64 \
221+
cmd = f'{qemu_bin} \
180222
-name "{name}" \
181223
-smp {args.cpu},sockets=1,cores={args.cpu},threads=1 \
182-
-cpu host \
183-
-machine {machine},accel=kvm \
224+
-cpu {cpu} \
225+
-machine {machine}{accel} \
184226
{uefi} \
185227
-m {args.memory}G \
186228
-vga none \
187229
-nographic \
188230
{vga} {vnc}\
189231
-uuid {uuid} \
190-
-cpu host \
232+
{scsi_controller} \
191233
{cdrom} \
192-
-enable-kvm \
234+
{enable_kvm} \
193235
-monitor unix:/tmp/qemu-monitor-socket-{disk_img},server,nowait \
194236
-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 \
195237
-netdev user,id=n1 -device virtio-net-pci,netdev=n1,mac={macbase}:01,romfile="",host_mtu=1500 \
@@ -199,7 +241,6 @@ def get_qemu_cmd(name, enable_uefi, disk_img, raid=None, iso_img=None, tpm=False
199241
-netdev user,id=n5 -device virtio-net-pci,netdev=n5,mac={macbase}:05,romfile="" \
200242
-netdev user,id=n6 -device virtio-net-pci,netdev=n6,mac={macbase}:06,romfile="" \
201243
-netdev user,id=n7 -device virtio-net-pci,netdev=n7,mac={macbase}:07,romfile="" \
202-
-device virtio-scsi-pci,id=scsi0 \
203244
-drive format=raw,file={disk_img},if=none,media=disk,id=drive-hd1,readonly=off \
204245
-device scsi-hd,bus=scsi0.0,drive=drive-hd1,id=hd1,bootindex=1'
205246

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

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

287329
# Creating diskimage!!
288330
diskname_raid = None

0 commit comments

Comments
 (0)