1 // SPDX-License-Identifier: GPL-2.0+
3 * efi_selftest_variables_runtime
5 * Copyright (c) 2019 Heinrich Schuchardt <xypron.glpk@gmx.de>
7 * This unit test checks the runtime services for variables after
9 * GetVariable, GetNextVariableName, SetVariable, QueryVariableInfo.
12 #include <efi_selftest.h>
14 #define EFI_ST_MAX_DATA_SIZE 16
15 #define EFI_ST_MAX_VARNAME_SIZE 40
17 static struct efi_boot_services *boottime;
18 static struct efi_runtime_services *runtime;
19 static const efi_guid_t guid_vendor0 =
20 EFI_GUID(0x67029eb5, 0x0af2, 0xf6b1,
21 0xda, 0x53, 0xfc, 0xb5, 0x66, 0xdd, 0x1c, 0xe6);
26 * @handle handle of the loaded image
27 * @systable system table
29 static int setup(const efi_handle_t img_handle,
30 const struct efi_system_table *systable)
32 boottime = systable->boottime;
33 runtime = systable->runtime;
35 return EFI_ST_SUCCESS;
39 * execute() - execute unit test
41 * As runtime support is not implmented expect EFI_UNSUPPORTED to be returned.
43 static int execute(void)
48 u8 v[16] = {0x5d, 0xd1, 0x5e, 0x51, 0x5a, 0x05, 0xc7, 0x0c,
49 0x35, 0x4a, 0xae, 0x87, 0xa5, 0xdf, 0x0f, 0x65,};
50 u8 data[EFI_ST_MAX_DATA_SIZE];
51 u16 varname[EFI_ST_MAX_VARNAME_SIZE];
53 u64 max_storage, rem_storage, max_size;
55 ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS,
56 &max_storage, &rem_storage,
58 if (ret != EFI_UNSUPPORTED) {
59 efi_st_error("QueryVariableInfo failed\n");
60 return EFI_ST_FAILURE;
63 ret = runtime->set_variable(L"efi_st_var0", &guid_vendor0,
64 EFI_VARIABLE_BOOTSERVICE_ACCESS |
65 EFI_VARIABLE_RUNTIME_ACCESS,
67 if (ret != EFI_UNSUPPORTED) {
68 efi_st_error("SetVariable failed\n");
69 return EFI_ST_FAILURE;
72 ret = runtime->get_variable(L"efi_st_var0", &guid_vendor0,
74 if (ret != EFI_UNSUPPORTED) {
75 efi_st_error("GetVariable failed\n");
76 return EFI_ST_FAILURE;
80 ret = runtime->get_next_variable_name(&len, varname, &guid);
81 if (ret != EFI_UNSUPPORTED) {
82 efi_st_error("GetNextVariableName failed\n");
83 return EFI_ST_FAILURE;
86 return EFI_ST_SUCCESS;
89 EFI_UNIT_TEST(variables_run) = {
90 .name = "variables at runtime",
91 .phase = EFI_SETUP_BEFORE_BOOTTIME_EXIT,