/vendor/gc/tests/huge_test.c

http://github.com/feyeleanor/RubyGoLightly · C · 45 lines · 31 code · 5 blank · 9 comment · 8 complexity · a14a6118cea66b8eb6f3a76497f0f61b MD5 · raw file

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