t40c term[] count fix
[minix.git] / test / test6.c
blob1e0d7a4231036d72673806002de286ad16b7ee20
1 /* test 6 */
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <errno.h>
6 #include <fcntl.h>
7 #include <limits.h>
8 #include <signal.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <stdio.h>
13 #define MAX_ERROR 3
15 int subtest = 1;
16 int zilch[5000];
18 #include "common.c"
20 int main(int argc, char *argv []);
21 void test6a(void);
22 void test6b(void);
24 int main(argc, argv)
25 int argc;
26 char *argv[];
28 int i, m = 0xFFFF;
30 if (argc == 2) m = atoi(argv[1]);
32 start(6);
34 for (i = 0; i < 70; i++) {
35 if (m & 00001) test6a();
36 if (m & 00002) test6b();
39 quit();
40 return(-1); /* impossible */
43 void test6a()
45 /* Test sbrk() and brk(). */
47 char *addr, *addr2, *addr3;
48 int i, del, click, click2;
50 subtest = 1;
51 addr = sbrk(0);
52 addr = sbrk(0); /* force break to a click boundary */
53 for (i = 0; i < 10; i++) sbrk(7 * i);
54 for (i = 0; i < 10; i++) sbrk(-7 * i);
55 if (sbrk(0) != addr) e(1);
56 sbrk(30);
57 if (brk(addr) != 0) e(2);
58 if (sbrk(0) != addr) e(3);
60 del = 0;
61 do {
62 del++;
63 brk(addr + del);
64 addr2 = sbrk(0);
65 } while (addr2 == addr);
66 click = addr2 - addr;
67 sbrk(-1);
68 if (sbrk(0) != addr) e(4);
69 brk(addr);
70 if (sbrk(0) != addr) e(5);
72 del = 0;
73 do {
74 del++;
75 brk(addr - del);
76 addr3 = sbrk(0);
77 } while (addr3 == addr);
78 click2 = addr - addr3;
79 sbrk(1);
80 if (sbrk(0) != addr) e(6);
81 brk(addr);
82 if (sbrk(0) != addr) e(8);
83 if (click != click2) e(9);
85 brk(addr + 2 * click);
86 if (sbrk(0) != addr + 2 * click) e(10);
87 sbrk(3 * click);
88 if (sbrk(0) != addr + 5 * click) e(11);
89 sbrk(-5 * click);
90 if (sbrk(0) != addr) e(12);
93 void test6b()
95 int i, err;
97 subtest = 2;
98 signal(SIGQUIT, SIG_IGN);
99 err = 0;
100 for (i = 0; i < 5000; i++)
101 if (zilch[i] != 0) err++;
102 if (err > 0) e(1);
103 kill(getpid(), SIGQUIT);