Skip to content

Commit 1e30e37

Browse files
committed
efi_selftest: unit test for EFI Conformance Profile Table
Add a new unit test to test the integrity of the EFI Conformance Profile Table. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
1 parent b33f246 commit 1e30e37

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

lib/efi_selftest/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ efi_selftest_variables.o \
4949
efi_selftest_variables_runtime.o \
5050
efi_selftest_watchdog.o
5151

52+
obj-$(CONFIG_EFI_ECPT) += efi_selftest_ecpt.o
5253
obj-$(CONFIG_NET) += efi_selftest_snp.o
5354

5455
obj-$(CONFIG_EFI_DEVICE_PATH_TO_TEXT) += efi_selftest_devicepath.o

lib/efi_selftest/efi_selftest_ecpt.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
/*
3+
* efi_selftest_fdt
4+
*
5+
* Copyright (c) 2022 Heinrich Schuchardt <xypron.glpk@gmx.de>
6+
*
7+
* Check the EFI_CONFORMANCE_PROFILE_TABLE
8+
*/
9+
10+
#include <efi_selftest.h>
11+
12+
static const efi_guid_t guid_ecpt = EFI_CONFORMANCE_PROFILES_TABLE_GUID;
13+
static const efi_guid_t guid_ebbr_2_0 = EFI_CONFORMANCE_PROFILE_EBBR_2_0_GUID;
14+
15+
/*
16+
* ecpt_find_guid() - find GUID in EFI Conformance Profile Table
17+
*
18+
* @ecpt: EFI Conformance Profile Table
19+
* @guid: GUID to find
20+
* Return: EFI_ST_SUCCESS for success
21+
*/
22+
static int ecpt_find_guid(struct efi_conformance_profiles_table *ecpt,
23+
const efi_guid_t *guid) {
24+
int i;
25+
26+
for (i = 0; i < ecpt->number_of_profiles; ++i) {
27+
if (!memcmp(&ecpt->conformance_profiles[i], guid, 16))
28+
return EFI_ST_SUCCESS;
29+
}
30+
efi_st_error("GUID %pU not found\n", guid);
31+
return EFI_ST_FAILURE;
32+
}
33+
34+
/*
35+
* Execute unit test.
36+
*
37+
* Return: EFI_ST_SUCCESS for success
38+
*/
39+
static int execute(void)
40+
{
41+
struct efi_conformance_profiles_table *ecpt;
42+
int expected_entries = 0;
43+
44+
ecpt = efi_st_get_config_table(&guid_ecpt);
45+
46+
if (!ecpt) {
47+
efi_st_error("Missing EFI Conformance Profile Table\n");
48+
return EFI_ST_FAILURE;
49+
}
50+
51+
if (ecpt->version != EFI_CONFORMANCE_PROFILES_TABLE_VERSION) {
52+
efi_st_error("Wrong table version\n");
53+
return EFI_ST_FAILURE;
54+
}
55+
56+
if (CONFIG_IS_ENABLED(EFI_EBBR_2_0_CONFORMANCE)) {
57+
++expected_entries;
58+
if (ecpt_find_guid(ecpt, &guid_ebbr_2_0))
59+
return EFI_ST_FAILURE;
60+
}
61+
62+
if (ecpt->number_of_profiles != expected_entries) {
63+
efi_st_error("Expected %d entries, found %d\n",
64+
expected_entries, ecpt->number_of_profiles);
65+
return EFI_ST_FAILURE;
66+
}
67+
68+
return EFI_ST_SUCCESS;
69+
}
70+
71+
72+
EFI_UNIT_TEST(ecpt) = {
73+
.name = "conformance profile table",
74+
.phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
75+
.execute = execute,
76+
};

0 commit comments

Comments
 (0)