Abdellatif El Khlifi | 10a69ce | 2023-08-04 14:33:39 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Functional tests for UCLASS_FFA class |
| 4 | * |
| 5 | * Copyright 2022-2023 Arm Limited and/or its affiliates <open-source-office@arm.com> |
| 6 | * |
| 7 | * Authors: |
| 8 | * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com> |
| 9 | */ |
| 10 | |
Caleb Connolly | 55ce3e9 | 2024-08-30 13:34:40 +0100 | [diff] [blame^] | 11 | #include <charset.h> |
Caleb Connolly | 29cab7c | 2024-08-30 13:34:37 +0100 | [diff] [blame] | 12 | #include <u-boot/uuid.h> |
Abdellatif El Khlifi | 10a69ce | 2023-08-04 14:33:39 +0100 | [diff] [blame] | 13 | #include <test/lib.h> |
| 14 | #include <test/test.h> |
| 15 | #include <test/ut.h> |
| 16 | |
Caleb Connolly | 55ce3e9 | 2024-08-30 13:34:40 +0100 | [diff] [blame^] | 17 | #include <efi.h> |
| 18 | |
Abdellatif El Khlifi | 10a69ce | 2023-08-04 14:33:39 +0100 | [diff] [blame] | 19 | /* test UUID */ |
| 20 | #define TEST_SVC_UUID "ed32d533-4209-99e6-2d72-cdd998a79cc0" |
Caleb Connolly | 55ce3e9 | 2024-08-30 13:34:40 +0100 | [diff] [blame^] | 21 | /* U-Boot default fw image namespace */ |
| 22 | #define DEFAULT_FW_IMAGE_NAMESPACE "8c9f137e-91dc-427b-b2d6-b420faebaf2a" |
Abdellatif El Khlifi | 10a69ce | 2023-08-04 14:33:39 +0100 | [diff] [blame] | 23 | |
| 24 | #define UUID_SIZE 16 |
| 25 | |
| 26 | /* The UUID binary data (little-endian format) */ |
| 27 | static const u8 ref_uuid_bin[UUID_SIZE] = { |
| 28 | 0x33, 0xd5, 0x32, 0xed, |
| 29 | 0x09, 0x42, 0xe6, 0x99, |
| 30 | 0x72, 0x2d, 0xc0, 0x9c, |
| 31 | 0xa7, 0x98, 0xd9, 0xcd |
| 32 | }; |
| 33 | |
| 34 | static int lib_test_uuid_to_le(struct unit_test_state *uts) |
| 35 | { |
| 36 | const char *uuid_str = TEST_SVC_UUID; |
| 37 | u8 ret_uuid_bin[UUID_SIZE] = {0}; |
| 38 | |
| 39 | ut_assertok(uuid_str_to_le_bin(uuid_str, ret_uuid_bin)); |
| 40 | ut_asserteq_mem(ref_uuid_bin, ret_uuid_bin, UUID_SIZE); |
| 41 | |
| 42 | return 0; |
| 43 | } |
Abdellatif El Khlifi | 10a69ce | 2023-08-04 14:33:39 +0100 | [diff] [blame] | 44 | LIB_TEST(lib_test_uuid_to_le, 0); |
Caleb Connolly | 55ce3e9 | 2024-08-30 13:34:40 +0100 | [diff] [blame^] | 45 | |
| 46 | struct dynamic_uuid_test_data { |
| 47 | const char *compatible; |
| 48 | const u16 *images[4]; |
| 49 | const char *expected_uuids[4]; |
| 50 | }; |
| 51 | |
| 52 | static int lib_test_dynamic_uuid_case(struct unit_test_state *uts, |
| 53 | const struct dynamic_uuid_test_data *data) |
| 54 | { |
| 55 | struct uuid namespace; |
| 56 | int j; |
| 57 | |
| 58 | ut_assertok(uuid_str_to_bin(DEFAULT_FW_IMAGE_NAMESPACE, (unsigned char *)&namespace, |
| 59 | UUID_STR_FORMAT_GUID)); |
| 60 | |
| 61 | for (j = 0; data->images[j]; j++) { |
| 62 | const char *expected_uuid = data->expected_uuids[j]; |
| 63 | const u16 *image = data->images[j]; |
| 64 | efi_guid_t uuid; |
| 65 | char uuid_str[37]; |
| 66 | |
| 67 | gen_v5_guid(&namespace, &uuid, |
| 68 | data->compatible, strlen(data->compatible), |
| 69 | image, u16_strlen(image) * sizeof(uint16_t), |
| 70 | NULL); |
| 71 | uuid_bin_to_str((unsigned char *)&uuid, uuid_str, UUID_STR_FORMAT_GUID); |
| 72 | |
| 73 | ut_asserteq_str(expected_uuid, uuid_str); |
| 74 | } |
| 75 | |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | static int lib_test_dynamic_uuid(struct unit_test_state *uts) |
| 80 | { |
| 81 | int ret, i; |
| 82 | const struct dynamic_uuid_test_data test_data[] = { |
| 83 | { |
| 84 | .compatible = "sandbox", |
| 85 | .images = { |
| 86 | u"SANDBOX-UBOOT", |
| 87 | u"SANDBOX-UBOOT-ENV", |
| 88 | u"SANDBOX-FIT", |
| 89 | NULL, |
| 90 | }, |
| 91 | .expected_uuids = { |
| 92 | "985f2937-7c2e-5e9a-8a5e-8e063312964b", |
| 93 | "9e339473-c2eb-530a-a69b-0cd6bbbed40e", |
| 94 | "46610520-469e-59dc-a8dd-c11832b877ea", |
| 95 | NULL, |
| 96 | } |
| 97 | }, |
| 98 | { |
| 99 | .compatible = "qcom,qrb4210-rb2", |
| 100 | .images = { |
| 101 | u"QUALCOMM-UBOOT", |
| 102 | NULL, |
| 103 | }, |
| 104 | .expected_uuids = { |
| 105 | "d5021fac-8dd0-5ed7-90c2-763c304aaf86", |
| 106 | NULL, |
| 107 | } |
| 108 | }, |
| 109 | }; |
| 110 | |
| 111 | for (i = 0; i < ARRAY_SIZE(test_data); i++) { |
| 112 | ret = lib_test_dynamic_uuid_case(uts, &test_data[i]); |
| 113 | if (ret) |
| 114 | return ret; |
| 115 | } |
| 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | LIB_TEST(lib_test_dynamic_uuid, 0); |