jehanne/qa/lib/c/longjmp.c
Giacomo Tesio 38aca7a581 first usable version of kernel and commands
After an year of hard work, this is a first "usable" version of Jehanne.
2016-11-26 03:49:29 +01:00

49 lines
697 B
C

#include <u.h>
#include <libc.h>
enum {
Njmps = 10000
};
void foo(void);
void
main(void)
{
int i, njmp;
int fail = 0;
jmp_buf label;
njmp = 0;
while((njmp = setjmp(label)) < Njmps)
longjmp(label, njmp+1);
for(i = 0; i < nelem(label); i++)
fprint(2, "label[%d] = %p\n", i, label[i]);
fprint(2, "main: %p foo: %p\n", main, foo);
if(njmp != Njmps)
fail++;
if(label[JMPBUFPC] < (uintptr_t)main)
fail++;
if(label[JMPBUFPC] > (uintptr_t)foo)
fail++;
if(label[JMPBUFSP] > (uintptr_t)&label[nelem(label)])
fail++;
if(label[JMPBUFSP] < 0x7fffffd00000)
fail++;
if(fail == 0){
print("PASS\n");
exits("PASS");
}
print("FAIL\n");
exits("FAIL");
}
void
foo(void)
{
}