summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorHeinrich Schuchardt <xypron.glpk@gmx.de>2017-09-15 08:06:11 (GMT)
committerAlexander Graf <agraf@suse.de>2017-09-18 21:53:57 (GMT)
commit623b3a579765f8e05723bd1eff6f8c7e56d33922 (patch)
tree6c51f2a6aa341c2e6c424201f48630d7c9c61f1c /include
parentea630ce9eae4858a2108bd019a6ef22e2bc1b3f6 (diff)
downloadu-boot-623b3a579765f8e05723bd1eff6f8c7e56d33922.tar.xz
efi_selftest: provide an EFI selftest application
A testing framework for the EFI API is provided. It can be executed with the 'bootefi selftest' command. It is coded in a way that at a later stage we may turn it into a standalone EFI application. The current build system does not allow this yet. All tests use a driver model and are run in three phases: setup, execute, teardown. A test may be setup and executed at boottime, it may be setup at boottime and executed at runtime, or it may be setup and executed at runtime. After executing all tests the system is reset. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
Diffstat (limited to 'include')
-rw-r--r--include/efi_loader.h9
-rw-r--r--include/efi_selftest.h91
2 files changed, 100 insertions, 0 deletions
diff --git a/include/efi_loader.h b/include/efi_loader.h
index f271925..f74b33d 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -254,6 +254,15 @@ efi_status_t __efi_runtime EFIAPI efi_get_time(
struct efi_time_cap *capabilities);
void efi_get_time_init(void);
+#ifdef CONFIG_CMD_BOOTEFI_SELFTEST
+/*
+ * Entry point for the tests of the EFI API.
+ * It is called by 'bootefi selftest'
+ */
+efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle,
+ struct efi_system_table *systab);
+#endif
+
#else /* defined(EFI_LOADER) && !defined(CONFIG_SPL_BUILD) */
/* Without CONFIG_EFI_LOADER we don't have a runtime section, stub it out */
diff --git a/include/efi_selftest.h b/include/efi_selftest.h
new file mode 100644
index 0000000..76304a2
--- /dev/null
+++ b/include/efi_selftest.h
@@ -0,0 +1,91 @@
+/*
+ * EFI application loader
+ *
+ * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef _EFI_SELFTEST_H
+#define _EFI_SELFTEST_H
+
+#include <common.h>
+#include <efi.h>
+#include <efi_api.h>
+#include <linker_lists.h>
+
+/*
+ * Prints an error message.
+ *
+ * @... format string followed by fields to print
+ */
+#define efi_st_error(...) \
+ efi_st_printf("%s(%u):\nERROR: ", __FILE__, __LINE__); \
+ efi_st_printf(__VA_ARGS__) \
+
+/*
+ * A test may be setup and executed at boottime,
+ * it may be setup at boottime and executed at runtime,
+ * or it may be setup and executed at runtime.
+ */
+enum efi_test_phase {
+ EFI_EXECUTE_BEFORE_BOOTTIME_EXIT = 1,
+ EFI_SETUP_BEFORE_BOOTTIME_EXIT,
+ EFI_SETUP_AFTER_BOOTTIME_EXIT,
+};
+
+extern struct efi_simple_text_output_protocol *con_out;
+extern struct efi_simple_input_interface *con_in;
+
+/*
+ * Exit the boot services.
+ *
+ * The size of the memory map is determined.
+ * Pool memory is allocated to copy the memory map.
+ * The memory amp is copied and the map key is obtained.
+ * The map key is used to exit the boot services.
+ */
+void efi_st_exit_boot_services(void);
+
+/*
+ * Print a pointer to an u16 string
+ *
+ * @pointer: pointer
+ * @buf: pointer to buffer address
+ * on return position of terminating zero word
+ */
+void efi_st_printf(const char *fmt, ...)
+ __attribute__ ((format (__printf__, 1, 2)));
+
+/*
+ * Reads an Unicode character from the input device.
+ *
+ * @return: Unicode character
+ */
+u16 efi_st_get_key(void);
+
+/**
+ * struct efi_unit_test - EFI unit test
+ *
+ * An efi_unit_test provides a interface to an EFI unit test.
+ *
+ * @name: name of unit test
+ * @phase: specifies when setup and execute are executed
+ * @setup: set up the unit test
+ * @teardown: tear down the unit test
+ * @execute: execute the unit test
+ */
+struct efi_unit_test {
+ const char *name;
+ const enum efi_test_phase phase;
+ int (*setup)(const efi_handle_t handle,
+ const struct efi_system_table *systable);
+ int (*execute)(void);
+ int (*teardown)(void);
+};
+
+/* Declare a new EFI unit test */
+#define EFI_UNIT_TEST(__name) \
+ ll_entry_declare(struct efi_unit_test, __name, efi_unit_test)
+
+#endif /* _EFI_SELFTEST_H */