newlib: add qa test for setjmp/longjmp

This commit is contained in:
Giacomo Tesio 2017-09-03 17:41:55 +02:00
parent 70623daadc
commit a97830e493
2 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,35 @@
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
/* declare variable of type jmp_buf */
jmp_buf resume_here;
void hello(void);
int main(void)
{
int ret_val;
printf("sizeof(jmp_buf) = %lu\n", sizeof(jmp_buf));
/* Initialize 'resume_here' by calling setjmp() */
if (ret_val = setjmp(resume_here)) {
printf("After \'longjump()\', back in \'main()\'\n");
printf("\'jump buffer variable \'resume_here\'\' becomes "
"INVALID!\n");
return 0;
} else {
printf("\'setjmp()\' returns first time\n");
hello();
return 1;
}
}
void hello(void)
{
printf("Hey, I'm in \'hello()\'\n");
longjmp(resume_here, 1);
/* other code */
printf("can't be reached here because I did longjmp!\n");
}

View File

@ -35,6 +35,7 @@
"010-fork.c",
"020-waitpid.c",
"030-pause.c",
"031-setjmp.c",
"040-gettimeofday.c",
"100-files.c",
"101-files.c",