newlib: add qa test for setjmp/longjmp
This commit is contained in:
parent
70623daadc
commit
a97830e493
35
qa/lib/newlib/031-setjmp.c
Normal file
35
qa/lib/newlib/031-setjmp.c
Normal 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");
|
||||||
|
}
|
@ -35,6 +35,7 @@
|
|||||||
"010-fork.c",
|
"010-fork.c",
|
||||||
"020-waitpid.c",
|
"020-waitpid.c",
|
||||||
"030-pause.c",
|
"030-pause.c",
|
||||||
|
"031-setjmp.c",
|
||||||
"040-gettimeofday.c",
|
"040-gettimeofday.c",
|
||||||
"100-files.c",
|
"100-files.c",
|
||||||
"101-files.c",
|
"101-files.c",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user