@@ -1,19 +1,26 @@
#include "libcflat.h"
#include "setjmp.h"
+static const int expected[] = {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
+};
+
+#define NUM_LONGJMPS ARRAY_SIZE(expected)
+
int main(void)
{
- volatile int i;
+ volatile int index = 0;
jmp_buf j;
+ int i;
- if (setjmp(j) == 0) {
- i = 0;
- }
- printf("%d\n", i);
- if (++i < 10) {
- longjmp(j, 1);
+ i = setjmp(j);
+ if (expected[index] != i) {
+ printf("FAIL: actual %d / expected %d\n", i, expected[index]);
+ return -1;
}
+ index++;
+ if (i + 1 < NUM_LONGJMPS)
+ longjmp(j, i + 1);
- printf("done\n");
return 0;
}
Use a list of expected values instead of printing out numbers, which aren't very meaningful. This prints only if the expected and actual values differ. Signed-off-by: Bill Wendling <morbo@google.com> --- x86/setjmp.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)