blob: 09c5e96c5e12e6692d0a72b281c3b2462e744afc [file] [log] [blame]
Heinrich Schuchardtfe89d5f2022-09-03 15:58:19 +02001// 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
12static const efi_guid_t guid_ecpt = EFI_CONFORMANCE_PROFILES_TABLE_GUID;
Vincent Stehléc53cec62022-12-16 17:55:04 +010013static const efi_guid_t guid_ebbr_2_1 = EFI_CONFORMANCE_PROFILE_EBBR_2_1_GUID;
Heinrich Schuchardtfe89d5f2022-09-03 15:58:19 +020014
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 */
22static 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 */
39static 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
Vincent Stehléc53cec62022-12-16 17:55:04 +010056 if (CONFIG_IS_ENABLED(EFI_EBBR_2_1_CONFORMANCE)) {
Heinrich Schuchardtfe89d5f2022-09-03 15:58:19 +020057 ++expected_entries;
Vincent Stehléc53cec62022-12-16 17:55:04 +010058 if (ecpt_find_guid(ecpt, &guid_ebbr_2_1))
Heinrich Schuchardtfe89d5f2022-09-03 15:58:19 +020059 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
72EFI_UNIT_TEST(ecpt) = {
73 .name = "conformance profile table",
74 .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
75 .execute = execute,
76};