Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / longjmp.c
blob5f3db9402d63e243406fac73399b9c63ab85ac82
1 /** setjmp/longjmp tests (focusing on getting the return value right).
2 */
3 #include <testfwk.h>
5 #if !defined(__SDCC_pic14) // Unimplemented setjmp
6 #include <setjmp.h>
8 jmp_buf buf;
10 void g(int v)
12 longjmp(buf, v);
15 void testJmp(void)
17 int r;
19 r = setjmp(buf);
20 if(!r)
21 g(0);
22 ASSERT(r == 1); // When called with an argument of 0, longjmp() makes setjmp() return 1 instead.
24 r = setjmp(buf);
25 if(!r)
26 g(1);
27 ASSERT(r == 1);
28 r = setjmp(buf);
29 if(!r)
30 g(42);
31 ASSERT(r == 42); // There used to be a bug affecting the Rabbit ports where return values other than 0/1 were wrong.
33 r = setjmp(buf);
34 if(!r)
35 g(0x5a5);
36 ASSERT(r == 0x5a5); // Ensure that we get the upper byte correct, too.
39 #endif