We have one boot test for a Debian kernel via GRUB. The kernel in this same image can be EFI booted directly thanks to its EFI stub and it can be even booted without EFI at all via the normal boot protocol.
Add a test exercising both. Signed-off-by: Ahmad Fatoum <[email protected]> --- test/arm/multi_v8_efiloader_defconfig.yaml | 5 ++ test/py/test_linux_efiloader.py | 64 ++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/test/arm/multi_v8_efiloader_defconfig.yaml b/test/arm/multi_v8_efiloader_defconfig.yaml index 42bb418af6f8..b24058da8e99 100644 --- a/test/arm/multi_v8_efiloader_defconfig.yaml +++ b/test/arm/multi_v8_efiloader_defconfig.yaml @@ -27,6 +27,11 @@ targets: - smbios - bootable - efi + options: + root_dev: virtioblk0.0 + bootm.image: 'boot/vmlinuz-*' + bootm.initrd: 'boot/initrd.img-*' + images: barebox-dt-2nd.img: !template "$LG_BUILDDIR/images/barebox-dt-2nd.img" imports: diff --git a/test/py/test_linux_efiloader.py b/test/py/test_linux_efiloader.py index 8530747a7a6b..b9ea82d27c0d 100644 --- a/test/py/test_linux_efiloader.py +++ b/test/py/test_linux_efiloader.py @@ -15,6 +15,70 @@ def get_journalctl(shell, kernel=True, grep=None): return stdout [email protected]_feature(['bootable', 'efi']) [email protected]('efiloader', [False, True]) +def test_boot_manual_with_initrd(strategy, barebox, env, efiloader): + """Test booting Debian kernel directly without GRUB""" + + barebox.run_check(f"global.bootm.efi={'required' if efiloader else 'disabled'}") + + def get_option(strategy, opt): + config = strategy.target.env.config + return config.get_target_option(strategy.target.name, opt) + + try: + root_dev = get_option(strategy, "root_dev") + kernel_path = get_option(strategy, "bootm.image") + except KeyError: + pytest.fail("Feature bootable enabled, but root_dev/bootm.image option missing.") # noqa + + # Detect block devices + barebox.run_check("detect -a") + barebox.run_check(f"ls /mnt/{root_dev}/") + + [kernel_path] = barebox.run_check(f"ls /mnt/{root_dev}/{kernel_path}") + + try: + initrd_path = get_option(strategy, "bootm.initrd") + [initrd_path] = barebox.run_check(f"ls /mnt/{root_dev}/{initrd_path}") + barebox.run_check(f"global.bootm.initrd={initrd_path}") + except KeyError: + pass + + barebox.run_check(f"global.bootm.image={kernel_path}") + barebox.run_check(f"global.bootm.root_dev=/dev/{root_dev}") + barebox.run_check("global.bootm.appendroot=1") + # Speed up subsequent runs a bit + barebox.run_check("global linux.bootargs.noapparmor=apparmor=0") + + # Boot the kernel - it should use EFI stub by default + with strategy.boot_kernel(bootm=True) as shell: + shell.run_check("grep -q apparmor=0 /proc/cmdline") + + initrd_freed = any("Freeing initrd memory" + in line for line in get_journalctl(shell, 'initrd')) + assert initrd_freed, "initrd was not loaded or freed" + + # Verify we booted to shell + dmesg = get_journalctl(shell, 'efi') + + uefi_not_found = re.search("efi: UEFI not found.", + "\n".join(dmesg)) is not None + + if efiloader: + test_efi_kernel_no_warn(shell) + test_expected_efi_messages(shell, env) + test_efi_systab(shell, env) + test_efivars_filesystem_not_empty(shell) + + assert not uefi_not_found, \ + "EFI stub was not used despite global.bootm.efi=required" + else: + # Verify that EFI was NOT used + assert uefi_not_found, \ + "EFI stub was used despite global.bootm.efi=disabled" + + @pytest.mark.lg_feature(['bootable', 'efi']) def test_efi_kernel_no_warn(shell): stdout, stderr, ret = shell.run("journalctl -k --no-pager --grep efi -o cat -p warning") -- 2.47.3
