diff options
Diffstat (limited to 'lib/efi_selftest')
-rw-r--r-- | lib/efi_selftest/Makefile | 3 | ||||
-rw-r--r-- | lib/efi_selftest/efi_selftest_open_protocol.c | 205 | ||||
-rw-r--r-- | lib/efi_selftest/efi_selftest_register_notify.c | 21 | ||||
-rw-r--r-- | lib/efi_selftest/efi_selftest_rtc.c | 17 |
4 files changed, 226 insertions, 20 deletions
diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile index cfbb40c8910..3bebd0f5737 100644 --- a/lib/efi_selftest/Makefile +++ b/lib/efi_selftest/Makefile @@ -26,8 +26,8 @@ efi_selftest_gop.o \ efi_selftest_loaded_image.o \ efi_selftest_manageprotocols.o \ efi_selftest_memory.o \ +efi_selftest_open_protocol.o \ efi_selftest_register_notify.o \ -efi_selftest_rtc.o \ efi_selftest_snp.o \ efi_selftest_textinput.o \ efi_selftest_textinputex.o \ @@ -43,6 +43,7 @@ efi_selftest_unicode_collation.o obj-$(CONFIG_CPU_V7) += efi_selftest_unaligned.o obj-$(CONFIG_EFI_LOADER_HII) += efi_selftest_hii.o +obj-$(CONFIG_EFI_GET_TIME) += efi_selftest_rtc.o ifeq ($(CONFIG_GENERATE_ACPI_TABLE),) obj-y += efi_selftest_fdt.o diff --git a/lib/efi_selftest/efi_selftest_open_protocol.c b/lib/efi_selftest/efi_selftest_open_protocol.c new file mode 100644 index 00000000000..e3f351df723 --- /dev/null +++ b/lib/efi_selftest/efi_selftest_open_protocol.c @@ -0,0 +1,205 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * efi_selftest_open_protocol + * + * Copyright (c) 2019 Heinrich Schuchardt <xypron.glpk@gmx.de> + * + * This unit test checks that open protocol information is correctly updated + * when calling: + * HandleProtocol, OpenProtocol, OpenProtocolInformation, CloseProtocol. + */ + +#include <efi_selftest.h> + +/* + * The test currently does not actually call the interface function. + * So this is just a dummy structure. + */ +struct interface { + void (EFIAPI *inc)(void); +}; + +static struct efi_boot_services *boottime; +static efi_guid_t guid1 = + EFI_GUID(0x492a0e38, 0x1442, 0xf819, + 0x14, 0xaa, 0x4b, 0x8d, 0x09, 0xfe, 0x5a, 0xb9); +static efi_handle_t handle1; +static struct interface interface1; + +/* + * Setup unit test. + * + * Create a handle and install a protocol interface on it. + * + * @handle: handle of the loaded image + * @systable: system table + */ +static int setup(const efi_handle_t img_handle, + const struct efi_system_table *systable) +{ + efi_status_t ret; + + boottime = systable->boottime; + + ret = boottime->install_protocol_interface(&handle1, &guid1, + EFI_NATIVE_INTERFACE, + &interface1); + if (ret != EFI_SUCCESS) { + efi_st_error("InstallProtocolInterface failed\n"); + return EFI_ST_FAILURE; + } + if (!handle1) { + efi_st_error + ("InstallProtocolInterface failed to create handle\n"); + return EFI_ST_FAILURE; + } + return EFI_ST_SUCCESS; +} + +/* + * Tear down unit test. + * + */ +static int teardown(void) +{ + efi_status_t ret; + + if (handle1) { + ret = boottime->uninstall_protocol_interface(handle1, &guid1, + &interface1); + if (ret != EFI_SUCCESS) { + efi_st_error("UninstallProtocolInterface failed\n"); + return EFI_ST_FAILURE; + } + } + return EFI_ST_SUCCESS; +} + +/* + * Execute unit test. + * + * Open the installed protocol twice via HandleProtocol() and once via + * OpenProtocol(EFI_OPEN_PROTOCOL_GET_PROTOCOL). Read the open protocol + * information and check the open counts. Finally close the protocol and + * check again. + */ +static int execute(void) +{ + void *interface; + struct efi_open_protocol_info_entry *entry_buffer; + efi_uintn_t entry_count; + efi_handle_t firmware_handle; + efi_status_t ret; + + ret = boottime->handle_protocol(handle1, &guid1, &interface); + if (ret != EFI_SUCCESS) { + efi_st_error("HandleProtocol failed\n"); + return EFI_ST_FAILURE; + } + if (interface != &interface1) { + efi_st_error("HandleProtocol returned wrong interface\n"); + return EFI_ST_FAILURE; + } + ret = boottime->open_protocol_information(handle1, &guid1, + &entry_buffer, &entry_count); + if (ret != EFI_SUCCESS) { + efi_st_error("OpenProtocolInformation failed\n"); + return EFI_ST_FAILURE; + } + if (entry_count != 1) { + efi_st_error("Incorrect OpenProtocolInformation count\n"); + efi_st_printf("Expected 1, got %u\n", + (unsigned int)entry_count); + return EFI_ST_FAILURE; + } + ret = boottime->free_pool(entry_buffer); + if (ret != EFI_SUCCESS) { + efi_st_error("FreePool failed\n"); + return EFI_ST_FAILURE; + } + ret = boottime->handle_protocol(handle1, &guid1, &interface); + if (ret != EFI_SUCCESS) { + efi_st_error("HandleProtocol failed\n"); + return EFI_ST_FAILURE; + } + ret = boottime->open_protocol_information(handle1, &guid1, + &entry_buffer, &entry_count); + if (ret != EFI_SUCCESS) { + efi_st_error("OpenProtocolInformation failed\n"); + return EFI_ST_FAILURE; + } + if (entry_count != 1) { + efi_st_error("Incorrect OpenProtocolInformation count\n"); + efi_st_printf("Expected 1, got %u\n", + (unsigned int)entry_count); + return EFI_ST_FAILURE; + } + if (entry_buffer[0].open_count != 2) { + efi_st_error("Incorrect open count: expected 2 got %u\n", + entry_buffer[0].open_count); + return EFI_ST_FAILURE; + } + firmware_handle = entry_buffer[0].agent_handle; + ret = boottime->free_pool(entry_buffer); + if (ret != EFI_SUCCESS) { + efi_st_error("FreePool failed\n"); + return EFI_ST_FAILURE; + } + ret = boottime->open_protocol(handle1, &guid1, &interface, + firmware_handle, NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (ret != EFI_SUCCESS) { + efi_st_error("OpenProtocol failed\n"); + return EFI_ST_FAILURE; + } + ret = boottime->open_protocol_information(handle1, &guid1, + &entry_buffer, &entry_count); + if (ret != EFI_SUCCESS) { + efi_st_error("OpenProtocolInformation failed\n"); + return EFI_ST_FAILURE; + } + if (entry_count != 2) { + efi_st_error("Incorrect OpenProtocolInformation count\n"); + efi_st_printf("Expected 2, got %u\n", + (unsigned int)entry_count); + return EFI_ST_FAILURE; + } + if (entry_buffer[0].open_count + entry_buffer[1].open_count != 3) { + efi_st_error("Incorrect open count: expected 3 got %u\n", + entry_buffer[0].open_count + + entry_buffer[1].open_count); + return EFI_ST_FAILURE; + } + ret = boottime->free_pool(entry_buffer); + if (ret != EFI_SUCCESS) { + efi_st_error("FreePool failed\n"); + return EFI_ST_FAILURE; + } + ret = boottime->close_protocol(handle1, &guid1, firmware_handle, NULL); + if (ret != EFI_SUCCESS) { + efi_st_error("CloseProtocol failed\n"); + return EFI_ST_FAILURE; + } + ret = boottime->open_protocol_information(handle1, &guid1, + &entry_buffer, &entry_count); + if (ret != EFI_SUCCESS) { + efi_st_error("OpenProtocolInformation failed\n"); + return EFI_ST_FAILURE; + } + if (entry_count) { + efi_st_error("Incorrect OpenProtocolInformation count\n"); + efi_st_printf("Expected 0, got %u\n", + (unsigned int)entry_count); + return EFI_ST_FAILURE; + } + + return EFI_ST_SUCCESS; +} + +EFI_UNIT_TEST(openprot) = { + .name = "open protocol", + .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, + .setup = setup, + .execute = execute, + .teardown = teardown, +}; diff --git a/lib/efi_selftest/efi_selftest_register_notify.c b/lib/efi_selftest/efi_selftest_register_notify.c index ee0ef395de4..ad763dd6cb8 100644 --- a/lib/efi_selftest/efi_selftest_register_notify.c +++ b/lib/efi_selftest/efi_selftest_register_notify.c @@ -47,15 +47,20 @@ static void EFIAPI notify(struct efi_event *event, void *context) { struct context *cp = context; efi_status_t ret; + efi_uintn_t handle_count; + efi_handle_t *handles; cp->notify_count++; - ret = boottime->locate_handle_buffer(BY_REGISTER_NOTIFY, NULL, - cp->registration_key, - &cp->handle_count, - &cp->handles); - if (ret != EFI_SUCCESS) - cp->handle_count = 0; + for (;;) { + ret = boottime->locate_handle_buffer(BY_REGISTER_NOTIFY, NULL, + cp->registration_key, + &handle_count, &handles); + if (ret != EFI_SUCCESS) + break; + cp->handle_count += handle_count; + cp->handles = handles; + } } /* @@ -170,7 +175,7 @@ static int execute(void) efi_st_error("reinstall was notified too often\n"); return EFI_ST_FAILURE; } - if (context.handle_count != 1) { + if (context.handle_count != 2) { efi_st_error("LocateHandle failed\n"); return EFI_ST_FAILURE; } @@ -195,7 +200,7 @@ static int execute(void) efi_st_error("install was notified too often\n"); return EFI_ST_FAILURE; } - if (context.handle_count != 2) { + if (context.handle_count != 3) { efi_st_error("LocateHandle failed\n"); return EFI_ST_FAILURE; } diff --git a/lib/efi_selftest/efi_selftest_rtc.c b/lib/efi_selftest/efi_selftest_rtc.c index 9eb29add3b0..6f7035dee61 100644 --- a/lib/efi_selftest/efi_selftest_rtc.c +++ b/lib/efi_selftest/efi_selftest_rtc.c @@ -40,7 +40,9 @@ static int setup(const efi_handle_t handle, static int execute(void) { efi_status_t ret; - struct efi_time tm, tm_old, tm_new = { + struct efi_time tm_old; +#ifdef CONFIG_EFI_SET_TIME + struct efi_time tm, tm_new = { .year = 2017, .month = 5, .day = 19, @@ -48,31 +50,23 @@ static int execute(void) .minute = 47, .second = 53, }; +#endif /* Display current time */ ret = runtime->get_time(&tm_old, NULL); if (ret != EFI_SUCCESS) { -#ifdef CONFIG_CMD_DATE efi_st_error(EFI_ST_NO_RTC); return EFI_ST_FAILURE; -#else - efi_st_todo(EFI_ST_NO_RTC); - return EFI_ST_SUCCESS; -#endif } efi_st_printf("Time according to real time clock: " "%.4u-%.2u-%.2u %.2u:%.2u:%.2u\n", tm_old.year, tm_old.month, tm_old.day, tm_old.hour, tm_old.minute, tm_old.second); +#ifdef CONFIG_EFI_SET_TIME ret = runtime->set_time(&tm_new); if (ret != EFI_SUCCESS) { -#ifdef CONFIG_CMD_DATE efi_st_error(EFI_ST_NO_RTC_SET); return EFI_ST_FAILURE; -#else - efi_st_todo(EFI_ST_NO_RTC_SET); - return EFI_ST_SUCCESS; -#endif } ret = runtime->get_time(&tm, NULL); if (ret != EFI_SUCCESS) { @@ -95,6 +89,7 @@ static int execute(void) efi_st_error(EFI_ST_NO_RTC_SET); return EFI_ST_FAILURE; } +#endif return EFI_ST_SUCCESS; } |