summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2009-12-13 12:50:01 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2009-12-13 12:50:01 (GMT)
commit6c9d003d4ee3bbcaf639149014e8e42ed9835621 (patch)
tree95169b1d25c154882a92b1c68d65c4bc65b04cc9 /test
parent7f46301cee98932ecf7ad87068adc0f5d051d544 (diff)
downloadhdf5-6c9d003d4ee3bbcaf639149014e8e42ed9835621.zip
hdf5-6c9d003d4ee3bbcaf639149014e8e42ed9835621.tar.gz
hdf5-6c9d003d4ee3bbcaf639149014e8e42ed9835621.tar.bz2
[svn-r18013] Description:
Bring r18011 from trunk to 1.8 branch: Bring Coverity changes into the trunk: (also other minor cleanups) r17991: Fix Coverity items 175 and 176. Fixed memory leak on error in print_enum in H5LT.c. r17993: (r17992 was not a Coverity change) Close Coverity issue #206: inconsistently checking whether dt->shared was non-NULL after H5T_alloc() returned a valid 'dt' value (which should guarantee that dt->shared is valid). r17994: Fix Coverity item 149. Fixed file handle leak on error in H5FD_stdio_open. r17995: Fixed Coverity issues 154 to 161: Added H5MP_close routine to error handling in the event *mp has not been freed before error. r17996: Close Coverity issue #126: potentially leaking merged_spans on routine failure. r17997: Fix Coverity items 147 and 148. Fixed resource leaks on error in H5FDloc.c. r17998: Coverity issue 269-272: Added integer result variable to functions that could return negative. Assigned to unsigned after checking. Added H5E_BEGIN_TRY block around H5Tclose and removed H5E_THROW in the catch block. Checked buffer is NULL before free. Changed HGOTO_ERROR outside of the if block to H5E_THROW. r17999: Close Coverity issue #127: release temporary spans in more generic manner. (Also add error checking to previous fix) r18000: Resolved Coverity issues 211 and 212 in H5T.c. Added comments to ignore Coverity warning regarding not checking pointer for NULL, as we are using an assert which catches the issue. r18001: Fix Coverity item 146. Fixed resource leak on error in H5O_layout_copy. r18002: Fix Coverity items 143 and 145. Fixed resource leaks on error in H5D_compact_copy and H5D_contig_copy. r18003: Close Coverity issue #192: close file on error r18004: Fix Coverity issue #125: release temporary spans on error r18005: Resolved Coverity issues 5, 25, and 83 (in H5T.c): Separated embedded functions in order to check for NULL on return of H5I_object before passing into H5T_copy. Check to see if new_dt is NULL within error handling before dereferencing it. Ignore Coverity's dead code warnings as the checks that lead to the code are machine dependent. r18006: Coverity 63,70,73: Checked result of function before assigning to an unsigned variable. r18007: Coverity 78,79: added continue statement if H5Pget_filter2 returns negative. r18008: Fixed Coverity issue # 138: Added support in error handling to free dst pointer (if allocated) on error. r18009: Whitespace & coding style cleanup Tested on: Mac OS X/32 10.6.2 (amazon) w/debug & production (h5committested on trunk)
Diffstat (limited to 'test')
-rw-r--r--test/pool.c209
1 files changed, 103 insertions, 106 deletions
diff --git a/test/pool.c b/test/pool.c
index 43e9cfd..9b2e8b9 100644
--- a/test/pool.c
+++ b/test/pool.c
@@ -46,14 +46,11 @@
* Purpose: Test trivial creating & closing memory pool
*
* Return: Success: 0
- *
* Failure: 1
*
* Programmer: Quincey Koziol
* Tuesday, May 3, 2005
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static int
@@ -74,18 +71,18 @@ test_create(void)
/* Check free space */
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ TEST_ERROR
if(free_size != 0)
TEST_ERROR
/* Check first page */
- if (H5MP_get_pool_first_page(mp, &page) < 0)
- TEST_ERROR;
+ if(H5MP_get_pool_first_page(mp, &page) < 0)
+ TEST_ERROR
if(page != NULL)
TEST_ERROR
/* Close the memory pool */
- if (H5MP_close(mp) < 0)
+ if(H5MP_close(mp) < 0)
TEST_ERROR
PASSED();
@@ -94,7 +91,10 @@ test_create(void)
error:
H5E_BEGIN_TRY {
+ if(mp)
+ H5MP_close(mp);
} H5E_END_TRY;
+
return 1;
} /* test_create() */
@@ -105,14 +105,11 @@ error:
* Purpose: Tests closing pool with one block allocated
*
* Return: Success: 0
- *
* Failure: 1
*
* Programmer: Quincey Koziol
* Friday, May 6, 2005
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static int
@@ -143,7 +140,10 @@ test_close_one(void)
error:
H5E_BEGIN_TRY {
+ if(mp)
+ H5MP_close(mp);
} H5E_END_TRY;
+
return 1;
} /* test_close_one() */
@@ -154,14 +154,11 @@ error:
* Purpose: Tests allocating first block in pool
*
* Return: Success: 0
- *
* Failure: 1
*
* Programmer: Quincey Koziol
* Tuesday, May 3, 2005
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static int
@@ -187,29 +184,29 @@ test_allocate_first(void)
/* Check pool's free space */
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ 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))))
TEST_ERROR
/* Get first page */
- if (H5MP_get_pool_first_page(mp, &page) < 0)
- TEST_ERROR;
+ if(H5MP_get_pool_first_page(mp, &page) < 0)
+ TEST_ERROR
if(page == NULL)
TEST_ERROR
/* Check page's free space */
- if (H5MP_get_page_free_size(page, &free_size) < 0)
- TEST_ERROR;
+ 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))))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ if(H5MP_pool_is_free_size_correct(mp) <= 0)
+ TEST_ERROR
/* Check next page */
- if (H5MP_get_page_next_page(page, &page) < 0)
- TEST_ERROR;
+ if(H5MP_get_page_next_page(page, &page) < 0)
+ TEST_ERROR
if(page != NULL)
TEST_ERROR
@@ -217,17 +214,17 @@ test_allocate_first(void)
H5MP_free(mp, spc);
/* Check pool's free space */
- if (H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ 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)))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ 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();
@@ -244,29 +241,29 @@ test_allocate_first(void)
/* Check pool's free space */
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ TEST_ERROR
if(free_size != 0)
TEST_ERROR
/* Get first page */
- if (H5MP_get_pool_first_page(mp, &page) < 0)
- TEST_ERROR;
+ if(H5MP_get_pool_first_page(mp, &page) < 0)
+ TEST_ERROR
if(page == NULL)
TEST_ERROR
/* Check page's free space */
- if (H5MP_get_page_free_size(page, &free_size) < 0)
- TEST_ERROR;
+ if(H5MP_get_page_free_size(page, &free_size) < 0)
+ TEST_ERROR
if(free_size != 0)
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ if(H5MP_pool_is_free_size_correct(mp) <= 0)
+ TEST_ERROR
/* Check next page */
- if (H5MP_get_page_next_page(page, &page) < 0)
- TEST_ERROR;
+ if(H5MP_get_page_next_page(page, &page) < 0)
+ TEST_ERROR
if(page != NULL)
TEST_ERROR
@@ -274,17 +271,17 @@ test_allocate_first(void)
H5MP_free(mp, spc);
/* Check pool's free space */
- if (H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ 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)))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ 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();
@@ -293,7 +290,10 @@ test_allocate_first(void)
error:
H5E_BEGIN_TRY {
+ if(mp)
+ H5MP_close(mp);
} H5E_END_TRY;
+
return 1;
} /* test_allocate_first() */
@@ -305,14 +305,11 @@ error:
* existing block
*
* Return: Success: 0
- *
* Failure: 1
*
* Programmer: Quincey Koziol
* Tuesday, May 3, 2005
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static int
@@ -338,13 +335,13 @@ test_allocate_split(void)
/* Check pool's free space */
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ 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))))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ 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)))
@@ -352,42 +349,42 @@ test_allocate_split(void)
/* Check pool's free space */
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ 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))))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ 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)
- TEST_ERROR;
+ 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))))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ 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)
- TEST_ERROR;
+ 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)))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ 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();
@@ -396,7 +393,10 @@ test_allocate_split(void)
error:
H5E_BEGIN_TRY {
+ if(mp)
+ H5MP_close(mp);
} H5E_END_TRY;
+
return 1;
} /* test_allocate_split() */
@@ -407,14 +407,11 @@ error:
* Purpose: Tests allocating many small blocks in a pool
*
* Return: Success: 0
- *
* Failure: 1
*
* Programmer: Quincey Koziol
* Tuesday, May 6, 2005
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static int
@@ -441,13 +438,13 @@ test_allocate_many_small(void)
/* Check pool's free space */
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ 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))))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ if(H5MP_pool_is_free_size_correct(mp) <= 0)
+ TEST_ERROR
/* Free blocks in pool */
/* (Tests free block merging with block after it */
@@ -455,17 +452,17 @@ test_allocate_many_small(void)
H5MP_free(mp, spc[i]);
/* Check pool's free space */
- if (H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ 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)))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ 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();
@@ -474,7 +471,10 @@ test_allocate_many_small(void)
error:
H5E_BEGIN_TRY {
+ if(mp)
+ H5MP_close(mp);
} H5E_END_TRY;
+
return 1;
} /* test_allocate_many_small() */
@@ -486,14 +486,11 @@ error:
* new page
*
* Return: Success: 0
- *
* Failure: 1
*
* Programmer: Quincey Koziol
* Friday, May 6, 2005
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static int
@@ -522,13 +519,13 @@ test_allocate_new_page(void)
/* Check pool's free space */
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ 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)))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ 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) */
@@ -538,17 +535,17 @@ test_allocate_new_page(void)
H5MP_free(mp, spc[u]);
/* Check pool's free space */
- if (H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ 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))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ 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();
@@ -568,32 +565,32 @@ test_allocate_new_page(void)
TEST_ERROR
/* Check pool's free space */
- if (H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ 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))))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ if(H5MP_pool_is_free_size_correct(mp) <= 0)
+ TEST_ERROR
/* Free blocks in pool */
H5MP_free(mp, spc1);
H5MP_free(mp, spc2);
/* Check pool's free space */
- if (H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ 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))))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ 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();
@@ -602,7 +599,10 @@ test_allocate_new_page(void)
error:
H5E_BEGIN_TRY {
+ if(mp)
+ H5MP_close(mp);
} H5E_END_TRY;
+
return 1;
} /* test_allocate_new_page() */
@@ -613,14 +613,11 @@ error:
* Purpose: Tests allocating random sized blocks in pool
*
* Return: Success: 0
- *
* Failure: 1
*
* Programmer: Quincey Koziol
* Friday, May 6, 2005
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static int
@@ -640,7 +637,7 @@ test_allocate_random(void)
TESTING("allocate many random sized blocks");
/* Initialize random number seed */
- curr_time=HDtime(NULL);
+ curr_time = HDtime(NULL);
#ifdef QAK
curr_time=1115412944;
HDfprintf(stderr,"curr_time=%lu\n",(unsigned long)curr_time);
@@ -670,7 +667,7 @@ HDfprintf(stderr,"curr_time=%lu\n",(unsigned long)curr_time);
/* Check that free space totals match */
if(H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ TEST_ERROR
/* Shuffle pointers to free */
for(u = 0; u < MPOOL_NUM_RANDOM; u++) {
@@ -685,8 +682,8 @@ HDfprintf(stderr,"curr_time=%lu\n",(unsigned long)curr_time);
H5MP_free(mp, spc[u]);
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ 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++)
@@ -700,10 +697,10 @@ HDfprintf(stderr,"curr_time=%lu\n",(unsigned long)curr_time);
/* Check that free space totals match */
if(H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ TEST_ERROR
/* Close the memory pool */
- if (H5MP_close(mp) < 0)
+ if(H5MP_close(mp) < 0)
TEST_ERROR
/* Free memory for block sizes & pointers */
@@ -720,7 +717,10 @@ error:
if(spc)
HDfree(spc);
H5E_BEGIN_TRY {
+ if(mp)
+ H5MP_close(mp);
} H5E_END_TRY;
+
return 1;
} /* test_allocate_random() */
@@ -731,20 +731,17 @@ error:
* Purpose: Test the memory pool code
*
* Return: Success:
- *
* Failure:
*
* Programmer: Quincey Koziol
* Tuesday, May 3, 2005
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
int
main(void)
{
- int nerrors=0;
+ int nerrors = 0;
/* Reset library */
h5_reset();
@@ -762,14 +759,14 @@ main(void)
nerrors += test_allocate_new_page();
nerrors += test_allocate_random();
- if (nerrors) goto error;
+ if(nerrors)
+ goto error;
puts("All memory pool tests passed.");
+
return 0;
error:
puts("*** TESTS FAILED ***");
- H5E_BEGIN_TRY {
- } H5E_END_TRY;
return 1;
}