Enhance the HII selftest to cause string table reallocation with
set_string().

The test method is the following:
1. Add string packages with two strings for en-US, and only one string
   for fr-FR.
2. Set string 2 for fr-FR, causing reallocation of the string table.
3. Get string 2 again, to verify that we did not forget the new string
   table size.

This can be tested on the sandbox with the following command:

  ./u-boot -T -c "setenv efi_selftest HII database protocols; \
                  bootefi selftest"

Signed-off-by: Vincent Stehlé <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Tom Rini <[email protected]>
---
 lib/efi_selftest/efi_selftest_hii.c      | 44 ++++++++++++++++++++++++++
 lib/efi_selftest/efi_selftest_hii_data.c | 53 ++++++++++++++++++++++++++++++++
 2 files changed, 97 insertions(+)

diff --git a/lib/efi_selftest/efi_selftest_hii.c 
b/lib/efi_selftest/efi_selftest_hii.c
index fdbb08fb417..2d7151b638f 100644
--- a/lib/efi_selftest/efi_selftest_hii.c
+++ b/lib/efi_selftest/efi_selftest_hii.c
@@ -820,6 +820,8 @@ static int test_hii_string_set_string(void)
        efi_string_id_t id;
        efi_status_t ret;
        int result = EFI_ST_FAILURE;
+       u16 string[32];
+       efi_uintn_t string_size;
 
        PRINT_TESTNAME;
        ret = hii_database_protocol->new_package_list(hii_database_protocol,
@@ -849,6 +851,48 @@ static int test_hii_string_set_string(void)
                goto out;
        }
 
+       ret = hii_database_protocol->remove_package_list(hii_database_protocol,
+                                                        handle);
+       if (ret != EFI_SUCCESS) {
+               efi_st_error("remove_package_list returned %u\n",
+                            (unsigned int)ret);
+               return EFI_ST_FAILURE;
+       }
+
+       /*
+        * Test the reallocation path.
+        * We create string 2 in package fr-FR, which has only one string.
+        * This forces the reallocation of the string table.
+        * Then we read string 2 again, to verify that we did not forget the
+        * size of the string table.
+        */
+       ret = hii_database_protocol->new_package_list(hii_database_protocol,
+                       (struct efi_hii_package_list_header *)packagelist3,
+                       NULL, &handle);
+       if (ret != EFI_SUCCESS || !handle) {
+               efi_st_error("new_package_list returned %u\n",
+                            (unsigned int)ret);
+               return EFI_ST_FAILURE;
+       }
+
+       ret = hii_string_protocol->set_string(hii_string_protocol, handle, 2,
+                                             (u8 *)"fr-FR", u"Realloc", NULL);
+       if (ret != EFI_SUCCESS) {
+               efi_st_error("set_string returned %u\n",
+                            (unsigned int)ret);
+               goto out;
+       }
+
+       string_size = sizeof(string);
+       ret = hii_string_protocol->get_string(hii_string_protocol,
+                                             (u8 *)"fr-FR", handle, 2, string,
+                                             &string_size, NULL);
+       if (ret != EFI_SUCCESS) {
+               efi_st_error("get_string returned %u\n",
+                            (unsigned int)ret);
+               goto out;
+       }
+
        result = EFI_ST_SUCCESS;
 
 out:
diff --git a/lib/efi_selftest/efi_selftest_hii_data.c 
b/lib/efi_selftest/efi_selftest_hii_data.c
index 2d29bb045d3..7ab70c61148 100644
--- a/lib/efi_selftest/efi_selftest_hii_data.c
+++ b/lib/efi_selftest/efi_selftest_hii_data.c
@@ -424,6 +424,59 @@ static u8 packagelist2[] = {
        EFI_HII_PACKAGE_END                     // 1
 };
 
+/*
+ * This package list is meant for testing the reallocation path of 
set_string().
+ * It contains two strings in en-US and only one string in fr-FR.
+ */
+static u8 packagelist3[] = {
+       // EFI_HII_PACKAGE_LIST_HEADER, length = 20
+       0xd3, 0xde, 0x85, 0x86, 0xce, 0x1b, 0xf3, 0x43,
+       0xa2, 0x0c, 0xa3, 0x06, 0xec, 0x69, 0x72, 0xdd, //16
+       0xad, 0x00, 0x00, 0x00,                         // 4: total 173
+       //
+       // EFI_HII_PACKAGE_STRINGS, length = 77
+       //
+       0x4d, 0x00, 0x00,                               // 3: length(header)
+       EFI_HII_PACKAGE_STRINGS,                        // 1: type(header)
+       0x34, 0x00, 0x00, 0x00,                         // 4: header_size
+       0x34, 0x00, 0x00, 0x00,                         // 4: string_offset
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //32: language_window
+       0x01, 0x00,                                     // 2: language name
+       0x65, 0x6e, 0x2d, 0x55, 0x53, 0x00,             // 6: language "en-US"
+       EFI_HII_SIBT_STRING_UCS2,                       // 1
+       0x45, 0x00, 0x6E, 0x00, 0x67, 0x00, 0x6C, 0x00,
+       0x69, 0x00, 0x73, 0x00, 0x68, 0x00, 0x00, 0x00, //16: "English"
+       EFI_HII_SIBT_STRING_UCS2,                       // 1
+       0x55, 0x00, 0x53, 0x00, 0x00, 0x00,             // 6: "US"
+       EFI_HII_SIBT_END,                               // 1
+       //
+       // EFI_HII_PACKAGE_STRINGS, length = 72
+       //
+       0x48, 0x00, 0x00,                               // 3: length(header)
+       EFI_HII_PACKAGE_STRINGS,                        // 1: type(header)
+       0x34, 0x00, 0x00, 0x00,                         // 4: header_size
+       0x34, 0x00, 0x00, 0x00,                         // 4: string_offset
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //32: language_window
+       0x01, 0x00,                                     // 2: language name
+       0x66, 0x72, 0x2d, 0x46, 0x52, 0x00,             // 6: language "fr-FR"
+       EFI_HII_SIBT_STRING_UCS2,                       // 1
+       0x46, 0x00, 0x72, 0x00, 0x61, 0x00, 0x6e, 0x00,
+       0xe7, 0x00, 0x61, 0x00, 0x69, 0x00, 0x73, 0x00,
+       0x00, 0x00,                                     //18: "Français"
+       EFI_HII_SIBT_END,                               // 1
+       //
+       // End of package list, length = 4
+       //
+       0x4, 0x00, 0x00,                                // 3
+       EFI_HII_PACKAGE_END                             // 1
+};
+
 static efi_guid_t kb_layout_guid11 =
        EFI_GUID(0x8d40e495, 0xe2aa, 0x4c6f,
                 0x89, 0x70, 0x68, 0x85, 0x09, 0xee, 0xc7, 0xd2);

-- 
2.53.0

Reply via email to