summaryrefslogtreecommitdiff
path: root/lib/efi_selftest/efi_selftest_rtc.c
blob: 8d440dc0b3c008ddb2bd95052db2d97a928d014c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// SPDX-License-Identifier: GPL-2.0+
/*
 * efi_selftest_rtc
 *
 * Copyright (c) 2018 Heinrich Schuchardt <xypron.glpk@gmx.de>
 *
 * Test the real time clock runtime services.
 */

#include <efi_selftest.h>

#define EFI_ST_NO_RTC "Could not read real time clock\n"

static struct efi_runtime_services *runtime;

/*
 * Setup unit test.
 *
 * @handle:	handle of the loaded image
 * @systable:	system table
 * @return:	EFI_ST_SUCCESS for success
 */
static int setup(const efi_handle_t handle,
		 const struct efi_system_table *systable)
{
	runtime = systable->runtime;
	return EFI_ST_SUCCESS;
}

/*
 * Execute unit test.
 *
 * Display current time.
 *
 * @return:	EFI_ST_SUCCESS for success
 */
static int execute(void)
{
	efi_status_t ret;
	struct efi_time tm;

	/* Display current time */
	ret = runtime->get_time(&tm, NULL);
	if (ret != EFI_SUCCESS) {
#ifdef CONFIG_CMD_DATE
		efi_st_error(EFI_ST_NO_RTC);
		return EFI_ST_FAILURE;
#else
		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);
	}

	return EFI_ST_SUCCESS;
}

EFI_UNIT_TEST(rtc) = {
	.name = "real time clock",
	.phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
	.setup = setup,
	.execute = execute,
};