diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2020-10-01 15:29:53 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2020-10-01 15:29:53 (GMT) |
commit | ec8ad09125032c9c232878d02e90aa86df162841 (patch) | |
tree | 5d63105d3a0db7d5bbee41c5b74b097649a2115e /test/pool.c | |
parent | 453238e90e1574ef1c15e3c79f7fb3d77920e77c (diff) | |
download | hdf5-ec8ad09125032c9c232878d02e90aa86df162841.zip hdf5-ec8ad09125032c9c232878d02e90aa86df162841.tar.gz hdf5-ec8ad09125032c9c232878d02e90aa86df162841.tar.bz2 |
Source formatted
Diffstat (limited to 'test/pool.c')
-rw-r--r-- | test/pool.c | 368 |
1 files changed, 196 insertions, 172 deletions
diff --git a/test/pool.c b/test/pool.c index 59f9201..05304e5 100644 --- a/test/pool.c +++ b/test/pool.c @@ -20,9 +20,9 @@ * This file needs to access private datatypes from the H5MP package. * This file also needs to access the memory pool testing code. */ -#define H5MP_FRIEND /*suppress error about including H5MPpkg */ +#define H5MP_FRIEND /*suppress error about including H5MPpkg */ #define H5MP_TESTING -#include "H5MPpkg.h" /* Memory Pools */ +#include "H5MPpkg.h" /* Memory Pools */ /* Other private headers that this test requires */ @@ -34,10 +34,9 @@ #define MPOOL_LARGE_BLOCK (MPOOL_PAGE_SIZE * 3) #define MPOOL_NUM_SMALL_BLOCKS 64 #define MPOOL_SMALL_BLOCK 1 -#define MPOOL_NUM_RANDOM 10*1024 +#define MPOOL_NUM_RANDOM 10 * 1024 #define MPOOL_RANDOM_MAX_SIZE (MPOOL_PAGE_SIZE * 2) - /*------------------------------------------------------------------------- * Function: test_create * @@ -54,9 +53,9 @@ static int test_create(void) { - H5MP_pool_t *mp; /* Memory pool */ - H5MP_page_t *page; /* Memory pool page */ - size_t free_size; /* Free size in pool */ + H5MP_pool_t *mp; /* Memory pool */ + H5MP_page_t *page; /* Memory pool page */ + size_t free_size; /* Free size in pool */ /* * Test memory pool creation @@ -64,23 +63,23 @@ test_create(void) TESTING("memory pool creation"); /* Create a memory pool */ - if(NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS))) + if (NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS))) TEST_ERROR /* Check free space */ - if(H5MP_get_pool_free_size(mp, &free_size) < 0) + if (H5MP_get_pool_free_size(mp, &free_size) < 0) TEST_ERROR - if(free_size != 0) + if (free_size != 0) TEST_ERROR /* Check first page */ - if(H5MP_get_pool_first_page(mp, &page) < 0) + if (H5MP_get_pool_first_page(mp, &page) < 0) TEST_ERROR - if(page != NULL) + if (page != NULL) TEST_ERROR /* Close the memory pool */ - if(H5MP_close(mp) < 0) + if (H5MP_close(mp) < 0) TEST_ERROR PASSED(); @@ -88,15 +87,16 @@ test_create(void) return 0; error: - H5E_BEGIN_TRY { - if(mp) + H5E_BEGIN_TRY + { + if (mp) H5MP_close(mp); - } H5E_END_TRY; + } + H5E_END_TRY; return 1; } /* test_create() */ - /*------------------------------------------------------------------------- * Function: test_close_one * @@ -113,7 +113,7 @@ error: static int test_close_one(void) { - H5MP_pool_t *mp; /* Memory pool */ + H5MP_pool_t *mp; /* Memory pool */ /* * Test memory pool closing @@ -121,15 +121,15 @@ test_close_one(void) TESTING("closing pool with blocks still allocated in one page"); /* Create a memory pool */ - if(NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS))) + if (NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS))) TEST_ERROR /* Allocate space in pool */ - if(NULL == H5MP_malloc(mp, (size_t)MPOOL_NORMAL_BLOCK)) + if (NULL == H5MP_malloc(mp, (size_t)MPOOL_NORMAL_BLOCK)) TEST_ERROR /* Close the memory pool */ - if(H5MP_close(mp) < 0) + if (H5MP_close(mp) < 0) TEST_ERROR PASSED(); @@ -137,15 +137,16 @@ test_close_one(void) return 0; error: - H5E_BEGIN_TRY { - if(mp) + H5E_BEGIN_TRY + { + if (mp) H5MP_close(mp); - } H5E_END_TRY; + } + H5E_END_TRY; return 1; } /* test_close_one() */ - /*------------------------------------------------------------------------- * Function: test_allocate_first * @@ -162,10 +163,10 @@ error: static int test_allocate_first(void) { - H5MP_pool_t *mp; /* Memory pool */ - H5MP_page_t *page; /* Memory pool page */ - size_t free_size; /* Free size in pool */ - void *spc; /* Pointer to space allocated */ + H5MP_pool_t *mp; /* Memory pool */ + H5MP_page_t *page; /* Memory pool page */ + size_t free_size; /* Free size in pool */ + void * spc; /* Pointer to space allocated */ /* * Test memory pool allocation @@ -173,56 +174,60 @@ test_allocate_first(void) TESTING("allocating first block in pool"); /* Create a memory pool */ - if(NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS))) + if (NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS))) TEST_ERROR /* Allocate space in pool */ - if(NULL == (spc = H5MP_malloc(mp, (size_t)MPOOL_NORMAL_BLOCK))) + if (NULL == (spc = H5MP_malloc(mp, (size_t)MPOOL_NORMAL_BLOCK))) TEST_ERROR /* Check pool's free space */ - if(H5MP_get_pool_free_size(mp, &free_size) < 0) + if (H5MP_get_pool_free_size(mp, &free_size) < 0) TEST_ERROR - if(free_size != MPOOL_PAGE_SIZE - (H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)))) + if (free_size != + MPOOL_PAGE_SIZE - (H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)) + + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)))) TEST_ERROR /* Get first page */ - if(H5MP_get_pool_first_page(mp, &page) < 0) + if (H5MP_get_pool_first_page(mp, &page) < 0) TEST_ERROR - if(page == NULL) + if (page == NULL) TEST_ERROR /* Check page's free space */ - if(H5MP_get_page_free_size(page, &free_size) < 0) + if (H5MP_get_page_free_size(page, &free_size) < 0) TEST_ERROR - if(free_size != MPOOL_PAGE_SIZE - (H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)))) + if (free_size != + MPOOL_PAGE_SIZE - (H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)) + + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)))) TEST_ERROR /* Check that free space totals match */ - if(H5MP_pool_is_free_size_correct(mp) <= 0) + if (H5MP_pool_is_free_size_correct(mp) <= 0) TEST_ERROR /* Check next page */ - if(H5MP_get_page_next_page(page, &page) < 0) + if (H5MP_get_page_next_page(page, &page) < 0) TEST_ERROR - if(page != NULL) + if (page != NULL) TEST_ERROR /* Free space in pool */ H5MP_free(mp, spc); /* Check pool's free space */ - if(H5MP_get_pool_free_size(mp, &free_size) < 0) + if (H5MP_get_pool_free_size(mp, &free_size) < 0) TEST_ERROR - if(free_size != MPOOL_PAGE_SIZE - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))) + if (free_size != MPOOL_PAGE_SIZE - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))) TEST_ERROR /* Check that free space totals match */ - if(H5MP_pool_is_free_size_correct(mp) <= 0) + if (H5MP_pool_is_free_size_correct(mp) <= 0) TEST_ERROR /* Close the memory pool */ - if(H5MP_close(mp) < 0) + if (H5MP_close(mp) < 0) TEST_ERROR PASSED(); @@ -230,56 +235,56 @@ test_allocate_first(void) TESTING("allocating large first block in pool"); /* Create a memory pool */ - if(NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS))) + if (NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS))) TEST_ERROR /* Allocate space in pool */ - if(NULL == (spc = H5MP_malloc(mp, (size_t)MPOOL_LARGE_BLOCK))) + if (NULL == (spc = H5MP_malloc(mp, (size_t)MPOOL_LARGE_BLOCK))) TEST_ERROR /* Check pool's free space */ - if(H5MP_get_pool_free_size(mp, &free_size) < 0) + if (H5MP_get_pool_free_size(mp, &free_size) < 0) TEST_ERROR - if(free_size != 0) + if (free_size != 0) TEST_ERROR /* Get first page */ - if(H5MP_get_pool_first_page(mp, &page) < 0) + if (H5MP_get_pool_first_page(mp, &page) < 0) TEST_ERROR - if(page == NULL) + if (page == NULL) TEST_ERROR /* Check page's free space */ - if(H5MP_get_page_free_size(page, &free_size) < 0) + if (H5MP_get_page_free_size(page, &free_size) < 0) TEST_ERROR - if(free_size != 0) + if (free_size != 0) TEST_ERROR /* Check that free space totals match */ - if(H5MP_pool_is_free_size_correct(mp) <= 0) + if (H5MP_pool_is_free_size_correct(mp) <= 0) TEST_ERROR /* Check next page */ - if(H5MP_get_page_next_page(page, &page) < 0) + if (H5MP_get_page_next_page(page, &page) < 0) TEST_ERROR - if(page != NULL) + if (page != NULL) TEST_ERROR /* Free space in pool */ H5MP_free(mp, spc); /* Check pool's free space */ - if(H5MP_get_pool_free_size(mp, &free_size) < 0) + if (H5MP_get_pool_free_size(mp, &free_size) < 0) TEST_ERROR - if(free_size != MPOOL_LARGE_BLOCK + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t))) + if (free_size != MPOOL_LARGE_BLOCK + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t))) TEST_ERROR /* Check that free space totals match */ - if(H5MP_pool_is_free_size_correct(mp) <= 0) + if (H5MP_pool_is_free_size_correct(mp) <= 0) TEST_ERROR /* Close the memory pool */ - if(H5MP_close(mp) < 0) + if (H5MP_close(mp) < 0) TEST_ERROR PASSED(); @@ -287,15 +292,16 @@ test_allocate_first(void) return 0; error: - H5E_BEGIN_TRY { - if(mp) + H5E_BEGIN_TRY + { + if (mp) H5MP_close(mp); - } H5E_END_TRY; + } + H5E_END_TRY; return 1; } /* test_allocate_first() */ - /*------------------------------------------------------------------------- * Function: test_allocate_split * @@ -313,10 +319,10 @@ error: static int test_allocate_split(void) { - H5MP_pool_t *mp; /* Memory pool */ - size_t free_size; /* Free size in pool */ - void *spc1; /* Pointer to space allocated */ - void *spc2; /* Pointer to space allocated */ + H5MP_pool_t *mp; /* Memory pool */ + size_t free_size; /* Free size in pool */ + void * spc1; /* Pointer to space allocated */ + void * spc2; /* Pointer to space allocated */ /* * Test memory pool allocation @@ -324,65 +330,72 @@ test_allocate_split(void) TESTING("splitting block in pool"); /* Create a memory pool */ - if(NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS))) + if (NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS))) TEST_ERROR /* Allocate space in pool */ - if(NULL == (spc1 = H5MP_malloc(mp, (size_t)MPOOL_NORMAL_BLOCK))) + if (NULL == (spc1 = H5MP_malloc(mp, (size_t)MPOOL_NORMAL_BLOCK))) TEST_ERROR /* Check pool's free space */ - if(H5MP_get_pool_free_size(mp, &free_size) < 0) + if (H5MP_get_pool_free_size(mp, &free_size) < 0) TEST_ERROR - if(free_size != MPOOL_PAGE_SIZE - (H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)))) + if (free_size != + MPOOL_PAGE_SIZE - (H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)) + + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)))) TEST_ERROR /* Check that free space totals match */ - if(H5MP_pool_is_free_size_correct(mp) <= 0) + if (H5MP_pool_is_free_size_correct(mp) <= 0) TEST_ERROR /* Allocate more space in pool */ - if(NULL == (spc2 = H5MP_malloc(mp, (size_t)MPOOL_NORMAL_BLOCK))) + if (NULL == (spc2 = H5MP_malloc(mp, (size_t)MPOOL_NORMAL_BLOCK))) TEST_ERROR /* Check pool's free space */ - if(H5MP_get_pool_free_size(mp, &free_size) < 0) + if (H5MP_get_pool_free_size(mp, &free_size) < 0) TEST_ERROR - if(free_size != MPOOL_PAGE_SIZE - (((H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t))) * 2) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)))) + if (free_size != + MPOOL_PAGE_SIZE - + (((H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t))) * 2) + + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)))) TEST_ERROR /* Check that free space totals match */ - if(H5MP_pool_is_free_size_correct(mp) <= 0) + if (H5MP_pool_is_free_size_correct(mp) <= 0) TEST_ERROR /* Free first block in pool */ H5MP_free(mp, spc1); /* Check pool's free space */ - if(H5MP_get_pool_free_size(mp, &free_size) < 0) + if (H5MP_get_pool_free_size(mp, &free_size) < 0) TEST_ERROR - if(free_size != MPOOL_PAGE_SIZE - (H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)))) + if (free_size != + MPOOL_PAGE_SIZE - (H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)) + + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)))) TEST_ERROR /* Check that free space totals match */ - if(H5MP_pool_is_free_size_correct(mp) <= 0) + if (H5MP_pool_is_free_size_correct(mp) <= 0) TEST_ERROR /* Free second block in pool (should merge with first block) */ H5MP_free(mp, spc2); /* Check pool's free space */ - if(H5MP_get_pool_free_size(mp, &free_size) < 0) + if (H5MP_get_pool_free_size(mp, &free_size) < 0) TEST_ERROR - if(free_size != MPOOL_PAGE_SIZE - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))) + if (free_size != MPOOL_PAGE_SIZE - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))) TEST_ERROR /* Check that free space totals match */ - if(H5MP_pool_is_free_size_correct(mp) <= 0) + if (H5MP_pool_is_free_size_correct(mp) <= 0) TEST_ERROR /* Close the memory pool */ - if(H5MP_close(mp) < 0) + if (H5MP_close(mp) < 0) TEST_ERROR PASSED(); @@ -390,15 +403,16 @@ test_allocate_split(void) return 0; error: - H5E_BEGIN_TRY { - if(mp) + H5E_BEGIN_TRY + { + if (mp) H5MP_close(mp); - } H5E_END_TRY; + } + H5E_END_TRY; return 1; } /* test_allocate_split() */ - /*------------------------------------------------------------------------- * Function: test_allocate_many_small * @@ -415,10 +429,10 @@ error: static int test_allocate_many_small(void) { - H5MP_pool_t *mp; /* Memory pool */ - size_t free_size; /* Free size in pool */ - void *spc[MPOOL_NUM_SMALL_BLOCKS]; /* Pointers to space allocated */ - int i; /* Local index variable */ + H5MP_pool_t *mp; /* Memory pool */ + size_t free_size; /* Free size in pool */ + void * spc[MPOOL_NUM_SMALL_BLOCKS]; /* Pointers to space allocated */ + int i; /* Local index variable */ /* * Test memory pool allocation @@ -426,41 +440,44 @@ test_allocate_many_small(void) TESTING("allocating many small blocks"); /* Create a memory pool */ - if(NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS))) + if (NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS))) TEST_ERROR /* Allocate space in pool */ - for(i = 0; i < MPOOL_NUM_SMALL_BLOCKS; i++) - if(NULL == (spc[i] = H5MP_malloc(mp, (size_t)MPOOL_SMALL_BLOCK))) + for (i = 0; i < MPOOL_NUM_SMALL_BLOCKS; i++) + if (NULL == (spc[i] = H5MP_malloc(mp, (size_t)MPOOL_SMALL_BLOCK))) TEST_ERROR /* Check pool's free space */ - if(H5MP_get_pool_free_size(mp, &free_size) < 0) + if (H5MP_get_pool_free_size(mp, &free_size) < 0) TEST_ERROR - if(free_size != MPOOL_PAGE_SIZE - (((H5MP_BLOCK_ALIGN(MPOOL_SMALL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t))) * MPOOL_NUM_SMALL_BLOCKS) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)))) + if (free_size != MPOOL_PAGE_SIZE - + (((H5MP_BLOCK_ALIGN(MPOOL_SMALL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t))) * + MPOOL_NUM_SMALL_BLOCKS) + + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)))) TEST_ERROR /* Check that free space totals match */ - if(H5MP_pool_is_free_size_correct(mp) <= 0) + if (H5MP_pool_is_free_size_correct(mp) <= 0) TEST_ERROR /* Free blocks in pool */ /* (Tests free block merging with block after it */ - for(i = (MPOOL_NUM_SMALL_BLOCKS - 1); i >= 0; i--) + for (i = (MPOOL_NUM_SMALL_BLOCKS - 1); i >= 0; i--) H5MP_free(mp, spc[i]); /* Check pool's free space */ - if(H5MP_get_pool_free_size(mp, &free_size) < 0) + if (H5MP_get_pool_free_size(mp, &free_size) < 0) TEST_ERROR - if(free_size != MPOOL_PAGE_SIZE - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))) + if (free_size != MPOOL_PAGE_SIZE - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))) TEST_ERROR /* Check that free space totals match */ - if(H5MP_pool_is_free_size_correct(mp) <= 0) + if (H5MP_pool_is_free_size_correct(mp) <= 0) TEST_ERROR /* Close the memory pool */ - if(H5MP_close(mp) < 0) + if (H5MP_close(mp) < 0) TEST_ERROR PASSED(); @@ -468,15 +485,16 @@ test_allocate_many_small(void) return 0; error: - H5E_BEGIN_TRY { - if(mp) + H5E_BEGIN_TRY + { + if (mp) H5MP_close(mp); - } H5E_END_TRY; + } + H5E_END_TRY; return 1; } /* test_allocate_many_small() */ - /*------------------------------------------------------------------------- * Function: test_allocate_new_page * @@ -494,12 +512,12 @@ error: static int test_allocate_new_page(void) { - H5MP_pool_t *mp; /* Memory pool */ - size_t free_size; /* Free size in pool */ - size_t u; /* Local index variable */ - void *spc[MPOOL_NUM_NORMAL_BLOCKS]; /* Pointer to space allocated */ - void *spc1; /* Pointer to space allocated */ - void *spc2; /* Pointer to space allocated */ + H5MP_pool_t *mp; /* Memory pool */ + size_t free_size; /* Free size in pool */ + size_t u; /* Local index variable */ + void * spc[MPOOL_NUM_NORMAL_BLOCKS]; /* Pointer to space allocated */ + void * spc1; /* Pointer to space allocated */ + void * spc2; /* Pointer to space allocated */ /* * Test memory pool allocation @@ -507,43 +525,46 @@ test_allocate_new_page(void) TESTING("allocate normal-sized block in new page"); /* Create a memory pool */ - if(NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS))) + if (NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS))) TEST_ERROR /* Allocate space in pool */ - for(u = 0; u < MPOOL_NUM_NORMAL_BLOCKS; u++) - if(NULL == (spc[u] = H5MP_malloc(mp, (size_t)MPOOL_NORMAL_BLOCK))) + for (u = 0; u < MPOOL_NUM_NORMAL_BLOCKS; u++) + if (NULL == (spc[u] = H5MP_malloc(mp, (size_t)MPOOL_NORMAL_BLOCK))) TEST_ERROR /* Check pool's free space */ - if(H5MP_get_pool_free_size(mp, &free_size) < 0) + if (H5MP_get_pool_free_size(mp, &free_size) < 0) TEST_ERROR - if(free_size != (MPOOL_PAGE_SIZE * 3) - (((H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t))) * MPOOL_NUM_NORMAL_BLOCKS) + (H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)) * 3))) + if (free_size != (MPOOL_PAGE_SIZE * 3) - (((H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t))) * + MPOOL_NUM_NORMAL_BLOCKS) + + (H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)) * 3))) TEST_ERROR /* Check that free space totals match */ - if(H5MP_pool_is_free_size_correct(mp) <= 0) + if (H5MP_pool_is_free_size_correct(mp) <= 0) TEST_ERROR /* Free blocks in pool */ /* (Free alternating blocks, in two passes, which tests block merging w/both neighbors) */ - for(u = 0; u < MPOOL_NUM_NORMAL_BLOCKS; u+=2) + for (u = 0; u < MPOOL_NUM_NORMAL_BLOCKS; u += 2) H5MP_free(mp, spc[u]); - for(u = 1; u < MPOOL_NUM_NORMAL_BLOCKS; u+=2) + for (u = 1; u < MPOOL_NUM_NORMAL_BLOCKS; u += 2) H5MP_free(mp, spc[u]); /* Check pool's free space */ - if(H5MP_get_pool_free_size(mp, &free_size) < 0) + if (H5MP_get_pool_free_size(mp, &free_size) < 0) TEST_ERROR - if(free_size != ((MPOOL_PAGE_SIZE - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))) * 3)) + if (free_size != ((MPOOL_PAGE_SIZE - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))) * 3)) TEST_ERROR /* Check that free space totals match */ - if(H5MP_pool_is_free_size_correct(mp) <= 0) + if (H5MP_pool_is_free_size_correct(mp) <= 0) TEST_ERROR /* Close the memory pool */ - if(H5MP_close(mp) < 0) + if (H5MP_close(mp) < 0) TEST_ERROR PASSED(); @@ -551,25 +572,27 @@ test_allocate_new_page(void) TESTING("allocate large-sized block in new page"); /* Create a memory pool */ - if(NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS))) + if (NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS))) TEST_ERROR /* Allocate space in pool */ /* (Normal sized block) */ - if(NULL == (spc1 = H5MP_malloc(mp, (size_t)MPOOL_NORMAL_BLOCK))) + if (NULL == (spc1 = H5MP_malloc(mp, (size_t)MPOOL_NORMAL_BLOCK))) TEST_ERROR /* (Larger sized block) */ - if(NULL == (spc2 = H5MP_malloc(mp, (size_t)MPOOL_LARGE_BLOCK))) + if (NULL == (spc2 = H5MP_malloc(mp, (size_t)MPOOL_LARGE_BLOCK))) TEST_ERROR /* Check pool's free space */ - if(H5MP_get_pool_free_size(mp, &free_size) < 0) + if (H5MP_get_pool_free_size(mp, &free_size) < 0) TEST_ERROR - if(free_size != MPOOL_PAGE_SIZE - (H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)))) + if (free_size != + MPOOL_PAGE_SIZE - (H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)) + + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)))) TEST_ERROR /* Check that free space totals match */ - if(H5MP_pool_is_free_size_correct(mp) <= 0) + if (H5MP_pool_is_free_size_correct(mp) <= 0) TEST_ERROR /* Free blocks in pool */ @@ -577,18 +600,18 @@ test_allocate_new_page(void) H5MP_free(mp, spc2); /* Check pool's free space */ - if(H5MP_get_pool_free_size(mp, &free_size) < 0) + if (H5MP_get_pool_free_size(mp, &free_size) < 0) TEST_ERROR - if(free_size != ((MPOOL_PAGE_SIZE - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))) + - MPOOL_LARGE_BLOCK + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)))) + if (free_size != ((MPOOL_PAGE_SIZE - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))) + MPOOL_LARGE_BLOCK + + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)))) TEST_ERROR /* Check that free space totals match */ - if(H5MP_pool_is_free_size_correct(mp) <= 0) + if (H5MP_pool_is_free_size_correct(mp) <= 0) TEST_ERROR /* Close the memory pool */ - if(H5MP_close(mp) < 0) + if (H5MP_close(mp) < 0) TEST_ERROR PASSED(); @@ -596,15 +619,16 @@ test_allocate_new_page(void) return 0; error: - H5E_BEGIN_TRY { - if(mp) + H5E_BEGIN_TRY + { + if (mp) H5MP_close(mp); - } H5E_END_TRY; + } + H5E_END_TRY; return 1; } /* test_allocate_new_page() */ - /*------------------------------------------------------------------------- * Function: test_allocate_random * @@ -621,13 +645,13 @@ error: static int test_allocate_random(void) { - H5MP_pool_t *mp; /* Memory pool */ - size_t u; /* Local index variable */ - time_t curr_time; /* Current time, for seeding random number generator */ - size_t *blk_size = NULL; /* Pointer to block sizes */ - void **spc = NULL; /* Pointer to space allocated */ - size_t swap_idx; /* Location to swap with when shuffling */ - void *swap_ptr; /* Pointer to swap when shuffling */ + H5MP_pool_t *mp; /* Memory pool */ + size_t u; /* Local index variable */ + time_t curr_time; /* Current time, for seeding random number generator */ + size_t * blk_size = NULL; /* Pointer to block sizes */ + void ** spc = NULL; /* Pointer to space allocated */ + size_t swap_idx; /* Location to swap with when shuffling */ + void * swap_ptr; /* Pointer to swap when shuffling */ /* * Test memory pool allocation @@ -643,62 +667,62 @@ HDfprintf(stderr,"curr_time=%lu\n",(unsigned long)curr_time); HDsrandom((unsigned)curr_time); /* Create a memory pool */ - if(NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS))) + if (NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS))) TEST_ERROR /* Allocate space for the block sizes */ - if(NULL == (blk_size = (size_t *)HDmalloc(sizeof(size_t) * MPOOL_NUM_RANDOM))) + if (NULL == (blk_size = (size_t *)HDmalloc(sizeof(size_t) * MPOOL_NUM_RANDOM))) TEST_ERROR /* Allocate space for the block pointers */ - if(NULL == (spc = (void **)HDmalloc(sizeof(void *) * MPOOL_NUM_RANDOM))) + if (NULL == (spc = (void **)HDmalloc(sizeof(void *) * MPOOL_NUM_RANDOM))) TEST_ERROR /* Initialize the block sizes with random values */ - for(u = 0; u < MPOOL_NUM_RANDOM; u++) + for (u = 0; u < MPOOL_NUM_RANDOM; u++) blk_size[u] = (size_t)(HDrandom() % MPOOL_RANDOM_MAX_SIZE) + 1; /* Allocate space in pool */ - for(u = 0; u < MPOOL_NUM_RANDOM; u++) - if(NULL == (spc[u] = H5MP_malloc(mp, blk_size[u]))) + for (u = 0; u < MPOOL_NUM_RANDOM; u++) + if (NULL == (spc[u] = H5MP_malloc(mp, blk_size[u]))) TEST_ERROR /* Check that free space totals match */ - if(H5MP_pool_is_free_size_correct(mp) <= 0) + if (H5MP_pool_is_free_size_correct(mp) <= 0) TEST_ERROR /* Shuffle pointers to free */ - for(u = 0; u < MPOOL_NUM_RANDOM; u++) { - swap_idx = (size_t)(HDrandom() % (int)(MPOOL_NUM_RANDOM - u)) + u; - swap_ptr = spc[u]; - spc[u] = spc[swap_idx]; + for (u = 0; u < MPOOL_NUM_RANDOM; u++) { + swap_idx = (size_t)(HDrandom() % (int)(MPOOL_NUM_RANDOM - u)) + u; + swap_ptr = spc[u]; + spc[u] = spc[swap_idx]; spc[swap_idx] = swap_ptr; } /* end for */ /* Free blocks in pool */ - for(u = 0; u < MPOOL_NUM_RANDOM; u++) + for (u = 0; u < MPOOL_NUM_RANDOM; u++) H5MP_free(mp, spc[u]); /* Check that free space totals match */ - if(H5MP_pool_is_free_size_correct(mp) <= 0) + if (H5MP_pool_is_free_size_correct(mp) <= 0) TEST_ERROR /* Initialize the block sizes with random values */ - for(u = 0; u < MPOOL_NUM_RANDOM; u++) + for (u = 0; u < MPOOL_NUM_RANDOM; u++) blk_size[u] = (size_t)(HDrandom() % MPOOL_RANDOM_MAX_SIZE) + 1; /* Allocate space in pool (again) */ /* (Leave allocated to test closing pool with many blocks still allocated) */ - for(u = 0; u < MPOOL_NUM_RANDOM; u++) - if(NULL == (spc[u] = H5MP_malloc(mp, blk_size[u]))) + for (u = 0; u < MPOOL_NUM_RANDOM; u++) + if (NULL == (spc[u] = H5MP_malloc(mp, blk_size[u]))) TEST_ERROR /* Check that free space totals match */ - if(H5MP_pool_is_free_size_correct(mp) <= 0) + if (H5MP_pool_is_free_size_correct(mp) <= 0) TEST_ERROR /* Close the memory pool */ - if(H5MP_close(mp) < 0) + if (H5MP_close(mp) < 0) TEST_ERROR /* Free memory for block sizes & pointers */ @@ -710,19 +734,20 @@ HDfprintf(stderr,"curr_time=%lu\n",(unsigned long)curr_time); return 0; error: - if(blk_size) + if (blk_size) HDfree(blk_size); - if(spc) + if (spc) HDfree(spc); - H5E_BEGIN_TRY { - if(mp) + H5E_BEGIN_TRY + { + if (mp) H5MP_close(mp); - } H5E_END_TRY; + } + H5E_END_TRY; return 1; } /* test_allocate_random() */ - /*------------------------------------------------------------------------- * Function: main * @@ -757,7 +782,7 @@ main(void) nerrors += test_allocate_new_page(); nerrors += test_allocate_random(); - if(nerrors) + if (nerrors) goto error; puts("All memory pool tests passed."); @@ -767,4 +792,3 @@ error: puts("*** TESTS FAILED ***"); return 1; } - |