Heinrich Schuchardt | fe89d5f | 2022-09-03 15:58:19 +0200 | [diff] [blame] | 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; |
Vincent Stehlé | c53cec6 | 2022-12-16 17:55:04 +0100 | [diff] [blame] | 13 | static const efi_guid_t guid_ebbr_2_1 = EFI_CONFORMANCE_PROFILE_EBBR_2_1_GUID; |
Heinrich Schuchardt | fe89d5f | 2022-09-03 15:58:19 +0200 | [diff] [blame] | 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 | |
Vincent Stehlé | c53cec6 | 2022-12-16 17:55:04 +0100 | [diff] [blame] | 56 | if (CONFIG_IS_ENABLED(EFI_EBBR_2_1_CONFORMANCE)) { |
Heinrich Schuchardt | fe89d5f | 2022-09-03 15:58:19 +0200 | [diff] [blame] | 57 | ++expected_entries; |
Vincent Stehlé | c53cec6 | 2022-12-16 17:55:04 +0100 | [diff] [blame] | 58 | if (ecpt_find_guid(ecpt, &guid_ebbr_2_1)) |
Heinrich Schuchardt | fe89d5f | 2022-09-03 15:58:19 +0200 | [diff] [blame] | 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 | |
Heinrich Schuchardt | fe89d5f | 2022-09-03 15:58:19 +0200 | [diff] [blame] | 71 | EFI_UNIT_TEST(ecpt) = { |
| 72 | .name = "conformance profile table", |
| 73 | .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, |
| 74 | .execute = execute, |
| 75 | }; |