Skip to content

Commit 7dbbc27

Browse files
authored
Merge pull request #468 from tock/multi_alarm
alarm: rewrite alarm virtualization with better comments and simpler logic, add tests
2 parents 97cc77d + 21d9a9c commit 7dbbc27

File tree

16 files changed

+226
-25
lines changed

16 files changed

+226
-25
lines changed

examples/tests/alarm_in_overflow/Makefile renamed to examples/tests/alarms/alarm_in_overflow/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Makefile for user application
22

33
# Specify this directory relative to the current application.
4-
TOCK_USERLAND_BASE_DIR = ../../..
4+
TOCK_USERLAND_BASE_DIR = ../../../..
55

66
# Which files to compile.
77
C_SRCS := $(wildcard *.c)
File renamed without changes.
File renamed without changes.

examples/tests/multi_alarm_simple_overflow_test/Makefile renamed to examples/tests/alarms/multi_alarm_dont_ignore_previous_overflow/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Makefile for user application
22

33
# Specify this directory relative to the current application.
4-
TOCK_USERLAND_BASE_DIR = ../../..
4+
TOCK_USERLAND_BASE_DIR = ../../../..
55

66
# Which files to compile.
77
C_SRCS := $(wildcard *.c)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Test Multiple Alarms (Ensure previous overflowing alarms aren't ignore)
2+
3+
This tests the virtual alarms available to userspace. It sets three
4+
alarms. The first two overflow and should result in multiple
5+
alarms under the hood, and a third 10 second alarm started after the
6+
second alarm fires. The first alarm is set first, but expires second
7+
(1 second after overflow vs 10ms after overflow). The third alarm
8+
should expire last.
9+
10+
(Not to scale; demonstrating alarm firing order)
11+
Alarm 1 (Overflow + 1s) ---Set----------------------Fires--------------
12+
Alarm 2 (Overflow + 10ms) --------Set------Fires -------------------
13+
Alarm 3 (Overflow + 10ms + 10s) --------------Set------------Fires
14+
15+
When successful, the first alarm should fire after a clock overflow +
16+
1 second, while the third should fire after a clock overflow + 10ms +
17+
10 seconds.
18+
19+
If the virtual alarm library is buggy, this test might fail by never
20+
firing the first alarm or firing it after the third alarm
21+
(specifically almost another clock overflow) because either alarm
22+
insertion or virtual alarm upcall handing misses it after the second
23+
alarm fires.
24+
25+
# Example Output
26+
27+
Output includes three columns on each line:
28+
29+
1. the expected order of the alarm firing
30+
2. the time the alarm is delivered to userspace
31+
3. the time the alarm was set to expire
32+
33+
Correct (numbers for the nRT52840DK, running with a 32768Hz timer at
34+
24-bits):
35+
36+
(after an entire clock overflow, ~8 minutes)
37+
38+
```
39+
1 10498816 10496827
40+
2 86100992 86099200
41+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
#include <libtock-sync/services/alarm.h>
5+
6+
static void event_cb(uint32_t now, uint32_t expiration, void* ud) {
7+
int i = (int)ud;
8+
printf("%d %lu %lu\n", i, now, expiration);
9+
}
10+
11+
int main(void) {
12+
libtock_alarm_t t1;
13+
libtock_alarm_t t2;
14+
15+
uint32_t overflow_ms = libtock_alarm_ticks_to_ms(UINT32_MAX);
16+
17+
libtock_alarm_in_ms(overflow_ms + 1000, event_cb, (void*)1, &t1);
18+
libtocksync_alarm_delay_ms(overflow_ms + 10);
19+
libtock_alarm_in_ms(10000, event_cb, (void*)2, &t2);
20+
21+
while (1) {
22+
yield();
23+
}
24+
}

examples/tests/multi_alarm_simple_test/Makefile renamed to examples/tests/alarms/multi_alarm_simple_overflow_test/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Makefile for user application
22

33
# Specify this directory relative to the current application.
4-
TOCK_USERLAND_BASE_DIR = ../../..
4+
TOCK_USERLAND_BASE_DIR = ../../../..
55

66
# Which files to compile.
77
C_SRCS := $(wildcard *.c)
File renamed without changes.
File renamed without changes.

examples/tests/multi_alarm_test/Makefile renamed to examples/tests/alarms/multi_alarm_simple_test/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Makefile for user application
22

33
# Specify this directory relative to the current application.
4-
TOCK_USERLAND_BASE_DIR = ../../..
4+
TOCK_USERLAND_BASE_DIR = ../../../..
55

66
# Which files to compile.
77
C_SRCS := $(wildcard *.c)

0 commit comments

Comments
 (0)