Skip to content

Commit 0765a56

Browse files
committed
bootloader: Add more test coverage
Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
1 parent c7cbafb commit 0765a56

3 files changed

Lines changed: 61 additions & 3 deletions

File tree

tests/data/grub-no-hypervisor.cfg

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
serial --unit=0 --speed=115200
2+
terminal_input serial console
3+
terminal_output serial console
4+
set default=0
5+
set timeout=5
6+
menuentry 'XCP-ng' {
7+
search --label --set root root-vgdorj
8+
xen_module /boot/vmlinuz-4.19-xen root=LABEL=root-vgdorj ro nolvm hpet=disable console=hvc0 console=tty0 quiet vga=785 splash plymouth.ignore-serial-consoles
9+
xen_module /boot/initrd-4.19-xen.img
10+
}

tests/data/grub-xen-boot.cfg

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
serial --unit=0 --speed=115200
2+
terminal_input serial console
3+
terminal_output serial console
4+
set default=0
5+
set timeout=5
6+
menuentry 'XCP-ng' {
7+
search --label --set root root-vgdorj
8+
xen_hypervisor /boot/xen.gz dom0_mem=7584M,max:7584M watchdog ucode=scan dom0_max_vcpus=1-16 crashkernel=256M,below=4G console=vga vga=mode-0x0311
9+
xen_module /boot/vmlinuz-4.19-xen root=LABEL=root-vgdorj ro nolvm hpet=disable console=hvc0 console=tty0 quiet vga=785 splash plymouth.ignore-serial-consoles
10+
xen_module /boot/initrd-4.19-xen.img
11+
}
12+
menuentry 'XCP-ng (Serial)' {
13+
search --label --set root root-vgdorj
14+
xen_hypervisor /boot/xen.gz com1=115200,8n1 console=com1,vga dom0_mem=7584M,max:7584M watchdog ucode=scan dom0_max_vcpus=1-16 crashkernel=256M,below=4G
15+
xen_module /boot/vmlinuz-4.19-xen root=LABEL=root-vgdorj ro nolvm hpet=disable console=tty0 console=hvc0
16+
xen_module /boot/initrd-4.19-xen.img
17+
}
18+
menuentry 'XCP-ng in Safe Mode' {
19+
search --label --set root root-vgdorj
20+
xen_hypervisor /boot/xen.gz nosmp noreboot noirqbalance no-mce no-bootscrub no-numa no-hap no-mmcfg max_cstate=0 nmi=ignore allow_unsafe dom0_mem=7584M,max:7584M com1=115200,8n1 console=com1,vga
21+
xen_module /boot/vmlinuz-4.19-xen earlyprintk=xen root=LABEL=root-vgdorj ro nolvm hpet=disable console=tty0 console=hvc0
22+
xen_module /boot/initrd-4.19-xen.img
23+
}
24+
menuentry 'XCP-ng (Xen 4.13.1 / Linux 4.19.0+1)' {
25+
search --label --set root root-vgdorj
26+
xen_hypervisor /boot/xen-fallback.gz dom0_mem=7584M,max:7584M watchdog ucode=scan dom0_max_vcpus=1-16 crashkernel=256M,below=4G
27+
xen_module /boot/vmlinuz-fallback root=LABEL=root-vgdorj ro nolvm hpet=disable console=hvc0 console=tty0
28+
xen_module /boot/initrd-fallback.img
29+
}
30+
menuentry 'XCP-ng (Serial, Xen 4.13.1 / Linux 4.19.0+1)' {
31+
search --label --set root root-vgdorj
32+
xen_hypervisor /boot/xen-fallback.gz com1=115200,8n1 console=com1,vga dom0_mem=7584M,max:7584M watchdog ucode=scan dom0_max_vcpus=1-16 crashkernel=256M,below=4G
33+
xen_module /boot/vmlinuz-fallback root=LABEL=root-vgdorj ro nolvm hpet=disable console=tty0 console=hvc0
34+
xen_module /boot/initrd-fallback.img
35+
}

tests/test_bootloader.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99

1010

1111
class TestBootloader(unittest.TestCase):
12-
def test_grub2(self):
13-
bl = Bootloader.readGrub2("tests/data/grub.cfg")
12+
def _test_cfg(self, cfg):
13+
bl = Bootloader.readGrub2(cfg)
1414
with NamedTemporaryFile("w") as temp:
1515
bl.writeGrub2(temp.name)
1616
# get a diff
17-
proc = subprocess.Popen(["diff", "tests/data/grub.cfg", temp.name],
17+
proc = subprocess.Popen(["diff", cfg, temp.name],
1818
stdout = subprocess.PIPE,
1919
universal_newlines=True)
2020

@@ -32,11 +32,24 @@ def test_grub2(self):
3232
proc.wait()
3333
self.assertEqual(proc.returncode, 1)
3434

35+
def test_grub2(self):
36+
'''Test read/write roundtrip of GRUB2 multiboot config'''
37+
self._test_cfg("tests/data/grub.cfg")
38+
39+
def test_grub2_xen_boot(self):
40+
'''Test read/write roundtrip of GRUB2 xen_boot config'''
41+
self._test_cfg("tests/data/grub-xen-boot.cfg")
42+
3543
def test_no_multiboot(self):
3644
# A module2 line without a multiboot2 line is an error
3745
with self.assertRaises(RuntimeError):
3846
Bootloader.readGrub2("tests/data/grub-no-multiboot.cfg")
3947

48+
def test_no_hypervisor(self):
49+
# A xen_module line without a xen_hypervisor line is an error
50+
with self.assertRaises(RuntimeError):
51+
Bootloader.readGrub2("tests/data/grub-no-hypervisor.cfg")
52+
4053

4154
class TestMenuEntry(unittest.TestCase):
4255
def setUp(self):

0 commit comments

Comments
 (0)