248b1d71218a159d351244c03a546c9c0d43b199
[cacao.git] / src / mm / boehm-gc / tests / huge_test.c
1 #include <stdlib.h>
2 #include <limits.h>
3 #include <stdio.h>
4 #include <gc.h>
5
6 /*
7  * Check that very large allocation requests fail.  "Success" would usually
8  * indicate that the the size was somehow converted to a negative
9  * number.  Clients shouldn't do this, but we should fail in the
10  * expected manner.
11  */
12
13
14 main()
15 {
16     GC_INIT();
17
18     GC_set_max_heap_size(100*1024*1024);
19         /* Otherwise heap expansion aborts when deallocating large block. */
20         /* That's OK.  We test this corner case mostly to make sure that  */
21         /* it fails predictably.                                          */
22     GC_expand_hp(1024*1024*5);
23     if (sizeof(long) == sizeof(void *)) {
24         void *r = GC_MALLOC(LONG_MAX-1024);
25         if (0 != r) {
26             fprintf(stderr,
27                     "Size LONG_MAX-1024 allocation unexpectedly succeeded\n");
28             exit(1);
29         }
30         r = GC_MALLOC(LONG_MAX);
31         if (0 != r) {
32             fprintf(stderr,
33                     "Size LONG_MAX allocation unexpectedly succeeded\n");
34             exit(1);
35         }
36         r = GC_MALLOC((size_t)LONG_MAX + 1024);
37         if (0 != r) {
38             fprintf(stderr,
39                     "Size LONG_MAX+1024 allocation unexpectedly succeeded\n");
40             exit(1);
41         }
42     }
43     return 0;
44 }
45