commit e273661227b4684265c09e04f75db81f7c5e697e Author: Ivan Maidanski <ivmai@mail.ru> Date: Thu Sep 29 00:32:47 2016 +0300 Description: Add more cases to huge_test to cover sizes close to word-type maximum Add more cases to huge_test to cover sizes close to word-type maximum * tests/huge_test.c (GC_WORD_MAX): New macro. * tests/huge_test.c (GC_SWORD_MAX): Use GC_WORD_MAX. * tests/huge_test.c (main): Add GC_SWORD_MAX+1, GC_WORD_MAX, GC_WORD_MAX-4/8/16/1024 test cases. [NOTE: this patch updates the version of huge_test.c to e273661227b4684265c09e04f75db81f7c5e697e, incorporating intermediate commits. -- sbeattie] Index: libgc-7.4.2/tests/huge_test.c =================================================================== --- libgc-7.4.2.orig/tests/huge_test.c +++ libgc-7.4.2/tests/huge_test.c @@ -5,11 +5,19 @@ #ifndef GC_IGNORE_WARN /* Ignore misleading "Out of Memory!" warning (which is printed on */ - /* every GC_MALLOC(LONG_MAX) call) by defining this macro before */ - /* "gc.h" inclusion. */ + /* every GC_MALLOC call below) by defining this macro before "gc.h" */ + /* inclusion. */ # define GC_IGNORE_WARN #endif +#ifndef GC_MAXIMUM_HEAP_SIZE +# define GC_MAXIMUM_HEAP_SIZE 100 * 1024 * 1024 +# define GC_INITIAL_HEAP_SIZE GC_MAXIMUM_HEAP_SIZE / 20 + /* Otherwise heap expansion aborts when deallocating large block. */ + /* That's OK. We test this corner case mostly to make sure that */ + /* it fails predictably. */ +#endif + #include "gc.h" /* @@ -19,34 +27,31 @@ * expected manner. */ +#define CHECK_ALLOC_FAILED(r, sz_str) \ + do { \ + if (NULL != (r)) { \ + fprintf(stderr, \ + "Size " sz_str " allocation unexpectedly succeeded\n"); \ + exit(1); \ + } \ + } while (0) + +#define GC_WORD_MAX ((GC_word)-1) +#define GC_SWORD_MAX ((GC_signed_word)(GC_WORD_MAX >> 1)) + int main(void) { GC_INIT(); - GC_set_max_heap_size(100*1024*1024); - /* Otherwise heap expansion aborts when deallocating large block. */ - /* That's OK. We test this corner case mostly to make sure that */ - /* it fails predictably. */ - GC_expand_hp(1024*1024*5); - if (sizeof(long) == sizeof(void *)) { - void *r = GC_MALLOC(LONG_MAX-1024); - if (0 != r) { - fprintf(stderr, - "Size LONG_MAX-1024 allocation unexpectedly succeeded\n"); - exit(1); - } - r = GC_MALLOC(LONG_MAX); - if (0 != r) { - fprintf(stderr, - "Size LONG_MAX allocation unexpectedly succeeded\n"); - exit(1); - } - r = GC_MALLOC((size_t)LONG_MAX + 1024); - if (0 != r) { - fprintf(stderr, - "Size LONG_MAX+1024 allocation unexpectedly succeeded\n"); - exit(1); - } - } + CHECK_ALLOC_FAILED(GC_MALLOC(GC_SWORD_MAX - 1024), "SWORD_MAX-1024"); + CHECK_ALLOC_FAILED(GC_MALLOC(GC_SWORD_MAX), "SWORD_MAX"); + CHECK_ALLOC_FAILED(GC_MALLOC((GC_word)GC_SWORD_MAX + 1), "SWORD_MAX+1"); + CHECK_ALLOC_FAILED(GC_MALLOC((GC_word)GC_SWORD_MAX + 1024), + "SWORD_MAX+1024"); + CHECK_ALLOC_FAILED(GC_MALLOC(GC_WORD_MAX - 1024), "WORD_MAX-1024"); + CHECK_ALLOC_FAILED(GC_MALLOC(GC_WORD_MAX - 16), "WORD_MAX-16"); + CHECK_ALLOC_FAILED(GC_MALLOC(GC_WORD_MAX - 8), "WORD_MAX-8"); + CHECK_ALLOC_FAILED(GC_MALLOC(GC_WORD_MAX - 4), "WORD_MAX-4"); + CHECK_ALLOC_FAILED(GC_MALLOC(GC_WORD_MAX), "WORD_MAX"); return 0; }