Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test/periph_rtc: reset struct tm time between tests #19344

Merged
merged 1 commit into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions tests/periph_rtc/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,8 @@ static inline void _get_rtc_mem(void) {}

int main(void)
{
struct tm time = {
.tm_year = 2020 - TM_YEAR_OFFSET, /* years are counted from 1900 */
.tm_mon = 1, /* 0 = January, 11 = December */
.tm_mday = 28,
.tm_hour = 23,
.tm_min = 59,
.tm_sec = 57
};
struct tm time = (struct tm){0};
uint16_t ms;

mutex_t rtc_mtx = MUTEX_INIT_LOCKED;

Expand All @@ -145,13 +139,33 @@ int main(void)
_set_rtc_mem();
_get_rtc_mem();

/* read RTC to retrieve initial */
if (IS_USED(MODULE_PERIPH_RTC_MS)) {
rtc_get_time_ms(&time, &ms);
print_time_ms("Clock value is now ", &time, ms);
} else {
rtc_get_time(&time);
print_time("Clock value is now ", &time);
}

time = (struct tm){
.tm_year = 2020 - TM_YEAR_OFFSET, /* years are counted from 1900 */
.tm_mon = 1, /* 0 = January, 11 = December */
.tm_mday = 28,
.tm_hour = 23,
.tm_min = 59,
.tm_sec = 57
};

/* set RTC */
print_time(" Setting clock to ", &time);
rtc_set_time(&time);

time = (struct tm){0};
ms = 0;

/* read RTC to confirm value */
if (IS_USED(MODULE_PERIPH_RTC_MS)) {
uint16_t ms;
rtc_get_time_ms(&time, &ms);
print_time_ms("Clock value is now ", &time, ms);
} else {
Expand All @@ -164,14 +178,19 @@ int main(void)
print_time(" Setting alarm to ", &time);
rtc_set_alarm(&time, cb, &rtc_mtx);

time = (struct tm){0};
ms = 0;

/* verify alarm */
rtc_get_alarm(&time);
print_time(" Alarm is set to ", &time);

time = (struct tm){0};
ms = 0;

/* clear alarm */
rtc_clear_alarm();
if (IS_USED(MODULE_PERIPH_RTC_MS)) {
uint16_t ms;
rtc_get_time_ms(&time, &ms);
print_time_ms(" Alarm cleared at ", &time, ms);
} else {
Expand All @@ -189,15 +208,20 @@ int main(void)
message = " No alarm at ";
}

time = (struct tm){0};
ms = 0;

if (IS_USED(MODULE_PERIPH_RTC_MS)) {
uint16_t ms;
rtc_get_time_ms(&time, &ms);
print_time_ms(message, &time, ms);
} else {
rtc_get_time(&time);
print_time(message, &time);
}

time = (struct tm){0};
ms = 0;

/* set alarm */
rtc_get_time(&time);
inc_secs(&time, PERIOD);
Expand Down
3 changes: 3 additions & 0 deletions tests/periph_rtc/tests/01-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ def testfunc(child):
child.expect(r'This test will display \'Alarm\!\' every 2 seconds '
r'for (\d{1}) times')
alarm_count = int(child.match.group(1))
child.expect(r'Clock value is now ({})'.format(DATE_PATTERN))
clock_reboot = child.match.group(1)
child.expect(r' Setting clock to ({})'.format(DATE_PATTERN))
clock_set = child.match.group(1)
child.expect(r'Clock value is now ({})'.format(DATE_PATTERN))
clock_value = child.match.group(1)
assert clock_set == clock_value
assert clock_reboot != clock_value

child.expect(r' Setting alarm to ({})'.format(DATE_PATTERN))
alarm_set = child.match.group(1)
Expand Down