xref: /kvm-unit-tests/x86/setjmp.c (revision 2c96b77ec9d3b1fcec7525174e23a6240ee05949)
1 #include "libcflat.h"
2 #include "setjmp.h"
3 
4 static const int expected[] = {
5 	0, 1, 2, 3, 4, 5, 6, 7, 8, 9
6 };
7 
8 #define NUM_LONGJMPS ARRAY_SIZE(expected)
9 
10 int main(void)
11 {
12 	volatile int index = 0;
13 	jmp_buf j;
14 	int i;
15 
16 	i = setjmp(j);
17 	report(expected[index] == i, "actual %d == expected %d",
18 	       i, expected[index]);
19 	index++;
20 	if (i + 1 < NUM_LONGJMPS)
21 		longjmp(j, i + 1);
22 
23 	return report_summary();
24 }
25