Skip to content

Commit

Permalink
tests/periph_rtt: add test for tick conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
haukepetersen committed Nov 13, 2020
1 parent fba351b commit 56ee87e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
22 changes: 21 additions & 1 deletion tests/periph_rtt/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

static volatile uint32_t last;

static const uint32_t _ticktest[] = { 1, 256, 65536, 16777216, 2147483648 };

void cb(void *arg)
{
(void)arg;
Expand All @@ -47,11 +49,29 @@ void cb(void *arg)
int main(void)
{
puts("\nRIOT RTT low-level driver test");
puts("This test will display 'Hello' every 5 seconds\n");

puts("RTT configuration:");
printf("RTT_MAX_VALUE: 0x%08x\n", (unsigned)RTT_MAX_VALUE);
printf("RTT_FREQUENCY: %u\n\n", (unsigned)RTT_FREQUENCY);

puts("Testing the tick conversion");
for (unsigned i = 0; i < ARRAY_SIZE(_ticktest); i++) {
uint32_t sec = RTT_TICKS_TO_SEC(_ticktest[i]);
uint32_t ticks = RTT_SEC_TO_TICKS(sec);
printf("Trying to convert %" PRIu32 " to seconds and back\n",
_ticktest[i]);
/* account for rounding errors... */
if ((ticks != 0) && (ticks != _ticktest[i])) {
puts("error: TICK conversion not working as expected\n");
return 1;
}
}
puts("All ok\n");

puts("Initializing the RTT driver");
rtt_init();

puts("This test will now display 'Hello' every 5 seconds\n");
uint32_t now = rtt_get_counter();
printf("RTT now: %" PRIu32 "\n", now);

Expand Down
7 changes: 5 additions & 2 deletions tests/periph_rtt/tests/01-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@


def testfunc(child):
child.expect(r'This test will display \'Hello\' every (\d+) seconds')
period = int(child.match.group(1))
child.expect_exact('Testing the tick conversion')
child.expect_exact('All ok')

child.expect_exact('Initializing the RTT driver')
child.expect(r'This test will now display \'Hello\' every (\d+) seconds')
period = int(child.match.group(1))
child.expect(r'RTT now: \d+')
child.expect(r'Setting initial alarm to now \+ {} s \(\d+\)'
.format(period))
Expand Down

0 comments on commit 56ee87e

Please sign in to comment.