2 Check that a fault signal handler gets the expected info
17 static const struct test *curr_test;
19 static jmp_buf escape;
21 static int testsig(int sig, int want)
24 fprintf(stderr, " FAIL: expected signal %d, not %d\n", want, sig);
30 static int testcode(int code, int want)
33 fprintf(stderr, " FAIL: expected si_code==%d, not %d\n", want, code);
39 static void handler(int sig, siginfo_t *si, void *uc)
43 ok = ok && testsig(sig, curr_test->sig);
44 ok = ok && testcode(si->si_code, curr_test->code);
47 fprintf(stderr, " PASS\n");
49 siglongjmp(escape, ok + 1);
52 static void test1(void)
54 __asm__ volatile("li $t0, 0x80000000\n\t"
56 "add $a0, $t0, $t1\n\t"
57 : : : "t0", "t1", "a0", "cc", "memory");
62 __asm__ volatile("li $t0, 0x7fffffff\n\t"
63 "addi $a0, $t0, 0x7fff\n\t"
64 : : : "t0", "a0", "cc", "memory");
67 static void test3(void)
69 __asm__ volatile("li $t0, 0xffff0000\n\t"
70 "li $t1, 0x7fffffff\n\t"
71 "sub $a0, $t0, $t1\n\t"
72 : : : "t0", "t1", "a0", "cc", "memory");
78 static const int sigs[] = { SIGFPE };
80 sa.sa_sigaction = handler;
81 sa.sa_flags = SA_SIGINFO;
82 sigfillset(&sa.sa_mask);
84 for(i = 0; i < sizeof(sigs)/sizeof(*sigs); i++)
85 sigaction(sigs[i], &sa, NULL);
87 const struct test tests[] = {
88 #define T(n, sig, code) { test##n, sig, code }
89 T(1, SIGFPE, FPE_INTOVF),
90 T(2, SIGFPE, FPE_INTOVF),
91 T(3, SIGFPE, FPE_INTOVF),
95 for(i = 0; i < sizeof(tests)/sizeof(*tests); i++) {
96 curr_test = &tests[i];
97 if (sigsetjmp(escape, 1) == 0) {
98 fprintf(stderr, "Test %d: ", i+1);
100 fprintf(stderr, " FAIL: no fault, or handler returned\n");