diff options
Diffstat (limited to 'meta/lib')
| -rw-r--r-- | meta/lib/oeqa/selftest/cases/uki.py | 142 |
1 files changed, 142 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..cd20a99aca --- /dev/null +++ b/meta/lib/oeqa/selftest/cases/uki.py | |||
| @@ -0,0 +1,142 @@ | |||
| 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 | DISTRO_FEATURES_NATIVE:append = " systemd" | ||
| 98 | IMAGE_CLASSES:append:pn-core-image-base = " uki" | ||
| 99 | |||
| 100 | # uki embeds also an initrd, no systemd or udev | ||
| 101 | INITRAMFS_IMAGE = "core-image-initramfs-boot" | ||
| 102 | |||
| 103 | # runqemu must not load kernel separately, it's in the uki | ||
| 104 | QB_KERNEL_ROOT = "" | ||
| 105 | QB_DEFAULT_KERNEL = "none" | ||
| 106 | |||
| 107 | # boot command line provided via uki, not via bootloader | ||
| 108 | UKI_CMDLINE = "rootwait root=LABEL=root console=${KERNEL_CONSOLE}" | ||
| 109 | |||
| 110 | # disable kvm, breaks boot | ||
| 111 | QEMU_USE_KVM = "" | ||
| 112 | |||
| 113 | IMAGE_CLASSES:remove = 'testimage' | ||
| 114 | """ | ||
| 115 | self.append_config(config) | ||
| 116 | bitbake('core-image-base ovmf') | ||
| 117 | runqemu_params = get_bb_var('TEST_RUNQEMUPARAMS', 'core-image-base') or "" | ||
| 118 | uki_filename = get_bb_var('UKI_FILENAME', 'core-image-base') | ||
| 119 | self.remove_config(config) | ||
| 120 | |||
| 121 | with runqemu('core-image-base', ssh=False, | ||
| 122 | runqemuparams='%s slirp nographic ovmf' % (runqemu_params), image_fstype='wic') as qemu: | ||
| 123 | # Verify from efivars that firmware was: | ||
| 124 | # x86_64, qemux86_64, ovmf = edk2 | ||
| 125 | cmd = "echo $( cat /sys/firmware/efi/efivars/LoaderFirmwareInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f ) | grep 'EDK II'" | ||
| 126 | status, output = qemu.run_serial(cmd) | ||
| 127 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) | ||
| 128 | |||
| 129 | # Check that systemd-boot was the loader | ||
| 130 | cmd = "echo $( cat /sys/firmware/efi/efivars/LoaderInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f ) | grep systemd-boot" | ||
| 131 | status, output = qemu.run_serial(cmd) | ||
| 132 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) | ||
| 133 | |||
| 134 | # Check that systemd-stub was used | ||
| 135 | cmd = "echo $( cat /sys/firmware/efi/efivars/StubInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f ) | grep systemd-stub" | ||
| 136 | status, output = qemu.run_serial(cmd) | ||
| 137 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) | ||
| 138 | |||
| 139 | # Check that the compiled uki file was booted into | ||
| 140 | cmd = "echo $( cat /sys/firmware/efi/efivars/LoaderEntrySelected-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f ) | grep '%s'" % (uki_filename) | ||
| 141 | status, output = qemu.run_serial(cmd) | ||
| 142 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) | ||
