Remove building with NOCRYPTO option
[minix.git] / minix / tests / test62.c
blob348d0353d605b90727bebf9a196fdf9d00335fe0
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 int max_error = 1;
10 #include "common.h"
13 double state = 2.0;
14 static int count;
16 static void use_fpu(int n)
18 state += (double) n * 0.5;
21 static void crashed(int sig)
23 exit(EXIT_SUCCESS);
26 static void handler(int sig, int code, struct sigcontext *sc)
28 memset(&sc->sc_fpu_state, count, sizeof(sc->sc_fpu_state));
31 int main(void)
33 int status;
35 start(62);
36 subtest = 0;
38 signal(SIGUSR1, (void (*)(int)) handler);
40 /* Initialize the FPU state. This state is inherited, too. */
41 use_fpu(-1);
43 for (count = 0; count <= 255; count++) {
44 switch (fork()) {
45 case -1:
46 e(1);
48 break;
50 case 0:
51 signal(SIGFPE, crashed);
53 /* Load bad state into the kernel. */
54 if (kill(getpid(), SIGUSR1)) e(2);
56 /* Let the kernel restore the state. */
57 use_fpu(count);
59 exit(EXIT_SUCCESS);
61 default:
62 /* We cannot tell exactly whether what happened is correct or
63 * not -- certainly not in a platform-independent way. However,
64 * if the whole system keeps running, that's good enough.
66 (void) wait(&status);
70 if (state <= 1.4 || state >= 1.6) e(3);
72 quit();
74 return 0;