middle.c raw
1 /*
2 * Test at the boundary between small and large objects.
3 * Inspired by a test case from Zoltan Varga.
4 */
5
6 #ifdef HAVE_CONFIG_H
7 # include "config.h"
8 #endif
9
10 #include <stdio.h>
11 #include <stdlib.h>
12
13 #define NOT_GCBUILD
14 #include "private/gc_priv.h"
15
16 #undef rand
17 static GC_RAND_STATE_T seed;
18 #define rand() GC_RAND_NEXT(&seed)
19
20 #define N_TESTS 32000
21
22 /* Typical page size. */
23 #define ALLOC_SZ 4096
24
25 #define CHECK_OUT_OF_MEMORY(p) \
26 do { \
27 if (NULL == (p)) { \
28 fprintf(stderr, "Out of memory\n"); \
29 exit(69); \
30 } \
31 } while (0)
32
33 int
34 main(void)
35 {
36 int i;
37
38 GC_set_all_interior_pointers(0);
39 GC_INIT();
40 if (GC_get_find_leak())
41 printf("This test program is not designed for leak detection mode\n");
42
43 for (i = 0; i < N_TESTS; ++i) {
44 CHECK_OUT_OF_MEMORY(GC_malloc_atomic(ALLOC_SZ));
45 CHECK_OUT_OF_MEMORY(GC_malloc(ALLOC_SZ));
46 }
47
48 /* Test delayed start of marker threads, if they are enabled. */
49 GC_start_mark_threads();
50
51 for (i = 0; i < N_TESTS; ++i) {
52 CHECK_OUT_OF_MEMORY(GC_malloc_atomic(ALLOC_SZ / 2));
53 CHECK_OUT_OF_MEMORY(GC_malloc(ALLOC_SZ / 2));
54 }
55
56 for (i = 0; i < N_TESTS; ++i) {
57 CHECK_OUT_OF_MEMORY(GC_malloc_atomic((unsigned)rand() % ALLOC_SZ));
58 CHECK_OUT_OF_MEMORY(GC_malloc((unsigned)rand() % (ALLOC_SZ / 8)));
59 }
60
61 printf("Final heap size is %lu\n", (unsigned long)GC_get_heap_size());
62 return 0;
63 }
64