Skip to content

Commit ed5c1b0

Browse files
committed
T8065: Dehardcode qemu settings to allow run tests on arch arm64
1 parent 29d6efe commit ed5c1b0

3 files changed

Lines changed: 121 additions & 15 deletions

File tree

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:
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Generic (aka "universal") ISO image
2+
3+
image_format = "iso"
4+
5+
[[includes_chroot]]
6+
path = "opt/vyatta/etc/config.boot.default"
7+
data = '''
8+
interfaces {
9+
loopback lo {
10+
}
11+
}
12+
service {
13+
ntp {
14+
allow-client {
15+
address "127.0.0.0/8"
16+
address "169.254.0.0/16"
17+
address "10.0.0.0/8"
18+
address "172.16.0.0/12"
19+
address "192.168.0.0/16"
20+
address "::1/128"
21+
address "fe80::/10"
22+
address "fc00::/7"
23+
}
24+
server time1.vyos.net {
25+
}
26+
server time2.vyos.net {
27+
}
28+
server time3.vyos.net {
29+
}
30+
}
31+
}
32+
system {
33+
config-management {
34+
commit-revisions "100"
35+
}
36+
console {
37+
device ttyAMA0 {
38+
speed "115200"
39+
}
40+
}
41+
host-name "vyos"
42+
login {
43+
operator-group default {
44+
command-policy {
45+
allow "*"
46+
}
47+
}
48+
user vyos {
49+
authentication {
50+
encrypted-password "$6$QxPS.uk6mfo$9QBSo8u1FkH16gMyAVhus6fU3LOzvLR9Z9.82m3tiHFAxTtIkhaZSWssSgzt4v4dGAL8rhVQxTg0oAG9/q11h/"
51+
plaintext-password ""
52+
}
53+
}
54+
}
55+
option {
56+
reboot-on-upgrade-failure 5
57+
}
58+
syslog {
59+
local {
60+
facility all {
61+
level "info"
62+
}
63+
facility local7 {
64+
level "debug"
65+
}
66+
}
67+
}
68+
}
69+
'''
70+
71+
[boot_settings]
72+
console_type = "ttyAMA"
73+
console_num = '0'
74+
console_speed = "115200"

scripts/check-qemu-install

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

58+
# Map QEMU arch
59+
QEMU_CONFIG = {
60+
"amd64": {
61+
"bin": "qemu-system-x86_64",
62+
"machine": "pc",
63+
"bios": "/usr/share/OVMF/OVMF_CODE.fd",
64+
},
65+
"arm64": {
66+
"bin": "qemu-system-aarch64",
67+
"machine": "virt",
68+
"bios": "/usr/share/qemu-efi-aarch64/QEMU_EFI.fd",
69+
},
70+
}
71+
5872
# getch.py
5973
KEY_F2 = chr(27) + chr(91) + chr(49) + chr(50) + chr(126)
6074
KEY_F10 = chr(27) + chr(91) + chr(50) + chr(49) + chr(126)
@@ -97,13 +111,15 @@ parser.add_argument('--sbtest', help='Execute Secure Boot tests',
97111
parser.add_argument('--qemu-cmd', help='Only generate QEMU launch command',
98112
action='store_true', default=False)
99113
parser.add_argument('--cpu', help='Set QEMU CPU', type=int, default=2)
114+
parser.add_argument('--cpu-type', help='Set QEMU CPU type', type=str, default='host')
100115
parser.add_argument('--memory', help='Set QEMU memory', type=int, default=4)
101116
parser.add_argument('--vyconf', help='Execute testsuite with vyconfd', action='store_true',
102117
default=False)
103118
parser.add_argument('--no-vpp', help='Execute testsuite without VPP tests',
104119
action='store_true', default=False)
105120
parser.add_argument('--huge-page-size', help='Huge page size (e.g., 2M, 1G)', type=str)
106121
parser.add_argument('--huge-page-count', help='Number of huge pages to allocate', type=int)
122+
parser.add_argument('--arch', help='Architecture')
107123

108124
args = parser.parse_args()
109125

@@ -146,18 +162,31 @@ OVMF_VARS_TMP = args.disk.replace('.img', '.efivars')
146162
if args.sbtest:
147163
shutil.copy('/usr/share/OVMF/OVMF_VARS_4M.ms.fd', OVMF_VARS_TMP)
148164

165+
166+
def _kvm_exists():
167+
return os.path.exists("/dev/kvm")
168+
169+
149170
def get_qemu_cmd(name, enable_uefi, disk_img, raid=None, iso_img=None, tpm=False, vnc_enabled=False, secure_boot=False):
150171
uefi = ""
151172
uuid = "f48b60b2-e6ad-49ef-9d09-4245d0585e52"
152-
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_type = args.cpu_type
178+
machine = qemu_arch_config['machine']
179+
accel = ',accel=kvm' if _kvm_exists() else ''
180+
enable_kvm = '-enable-kvm' if _kvm_exists() else ''
153181
vga = '-vga none'
154182
vnc = ''
183+
155184
if vnc_enabled:
156185
vga = '-vga virtio'
157186
vnc = '-vnc :0'
158187

159188
if enable_uefi:
160-
uefi = '-bios /usr/share/OVMF/OVMF_CODE.fd'
189+
uefi = f'-bios {bios}'
161190
name = f'{name}-UEFI'
162191

163192
if secure_boot:
@@ -171,26 +200,25 @@ def get_qemu_cmd(name, enable_uefi, disk_img, raid=None, iso_img=None, tpm=False
171200

172201
cdrom = ""
173202
if iso_img:
174-
cdrom = f' -drive file={iso_img},format=raw,if=none,media=cdrom,id=drive-cd1,readonly=on' \
175-
f' -device ahci,id=achi0' \
176-
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+
)
177207

178208
# RFC7042 section 2.1.2 MAC addresses used for documentation
179209
macbase = '00:00:5E:00:53'
180-
cmd = f'qemu-system-x86_64 \
210+
cmd = f'{qemu_bin} \
181211
-name "{name}" \
182212
-smp {args.cpu},sockets=1,cores={args.cpu},threads=1 \
183-
-cpu host \
184-
-machine {machine},accel=kvm \
213+
-cpu {cpu_type} \
214+
-machine {machine}{accel} \
185215
{uefi} \
186216
-m {args.memory}G \
187217
-vga none \
188218
-nographic \
189219
{vga} {vnc}\
190220
-uuid {uuid} \
191-
-cpu host \
192-
{cdrom} \
193-
-enable-kvm \
221+
{enable_kvm} \
194222
-monitor unix:/tmp/qemu-monitor-socket-{disk_img},server,nowait \
195223
-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 \
196224
-netdev user,id=n1 -device virtio-net-pci,netdev=n1,mac={macbase}:01,romfile="",host_mtu=1500 \
@@ -201,6 +229,7 @@ def get_qemu_cmd(name, enable_uefi, disk_img, raid=None, iso_img=None, tpm=False
201229
-netdev user,id=n6 -device virtio-net-pci,netdev=n6,mac={macbase}:06,romfile="" \
202230
-netdev user,id=n7 -device virtio-net-pci,netdev=n7,mac={macbase}:07,romfile="" \
203231
-device virtio-scsi-pci,id=scsi0 \
232+
{cdrom} \
204233
-drive format=raw,file={disk_img},if=none,media=disk,id=drive-hd1,readonly=off \
205234
-device scsi-hd,bus=scsi0.0,drive=drive-hd1,id=hd1,bootindex=1'
206235

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

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

288318
# Creating diskimage!!
289319
diskname_raid = None

0 commit comments

Comments
 (0)