diff options
Diffstat (limited to 'lib/efi_selftest')
-rw-r--r-- | lib/efi_selftest/efi_selftest_rtc.c | 56 | ||||
-rw-r--r-- | lib/efi_selftest/efi_selftest_variables.c | 28 |
2 files changed, 62 insertions, 22 deletions
diff --git a/lib/efi_selftest/efi_selftest_rtc.c b/lib/efi_selftest/efi_selftest_rtc.c index 8d440dc0b3c..9eb29add3b0 100644 --- a/lib/efi_selftest/efi_selftest_rtc.c +++ b/lib/efi_selftest/efi_selftest_rtc.c @@ -10,6 +10,7 @@ #include <efi_selftest.h> #define EFI_ST_NO_RTC "Could not read real time clock\n" +#define EFI_ST_NO_RTC_SET "Could not set real time clock\n" static struct efi_runtime_services *runtime; @@ -30,17 +31,26 @@ static int setup(const efi_handle_t handle, /* * Execute unit test. * - * Display current time. + * Read and display current time. + * Set a new value and read it back. + * Set the real time clock back the current time. * * @return: EFI_ST_SUCCESS for success */ static int execute(void) { efi_status_t ret; - struct efi_time tm; + struct efi_time tm, tm_old, tm_new = { + .year = 2017, + .month = 5, + .day = 19, + .hour = 13, + .minute = 47, + .second = 53, + }; /* Display current time */ - ret = runtime->get_time(&tm, NULL); + ret = runtime->get_time(&tm_old, NULL); if (ret != EFI_SUCCESS) { #ifdef CONFIG_CMD_DATE efi_st_error(EFI_ST_NO_RTC); @@ -49,11 +59,41 @@ static int execute(void) efi_st_todo(EFI_ST_NO_RTC); return EFI_ST_SUCCESS; #endif - } else { - efi_st_printf("Time according to real time clock: " - "%.4u-%.2u-%.2u %.2u:%.2u:%.2u\n", - tm.year, tm.month, tm.day, - tm.hour, tm.minute, tm.second); + } + efi_st_printf("Time according to real time clock: " + "%.4u-%.2u-%.2u %.2u:%.2u:%.2u\n", + tm_old.year, tm_old.month, tm_old.day, + tm_old.hour, tm_old.minute, tm_old.second); + ret = runtime->set_time(&tm_new); + if (ret != EFI_SUCCESS) { +#ifdef CONFIG_CMD_DATE + efi_st_error(EFI_ST_NO_RTC_SET); + return EFI_ST_FAILURE; +#else + efi_st_todo(EFI_ST_NO_RTC_SET); + return EFI_ST_SUCCESS; +#endif + } + ret = runtime->get_time(&tm, NULL); + if (ret != EFI_SUCCESS) { + efi_st_error(EFI_ST_NO_RTC); + return EFI_ST_FAILURE; + } + if (tm.year != tm_new.year || + tm.month != tm_new.month || + tm.day != tm_new.day || + tm.hour != tm_new.hour || + tm.minute != tm_new.minute || + tm.second < tm_new.second || + tm.second > tm_new.second + 2) { + efi_st_error(EFI_ST_NO_RTC_SET); + return EFI_ST_FAILURE; + } + /* Set time back to old value */ + ret = runtime->set_time(&tm_old); + if (ret != EFI_SUCCESS) { + efi_st_error(EFI_ST_NO_RTC_SET); + return EFI_ST_FAILURE; } return EFI_ST_SUCCESS; diff --git a/lib/efi_selftest/efi_selftest_variables.c b/lib/efi_selftest/efi_selftest_variables.c index b028c64bbc8..06c1a032dd0 100644 --- a/lib/efi_selftest/efi_selftest_variables.c +++ b/lib/efi_selftest/efi_selftest_variables.c @@ -116,21 +116,21 @@ static int execute(void) EFI_VARIABLE_APPEND_WRITE, 7, v + 8); if (ret != EFI_SUCCESS) { - efi_st_error("SetVariable failed\n"); - return EFI_ST_FAILURE; - } - len = EFI_ST_MAX_DATA_SIZE; - ret = runtime->get_variable(L"efi_st_var1", &guid_vendor1, - &attr, &len, data); - if (ret != EFI_SUCCESS) { - efi_st_error("GetVariable failed\n"); - return EFI_ST_FAILURE; + efi_st_todo("SetVariable(APPEND_WRITE) failed\n"); + } else { + len = EFI_ST_MAX_DATA_SIZE; + ret = runtime->get_variable(L"efi_st_var1", &guid_vendor1, + &attr, &len, data); + if (ret != EFI_SUCCESS) { + efi_st_error("GetVariable failed\n"); + return EFI_ST_FAILURE; + } + if (len != 15) + efi_st_todo("GetVariable returned wrong length %u\n", + (unsigned int)len); + if (memcmp(data, v, len)) + efi_st_todo("GetVariable returned wrong value\n"); } - if (len != 15) - efi_st_todo("GetVariable returned wrong length %u\n", - (unsigned int)len); - if (memcmp(data, v, len)) - efi_st_todo("GetVariable returned wrong value\n"); /* Enumerate variables */ boottime->set_mem(&guid, 16, 0); *varname = 0; |