sdallocx.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "test/jemalloc_test.h"
  2. #define MAXALIGN (((size_t)1) << 22)
  3. #define NITER 3
  4. TEST_BEGIN(test_basic) {
  5. void *ptr = mallocx(64, 0);
  6. sdallocx(ptr, 64, 0);
  7. }
  8. TEST_END
  9. TEST_BEGIN(test_alignment_and_size) {
  10. size_t nsz, sz, alignment, total;
  11. unsigned i;
  12. void *ps[NITER];
  13. for (i = 0; i < NITER; i++) {
  14. ps[i] = NULL;
  15. }
  16. for (alignment = 8;
  17. alignment <= MAXALIGN;
  18. alignment <<= 1) {
  19. total = 0;
  20. for (sz = 1;
  21. sz < 3 * alignment && sz < (1U << 31);
  22. sz += (alignment >> (LG_SIZEOF_PTR-1)) - 1) {
  23. for (i = 0; i < NITER; i++) {
  24. nsz = nallocx(sz, MALLOCX_ALIGN(alignment) |
  25. MALLOCX_ZERO);
  26. ps[i] = mallocx(sz, MALLOCX_ALIGN(alignment) |
  27. MALLOCX_ZERO);
  28. total += nsz;
  29. if (total >= (MAXALIGN << 1)) {
  30. break;
  31. }
  32. }
  33. for (i = 0; i < NITER; i++) {
  34. if (ps[i] != NULL) {
  35. sdallocx(ps[i], sz,
  36. MALLOCX_ALIGN(alignment));
  37. ps[i] = NULL;
  38. }
  39. }
  40. }
  41. }
  42. }
  43. TEST_END
  44. int
  45. main(void) {
  46. return test_no_reentrancy(
  47. test_basic,
  48. test_alignment_and_size);
  49. }