efi_selftest_rtc.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #include <efi_selftest.h>
  10. #define EFI_ST_NO_RTC "Could not read real time clock\n"
  11. static struct efi_runtime_services *runtime;
  12. /*
  13. * Setup unit test.
  14. *
  15. * @handle: handle of the loaded image
  16. * @systable: system table
  17. * @return: EFI_ST_SUCCESS for success
  18. */
  19. static int setup(const efi_handle_t handle,
  20. const struct efi_system_table *systable)
  21. {
  22. runtime = systable->runtime;
  23. return EFI_ST_SUCCESS;
  24. }
  25. /*
  26. * Execute unit test.
  27. *
  28. * Display current time.
  29. *
  30. * @return: EFI_ST_SUCCESS for success
  31. */
  32. static int execute(void)
  33. {
  34. efi_status_t ret;
  35. struct efi_time tm;
  36. /* Display current time */
  37. ret = runtime->get_time(&tm, NULL);
  38. if (ret != EFI_SUCCESS) {
  39. #ifdef CONFIG_CMD_DATE
  40. efi_st_error(EFI_ST_NO_RTC);
  41. return EFI_ST_FAILURE;
  42. #else
  43. efi_st_todo(EFI_ST_NO_RTC);
  44. return EFI_ST_SUCCESS;
  45. #endif
  46. } else {
  47. efi_st_printf("Time according to real time clock: "
  48. "%.4u-%.2u-%.2u %.2u:%.2u:%.2u\n",
  49. tm.year, tm.month, tm.day,
  50. tm.hour, tm.minute, tm.second);
  51. }
  52. return EFI_ST_SUCCESS;
  53. }
  54. EFI_UNIT_TEST(rtc) = {
  55. .name = "real time clock",
  56. .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
  57. .setup = setup,
  58. .execute = execute,
  59. };