]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
efi_selftest: add tests for QueryVariableInfo at runtime
authorIlias Apalodimas <ilias.apalodimas@linaro.org>
Thu, 25 Apr 2024 05:18:20 +0000 (08:18 +0300)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Wed, 1 May 2024 06:39:16 +0000 (08:39 +0200)
Since we support QueryVariableInfo at runtime now add the relevant
tests. Since we want those to be reusable at bootime, add them
in a separate file

Add tests for
- Test QueryVariableInfo returns EFI_SUCCESS
- Test null pointers for the function arguments
- Test invalid combination of attributes

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
include/efi_selftest.h
lib/efi_selftest/Makefile
lib/efi_selftest/efi_selftest_variables_common.c [new file with mode: 0644]
lib/efi_selftest/efi_selftest_variables_runtime.c

index 5bcebb368287c50b5be1e4e52547703d010e39c4..1b708849bcb9f3b07995b399d996add754324b2e 100644 (file)
@@ -147,6 +147,17 @@ void *efi_st_get_config_table(const efi_guid_t *guid);
  */
 u16 efi_st_get_key(void);
 
+/**
+ * efi_st_query_variable_common - Common variable tests for boottime/runtime
+ *
+ * @runtime:   Pointer to services table
+ * @attributes: Attributes used
+ *
+ * Return:     EFI_ST_SUCCESS/FAILURE
+ */
+int efi_st_query_variable_common(struct efi_runtime_services *runtime,
+                                u32 attributes);
+
 /**
  * struct efi_unit_test - EFI unit test
  *
index e4d75420bff6ab4e37c4bb11f266ae879c5b9c06..414701893f6563fff8bf20fe3cf098d1d0aafaac 100644 (file)
@@ -45,6 +45,7 @@ efi_selftest_textinputex.o \
 efi_selftest_textoutput.o \
 efi_selftest_tpl.o \
 efi_selftest_util.o \
+efi_selftest_variables_common.o \
 efi_selftest_variables.o \
 efi_selftest_variables_runtime.o \
 efi_selftest_watchdog.o
diff --git a/lib/efi_selftest/efi_selftest_variables_common.c b/lib/efi_selftest/efi_selftest_variables_common.c
new file mode 100644 (file)
index 0000000..e29a4be
--- /dev/null
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * efi_selftest_variables_runtime
+ *
+ * Copyright (c) 2024 Ilias Apalodimas <ilias.apalodimas@linaro.org>
+ *
+ * This unit test checks common service across boottime/runtime
+ */
+
+#include <efi_selftest.h>
+
+#define EFI_INVALID_ATTR BIT(30)
+
+int efi_st_query_variable_common(struct efi_runtime_services *runtime,
+                                u32 attributes)
+{
+       efi_status_t ret;
+       u64 max_storage, rem_storage, max_size;
+
+       ret = runtime->query_variable_info(attributes,
+                                          &max_storage, &rem_storage,
+                                          &max_size);
+       if (ret != EFI_SUCCESS) {
+               efi_st_error("QueryVariableInfo failed\n");
+               return EFI_ST_FAILURE;
+       }
+
+       ret = runtime->query_variable_info(EFI_VARIABLE_RUNTIME_ACCESS,
+                                          &max_storage, &rem_storage,
+                                          &max_size);
+       if (ret != EFI_INVALID_PARAMETER) {
+               efi_st_error("QueryVariableInfo failed\n");
+               return EFI_ST_FAILURE;
+       }
+
+       ret = runtime->query_variable_info(attributes,
+                                          NULL, &rem_storage,
+                                          &max_size);
+       if (ret != EFI_INVALID_PARAMETER) {
+               efi_st_error("QueryVariableInfo failed\n");
+               return EFI_ST_FAILURE;
+       }
+
+       ret = runtime->query_variable_info(attributes,
+                                          &max_storage, NULL,
+                                          &max_size);
+       if (ret != EFI_INVALID_PARAMETER) {
+               efi_st_error("QueryVariableInfo failed\n");
+               return EFI_ST_FAILURE;
+       }
+
+       ret = runtime->query_variable_info(attributes,
+                                          &max_storage, &rem_storage,
+                                          NULL);
+       if (ret != EFI_INVALID_PARAMETER) {
+               efi_st_error("QueryVariableInfo failed\n");
+               return EFI_ST_FAILURE;
+       }
+
+       ret = runtime->query_variable_info(0, &max_storage, &rem_storage,
+                                          &max_size);
+       if (ret != EFI_INVALID_PARAMETER) {
+               efi_st_error("QueryVariableInfo failed\n");
+               return EFI_ST_FAILURE;
+       }
+
+       ret = runtime->query_variable_info(attributes |
+                                          EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS |
+                                          EFI_VARIABLE_NON_VOLATILE,
+                                          &max_storage, &rem_storage,
+                                          &max_size);
+       if (ret != EFI_UNSUPPORTED) {
+               efi_st_error("QueryVariableInfo failed\n");
+               return EFI_ST_FAILURE;
+       }
+
+       ret = runtime->query_variable_info(EFI_VARIABLE_NON_VOLATILE,
+                                          &max_storage, &rem_storage,
+                                          &max_size);
+       if (ret != EFI_INVALID_PARAMETER) {
+               efi_st_error("QueryVariableInfo failed\n");
+               return EFI_ST_FAILURE;
+       }
+
+       /*
+        * Use a mix existing/non-existing attribute bits from the
+        * UEFI spec
+        */
+       ret = runtime->query_variable_info(attributes | EFI_INVALID_ATTR |
+                                          EFI_VARIABLE_NON_VOLATILE,
+                                          &max_storage, &rem_storage,
+                                          &max_size);
+       if (ret != EFI_INVALID_PARAMETER) {
+               efi_st_error("QueryVariableInfo failed\n");
+               return EFI_ST_FAILURE;
+       }
+
+       return EFI_ST_SUCCESS;
+}
index 5794a7b2d40568c5728d89627b76f95501ae3648..379c4f9c47b73d58022c344330535fcd855e5193 100644 (file)
@@ -55,18 +55,21 @@ static int execute(void)
        u16 varname[EFI_ST_MAX_VARNAME_SIZE];
        efi_guid_t guid;
        u64 max_storage, rem_storage, max_size;
+       int test_ret;
 
        memset(v2, 0x1, sizeof(v2));
-       ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS,
-                                          &max_storage, &rem_storage,
-                                          &max_size);
 
        if (IS_ENABLED(CONFIG_EFI_VARIABLE_FILE_STORE)) {
-               if (ret != EFI_SUCCESS) {
+               test_ret = efi_st_query_variable_common(runtime, EFI_VARIABLE_BOOTSERVICE_ACCESS |
+                                                                EFI_VARIABLE_RUNTIME_ACCESS);
+               if (test_ret != EFI_ST_SUCCESS) {
                        efi_st_error("QueryVariableInfo failed\n");
                        return EFI_ST_FAILURE;
                }
        } else {
+               ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS,
+                                          &max_storage, &rem_storage,
+                                          &max_size);
                if (ret != EFI_UNSUPPORTED) {
                        efi_st_error("QueryVariableInfo failed\n");
                        return EFI_ST_FAILURE;