[PATCH 13/15] test: efi_loader: Add a simple test for the EFI log
Simon Glass
sjg at chromium.org
Mon Oct 28 13:48:04 CET 2024
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 at chromium.org>
---
MAINTAINERS | 1 +
configs/sandbox_defconfig | 3 +++
lib/efi_loader/efi_log.c | 7 +++---
test/lib/Makefile | 1 +
test/lib/efi_log.c | 49 +++++++++++++++++++++++++++++++++++++++
5 files changed, 57 insertions(+), 4 deletions(-)
create mode 100644 test/lib/efi_log.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 9ade0ca4bc3..3e571174ad5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1072,6 +1072,7 @@ M: Simon Glass <sjg at 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 at gmx.de>
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index d111858082d..afba6c78e28 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -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
@@ -50,6 +51,7 @@ CONFIG_LOG_DEFAULT_LEVEL=6
CONFIG_LOGF_FUNC=y
CONFIG_DISPLAY_BOARDINFO_LATE=y
CONFIG_STACKPROTECTOR=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_SELECT=y
CONFIG_LOOPW=y
CONFIG_CMD_MD5SUM=y
CONFIG_CMD_MEMINFO=y
+CONFIG_CMD_MEMINFO=y
CONFIG_CMD_MEM_SEARCH=y
CONFIG_CMD_MX_CYCLIC=y
CONFIG_CMD_MEMTEST=y
diff --git a/lib/efi_loader/efi_log.c b/lib/efi_loader/efi_log.c
index 01e495d3995..780860d8b2f 100644
--- a/lib/efi_loader/efi_log.c
+++ b/lib/efi_loader/efi_log.c
@@ -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);
}
}
diff --git a/test/lib/Makefile b/test/lib/Makefile
index 217c3baf881..050eaef4bb9 100644
--- a/test/lib/Makefile
+++ b/test/lib/Makefile
@@ -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
diff --git a/test/lib/efi_log.c b/test/lib/efi_log.c
new file mode 100644
index 00000000000..414b7081bd9
--- /dev/null
+++ b/test/lib/efi_log.c
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2024 Google LLC
+ * Written by Simon Glass <sjg at 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);
--
2.43.0
More information about the U-Boot
mailing list