diff options
Diffstat (limited to 'meta/lib/oeqa/selftest/cases/uki.py')
-rw-r--r-- | meta/lib/oeqa/selftest/cases/uki.py | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/cases/uki.py b/meta/lib/oeqa/selftest/cases/uki.py new file mode 100644 index 0000000000..9a1aa4e269 --- /dev/null +++ b/meta/lib/oeqa/selftest/cases/uki.py | |||
@@ -0,0 +1,141 @@ | |||
1 | # Based on runqemu.py test file | ||
2 | # | ||
3 | # Copyright (c) 2017 Wind River Systems, Inc. | ||
4 | # | ||
5 | # SPDX-License-Identifier: MIT | ||
6 | # | ||
7 | |||
8 | from oeqa.selftest.case import OESelftestTestCase | ||
9 | from oeqa.utils.commands import bitbake, runqemu, get_bb_var | ||
10 | from oeqa.core.decorator.data import skipIfNotArch | ||
11 | from oeqa.core.decorator import OETestTag | ||
12 | import oe.types | ||
13 | |||
14 | class UkiTest(OESelftestTestCase): | ||
15 | """Boot Unified Kernel Image (UKI) generated with uki.bbclass on UEFI firmware (omvf/edk2)""" | ||
16 | |||
17 | @skipIfNotArch(['i586', 'i686', 'x86_64']) | ||
18 | @OETestTag("runqemu") | ||
19 | def test_uki_boot_systemd(self): | ||
20 | """Build and boot into UEFI firmware (omvf/edk2), systemd-boot, initrd without systemd, rootfs with systemd""" | ||
21 | image = "core-image-minimal" | ||
22 | runqemu_params = get_bb_var('TEST_RUNQEMUPARAMS', image) or "" | ||
23 | cmd = "runqemu %s nographic serial wic ovmf" % (runqemu_params) | ||
24 | if oe.types.qemu_use_kvm(self.td.get('QEMU_USE_KVM', 0), self.td["TARGET_ARCH"]): | ||
25 | cmd += " kvm" | ||
26 | |||
27 | self.write_config(""" | ||
28 | # efi firmware must load systemd-boot, not grub | ||
29 | EFI_PROVIDER = "systemd-boot" | ||
30 | |||
31 | # image format must be wic, needs esp partition for firmware etc | ||
32 | IMAGE_FSTYPES:pn-%s:append = " wic" | ||
33 | WKS_FILE = "efi-uki-bootdisk.wks.in" | ||
34 | |||
35 | # efi, uki and systemd features must be enabled | ||
36 | INIT_MANAGER = "systemd" | ||
37 | MACHINE_FEATURES:append = " efi" | ||
38 | IMAGE_CLASSES:append:pn-core-image-minimal = " uki" | ||
39 | |||
40 | # uki embeds also an initrd | ||
41 | INITRAMFS_IMAGE = "core-image-minimal-initramfs" | ||
42 | |||
43 | # runqemu must not load kernel separately, it's in the uki | ||
44 | QB_KERNEL_ROOT = "" | ||
45 | QB_DEFAULT_KERNEL = "none" | ||
46 | |||
47 | # boot command line provided via uki, not via bootloader | ||
48 | UKI_CMDLINE = "rootwait root=LABEL=root console=${KERNEL_CONSOLE}" | ||
49 | |||
50 | # disable kvm, breaks boot | ||
51 | QEMU_USE_KVM = "" | ||
52 | |||
53 | IMAGE_CLASSES:remove = 'testimage' | ||
54 | """ % (image)) | ||
55 | |||
56 | uki_filename = get_bb_var('UKI_FILENAME', image) | ||
57 | |||
58 | bitbake(image + " ovmf") | ||
59 | with runqemu(image, ssh=False, launch_cmd=cmd) as qemu: | ||
60 | self.assertTrue(qemu.runner.logged, "Failed: %s" % cmd) | ||
61 | |||
62 | # Verify from efivars that firmware was: | ||
63 | # x86_64, qemux86_64, ovmf = edk2 | ||
64 | cmd = "echo $( cat /sys/firmware/efi/efivars/LoaderFirmwareInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f ) | grep 'EDK II'" | ||
65 | status, output = qemu.run_serial(cmd) | ||
66 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) | ||
67 | |||
68 | # Check that systemd-boot was the loader | ||
69 | cmd = "echo $( cat /sys/firmware/efi/efivars/LoaderInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f ) | grep systemd-boot" | ||
70 | status, output = qemu.run_serial(cmd) | ||
71 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) | ||
72 | |||
73 | # Check that systemd-stub was used | ||
74 | cmd = "echo $( cat /sys/firmware/efi/efivars/StubInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f ) | grep systemd-stub" | ||
75 | status, output = qemu.run_serial(cmd) | ||
76 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) | ||
77 | |||
78 | # Check that the compiled uki file was booted into | ||
79 | cmd = "echo $( cat /sys/firmware/efi/efivars/LoaderEntrySelected-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f ) | grep '%s'" % (uki_filename) | ||
80 | status, output = qemu.run_serial(cmd) | ||
81 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) | ||
82 | |||
83 | @skipIfNotArch(['i586', 'i686', 'x86_64']) | ||
84 | @OETestTag("runqemu") | ||
85 | def test_uki_sysvinit(self): | ||
86 | """Build and boot into UEFI firmware (omvf/edk2), systemd-boot, initrd with sysvinit, rootfs with sysvinit""" | ||
87 | config = """ | ||
88 | # efi firmware must load systemd-boot, not grub | ||
89 | EFI_PROVIDER = "systemd-boot" | ||
90 | |||
91 | # image format must be wic, needs esp partition for firmware etc | ||
92 | IMAGE_FSTYPES:pn-core-image-base:append = " wic" | ||
93 | WKS_FILE = "efi-uki-bootdisk.wks.in" | ||
94 | |||
95 | # efi, uki and systemd features must be enabled | ||
96 | MACHINE_FEATURES:append = " efi" | ||
97 | IMAGE_CLASSES:append:pn-core-image-base = " uki" | ||
98 | |||
99 | # uki embeds also an initrd, no systemd or udev | ||
100 | INITRAMFS_IMAGE = "core-image-initramfs-boot" | ||
101 | |||
102 | # runqemu must not load kernel separately, it's in the uki | ||
103 | QB_KERNEL_ROOT = "" | ||
104 | QB_DEFAULT_KERNEL = "none" | ||
105 | |||
106 | # boot command line provided via uki, not via bootloader | ||
107 | UKI_CMDLINE = "rootwait root=LABEL=root console=${KERNEL_CONSOLE}" | ||
108 | |||
109 | # disable kvm, breaks boot | ||
110 | QEMU_USE_KVM = "" | ||
111 | |||
112 | IMAGE_CLASSES:remove = 'testimage' | ||
113 | """ | ||
114 | self.append_config(config) | ||
115 | bitbake('core-image-base ovmf') | ||
116 | runqemu_params = get_bb_var('TEST_RUNQEMUPARAMS', 'core-image-base') or "" | ||
117 | uki_filename = get_bb_var('UKI_FILENAME', 'core-image-base') | ||
118 | self.remove_config(config) | ||
119 | |||
120 | with runqemu('core-image-base', ssh=False, | ||
121 | runqemuparams='%s slirp nographic ovmf' % (runqemu_params), image_fstype='wic') as qemu: | ||
122 | # Verify from efivars that firmware was: | ||
123 | # x86_64, qemux86_64, ovmf = edk2 | ||
124 | cmd = "echo $( cat /sys/firmware/efi/efivars/LoaderFirmwareInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f ) | grep 'EDK II'" | ||
125 | status, output = qemu.run_serial(cmd) | ||
126 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) | ||
127 | |||
128 | # Check that systemd-boot was the loader | ||
129 | cmd = "echo $( cat /sys/firmware/efi/efivars/LoaderInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f ) | grep systemd-boot" | ||
130 | status, output = qemu.run_serial(cmd) | ||
131 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) | ||
132 | |||
133 | # Check that systemd-stub was used | ||
134 | cmd = "echo $( cat /sys/firmware/efi/efivars/StubInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f ) | grep systemd-stub" | ||
135 | status, output = qemu.run_serial(cmd) | ||
136 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) | ||
137 | |||
138 | # Check that the compiled uki file was booted into | ||
139 | cmd = "echo $( cat /sys/firmware/efi/efivars/LoaderEntrySelected-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f ) | grep '%s'" % (uki_filename) | ||
140 | status, output = qemu.run_serial(cmd) | ||
141 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) | ||