Merge branch 'vendor/GDB'
[dragonfly.git] / test / stress / eatmem.c
1 /*
2  * EATMEM.C
3  *
4  * (c)Copyright 2003 Matthew Dillon <dillon@backplane.com>.  This code is
5  *    hereby placed in the public domain.
6  *
7  * This program 'eats' memory by allocating and touching it.  Make sure your
8  * datasize resource limit is sufficient for the amount of memory you specify.
9  *
10  * $DragonFly: src/test/stress/eatmem.c,v 1.1 2003/08/25 19:41:00 dillon Exp $
11  */
12 #include <sys/types.h>
13 #include <sys/mman.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <unistd.h>
18
19 int
20 main(int ac, char **av)
21 {
22     size_t bytes;
23     size_t i;
24     char *ptr;
25
26     if (ac == 1) {
27         printf("eatmem MB [msec/page]\n");
28         printf("specifying msec/page will cause eatmem to loop forever\n");
29         exit(1);
30     }
31     bytes = strtoul(av[1], NULL, 0) * 1024 * 1024;
32     ptr = malloc(bytes);
33
34     for (;;) {
35         for (i = 0; i < bytes; i += 4096) {
36             ++ptr[i];
37             if (av[2] && strtol(av[2], NULL, 0))
38                 usleep(1000 * strtol(av[2], NULL, 0));
39             if (i == 0)
40                 puts("loop0");
41         }
42         if (ac != 3)
43                 break;
44         puts("loop");
45     }
46     puts("ok");
47     sleep(10);
48     puts("done");
49     exit(0);
50 }