diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/earray.c | 256 |
1 files changed, 254 insertions, 2 deletions
diff --git a/test/earray.c b/test/earray.c index 3b33c0a..c0c7bb7 100644 --- a/test/earray.c +++ b/test/earray.c @@ -1120,7 +1120,7 @@ error: /*------------------------------------------------------------------------- - * Function: test_set_first_dblock + * Function: test_set_first_dblock_first * * Purpose: Set first element in extensible array's first data block * @@ -1133,7 +1133,7 @@ error: *------------------------------------------------------------------------- */ static unsigned -test_set_first_dblock(hid_t fapl, H5EA_create_t *cparam, earray_test_param_t *tparam) +test_set_first_dblock_first(hid_t fapl, H5EA_create_t *cparam, earray_test_param_t *tparam) { hid_t file = -1; /* File ID */ H5F_t *f = NULL; /* Internal file object pointer */ @@ -1236,10 +1236,260 @@ error: } H5E_END_TRY; return 1; +} /* test_set_first_dblock_first() */ + + +/*------------------------------------------------------------------------- + * Function: test_set_first_dblock + * + * Purpose: Set all elements in extensible array's first data block + * + * Return: Success: 0 + * Failure: 1 + * + * Programmer: Quincey Koziol + * Thursday, September 22, 2008 + * + *------------------------------------------------------------------------- + */ +static unsigned +test_set_first_dblock(hid_t fapl, H5EA_create_t *cparam, earray_test_param_t *tparam) +{ + hid_t file = -1; /* File ID */ + H5F_t *f = NULL; /* Internal file object pointer */ + H5EA_t *ea = NULL; /* Extensible array wrapper */ + earray_state_t state; /* State of extensible array */ + uint64_t welmt; /* Element to write */ + uint64_t relmt; /* Element to read */ + hsize_t nelmts; /* Highest element written in array */ + hsize_t idx; /* Index value of first element of first data block */ + haddr_t ea_addr = HADDR_UNDEF; /* Array address in file */ + unsigned u; /* Local index variable */ + + /* + * Display testing message + */ + TESTING("setting all elements of array's first data block"); + + /* Create file & retrieve pointer to internal file object */ + if(create_file(fapl, &file, &f) < 0) + TEST_ERROR + + /* Create array */ + if(create_array(f, H5P_DATASET_XFER_DEFAULT, cparam, &ea, &ea_addr) < 0) + TEST_ERROR + + /* Verify the creation parameters */ + if(verify_cparam(ea, cparam) < 0) + TEST_ERROR + + /* Check for closing & re-opening the file */ + if(reopen_file(&file, &f, fapl, H5P_DATASET_XFER_DEFAULT, &ea, ea_addr, cparam->cls, tparam) < 0) + TEST_ERROR + + /* Verify high-water # of elements written */ + nelmts = (hsize_t)ULLONG_MAX; + if(H5EA_get_nelmts(ea, &nelmts) < 0) + FAIL_STACK_ERROR + if(nelmts != 0) + TEST_ERROR + + /* Verify array state */ + HDmemset(&state, 0, sizeof(state)); + if(check_stats(ea, &state)) + TEST_ERROR + + /* Retrieve elements of array in data block (not set yet) */ + for(u = 0; u < cparam->data_blk_min_elmts; u++) { + /* Compute index of element of first data block */ + idx = cparam->idx_blk_elmts + u; + + /* Retrieve element of first data block of array (not set yet) */ + relmt = (uint64_t)0; + if(H5EA_get(ea, H5P_DATASET_XFER_DEFAULT, idx, &relmt) < 0) + FAIL_STACK_ERROR + + /* Verify element is fill value for array */ + if(relmt != H5EA_TEST_FILL) + TEST_ERROR + } /* end for */ + + /* Set elements of array in index block */ + for(u = 0; u < cparam->data_blk_min_elmts; u++) { + /* Compute index of element of first data block */ + idx = cparam->idx_blk_elmts + u; + + /* Set element of first data block */ + welmt = (uint64_t)7 + u; + if(H5EA_set(ea, H5P_DATASET_XFER_DEFAULT, idx, &welmt) < 0) + FAIL_STACK_ERROR + + /* Verify high-water # of elements written */ + nelmts = (hsize_t)ULLONG_MAX; + if(H5EA_get_nelmts(ea, &nelmts) < 0) + FAIL_STACK_ERROR + if(nelmts != (idx + 1)) + TEST_ERROR + + /* Verify array state */ + HDmemset(&state, 0, sizeof(state)); + state.max_idx_set = idx + 1; + state.ndata_blks = 1; + state.nelmts = (hsize_t)(cparam->idx_blk_elmts + cparam->data_blk_min_elmts); + if(check_stats(ea, &state)) + TEST_ERROR + + /* Retrieve element of array (set now) */ + relmt = (uint64_t)0; + if(H5EA_get(ea, H5P_DATASET_XFER_DEFAULT, idx, &relmt) < 0) + FAIL_STACK_ERROR + + /* Verify element is value written */ + if(relmt != welmt) + TEST_ERROR + } /* end for */ + + /* Close array, delete array, close file & verify file is empty */ + if(finish(file, f, ea, ea_addr) < 0) + TEST_ERROR + + /* All tests passed */ + PASSED() + + return 0; + +error: + H5E_BEGIN_TRY { + if(ea) + H5EA_close(ea, H5P_DATASET_XFER_DEFAULT); + H5Fclose(file); + } H5E_END_TRY; + + return 1; } /* test_set_first_dblock() */ /*------------------------------------------------------------------------- + * Function: test_set_second_dblock_first + * + * Purpose: Set first element in extensible array's second data block + * + * Return: Success: 0 + * Failure: 1 + * + * Programmer: Quincey Koziol + * Thursday, September 22, 2008 + * + *------------------------------------------------------------------------- + */ +static unsigned +test_set_second_dblock_first(hid_t fapl, H5EA_create_t *cparam, earray_test_param_t *tparam) +{ + hid_t file = -1; /* File ID */ + H5F_t *f = NULL; /* Internal file object pointer */ + H5EA_t *ea = NULL; /* Extensible array wrapper */ + earray_state_t state; /* State of extensible array */ + uint64_t welmt; /* Element to write */ + uint64_t relmt; /* Element to read */ + hsize_t nelmts; /* Highest element written in array */ + hsize_t idx; /* Index value of first element of first data block */ + haddr_t ea_addr = HADDR_UNDEF; /* Array address in file */ + + /* + * Display testing message + */ + TESTING("setting first element of array's second data block"); + + /* Create file & retrieve pointer to internal file object */ + if(create_file(fapl, &file, &f) < 0) + TEST_ERROR + + /* Create array */ + if(create_array(f, H5P_DATASET_XFER_DEFAULT, cparam, &ea, &ea_addr) < 0) + TEST_ERROR + + /* Verify the creation parameters */ + if(verify_cparam(ea, cparam) < 0) + TEST_ERROR + + /* Check for closing & re-opening the file */ + if(reopen_file(&file, &f, fapl, H5P_DATASET_XFER_DEFAULT, &ea, ea_addr, cparam->cls, tparam) < 0) + TEST_ERROR + + /* Verify high-water # of elements written */ + nelmts = (hsize_t)ULLONG_MAX; + if(H5EA_get_nelmts(ea, &nelmts) < 0) + FAIL_STACK_ERROR + if(nelmts != 0) + TEST_ERROR + + /* Verify array state */ + HDmemset(&state, 0, sizeof(state)); + if(check_stats(ea, &state)) + TEST_ERROR + + /* Compute index of first element of second data block */ + idx = (hsize_t)(cparam->idx_blk_elmts + cparam->data_blk_min_elmts); + + /* Retrieve element from array (not set yet) */ + relmt = (uint64_t)0; + if(H5EA_get(ea, H5P_DATASET_XFER_DEFAULT, idx, &relmt) < 0) + FAIL_STACK_ERROR + + /* Verify element is fill value for array */ + if(relmt != H5EA_TEST_FILL) + TEST_ERROR + + /* Set element of array */ + welmt = (uint64_t)7; + if(H5EA_set(ea, H5P_DATASET_XFER_DEFAULT, idx, &welmt) < 0) + FAIL_STACK_ERROR + + /* Verify high-water # of elements written */ + nelmts = (hsize_t)ULLONG_MAX; + if(H5EA_get_nelmts(ea, &nelmts) < 0) + FAIL_STACK_ERROR + if(nelmts != (idx + 1)) + TEST_ERROR + + /* Verify array state */ + HDmemset(&state, 0, sizeof(state)); + state.max_idx_set = idx + 1; + state.ndata_blks = 1; + state.nelmts = (hsize_t)(cparam->idx_blk_elmts + cparam->data_blk_min_elmts * 2); + if(check_stats(ea, &state)) + TEST_ERROR + + /* Retrieve element of array (set now) */ + relmt = (uint64_t)0; + if(H5EA_get(ea, H5P_DATASET_XFER_DEFAULT, idx, &relmt) < 0) + FAIL_STACK_ERROR + + /* Verify element is value written */ + if(relmt != welmt) + TEST_ERROR + + /* Close array, delete array, close file & verify file is empty */ + if(finish(file, f, ea, ea_addr) < 0) + TEST_ERROR + + /* All tests passed */ + PASSED() + + return 0; + +error: + H5E_BEGIN_TRY { + if(ea) + H5EA_close(ea, H5P_DATASET_XFER_DEFAULT); + H5Fclose(file); + } H5E_END_TRY; + + return 1; +} /* test_set_second_dblock_first() */ + + +/*------------------------------------------------------------------------- * Function: main * * Purpose: Test the extensible array code @@ -1332,7 +1582,9 @@ main(void) /* Basic capacity tests */ nerrors += test_set_first(fapl, &cparam, &tparam); nerrors += test_set_iblock(fapl, &cparam, &tparam); + nerrors += test_set_first_dblock_first(fapl, &cparam, &tparam); nerrors += test_set_first_dblock(fapl, &cparam, &tparam); + nerrors += test_set_second_dblock_first(fapl, &cparam, &tparam); } /* end for */ if(nerrors) |