summaryrefslogtreecommitdiff
path: root/zephyr/test/drivers/default/src/console_cmd/rtc.c
blob: 974d3709b7a91a34358ac0f8cf3b05400947b803 (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
68
69
70
71
72
73
/* Copyright 2022 The ChromiumOS Authors
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "console.h"
#include "ec_commands.h"
#include "system.h"
#include "test/drivers/test_state.h"
#include "test/drivers/utils.h"

#include <zephyr/ztest.h>

ZTEST_USER(console_cmd_rtc, test_rtc_no_arg)
{
	char expected_buffer[32];
	uint32_t sec = 7;

	snprintf(expected_buffer, sizeof(expected_buffer),
		 "RTC: 0x%08x (%d.00 s)", sec, sec);

	system_set_rtc(sec);

	CHECK_CONSOLE_CMD("rtc", expected_buffer, EC_SUCCESS);
}

ZTEST_USER(console_cmd_rtc, test_rtc_invalid)
{
	CHECK_CONSOLE_CMD("rtc set", NULL, EC_ERROR_INVAL);
}

ZTEST_USER(console_cmd_rtc, test_rtc_set)
{
	char command[32];
	char expected_buffer[32];
	uint32_t sec = 48879;

	snprintf(expected_buffer, sizeof(expected_buffer),
		 "RTC: 0x%08x (%d.00 s)", sec, sec);
	snprintf(command, sizeof(command), "rtc set %d", sec);

	CHECK_CONSOLE_CMD(command, expected_buffer, EC_SUCCESS);
}

ZTEST_USER(console_cmd_rtc, test_rtc_set_bad)
{
	CHECK_CONSOLE_CMD("rtc set t", NULL, EC_ERROR_PARAM2);
}

ZTEST_USER(console_cmd_rtc, test_rtc_alarm_no_args)
{
	CHECK_CONSOLE_CMD("rtc_alarm", "Setting RTC alarm", EC_SUCCESS);
}

ZTEST_USER(console_cmd_rtc, test_rtc_alarm_good_args)
{
	CHECK_CONSOLE_CMD("rtc_alarm 1", "Setting RTC alarm", EC_SUCCESS);
	CHECK_CONSOLE_CMD("rtc_alarm 1 5", "Setting RTC alarm", EC_SUCCESS);
}

ZTEST_USER(console_cmd_rtc, test_rtc_alarm_bad_args)
{
	CHECK_CONSOLE_CMD("rtc_alarm t", NULL, EC_ERROR_PARAM1);
	CHECK_CONSOLE_CMD("rtc_alarm 1 t", NULL, EC_ERROR_PARAM2);
}

ZTEST_USER(console_cmd_rtc, test_rtc_alarm_reset)
{
	CHECK_CONSOLE_CMD("rtc_alarm 0", "Setting RTC alarm", EC_SUCCESS);
	CHECK_CONSOLE_CMD("rtc_alarm 0 0", "Setting RTC alarm", EC_SUCCESS);
}

ZTEST_SUITE(console_cmd_rtc, NULL, NULL, NULL, NULL, NULL);