blob: 4700d9424105cb0401c2e8611137a7aa0d07c246 [file] [log] [blame]
Heinrich Schuchardtc0267f92019-06-20 16:18:48 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * efi_selftest_variables_runtime
4 *
5 * Copyright (c) 2019 Heinrich Schuchardt <xypron.glpk@gmx.de>
6 *
7 * This unit test checks the runtime services for variables after
8 * ExitBootServices():
9 * GetVariable, GetNextVariableName, SetVariable, QueryVariableInfo.
10 */
11
12#include <efi_selftest.h>
13
14#define EFI_ST_MAX_DATA_SIZE 16
15#define EFI_ST_MAX_VARNAME_SIZE 40
16
17static struct efi_boot_services *boottime;
18static struct efi_runtime_services *runtime;
Heinrich Schuchardtfd956fc2020-07-06 17:06:07 +020019static const efi_guid_t guid_vendor0 = EFI_GLOBAL_VARIABLE_GUID;
Heinrich Schuchardtc0267f92019-06-20 16:18:48 +020020
21/*
22 * Setup unit test.
23 *
24 * @handle handle of the loaded image
25 * @systable system table
26 */
27static int setup(const efi_handle_t img_handle,
28 const struct efi_system_table *systable)
29{
30 boottime = systable->boottime;
31 runtime = systable->runtime;
32
33 return EFI_ST_SUCCESS;
34}
35
36/**
37 * execute() - execute unit test
38 *
39 * As runtime support is not implmented expect EFI_UNSUPPORTED to be returned.
40 */
41static int execute(void)
42{
43 efi_status_t ret;
44 efi_uintn_t len;
45 u32 attr;
46 u8 v[16] = {0x5d, 0xd1, 0x5e, 0x51, 0x5a, 0x05, 0xc7, 0x0c,
47 0x35, 0x4a, 0xae, 0x87, 0xa5, 0xdf, 0x0f, 0x65,};
48 u8 data[EFI_ST_MAX_DATA_SIZE];
49 u16 varname[EFI_ST_MAX_VARNAME_SIZE];
50 efi_guid_t guid;
51 u64 max_storage, rem_storage, max_size;
52
53 ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS,
54 &max_storage, &rem_storage,
55 &max_size);
56 if (ret != EFI_UNSUPPORTED) {
57 efi_st_error("QueryVariableInfo failed\n");
58 return EFI_ST_FAILURE;
59 }
60
Simon Glass90975372022-01-23 12:55:12 -070061 ret = runtime->set_variable(u"efi_st_var0", &guid_vendor0,
Heinrich Schuchardtc0267f92019-06-20 16:18:48 +020062 EFI_VARIABLE_BOOTSERVICE_ACCESS |
63 EFI_VARIABLE_RUNTIME_ACCESS,
64 3, v + 4);
65 if (ret != EFI_UNSUPPORTED) {
66 efi_st_error("SetVariable failed\n");
67 return EFI_ST_FAILURE;
68 }
Heinrich Schuchardtfd956fc2020-07-06 17:06:07 +020069 len = EFI_ST_MAX_DATA_SIZE;
Simon Glass90975372022-01-23 12:55:12 -070070 ret = runtime->get_variable(u"PlatformLangCodes", &guid_vendor0,
Heinrich Schuchardtc0267f92019-06-20 16:18:48 +020071 &attr, &len, data);
Heinrich Schuchardtfd956fc2020-07-06 17:06:07 +020072 if (ret != EFI_SUCCESS) {
Heinrich Schuchardtc0267f92019-06-20 16:18:48 +020073 efi_st_error("GetVariable failed\n");
74 return EFI_ST_FAILURE;
75 }
76 memset(&guid, 0, 16);
77 *varname = 0;
Heinrich Schuchardtfd956fc2020-07-06 17:06:07 +020078 len = 2 * EFI_ST_MAX_VARNAME_SIZE;
Heinrich Schuchardtc0267f92019-06-20 16:18:48 +020079 ret = runtime->get_next_variable_name(&len, varname, &guid);
Heinrich Schuchardtfd956fc2020-07-06 17:06:07 +020080 if (ret != EFI_SUCCESS) {
Heinrich Schuchardtc0267f92019-06-20 16:18:48 +020081 efi_st_error("GetNextVariableName failed\n");
82 return EFI_ST_FAILURE;
83 }
84
85 return EFI_ST_SUCCESS;
86}
87
88EFI_UNIT_TEST(variables_run) = {
89 .name = "variables at runtime",
90 .phase = EFI_SETUP_BEFORE_BOOTTIME_EXIT,
91 .setup = setup,
92 .execute = execute,
93};