Heinrich Schuchardt | a7be4b8 | 2018-07-07 23:39:16 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * efi_selftest_rtc |
| 4 | * |
| 5 | * Copyright (c) 2018 Heinrich Schuchardt <xypron.glpk@gmx.de> |
| 6 | * |
| 7 | * Test the real time clock runtime services. |
| 8 | */ |
| 9 | |
| 10 | #include <efi_selftest.h> |
| 11 | |
| 12 | #define EFI_ST_NO_RTC "Could not read real time clock\n" |
| 13 | |
| 14 | static struct efi_runtime_services *runtime; |
| 15 | |
| 16 | /* |
| 17 | * Setup unit test. |
| 18 | * |
| 19 | * @handle: handle of the loaded image |
| 20 | * @systable: system table |
| 21 | * @return: EFI_ST_SUCCESS for success |
| 22 | */ |
| 23 | static int setup(const efi_handle_t handle, |
| 24 | const struct efi_system_table *systable) |
| 25 | { |
| 26 | runtime = systable->runtime; |
| 27 | return EFI_ST_SUCCESS; |
| 28 | } |
| 29 | |
| 30 | /* |
| 31 | * Execute unit test. |
| 32 | * |
| 33 | * Display current time. |
| 34 | * |
| 35 | * @return: EFI_ST_SUCCESS for success |
| 36 | */ |
| 37 | static int execute(void) |
| 38 | { |
| 39 | efi_status_t ret; |
| 40 | struct efi_time tm; |
| 41 | |
| 42 | /* Display current time */ |
| 43 | ret = runtime->get_time(&tm, NULL); |
| 44 | if (ret != EFI_SUCCESS) { |
| 45 | #ifdef CONFIG_CMD_DATE |
| 46 | efi_st_error(EFI_ST_NO_RTC); |
| 47 | return EFI_ST_FAILURE; |
| 48 | #else |
| 49 | efi_st_todo(EFI_ST_NO_RTC); |
| 50 | return EFI_ST_SUCCESS; |
| 51 | #endif |
| 52 | } else { |
| 53 | efi_st_printf("Time according to real time clock: " |
| 54 | "%.4u-%.2u-%.2u %.2u:%.2u:%.2u\n", |
| 55 | tm.year, tm.month, tm.day, |
| 56 | tm.hour, tm.minute, tm.second); |
| 57 | } |
| 58 | |
| 59 | return EFI_ST_SUCCESS; |
| 60 | } |
| 61 | |
| 62 | EFI_UNIT_TEST(rtc) = { |
| 63 | .name = "real time clock", |
| 64 | .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, |
| 65 | .setup = setup, |
| 66 | .execute = execute, |
| 67 | }; |