1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
19344: test/periph_rtc: reset struct tm time between tests r=benpicco a=kfessel

### Contribution description

while reviewing #19340 i found test/periph_rtc to be insufficient to prove rtc_set_time is working. this changes that and avoids accidental reuse of struct tm time and ms  values by resetting time and ms;

### Testing procedure

run the test

### Issues/PRs references

#19340

Co-authored-by: Karl Fessel <karl.fessel@ovgu.de>
This commit is contained in:
bors[bot] 2023-03-03 20:34:28 +00:00 committed by GitHub
commit 8c6926d0ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 11 deletions

View File

@ -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;
@ -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 {
@ -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 {
@ -189,8 +208,10 @@ 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 {
@ -198,6 +219,9 @@ int main(void)
print_time(message, &time);
}
time = (struct tm){0};
ms = 0;
/* set alarm */
rtc_get_time(&time);
inc_secs(&time, PERIOD);

View File

@ -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)