test: efi_loader: Add a simple test for the EFI log
Create a test which does some sample calls and checks the output. Expand the size of the sandbox bloblist to accommodate the log. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -1080,6 +1080,7 @@ M: Simon Glass <sjg@chromium.org>
|
||||
S: Maintained
|
||||
F: include/efi_log.h
|
||||
F: lib/efi_loader/efi_log.c
|
||||
F: test/lib/efi_log.c
|
||||
|
||||
EFI PAYLOAD
|
||||
M: Heinrich Schuchardt <xypron.glpk@gmx.de>
|
||||
|
||||
@@ -17,6 +17,7 @@ CONFIG_EFI_CAPSULE_ON_DISK=y
|
||||
CONFIG_EFI_CAPSULE_FIRMWARE_RAW=y
|
||||
CONFIG_EFI_CAPSULE_AUTHENTICATE=y
|
||||
CONFIG_EFI_CAPSULE_CRT_FILE="board/sandbox/capsule_pub_key_good.crt"
|
||||
CONFIG_EFI_LOG=y
|
||||
CONFIG_BUTTON_CMD=y
|
||||
CONFIG_FIT=y
|
||||
CONFIG_FIT_RSASSA_PSS=y
|
||||
@@ -51,6 +52,7 @@ CONFIG_LOGF_FUNC=y
|
||||
CONFIG_DISPLAY_BOARDINFO_LATE=y
|
||||
CONFIG_STACKPROTECTOR=y
|
||||
CONFIG_ANDROID_AB=y
|
||||
CONFIG_BLOBLIST_SIZE_RELOC=0x5000
|
||||
CONFIG_CMD_CPU=y
|
||||
CONFIG_CMD_LICENSE=y
|
||||
CONFIG_CMD_SMBIOS=y
|
||||
@@ -72,6 +74,7 @@ CONFIG_CMD_NVEDIT_LOAD=y
|
||||
CONFIG_CMD_NVEDIT_SELECT=y
|
||||
CONFIG_LOOPW=y
|
||||
CONFIG_CMD_MD5SUM=y
|
||||
CONFIG_CMD_MEMINFO=y
|
||||
CONFIG_CMD_MEM_SEARCH=y
|
||||
CONFIG_CMD_MX_CYCLIC=y
|
||||
CONFIG_CMD_MEMTEST=y
|
||||
|
||||
@@ -129,6 +129,7 @@ int efi_logs_testing(enum efil_test_t enum_val, efi_uintn_t int_val,
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
rec->enum_val = enum_val;
|
||||
rec->int_val = int_val;
|
||||
rec->buffer = buffer;
|
||||
rec->memory = memory;
|
||||
@@ -194,10 +195,8 @@ void show_rec(int seq, struct efil_rec_hdr *rec_hdr)
|
||||
show_addr("buf", map_to_sysmem(rec->buffer));
|
||||
show_addr("mem", map_to_sysmem(rec->memory));
|
||||
if (rec_hdr->ended) {
|
||||
show_addr("*buf",
|
||||
(ulong)map_to_sysmem((void *)rec->e_buffer));
|
||||
show_addr("*mem",
|
||||
(ulong)rec->e_memory);
|
||||
show_addr("*buf", (ulong)map_to_sysmem(rec->e_buffer));
|
||||
show_addr("*mem", (ulong)rec->e_memory);
|
||||
show_ret(rec_hdr->e_ret);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ obj-y += abuf.o
|
||||
obj-y += alist.o
|
||||
obj-$(CONFIG_EFI_LOADER) += efi_device_path.o
|
||||
obj-$(CONFIG_EFI_SECURE_BOOT) += efi_image_region.o
|
||||
obj-$(CONFIG_EFI_LOG) += efi_log.o
|
||||
obj-y += hexdump.o
|
||||
obj-$(CONFIG_SANDBOX) += kconfig.o
|
||||
obj-y += lmb.o
|
||||
|
||||
49
test/lib/efi_log.c
Normal file
49
test/lib/efi_log.c
Normal file
@@ -0,0 +1,49 @@
|
||||
// SPDX-License-Identifier: GPL-2.0+
|
||||
/*
|
||||
* Copyright 2024 Google LLC
|
||||
* Written by Simon Glass <sjg@chromium.org>
|
||||
*/
|
||||
|
||||
#include <efi_log.h>
|
||||
#include <mapmem.h>
|
||||
#include <test/lib.h>
|
||||
#include <test/test.h>
|
||||
#include <test/ut.h>
|
||||
|
||||
/* basic test of logging */
|
||||
static int lib_test_efi_log_base(struct unit_test_state *uts)
|
||||
{
|
||||
void **buf = map_sysmem(0x1000, 0);
|
||||
u64 *addr = map_sysmem(0x1010, 0);
|
||||
int ofs1, ofs2;
|
||||
|
||||
ut_assertok(efi_log_reset());
|
||||
|
||||
ofs1 = efi_logs_testing(EFI_LOG_TEST0, 123, &buf[0], &addr[0]);
|
||||
|
||||
ofs2 = efi_logs_testing(EFI_LOG_TEST1, 456, &buf[1], &addr[1]);
|
||||
|
||||
/* simulate an EFI call setting the return values */
|
||||
addr[0] = 0x100;
|
||||
buf[0] = map_sysmem(0x1100, 0);
|
||||
addr[1] = 0x200;
|
||||
buf[1] = map_sysmem(0x1200, 0);
|
||||
|
||||
ut_assertok(efi_loge_testing(ofs2, EFI_LOAD_ERROR));
|
||||
ut_assertok(efi_loge_testing(ofs1, EFI_SUCCESS));
|
||||
|
||||
ut_assertok(efi_log_show());
|
||||
ut_assert_nextline("EFI log (size 98)");
|
||||
ut_assert_nextline(
|
||||
" 0 testing test0 int 7b/123 buf 1000 mem 1010 *buf 1100 *mem 100 ret OK");
|
||||
ut_assert_nextline(
|
||||
" 1 testing test1 int 1c8/456 buf 1008 mem 1018 *buf 1200 *mem 200 ret load");
|
||||
ut_assert_nextline("2 records");
|
||||
ut_assert_console_end();
|
||||
|
||||
unmap_sysmem(buf);
|
||||
unmap_sysmem(addr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
LIB_TEST(lib_test_efi_log_base, UTF_CONSOLE);
|
||||
Reference in New Issue
Block a user