setjmp: add a test to longjmp out of an interrupt

This commit is contained in:
Lephenixnoir 2021-05-30 10:44:27 +02:00
parent ef59e956bb
commit f5e55ecc22
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
4 changed files with 50 additions and 0 deletions

View File

@ -28,6 +28,7 @@ set(SOURCES
src/inttypes/functions.c
src/inttypes/sizes.c
# setjmp
src/setjmp/interrupt.c
src/setjmp/massive.c
src/setjmp/simple.c
# stdlib

View File

@ -18,6 +18,7 @@ extern ft_test ft_inttypes_functions;
/* setjmp */
extern ft_test ft_setjmp_simple;
extern ft_test ft_setjmp_massive;
extern ft_test ft_setjmp_interrupt;
/* stdlib */
extern ft_test ft_stdlib_arith;

View File

@ -31,6 +31,7 @@ ft_list headers_libc[] = {
{ "<setjmp.h>", (ft_test*[]){
&ft_setjmp_simple,
&ft_setjmp_massive,
&ft_setjmp_interrupt,
NULL,
}},
{ "<signal.h>", NULL },

47
src/setjmp/interrupt.c Normal file
View File

@ -0,0 +1,47 @@
#include <ft/test.h>
#include <ft/all-tests.h>
#include <gint/timer.h>
#include <setjmp.h>
static int timer_id = -1;
int callback(ft_test *t, jmp_buf *jb)
{
/* We need to stop the timer now, as jumping out of the interrupt
handler will restore SR which enables the interrupt again */
ft_log(t, "Stopping timer!\n");
timer_stop(timer_id);
ft_log(t, "Long jumping from callback()!\n");
longjmp((*jb), 73);
return TIMER_STOP;
}
static void _ft_setjmp_interrupt(ft_test *t)
{
jmp_buf jb;
int rc = setjmp(jb);
if(rc == 0) {
timer_id = timer_configure(TIMER_TMU, 1000,
GINT_CALL(callback, (void *)t, (void *)&jb));
if(timer_id >= 0) {
ft_log(t, "Starting timer!\n");
timer_start(timer_id);
}
else {
ft_log(t, "Cannot get timer: %d\n", timer_id);
}
callback(t, &jb);
}
else {
ft_log(t, "Got setjmp rc = %d\n", rc);
ft_assert(t, rc == 73);
}
}
ft_test ft_setjmp_interrupt = {
.name = "Jump out of interrupt",
.function = _ft_setjmp_interrupt,
};