2005-05-18 03:01:07 +08:00
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2007-02-07 22:56:24 +08:00
|
|
|
|
* Copyright by The HDF Group. *
|
2005-05-18 03:01:07 +08:00
|
|
|
|
* Copyright by the Board of Trustees of the University of Illinois. *
|
|
|
|
|
* All rights reserved. *
|
|
|
|
|
* *
|
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
2017-04-18 03:32:16 +08:00
|
|
|
|
* the COPYING file, which can be found at the root of the source code *
|
|
|
|
|
* distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
|
|
|
|
|
* If you do not have access to either file, you may request a copy from *
|
|
|
|
|
* help@hdfgroup.org. *
|
2005-05-18 03:01:07 +08:00
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
|
|
/* Programmer: Quincey Koziol <koziol@ncsa.uiuc.edu>
|
|
|
|
|
* Tuesday, May 3, 2005
|
|
|
|
|
*/
|
|
|
|
|
#include "h5test.h"
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This file needs to access private datatypes from the H5MP package.
|
|
|
|
|
* This file also needs to access the memory pool testing code.
|
|
|
|
|
*/
|
2015-09-14 11:58:59 +08:00
|
|
|
|
#define H5MP_FRIEND /*suppress error about including H5MPpkg */
|
2005-05-18 03:01:07 +08:00
|
|
|
|
#define H5MP_TESTING
|
|
|
|
|
#include "H5MPpkg.h" /* Memory Pools */
|
|
|
|
|
|
|
|
|
|
/* Other private headers that this test requires */
|
|
|
|
|
|
|
|
|
|
/* Local macros */
|
|
|
|
|
#define MPOOL_PAGE_SIZE H5MP_PAGE_SIZE_DEFAULT
|
|
|
|
|
#define MPOOL_FLAGS H5MP_FLG_DEFAULT
|
|
|
|
|
#define MPOOL_NUM_NORMAL_BLOCKS 15
|
|
|
|
|
#define MPOOL_NORMAL_BLOCK 512
|
|
|
|
|
#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_RANDOM_MAX_SIZE (MPOOL_PAGE_SIZE * 2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: test_create
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Test trivial creating & closing memory pool
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: 0
|
|
|
|
|
* Failure: 1
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Quincey Koziol
|
|
|
|
|
* Tuesday, May 3, 2005
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Test memory pool creation
|
|
|
|
|
*/
|
|
|
|
|
TESTING("memory pool creation");
|
|
|
|
|
|
|
|
|
|
/* Create a memory pool */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS)))
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Check free space */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
|
2009-12-13 13:28:30 +08:00
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
if(free_size != 0)
|
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Check first page */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_get_pool_first_page(mp, &page) < 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
if(page != NULL)
|
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Close the memory pool */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_close(mp) < 0)
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
PASSED();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
H5E_BEGIN_TRY {
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(mp)
|
|
|
|
|
H5MP_close(mp);
|
2005-05-18 03:01:07 +08:00
|
|
|
|
} H5E_END_TRY;
|
2009-12-13 13:28:30 +08:00
|
|
|
|
|
2005-05-18 03:01:07 +08:00
|
|
|
|
return 1;
|
|
|
|
|
} /* test_create() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: test_close_one
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Tests closing pool with one block allocated
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: 0
|
|
|
|
|
* Failure: 1
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Quincey Koziol
|
|
|
|
|
* Friday, May 6, 2005
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
test_close_one(void)
|
|
|
|
|
{
|
|
|
|
|
H5MP_pool_t *mp; /* Memory pool */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Test memory pool closing
|
|
|
|
|
*/
|
|
|
|
|
TESTING("closing pool with blocks still allocated in one page");
|
|
|
|
|
|
|
|
|
|
/* Create a memory pool */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS)))
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Allocate space in pool */
|
2009-07-30 09:59:24 +08:00
|
|
|
|
if(NULL == H5MP_malloc(mp, (size_t)MPOOL_NORMAL_BLOCK))
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Close the memory pool */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(H5MP_close(mp) < 0)
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
PASSED();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
H5E_BEGIN_TRY {
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(mp)
|
|
|
|
|
H5MP_close(mp);
|
2005-05-18 03:01:07 +08:00
|
|
|
|
} H5E_END_TRY;
|
2009-12-13 13:28:30 +08:00
|
|
|
|
|
2005-05-18 03:01:07 +08:00
|
|
|
|
return 1;
|
|
|
|
|
} /* test_close_one() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: test_allocate_first
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Tests allocating first block in pool
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: 0
|
|
|
|
|
* Failure: 1
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Quincey Koziol
|
|
|
|
|
* Tuesday, May 3, 2005
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Test memory pool allocation
|
|
|
|
|
*/
|
|
|
|
|
TESTING("allocating first block in pool");
|
|
|
|
|
|
|
|
|
|
/* Create a memory pool */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS)))
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Allocate space in pool */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(NULL == (spc = H5MP_malloc(mp, (size_t)MPOOL_NORMAL_BLOCK)))
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Check pool's free space */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
|
2009-12-13 13:28:30 +08:00
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
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 */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_get_pool_first_page(mp, &page) < 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
if(page == NULL)
|
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Check page's free space */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_get_page_free_size(page, &free_size) < 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
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 */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_pool_is_free_size_correct(mp) <= 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
|
|
|
|
|
/* Check next page */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_get_page_next_page(page, &page) < 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
if(page != NULL)
|
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Free space in pool */
|
|
|
|
|
H5MP_free(mp, spc);
|
|
|
|
|
|
|
|
|
|
/* Check pool's free space */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
if(free_size != MPOOL_PAGE_SIZE - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)))
|
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Check that free space totals match */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_pool_is_free_size_correct(mp) <= 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
|
|
|
|
|
/* Close the memory pool */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_close(mp) < 0)
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
PASSED();
|
|
|
|
|
|
|
|
|
|
TESTING("allocating large first block in pool");
|
|
|
|
|
|
|
|
|
|
/* Create a memory pool */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS)))
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Allocate space in pool */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(NULL == (spc = H5MP_malloc(mp, (size_t)MPOOL_LARGE_BLOCK)))
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Check pool's free space */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
|
2009-12-13 13:28:30 +08:00
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
if(free_size != 0)
|
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Get first page */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_get_pool_first_page(mp, &page) < 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
if(page == NULL)
|
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Check page's free space */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_get_page_free_size(page, &free_size) < 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
if(free_size != 0)
|
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Check that free space totals match */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_pool_is_free_size_correct(mp) <= 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
|
|
|
|
|
/* Check next page */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_get_page_next_page(page, &page) < 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
if(page != NULL)
|
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Free space in pool */
|
|
|
|
|
H5MP_free(mp, spc);
|
|
|
|
|
|
|
|
|
|
/* Check pool's free space */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
if(free_size != MPOOL_LARGE_BLOCK + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)))
|
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Check that free space totals match */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_pool_is_free_size_correct(mp) <= 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
|
|
|
|
|
/* Close the memory pool */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_close(mp) < 0)
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
PASSED();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
H5E_BEGIN_TRY {
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(mp)
|
|
|
|
|
H5MP_close(mp);
|
2005-05-18 03:01:07 +08:00
|
|
|
|
} H5E_END_TRY;
|
2009-12-13 13:28:30 +08:00
|
|
|
|
|
2005-05-18 03:01:07 +08:00
|
|
|
|
return 1;
|
|
|
|
|
} /* test_allocate_first() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: test_allocate_split
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Tests allocating block in pool that requires splitting
|
|
|
|
|
* existing block
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: 0
|
|
|
|
|
* Failure: 1
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Quincey Koziol
|
|
|
|
|
* Tuesday, May 3, 2005
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Test memory pool allocation
|
|
|
|
|
*/
|
|
|
|
|
TESTING("splitting block in pool");
|
|
|
|
|
|
|
|
|
|
/* Create a memory pool */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS)))
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Allocate space in pool */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(NULL == (spc1 = H5MP_malloc(mp, (size_t)MPOOL_NORMAL_BLOCK)))
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Check pool's free space */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
|
2009-12-13 13:28:30 +08:00
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
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 */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_pool_is_free_size_correct(mp) <= 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
|
|
|
|
|
/* Allocate more space in pool */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(NULL == (spc2 = H5MP_malloc(mp, (size_t)MPOOL_NORMAL_BLOCK)))
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Check pool's free space */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
|
2009-12-13 13:28:30 +08:00
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
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 */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_pool_is_free_size_correct(mp) <= 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
|
|
|
|
|
/* Free first block in pool */
|
|
|
|
|
H5MP_free(mp, spc1);
|
|
|
|
|
|
|
|
|
|
/* Check pool's free space */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
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 */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_pool_is_free_size_correct(mp) <= 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
|
|
|
|
|
/* Free second block in pool (should merge with first block) */
|
|
|
|
|
H5MP_free(mp, spc2);
|
|
|
|
|
|
|
|
|
|
/* Check pool's free space */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
if(free_size != MPOOL_PAGE_SIZE - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)))
|
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Check that free space totals match */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_pool_is_free_size_correct(mp) <= 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
|
|
|
|
|
/* Close the memory pool */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_close(mp) < 0)
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
PASSED();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
H5E_BEGIN_TRY {
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(mp)
|
|
|
|
|
H5MP_close(mp);
|
2005-05-18 03:01:07 +08:00
|
|
|
|
} H5E_END_TRY;
|
2009-12-13 13:28:30 +08:00
|
|
|
|
|
2005-05-18 03:01:07 +08:00
|
|
|
|
return 1;
|
|
|
|
|
} /* test_allocate_split() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: test_allocate_many_small
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Tests allocating many small blocks in a pool
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: 0
|
|
|
|
|
* Failure: 1
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Quincey Koziol
|
|
|
|
|
* Tuesday, May 6, 2005
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Test memory pool allocation
|
|
|
|
|
*/
|
|
|
|
|
TESTING("allocating many small blocks");
|
|
|
|
|
|
|
|
|
|
/* Create a memory pool */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS)))
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Allocate space in pool */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
for(i = 0; i < MPOOL_NUM_SMALL_BLOCKS; i++)
|
|
|
|
|
if(NULL == (spc[i] = H5MP_malloc(mp, (size_t)MPOOL_SMALL_BLOCK)))
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Check pool's free space */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
|
2009-12-13 13:28:30 +08:00
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
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 */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_pool_is_free_size_correct(mp) <= 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
|
|
|
|
|
/* Free blocks in pool */
|
|
|
|
|
/* (Tests free block merging with block after it */
|
|
|
|
|
for(i = (MPOOL_NUM_SMALL_BLOCKS - 1); i >= 0; i--)
|
|
|
|
|
H5MP_free(mp, spc[i]);
|
|
|
|
|
|
|
|
|
|
/* Check pool's free space */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
if(free_size != MPOOL_PAGE_SIZE - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)))
|
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Check that free space totals match */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_pool_is_free_size_correct(mp) <= 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
|
|
|
|
|
/* Close the memory pool */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_close(mp) < 0)
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
PASSED();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
H5E_BEGIN_TRY {
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(mp)
|
|
|
|
|
H5MP_close(mp);
|
2005-05-18 03:01:07 +08:00
|
|
|
|
} H5E_END_TRY;
|
2009-12-13 13:28:30 +08:00
|
|
|
|
|
2005-05-18 03:01:07 +08:00
|
|
|
|
return 1;
|
|
|
|
|
} /* test_allocate_many_small() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: test_allocate_new_page
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Tests allocating block in pool that requires allocating
|
|
|
|
|
* new page
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: 0
|
|
|
|
|
* Failure: 1
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Quincey Koziol
|
|
|
|
|
* Friday, May 6, 2005
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Test memory pool allocation
|
|
|
|
|
*/
|
|
|
|
|
TESTING("allocate normal-sized block in new page");
|
|
|
|
|
|
|
|
|
|
/* Create a memory pool */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS)))
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Allocate space in pool */
|
|
|
|
|
for(u = 0; u < MPOOL_NUM_NORMAL_BLOCKS; u++)
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(NULL == (spc[u] = H5MP_malloc(mp, (size_t)MPOOL_NORMAL_BLOCK)))
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Check pool's free space */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
|
2009-12-13 13:28:30 +08:00
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
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 */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_pool_is_free_size_correct(mp) <= 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
|
H5MP_free(mp, spc[u]);
|
|
|
|
|
for(u = 1; u < MPOOL_NUM_NORMAL_BLOCKS; u+=2)
|
|
|
|
|
H5MP_free(mp, spc[u]);
|
|
|
|
|
|
|
|
|
|
/* Check pool's free space */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
if(free_size != ((MPOOL_PAGE_SIZE - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))) * 3))
|
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Check that free space totals match */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_pool_is_free_size_correct(mp) <= 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
|
|
|
|
|
/* Close the memory pool */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_close(mp) < 0)
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
PASSED();
|
|
|
|
|
|
|
|
|
|
TESTING("allocate large-sized block in new page");
|
|
|
|
|
|
|
|
|
|
/* Create a memory pool */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS)))
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Allocate space in pool */
|
|
|
|
|
/* (Normal sized block) */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(NULL == (spc1 = H5MP_malloc(mp, (size_t)MPOOL_NORMAL_BLOCK)))
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
/* (Larger sized block) */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(NULL == (spc2 = H5MP_malloc(mp, (size_t)MPOOL_LARGE_BLOCK)))
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Check pool's free space */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
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 */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_pool_is_free_size_correct(mp) <= 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
|
|
|
|
|
/* Free blocks in pool */
|
|
|
|
|
H5MP_free(mp, spc1);
|
|
|
|
|
H5MP_free(mp, spc2);
|
|
|
|
|
|
|
|
|
|
/* Check pool's free space */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
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 */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_pool_is_free_size_correct(mp) <= 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
|
|
|
|
|
/* Close the memory pool */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_close(mp) < 0)
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
PASSED();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
H5E_BEGIN_TRY {
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(mp)
|
|
|
|
|
H5MP_close(mp);
|
2005-05-18 03:01:07 +08:00
|
|
|
|
} H5E_END_TRY;
|
2009-12-13 13:28:30 +08:00
|
|
|
|
|
2005-05-18 03:01:07 +08:00
|
|
|
|
return 1;
|
|
|
|
|
} /* test_allocate_new_page() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: test_allocate_random
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Tests allocating random sized blocks in pool
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: 0
|
|
|
|
|
* Failure: 1
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Quincey Koziol
|
|
|
|
|
* Friday, May 6, 2005
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Test memory pool allocation
|
|
|
|
|
*/
|
|
|
|
|
TESTING("allocate many random sized blocks");
|
|
|
|
|
|
|
|
|
|
/* Initialize random number seed */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
curr_time = HDtime(NULL);
|
2005-05-18 03:01:07 +08:00
|
|
|
|
#ifdef QAK
|
|
|
|
|
curr_time=1115412944;
|
|
|
|
|
HDfprintf(stderr,"curr_time=%lu\n",(unsigned long)curr_time);
|
|
|
|
|
#endif /* QAK */
|
[svn-r17980] Description:
Bring Coverity changes into the trunk: (also other minor cleanups)
r17955:
Fix Coverity item 24. Add missing error condition to
H5AC_ext_config_2_int_config.
r17956:
Fix Coverity item 24. Improve error checking in H5A_compact_build_table_cb.
r17957:
Fix Coverity item 150. Fix warning in H5A_compact_build_table_cb.
r17958:
Fix Coverity item 117. Fix error handling in H5B_shared_new.
r17959:
Fix Coverity item 209. Added an assertion for leaf->shared in
H5B2_cache_leaf_dest.
r17960:
Fix Coverity item 208. Added an assertion for internal->shared in
H5B2_cache_internal_dest.
r17961:
Fix Coverity item 89. Reworked the code to avoid array overrun in
H5C__autoadjust__ageout__insert_new_marker.
r17962:
Fix for coverity Resource_leak 195,203,204,205.
r17963:
Fix Coverity item 44. Prevented potential NULL dereference in H5D_btree_debug.
r17964:
Fix Coverity issues #197, 198 & 199: memory not being released. (Also
clean up other resource leaks in nearby and/or similar code).
r17965:
Fix Coverity issue #151: release resources on error
r17966:
Fix Coverity issue #187: Remove leftover code remnant from prior bugfix
which was causing resource leak of open files.
r17967:
Fixed Coverity issues # 193 & 194. Removed unnecessary memory allocation and
added comparison of length of path parameter to the size of the destination
buffer in h5import.h/h5import.c.
r17968:
Fix Coverity item 144. Fixed memory leak on error in H5D_chunk_copy.
r17969:
Fix for coverity Resource_leak #196.
r17970:
Coverity 167-173:
Initialized pointer of buffers.
In error handling, closed types and free memory.
Tested on:
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (jam) w/PGI compilers, w/default API=1.8.x,
w/C++ & FORTRAN, w/threadsafe, in debug mode
Linux/64-amd64 2.6 (smirom) w/Intel compilers, w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in debug mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
Mac OS X/32 10.6.2 (amazon) in debug mode
Mac OS X/32 10.6.2 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
2009-12-10 20:36:56 +08:00
|
|
|
|
HDsrandom((unsigned)curr_time);
|
2005-05-18 03:01:07 +08:00
|
|
|
|
|
|
|
|
|
/* Create a memory pool */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS)))
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Allocate space for the block sizes */
|
2010-08-21 05:37:12 +08:00
|
|
|
|
if(NULL == (blk_size = (size_t *)HDmalloc(sizeof(size_t) * MPOOL_NUM_RANDOM)))
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Allocate space for the block pointers */
|
2010-08-21 05:37:12 +08:00
|
|
|
|
if(NULL == (spc = (void **)HDmalloc(sizeof(void *) * MPOOL_NUM_RANDOM)))
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Initialize the block sizes with random values */
|
|
|
|
|
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++)
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(NULL == (spc[u] = H5MP_malloc(mp, blk_size[u])))
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Check that free space totals match */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(H5MP_pool_is_free_size_correct(mp) <= 0)
|
2009-12-13 13:28:30 +08:00
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
|
|
|
|
|
/* Shuffle pointers to free */
|
|
|
|
|
for(u = 0; u < MPOOL_NUM_RANDOM; u++) {
|
2016-06-06 08:45:37 +08:00
|
|
|
|
swap_idx = (size_t)(HDrandom() % (int)(MPOOL_NUM_RANDOM - u)) + u;
|
2005-05-18 03:01:07 +08:00
|
|
|
|
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++)
|
|
|
|
|
H5MP_free(mp, spc[u]);
|
|
|
|
|
|
|
|
|
|
/* Check that free space totals match */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_pool_is_free_size_correct(mp) <= 0)
|
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
|
|
|
|
|
/* Initialize the block sizes with random values */
|
|
|
|
|
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++)
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(NULL == (spc[u] = H5MP_malloc(mp, blk_size[u])))
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Check that free space totals match */
|
2006-10-31 08:13:27 +08:00
|
|
|
|
if(H5MP_pool_is_free_size_correct(mp) <= 0)
|
2009-12-13 13:28:30 +08:00
|
|
|
|
TEST_ERROR
|
2005-05-18 03:01:07 +08:00
|
|
|
|
|
|
|
|
|
/* Close the memory pool */
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(H5MP_close(mp) < 0)
|
2005-05-18 03:01:07 +08:00
|
|
|
|
TEST_ERROR
|
|
|
|
|
|
|
|
|
|
/* Free memory for block sizes & pointers */
|
|
|
|
|
HDfree(blk_size);
|
|
|
|
|
HDfree(spc);
|
|
|
|
|
|
|
|
|
|
PASSED();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
if(blk_size)
|
|
|
|
|
HDfree(blk_size);
|
|
|
|
|
if(spc)
|
|
|
|
|
HDfree(spc);
|
|
|
|
|
H5E_BEGIN_TRY {
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(mp)
|
|
|
|
|
H5MP_close(mp);
|
2005-05-18 03:01:07 +08:00
|
|
|
|
} H5E_END_TRY;
|
2009-12-13 13:28:30 +08:00
|
|
|
|
|
2005-05-18 03:01:07 +08:00
|
|
|
|
return 1;
|
|
|
|
|
} /* test_allocate_random() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: main
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Test the memory pool code
|
|
|
|
|
*
|
2005-08-14 04:53:35 +08:00
|
|
|
|
* Return: Success:
|
|
|
|
|
* Failure:
|
2005-05-18 03:01:07 +08:00
|
|
|
|
*
|
|
|
|
|
* Programmer: Quincey Koziol
|
|
|
|
|
* Tuesday, May 3, 2005
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
int
|
|
|
|
|
main(void)
|
|
|
|
|
{
|
2009-12-13 13:28:30 +08:00
|
|
|
|
int nerrors = 0;
|
2005-05-18 03:01:07 +08:00
|
|
|
|
|
|
|
|
|
/* Reset library */
|
|
|
|
|
h5_reset();
|
|
|
|
|
|
|
|
|
|
/* Test memory pool creation */
|
|
|
|
|
nerrors += test_create();
|
|
|
|
|
|
|
|
|
|
/* Test memory pool space closing */
|
|
|
|
|
nerrors += test_close_one();
|
|
|
|
|
|
|
|
|
|
/* Test memory pool space allocation */
|
|
|
|
|
nerrors += test_allocate_first();
|
|
|
|
|
nerrors += test_allocate_split();
|
|
|
|
|
nerrors += test_allocate_many_small();
|
|
|
|
|
nerrors += test_allocate_new_page();
|
|
|
|
|
nerrors += test_allocate_random();
|
|
|
|
|
|
2009-12-13 13:28:30 +08:00
|
|
|
|
if(nerrors)
|
|
|
|
|
goto error;
|
2005-05-18 03:01:07 +08:00
|
|
|
|
puts("All memory pool tests passed.");
|
2009-12-13 13:28:30 +08:00
|
|
|
|
|
2005-05-18 03:01:07 +08:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
puts("*** TESTS FAILED ***");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|