make minix lwip make explicit use of 'int'
[minix3.git] / test / test62.c
blobeb625aea3048a9c7e55cdb5332ccc9a6ac1b8d51
1 /* FPU state corruption test. This used to be able to crash the kernel. */
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <signal.h>
6 #include <sys/wait.h>
7 #include <machine/fpu.h>
9 #define MAX_ERROR 1
10 #include "common.c"
12 double state = 2.0;
13 static int count;
15 static void use_fpu(int n)
17 state += (double) n * 0.5;
20 static void crashed(int sig)
22 exit(EXIT_SUCCESS);
25 static void handler(int sig, int code, struct sigcontext *sc)
27 memset(&sc->sc_fpu_state, count, sizeof(sc->sc_fpu_state));
30 int main(void)
32 int status;
34 start(62);
35 subtest = 0;
37 signal(SIGUSR1, (void (*)(int)) handler);
39 /* Initialize the FPU state. This state is inherited, too. */
40 use_fpu(-1);
42 for (count = 0; count <= 255; count++) {
43 switch (fork()) {
44 case -1:
45 e(1);
47 break;
49 case 0:
50 signal(SIGFPE, crashed);
52 /* Load bad state into the kernel. */
53 if (kill(getpid(), SIGUSR1)) e(2);
55 /* Let the kernel restore the state. */
56 use_fpu(count);
58 exit(EXIT_SUCCESS);
60 default:
61 /* We cannot tell exactly whether what happened is correct or
62 * not -- certainly not in a platform-independent way. However,
63 * if the whole system keeps running, that's good enough.
65 (void) wait(&status);
69 if (state <= 1.4 || state >= 1.6) e(3);
71 quit();
73 return 0;