summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mock-variables.h9
-rw-r--r--mock-variables.c171
-rw-r--r--test-mock-variables.c421
3 files changed, 599 insertions, 2 deletions
diff --git a/include/mock-variables.h b/include/mock-variables.h
index fc276ce7..759fd1f0 100644
--- a/include/mock-variables.h
+++ b/include/mock-variables.h
@@ -21,6 +21,8 @@ EFI_STATUS EFIAPI mock_query_variable_info(UINT32 attrs,
UINT64 *remaining_var_storage,
UINT64 *max_var_size);
+EFI_STATUS EFIAPI mock_install_configuration_table(EFI_GUID *guid, VOID *table);
+
struct mock_variable_limits {
UINT32 attrs;
UINT64 *max_var_storage;
@@ -40,6 +42,7 @@ typedef enum {
} mock_sort_policy_t;
extern mock_sort_policy_t mock_variable_sort_policy;
+extern mock_sort_policy_t mock_config_table_sort_policy;
#define MOCK_VAR_DELETE_ATTR_ALLOW_ZERO 0x01
#define MOCK_VAR_DELETE_ATTR_ALOW_MISMATCH 0x02
@@ -110,7 +113,8 @@ void mock_load_variables(const char *const dirname, const char *filters[],
void mock_install_query_variable_info(void);
void mock_uninstall_query_variable_info(void);
void mock_reset_variables(void);
-void mock_finalize_vars(void);
+void mock_reset_config_table(void);
+void mock_finalize_vars_and_configs(void);
typedef enum {
NONE = 0,
@@ -171,5 +175,8 @@ typedef void (mock_query_variable_info_post_hook_t)(
const int line, const char * const func);
extern mock_query_variable_info_post_hook_t *mock_query_variable_info_post_hook;
+#define MOCK_CONFIG_TABLE_ENTRIES 1024
+extern EFI_CONFIGURATION_TABLE mock_config_table[MOCK_CONFIG_TABLE_ENTRIES];
+
#endif /* !SHIM_MOCK_VARIABLES_H_ */
// vim:fenc=utf-8:tw=75:noet
diff --git a/mock-variables.c b/mock-variables.c
index 6a9a9dea..e9bce544 100644
--- a/mock-variables.c
+++ b/mock-variables.c
@@ -26,6 +26,7 @@ list_t *mock_sv_limits = &mock_default_variable_limits;
list_t mock_variables = LIST_HEAD_INIT(mock_variables);
mock_sort_policy_t mock_variable_sort_policy = MOCK_SORT_APPEND;
+mock_sort_policy_t mock_config_table_sort_policy = MOCK_SORT_APPEND;
UINT32 mock_variable_delete_attr_policy;
@@ -1165,6 +1166,140 @@ mock_uninstall_query_variable_info(void)
RT->QueryVariableInfo = mock_efi_unsupported;
}
+EFI_CONFIGURATION_TABLE mock_config_table[MOCK_CONFIG_TABLE_ENTRIES] = {
+ {
+ .VendorGuid = { 0, },
+ .VendorTable = NULL
+ },
+};
+
+int
+mock_config_table_cmp(const void *p0, const void *p1)
+{
+ EFI_CONFIGURATION_TABLE *entry0, *entry1;
+ long cmp;
+
+ if (!p0 || !p1) {
+ cmp = (int)((intptr_t)p0 - (intptr_t)p1);
+ } else {
+ entry0 = (EFI_CONFIGURATION_TABLE *)p0;
+ entry1 = (EFI_CONFIGURATION_TABLE *)p1;
+#if (defined(SHIM_DEBUG) && SHIM_DEBUG != 0)
+ printf("comparing %p to %p\n", p0, p1);
+#endif
+ cmp = CompareGuid(&entry0->VendorGuid, &entry1->VendorGuid);
+ }
+
+ if (mock_config_table_sort_policy == MOCK_SORT_DESCENDING) {
+ cmp = -cmp;
+ }
+
+ return cmp;
+}
+
+EFI_STATUS EFIAPI
+mock_install_configuration_table(EFI_GUID *guid, VOID *table)
+{
+ bool found = false;
+ EFI_CONFIGURATION_TABLE *entry;
+ int idx = 0;
+ size_t sz;
+
+ if (!guid)
+ return EFI_INVALID_PARAMETER;
+
+ for (UINTN i = 0; i < ST->NumberOfTableEntries; i++) {
+ EFI_CONFIGURATION_TABLE *entry = &ST->ConfigurationTable[i];
+
+ if (CompareGuid(guid, &entry->VendorGuid) == 0) {
+ found = true;
+ if (table) {
+ // replace it
+ entry->VendorTable = table;
+ } else {
+ // delete it
+ ST->NumberOfTableEntries -= 1;
+ sz = ST->NumberOfTableEntries - i;
+ sz *= sizeof(*entry);
+ memmove(&entry[0], &entry[1], sz);
+ }
+ return EFI_SUCCESS;
+ }
+ }
+ if (!found && table == NULL)
+ return EFI_NOT_FOUND;
+ if (ST->NumberOfTableEntries == MOCK_CONFIG_TABLE_ENTRIES - 1) {
+ /*
+ * If necessary, we could allocate another table and copy
+ * the data, but I'm lazy and we probably don't need to.
+ */
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ switch (mock_config_table_sort_policy) {
+ case MOCK_SORT_DESCENDING:
+ case MOCK_SORT_ASCENDING:
+ case MOCK_SORT_APPEND:
+ idx = ST->NumberOfTableEntries;
+ break;
+ case MOCK_SORT_PREPEND:
+ sz = ST->NumberOfTableEntries ? ST->NumberOfTableEntries : 0;
+ sz *= sizeof(ST->ConfigurationTable[0]);
+ memmove(&ST->ConfigurationTable[1], &ST->ConfigurationTable[0], sz);
+ idx = 0;
+ break;
+ default:
+ break;
+ }
+
+ entry = &ST->ConfigurationTable[idx];
+ memcpy(&entry->VendorGuid, guid, sizeof(EFI_GUID));
+ entry->VendorTable = table;
+#if (defined(SHIM_DEBUG) && SHIM_DEBUG != 0)
+ printf("%s:%d:%s(): installing entry %p={%p,%p} as entry %d\n",
+ __FILE__, __LINE__, __func__,
+ entry, &entry->VendorGuid, entry->VendorTable, idx);
+#endif
+ ST->NumberOfTableEntries += 1;
+
+#if (defined(SHIM_DEBUG) && SHIM_DEBUG != 0)
+ printf("%s:%d:%s():ST->ConfigurationTable:%p\n"
+ "\t[%d]:%p\n"
+ "\t[%d]:%p\n",
+ __FILE__, __LINE__, __func__, ST->ConfigurationTable,
+ 0, &ST->ConfigurationTable[0],
+ 1, &ST->ConfigurationTable[1]);
+#endif
+ switch (mock_config_table_sort_policy) {
+ case MOCK_SORT_DESCENDING:
+ case MOCK_SORT_ASCENDING:
+#if (defined(SHIM_DEBUG) && SHIM_DEBUG != 0)
+ printf("%s:%d:%s(): entries before sorting:\n", __FILE__, __LINE__, __func__);
+ for (UINTN i = 0; i < ST->NumberOfTableEntries; i++) {
+ printf("\t[%d] = %p = {", i, &ST->ConfigurationTable[i]);
+ printf(".VendorGuid=" GUID_FMT, GUID_ARGS(ST->ConfigurationTable[i].VendorGuid));
+ printf(".VendorTable=%p}\n", ST->ConfigurationTable[i].VendorTable);
+ }
+#endif
+ qsort(&ST->ConfigurationTable[0], ST->NumberOfTableEntries,
+ sizeof(ST->ConfigurationTable[0]),
+ mock_config_table_cmp);
+ break;
+ default:
+ break;
+ }
+#if (defined(SHIM_DEBUG) && SHIM_DEBUG != 0)
+ printf("%s:%d:%s(): entries:\n", __FILE__, __LINE__, __func__);
+ for (UINTN i = 0; i < ST->NumberOfTableEntries; i++) {
+ printf("\t[%d] = %p = {", i, &ST->ConfigurationTable[i]);
+ printf(".VendorGuid=" GUID_FMT, GUID_ARGS(ST->ConfigurationTable[i].VendorGuid));
+ printf(".VendorTable=%p}\n", ST->ConfigurationTable[i].VendorTable);
+ }
+#endif
+
+ return EFI_SUCCESS;
+}
+
void CONSTRUCTOR
mock_reset_variables(void)
{
@@ -1222,10 +1357,44 @@ mock_reset_variables(void)
mock_uninstall_query_variable_info();
}
+void CONSTRUCTOR
+mock_reset_config_table(void)
+{
+ init_efi_system_table();
+
+ /*
+ * Note that BS->InstallConfigurationTable() is *not* defined as
+ * freeing these. If a test case installs non-malloc()ed tables,
+ * it needs to call BS->InstallConfigurationTable(guid, NULL) to
+ * clear them.
+ */
+ for (UINTN i = 0; i < ST->NumberOfTableEntries; i++) {
+ EFI_CONFIGURATION_TABLE *entry = &ST->ConfigurationTable[i];
+
+ if (entry->VendorTable)
+ free(entry->VendorTable);
+ }
+
+ SetMem(ST->ConfigurationTable,
+ ST->NumberOfTableEntries * sizeof(EFI_CONFIGURATION_TABLE),
+ 0);
+
+ ST->NumberOfTableEntries = 0;
+
+ if (ST->ConfigurationTable != mock_config_table) {
+ free(ST->ConfigurationTable);
+ ST->ConfigurationTable = mock_config_table;
+ SetMem(mock_config_table, sizeof(mock_config_table), 0);
+ }
+
+ BS->InstallConfigurationTable = mock_install_configuration_table;
+}
+
void DESTRUCTOR
-mock_finalize_vars(void)
+mock_finalize_vars_and_configs(void)
{
mock_reset_variables();
+ mock_reset_config_table();
}
// vim:fenc=utf-8:tw=75:noet
diff --git a/test-mock-variables.c b/test-mock-variables.c
index 5ea5a981..c7e42b05 100644
--- a/test-mock-variables.c
+++ b/test-mock-variables.c
@@ -8,6 +8,7 @@
#include "mock-variables.h"
#include <errno.h>
+#include <efivar/efivar.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
@@ -16,6 +17,8 @@
#pragma GCC diagnostic ignored "-Wunused-label"
+static const size_t guidstr_size = sizeof("8be4df61-93ca-11d2-aa0d-00e098032b8c");
+
void mock_print_guidname(EFI_GUID *guid, CHAR16 *name);
void mock_print_var_list(list_t *head);
@@ -386,6 +389,421 @@ err:
return ret;
}
+static void
+dump_config_table_if_wrong(const char * const func, int line, ...)
+{
+ va_list alist, blist;
+ bool okay = true;
+ size_t n = 0, m = 0;
+
+ va_start(alist, line);
+ va_copy(blist, alist);
+
+ int idx = va_arg(alist, int);
+ EFI_GUID *guid = va_arg(alist, EFI_GUID *);
+ while (idx >= 0 && guid != NULL) {
+ EFI_CONFIGURATION_TABLE *entry;
+ if (idx < 0)
+ goto nexta;
+
+ n += 1;
+ if (idx >= (int)ST->NumberOfTableEntries) {
+ okay = false;
+ goto nexta;
+ }
+
+ entry = &ST->ConfigurationTable[idx];
+ if (CompareGuid(guid, &entry->VendorGuid) != 0)
+ okay = false;
+
+nexta:
+ idx = va_arg(alist, int);
+ guid = va_arg(alist, EFI_GUID *);
+ }
+ va_end(alist);
+
+ if (okay)
+ return;
+
+ printf("%s:%d:%s(): %d entries:\n", __FILE__, line, func, ST->NumberOfTableEntries);
+ idx = va_arg(blist, int);
+ guid = va_arg(blist, EFI_GUID *);
+ while (idx >= 0 && guid != NULL) {
+ EFI_CONFIGURATION_TABLE *entry;
+
+ if (idx >= (int)ST->NumberOfTableEntries) {
+ printf("\t[%d]: invalid index for " GUID_FMT "\n",
+ idx, GUID_ARGS(*guid));
+ goto nexta;
+ }
+
+ if (idx < 0) {
+ printf("\t[%d]: " GUID_FMT "\n", idx, GUID_ARGS(*guid));
+ } else {
+ entry = &ST->ConfigurationTable[idx];
+ printf("\t[%d]: %p ", idx, entry);
+ printf("{.VendorGuid:" GUID_FMT ",", GUID_ARGS(entry->VendorGuid));
+ printf("&.VendorTable:%p}\n", entry->VendorTable);
+ if (CompareGuid(guid, &entry->VendorGuid) != 0)
+ printf("\t\t\t expected:" GUID_FMT "\n", GUID_ARGS(*guid));
+ }
+next:
+ idx = va_arg(blist, int);
+ guid = va_arg(blist, EFI_GUID *);
+ }
+ va_end(blist);
+
+ if ((int)ST->NumberOfTableEntries - n == 0)
+ return;
+
+ printf("%d extra table entries:\n", ST->NumberOfTableEntries - n);
+ for (m = n; m < ST->NumberOfTableEntries; m++) {
+ EFI_CONFIGURATION_TABLE *entry;
+
+ entry = &ST->ConfigurationTable[m];
+
+ printf("\t[%d]: %p ", m, entry);
+ printf("{.VendorGuid:" GUID_FMT ",", GUID_ARGS(entry->VendorGuid));
+ printf("&.VendorTable:%p}\n", entry->VendorTable);
+ }
+}
+
+static int
+test_install_config_table_0(void)
+{
+ int ret = -1;
+ EFI_STATUS status;
+
+ /*
+ * These three guids are chosen on purpose: they start with "a",
+ * "b", and "c", respective to their variable names, so you can
+ * identify them when dumped.
+ */
+ EFI_GUID aguid = SECURITY_PROTOCOL_GUID;
+ char astr[guidstr_size];
+ void *astrp = &astr[0];
+ int aidx = -1;
+
+ EFI_GUID bguid = EFI_HTTP_BINDING_GUID;
+ char bstr[guidstr_size];
+ void *bstrp = &bstr[0];
+ int bidx = -1;
+
+ EFI_GUID cguid = MOK_VARIABLE_STORE;
+ char cstr[guidstr_size];
+ void *cstrp = &cstr[0];
+ int cidx = -1;
+
+ EFI_GUID lip = LOADED_IMAGE_PROTOCOL;
+
+ EFI_GUID guids[3];
+
+ char tmpstr[guidstr_size];
+
+ sprintf(astrp, GUID_FMT, GUID_ARGS(aguid));
+ sprintf(bstrp, GUID_FMT, GUID_ARGS(bguid));
+ sprintf(cstrp, GUID_FMT, GUID_ARGS(cguid));
+
+ assert_equal_return(ST->NumberOfTableEntries, 0, -1, "%lu != %lu\n");
+
+ /*
+ * test installing one
+ */
+ status = BS->InstallConfigurationTable(&bguid, bstrp);
+ assert_equal_return(status, EFI_SUCCESS, -1, "%lx != %lx\n");
+ assert_equal_goto(ST->NumberOfTableEntries, 1, err, "%lu != %lu\n");
+
+ sprintf(tmpstr, GUID_FMT, GUID_ARGS(ST->ConfigurationTable[0].VendorGuid));
+ assert_zero_goto(CompareGuid(&ST->ConfigurationTable[0].VendorGuid, &bguid),
+ err, "%d != 0 (%s != %s)\n", tmpstr, bstr);
+ assert_equal_goto(ST->ConfigurationTable[0].VendorTable,
+ bstrp, err, "%p != %p\n");
+
+ /*
+ * test re-installing the same one
+ */
+ status = BS->InstallConfigurationTable(&bguid, bstrp);
+ assert_equal_goto(status, EFI_SUCCESS, err, "%lx != %lx\n");
+ assert_equal_goto(ST->NumberOfTableEntries, 1, err, "%lu != %lu\n");
+
+ sprintf(tmpstr, GUID_FMT, GUID_ARGS(ST->ConfigurationTable[0].VendorGuid));
+ assert_zero_goto(CompareGuid(&ST->ConfigurationTable[0].VendorGuid, &bguid),
+ err, "%d != 0 (%s != %s)\n", tmpstr, bstr);
+ assert_equal_goto(ST->ConfigurationTable[0].VendorTable,
+ bstrp, err, "%p != %p\n");
+
+ /*
+ * Test installing a second one
+ */
+ status = BS->InstallConfigurationTable(&aguid, astrp);
+ assert_equal_goto(status, EFI_SUCCESS, err, "%lx != %lx\n");
+ assert_equal_goto(ST->NumberOfTableEntries, 2, err, "%lu != %lu\n");
+
+ switch (mock_config_table_sort_policy) {
+ case MOCK_SORT_DESCENDING:
+ aidx = 1;
+ bidx = 0;
+ break;
+ case MOCK_SORT_PREPEND:
+ aidx = 0;
+ bidx = 1;
+ break;
+ case MOCK_SORT_APPEND:
+ aidx = 1;
+ bidx = 0;
+ break;
+ case MOCK_SORT_ASCENDING:
+ aidx = 0;
+ bidx = 1;
+ break;
+ default:
+ break;
+ }
+
+ dump_config_table_if_wrong(__func__, __LINE__,
+ aidx, &aguid,
+ bidx, &bguid,
+ cidx, &cguid,
+ -1, NULL);
+
+ sprintf(tmpstr, GUID_FMT, GUID_ARGS(ST->ConfigurationTable[aidx].VendorGuid));
+ assert_zero_goto(CompareGuid(&ST->ConfigurationTable[aidx].VendorGuid, &aguid),
+ err, "%d != 0 (%s != %s)\n", tmpstr, astr);
+ assert_equal_goto(ST->ConfigurationTable[aidx].VendorTable, astrp,
+ err, "%p != %p\n");
+
+ sprintf(tmpstr, GUID_FMT, GUID_ARGS(ST->ConfigurationTable[bidx].VendorGuid));
+ assert_zero_goto(CompareGuid(&ST->ConfigurationTable[bidx].VendorGuid, &bguid),
+ err, "%d != 0 (%s != %s)\n", tmpstr, bstr);
+ assert_equal_goto(ST->ConfigurationTable[bidx].VendorTable, bstrp,
+ err, "%p != %p\n");
+
+ /*
+ * Test installing a third one
+ */
+ status = BS->InstallConfigurationTable(&cguid, cstrp);
+ assert_equal_goto(status, EFI_SUCCESS, err, "%lx != %lx\n");
+ assert_equal_goto(ST->NumberOfTableEntries, 3, err, "%lu != %lu\n");
+
+ switch (mock_config_table_sort_policy) {
+ case MOCK_SORT_DESCENDING:
+ aidx = 2;
+ bidx = 1;
+ cidx = 0;
+ break;
+ case MOCK_SORT_PREPEND:
+ aidx = 1;
+ bidx = 2;
+ cidx = 0;
+ break;
+ case MOCK_SORT_APPEND:
+ aidx = 1;
+ bidx = 0;
+ cidx = 2;
+ break;
+ case MOCK_SORT_ASCENDING:
+ aidx = 0;
+ bidx = 1;
+ cidx = 2;
+ break;
+ default:
+ break;
+ }
+
+ dump_config_table_if_wrong(__func__, __LINE__,
+ aidx, &aguid,
+ bidx, &bguid,
+ cidx, &cguid,
+ -1, NULL);
+
+ sprintf(tmpstr, GUID_FMT, GUID_ARGS(ST->ConfigurationTable[aidx].VendorGuid));
+ assert_zero_goto(CompareGuid(&ST->ConfigurationTable[aidx].VendorGuid, &aguid),
+ err, "%d != 0 (%s != %s)\n", tmpstr, astr);
+ assert_equal_goto(ST->ConfigurationTable[aidx].VendorTable, astrp,
+ err, "%p != %p\n");
+ memcpy(&guids[aidx], &aguid, sizeof(EFI_GUID));
+
+ sprintf(tmpstr, GUID_FMT, GUID_ARGS(ST->ConfigurationTable[bidx].VendorGuid));
+ assert_zero_goto(CompareGuid(&ST->ConfigurationTable[bidx].VendorGuid, &bguid),
+ err, "%d != 0 (%s != %s)\n", tmpstr, bstr);
+ assert_equal_goto(ST->ConfigurationTable[bidx].VendorTable, bstrp,
+ err, "%p != %p\n");
+ memcpy(&guids[bidx], &bguid, sizeof(EFI_GUID));
+
+ sprintf(tmpstr, GUID_FMT, GUID_ARGS(ST->ConfigurationTable[cidx].VendorGuid));
+ assert_zero_goto(CompareGuid(&ST->ConfigurationTable[cidx].VendorGuid, &cguid),
+ err, "%d != 0 (%s != %s)\n", tmpstr, cstr);
+ assert_equal_goto(ST->ConfigurationTable[cidx].VendorTable, cstrp,
+ err, "%p != %p\n");
+ memcpy(&guids[cidx], &cguid, sizeof(EFI_GUID));
+
+ /*
+ * Test removing NULL guid
+ */
+ status = BS->InstallConfigurationTable(NULL, NULL);
+ assert_equal_goto(status, EFI_INVALID_PARAMETER, err, "%lx != %lx\n");
+ assert_equal_goto(ST->NumberOfTableEntries, 3, err, "%lu != %lu\n");
+
+ /*
+ * Test removing a guid that's not present
+ */
+ status = BS->InstallConfigurationTable(&lip, NULL);
+ assert_equal_goto(status, EFI_NOT_FOUND, err, "%lx != %lx\n");
+ assert_equal_goto(ST->NumberOfTableEntries, 3, err, "%lu != %lu\n");
+
+ /*
+ * Test removing the middle one
+ */
+ status = BS->InstallConfigurationTable(&guids[1], NULL);
+ assert_equal_goto(status, EFI_SUCCESS, err, "%lx != %lx\n");
+ assert_equal_goto(ST->NumberOfTableEntries, 2, err, "%lu != %lu\n");
+
+ switch (mock_config_table_sort_policy) {
+ case MOCK_SORT_DESCENDING:
+ aidx = 1;
+ bidx = -1;
+ cidx = 0;
+ break;
+ case MOCK_SORT_PREPEND:
+ aidx = -1;
+ bidx = 1;
+ cidx = 0;
+ break;
+ case MOCK_SORT_APPEND:
+ aidx = -1;
+ bidx = 0;
+ cidx = 1;
+ break;
+ case MOCK_SORT_ASCENDING:
+ aidx = 0;
+ bidx = -1;
+ cidx = 1;
+ break;
+ default:
+ break;
+ }
+
+ dump_config_table_if_wrong(__func__, __LINE__,
+ aidx, &aguid,
+ bidx, &bguid,
+ cidx, &cguid,
+ -1, NULL);
+
+ if (aidx >= 0) {
+ sprintf(tmpstr, GUID_FMT, GUID_ARGS(ST->ConfigurationTable[aidx].VendorGuid));
+ assert_zero_goto(CompareGuid(&ST->ConfigurationTable[aidx].VendorGuid, &aguid),
+ err, "%d != 0 (%s != %s)\n", tmpstr, astr);
+ assert_equal_goto(ST->ConfigurationTable[aidx].VendorTable, astrp,
+ err, "%p != %p\n");
+ memcpy(&guids[aidx], &aguid, sizeof(EFI_GUID));
+ }
+
+ if (bidx >= 0) {
+ sprintf(tmpstr, GUID_FMT, GUID_ARGS(ST->ConfigurationTable[bidx].VendorGuid));
+ assert_zero_goto(CompareGuid(&ST->ConfigurationTable[bidx].VendorGuid, &bguid),
+ err, "%d != 0 (%s != %s)\n", tmpstr, bstr);
+ assert_equal_goto(ST->ConfigurationTable[bidx].VendorTable, bstrp,
+ err, "%p != %p\n");
+ memcpy(&guids[bidx], &bguid, sizeof(EFI_GUID));
+ }
+
+ if (cidx >= 0) {
+ sprintf(tmpstr, GUID_FMT, GUID_ARGS(ST->ConfigurationTable[cidx].VendorGuid));
+ assert_zero_goto(CompareGuid(&ST->ConfigurationTable[cidx].VendorGuid, &cguid),
+ err, "%d != 0 (%s != %s)\n", tmpstr, cstr);
+ assert_equal_goto(ST->ConfigurationTable[cidx].VendorTable, cstrp,
+ err, "%p != %p\n");
+ memcpy(&guids[cidx], &cguid, sizeof(EFI_GUID));
+ }
+
+ /*
+ * Test removing the lowest one
+ */
+ status = BS->InstallConfigurationTable(&guids[0], NULL);
+ assert_equal_goto(status, EFI_SUCCESS, err, "%lx != %lx\n");
+ assert_equal_goto(ST->NumberOfTableEntries, 1, err, "%lu != %lu\n");
+
+ switch (mock_config_table_sort_policy) {
+ case MOCK_SORT_DESCENDING:
+ aidx = 0;
+ bidx = -1;
+ cidx = -1;
+ break;
+ case MOCK_SORT_PREPEND:
+ aidx = -1;
+ bidx = 0;
+ cidx = -1;
+ break;
+ case MOCK_SORT_APPEND:
+ aidx = -1;
+ bidx = -1;
+ cidx = 0;
+ break;
+ case MOCK_SORT_ASCENDING:
+ aidx = -1;
+ bidx = -1;
+ cidx = 0;
+ break;
+ default:
+ break;
+ }
+
+ dump_config_table_if_wrong(__func__, __LINE__,
+ aidx, &aguid,
+ bidx, &bguid,
+ cidx, &cguid,
+ -1, NULL);
+
+ if (aidx >= 0) {
+ sprintf(tmpstr, GUID_FMT, GUID_ARGS(ST->ConfigurationTable[aidx].VendorGuid));
+ assert_zero_goto(CompareGuid(&ST->ConfigurationTable[aidx].VendorGuid, &aguid),
+ err, "%d != 0 (%s != %s)\n", tmpstr, astr);
+ assert_equal_goto(ST->ConfigurationTable[aidx].VendorTable, astrp,
+ err, "%p != %p\n");
+ memcpy(&guids[aidx], &aguid, sizeof(EFI_GUID));
+ }
+
+ if (bidx >= 0) {
+ sprintf(tmpstr, GUID_FMT, GUID_ARGS(ST->ConfigurationTable[bidx].VendorGuid));
+ assert_zero_goto(CompareGuid(&ST->ConfigurationTable[bidx].VendorGuid, &bguid),
+ err, "%d != 0 (%s != %s)\n", tmpstr, bstr);
+ assert_equal_goto(ST->ConfigurationTable[bidx].VendorTable, bstrp,
+ err, "%p != %p\n");
+ memcpy(&guids[bidx], &bguid, sizeof(EFI_GUID));
+ }
+
+ if (cidx >= 0) {
+ sprintf(tmpstr, GUID_FMT, GUID_ARGS(ST->ConfigurationTable[cidx].VendorGuid));
+ assert_zero_goto(CompareGuid(&ST->ConfigurationTable[cidx].VendorGuid, &cguid),
+ err, "%d != 0 (%s != %s)\n", tmpstr, cstr);
+ assert_equal_goto(ST->ConfigurationTable[cidx].VendorTable, cstrp,
+ err, "%p != %p\n");
+ memcpy(&guids[cidx], &cguid, sizeof(EFI_GUID));
+ }
+
+ /*
+ * Test removing the last one
+ */
+ status = BS->InstallConfigurationTable(&guids[0], NULL);
+ assert_equal_goto(status, EFI_SUCCESS, err, "%lx != %lx\n");
+ assert_equal_goto(ST->NumberOfTableEntries, 0, err, "%lu != %lu\n");
+
+ /*
+ * Test removing it again
+ */
+ status = BS->InstallConfigurationTable(&guids[0], NULL);
+ assert_equal_goto(status, EFI_NOT_FOUND, err, "%lx != %lx\n");
+ assert_equal_goto(ST->NumberOfTableEntries, 0, err, "%lu != %lu\n");
+
+ ret = 0;
+err:
+ while (ST->NumberOfTableEntries)
+ BS->InstallConfigurationTable(&ST->ConfigurationTable[0].VendorGuid, NULL);
+ mock_reset_config_table();
+
+ return ret;
+}
+
int
main(void)
{
@@ -405,12 +823,15 @@ main(void)
for (int i = 0; i < MOCK_SORT_MAX_SENTINEL; i++) {
mock_variable_sort_policy = i;
+ mock_config_table_sort_policy = i;
printf("%s: setting variable sort policy to %s\n",
program_invocation_short_name, policies[i]);
test(test_gnvn_buf_size_0);
test(test_gnvn_0);
test(test_gnvn_1);
+
+ test(test_install_config_table_0);
}
test(test_get_variable_0);