1# SPDX-License-Identifier:      GPL-2.0+
2""" Unit test for UEFI bootmanager
3"""
4
5import pytest
6
7@pytest.mark.boardspec('sandbox')
8@pytest.mark.buildconfigspec('cmd_efidebug')
9@pytest.mark.buildconfigspec('cmd_bootefi_bootmgr')
10@pytest.mark.singlethread
11def test_efi_bootmgr(u_boot_console, efi_bootmgr_data):
12    """ Unit test for UEFI bootmanager
13    The efidebug command is used to set up UEFI load options.
14    The bootefi bootmgr loads initrddump.efi as a payload.
15    The crc32 of the loaded initrd.img is checked
16
17    Args:
18        u_boot_console -- U-Boot console
19        efi_bootmgr_data -- Path to the disk image used for testing.
20    """
21    u_boot_console.run_command(cmd = f'host bind 0 {efi_bootmgr_data}')
22
23    u_boot_console.run_command(cmd = 'efidebug boot add ' \
24        '-b 0001 label-1 host 0:1 initrddump.efi ' \
25        '-i host 0:1 initrd-1.img -s nocolor')
26    u_boot_console.run_command(cmd = 'efidebug boot dump')
27    u_boot_console.run_command(cmd = 'efidebug boot order 0001')
28    u_boot_console.run_command(cmd = 'bootefi bootmgr')
29    response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False)
30    assert 'crc32: 0x181464af' in response
31    u_boot_console.run_command(cmd = 'exit', wait_for_echo=False)
32
33    u_boot_console.run_command(cmd = 'efidebug boot add ' \
34        '-B 0002 label-2 host 0:1 initrddump.efi ' \
35        '-I host 0:1 initrd-2.img -s nocolor')
36    u_boot_console.run_command(cmd = 'efidebug boot dump')
37    u_boot_console.run_command(cmd = 'efidebug boot order 0002')
38    u_boot_console.run_command(cmd = 'bootefi bootmgr')
39    response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False)
40    assert 'crc32: 0x811d3515' in response
41    u_boot_console.run_command(cmd = 'exit', wait_for_echo=False)
42
43    u_boot_console.run_command(cmd = 'efidebug boot rm 0001')
44    u_boot_console.run_command(cmd = 'efidebug boot rm 0002')
45