Skip to content

Commit

Permalink
test: simple multi alarm test
Browse files Browse the repository at this point in the history
An intentionally simple test for multiple alarms that only sets exactly
two repeating alarms that should overlap frequently (one is twice the
other's frequency).
  • Loading branch information
alevy committed Sep 5, 2024
1 parent 8a11ec7 commit af4c927
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
11 changes: 11 additions & 0 deletions examples/tests/multi_alarm_simple_test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Makefile for user application

# Specify this directory relative to the current application.
TOCK_USERLAND_BASE_DIR = ../../..

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

# Include userland master makefile. Contains rules and flags for actually
# building the application.
include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk
7 changes: 7 additions & 0 deletions examples/tests/multi_alarm_simple_test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Test Multiple Alarms (Simple)

This tests the virtual alarms available to userspace. It sets two
repeating alarms, at 500ms and 1s respectively, each prints the alarm
index (1 or 2), current tick and alarm expiration to the console. When
successful, both alarms should fire and alarm 1 should fire twice as
often as alarm 2.
23 changes: 23 additions & 0 deletions examples/tests/multi_alarm_simple_test/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <stdlib.h>
#include <stdio.h>

#include <libtock-sync/services/alarm.h>

static void event_cb(__attribute__ ((unused)) uint32_t now,
__attribute__ ((unused)) uint32_t expiration,
void* ud) {
int i = (int)ud;
printf("%d %ld %ld\n", i, now, expiration);
}

int main(void) {
libtock_alarm_t t1;
libtock_alarm_t t2;

libtock_alarm_repeating_every_ms( 500, event_cb, (void*)1, &t1);
libtock_alarm_repeating_every_ms(1000, event_cb, (void*)2, &t2);

while (1) {
yield();
}
}

0 comments on commit af4c927

Please sign in to comment.