From df937a7e8219812a00a73b76f9b6f09bb9e3bf86 Mon Sep 17 00:00:00 2001 From: mattjala <124107509+mattjala@users.noreply.github.com> Date: Tue, 9 Jan 2024 11:20:43 -0600 Subject: Add H5Dread/write_multi to API tests (#3931) * Add H5Dread/write_multi to API tests * Remove debug prints, set NULL for safety --- test/API/H5_api_dataset_test.c | 3229 +++++++++++++++++++++++++++++----------- test/API/H5_api_dataset_test.h | 20 + 2 files changed, 2395 insertions(+), 854 deletions(-) diff --git a/test/API/H5_api_dataset_test.c b/test/API/H5_api_dataset_test.c index d36b77b..df22fef 100644 --- a/test/API/H5_api_dataset_test.c +++ b/test/API/H5_api_dataset_test.c @@ -49,12 +49,19 @@ static int test_get_dataset_offset_invalid_params(void); static int test_read_dataset_small_all(void); static int test_read_dataset_small_hyperslab(void); static int test_read_dataset_small_point_selection(void); +static int test_read_multi_dataset_small_all(void); +static int test_read_multi_dataset_small_hyperslab(void); +static int test_read_multi_dataset_small_point_selection(void); static int test_dataset_io_point_selections(void); static int test_read_dataset_invalid_params(void); static int test_write_dataset_small_all(void); static int test_write_dataset_small_hyperslab(void); static int test_write_dataset_small_point_selection(void); static int test_write_dataset_data_verification(void); +static int test_write_multi_dataset_small_all(void); +static int test_write_multi_dataset_small_hyperslab(void); +static int test_write_multi_dataset_small_point_selection(void); +static int test_write_multi_dataset_data_verification(void); static int test_write_dataset_invalid_params(void); static int test_dataset_builtin_type_conversion(void); static int test_dataset_compound_partial_io(void); @@ -121,12 +128,19 @@ static int (*dataset_tests[])(void) = { test_read_dataset_small_all, test_read_dataset_small_hyperslab, test_read_dataset_small_point_selection, + test_read_multi_dataset_small_all, + test_read_multi_dataset_small_hyperslab, + test_read_multi_dataset_small_point_selection, test_dataset_io_point_selections, test_read_dataset_invalid_params, test_write_dataset_small_all, test_write_dataset_small_hyperslab, test_write_dataset_small_point_selection, test_write_dataset_data_verification, + test_write_multi_dataset_small_all, + test_write_multi_dataset_small_hyperslab, + test_write_multi_dataset_small_point_selection, + test_write_multi_dataset_data_verification, test_write_dataset_invalid_params, test_dataset_builtin_type_conversion, test_dataset_compound_partial_io, @@ -4411,50 +4425,24 @@ error: } /* - * Tests point selection I/O with different patterns + * A test to check that a small amount of data can be + * read back from multiple datasets using H5S_ALL selections. */ -#define DATASET_IO_POINT_DIM_0 6 -#define DATASET_IO_POINT_DIM_1 9 -#define DATASET_IO_POINT_CDIM_0 4 -#define DATASET_IO_POINT_CDIM_1 3 -#define DATASET_IO_POINT_NPOINTS 10 -#define DATASET_IO_POINT_GEN_POINTS(POINTS, I, J) \ - { \ - for ((I) = 0; (I) < DATASET_IO_POINT_NPOINTS; (I)++) \ - do { \ - (POINTS)[2 * (I)] = (hsize_t)(rand() % DATASET_IO_POINT_DIM_0); \ - (POINTS)[2 * (I) + 1] = (hsize_t)(rand() % DATASET_IO_POINT_DIM_1); \ - for ((J) = 0; ((J) < (I)) && (((POINTS)[2 * (I)] != (POINTS)[2 * (J)]) || \ - ((POINTS)[2 * (I) + 1] != (POINTS)[2 * (J) + 1])); \ - (J)++) \ - ; \ - } while ((J) < (I)); \ - } static int -test_dataset_io_point_selections(void) +test_read_multi_dataset_small_all(void) { + + hsize_t dims[DATASET_SMALL_READ_TEST_ALL_DSET_SPACE_RANK] = {10, 5, 3}; + size_t i, data_size; hid_t file_id = H5I_INVALID_HID; - hid_t dset_id = H5I_INVALID_HID; hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID; - hid_t mspace_id_full = H5I_INVALID_HID, mspace_id_all = H5I_INVALID_HID, fspace_id = H5I_INVALID_HID; - hid_t dcpl_id_chunk = H5I_INVALID_HID; - hsize_t dims[2] = {DATASET_IO_POINT_DIM_0, DATASET_IO_POINT_DIM_1}; - hsize_t cdims[2] = {DATASET_IO_POINT_CDIM_0, DATASET_IO_POINT_CDIM_1}; - hsize_t points[DATASET_IO_POINT_NPOINTS * 2]; - hsize_t points2[DATASET_IO_POINT_NPOINTS * 2]; - hsize_t npoints = DATASET_IO_POINT_NPOINTS; - hsize_t start[2] = {1, 2}; - hsize_t stride[2] = {2, 5}; - hsize_t count[2] = {2, 1}; - hsize_t block[2] = {1, 5}; - int buf_all[DATASET_IO_POINT_DIM_0][DATASET_IO_POINT_DIM_1]; - int file_state[DATASET_IO_POINT_DIM_0][DATASET_IO_POINT_DIM_1]; - int erbuf[DATASET_IO_POINT_DIM_0][DATASET_IO_POINT_DIM_1]; - int buf_point[DATASET_IO_POINT_NPOINTS]; - bool do_chunk; - int i, j; + hid_t fspace_id = H5I_INVALID_HID; + hid_t dset_id_arr[DATASET_MULTI_COUNT]; + hid_t fspace_id_arr[DATASET_MULTI_COUNT]; + hid_t dtype_id_arr[DATASET_MULTI_COUNT]; + void *read_buf_arr[DATASET_MULTI_COUNT]; - TESTING("point selection I/O with all selection in memory and points in file"); + TESTING("small multi read from datasets with H5S_ALL"); /* Make sure the connector supports the API functions being tested */ if (!(vol_cap_flags_g & H5VL_CAP_FLAG_FILE_BASIC) || !(vol_cap_flags_g & H5VL_CAP_FLAG_GROUP_BASIC) || @@ -4464,426 +4452,1510 @@ test_dataset_io_point_selections(void) return 0; } - /* Create dataspaces and DCPL */ - if ((mspace_id_full = H5Screate_simple(2, dims, NULL)) < 0) - TEST_ERROR; - if ((mspace_id_all = H5Screate_simple(1, &npoints, NULL)) < 0) - TEST_ERROR; - if ((fspace_id = H5Screate_simple(2, dims, NULL)) < 0) - TEST_ERROR; - if ((dcpl_id_chunk = H5Pcreate(H5P_DATASET_CREATE)) < 0) - TEST_ERROR; + /* Prevent uninitialized memory usage on test failure */ + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + read_buf_arr[i] = NULL; + dset_id_arr[i] = H5I_INVALID_HID; + } - /* Enable chunking on chunk DCPL */ - if (H5Pset_chunk(dcpl_id_chunk, 2, cdims) < 0) - TEST_ERROR; + if ((file_id = H5Fopen(H5_api_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open file '%s'\n", H5_api_test_filename); + goto error; + } - /* Open file */ - if ((file_id = H5Fopen(H5_api_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) - TEST_ERROR; + if ((container_group = H5Gopen2(file_id, DATASET_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open container group '%s'\n", DATASET_TEST_GROUP_NAME); + goto error; + } - /* Open container group */ - if ((container_group = H5Gopen2(file_id, DATASET_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) - TEST_ERROR; + if ((group_id = H5Gcreate2(container_group, DATASET_SMALL_READ_MULTI_TEST_ALL_GROUP_NAME, H5P_DEFAULT, + H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create container sub-group '%s'\n", DATASET_SMALL_READ_TEST_ALL_GROUP_NAME); + goto error; + } - /* Create group */ - if ((group_id = H5Gcreate2(container_group, DATASET_IO_POINT_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, - H5P_DEFAULT)) < 0) + if ((fspace_id = H5Screate_simple(DATASET_SMALL_READ_TEST_ALL_DSET_SPACE_RANK, dims, NULL)) < 0) TEST_ERROR; - /* Perform with and without chunking */ - for (do_chunk = false;; do_chunk = true) { - if (do_chunk) { - TESTING("point selection I/O with all selection in memory and points in file with chunking"); + for (i = 0, data_size = 1; i < DATASET_SMALL_READ_TEST_ALL_DSET_SPACE_RANK; i++) + data_size *= dims[i]; + data_size *= DATASET_SMALL_READ_TEST_ALL_DSET_DTYPESIZE; - /* Create chunked dataset */ - if ((dset_id = H5Dcreate2(group_id, DATASET_IO_POINT_DSET_NAME_CHUNK, H5T_NATIVE_INT, fspace_id, - H5P_DEFAULT, dcpl_id_chunk, H5P_DEFAULT)) < 0) - TEST_ERROR; - } /* end if */ - else - /* Create non-chunked dataset */ - if ((dset_id = H5Dcreate2(group_id, DATASET_IO_POINT_DSET_NAME_NOCHUNK, H5T_NATIVE_INT, fspace_id, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) - TEST_ERROR; + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + char dset_name[DSET_NAME_BUF_SIZE]; - /* Fill write buffer */ - for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) - for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) - buf_all[i][j] = rand(); + if (DSET_NAME_BUF_SIZE <= snprintf(dset_name, DSET_NAME_BUF_SIZE, "%s%zu%c", + DATASET_SMALL_READ_TEST_ALL_DSET_NAME, i, '\0')) + TEST_ERROR; - /* Write data */ - if (H5Dwrite(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_all) < 0) - FAIL_PUTS_ERROR("Failed to write entire dataset"); + if ((dset_id_arr[i] = H5Dcreate2(group_id, dset_name, DATASET_SMALL_READ_TEST_ALL_DSET_DTYPE, + fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset '%s'\n", DATASET_SMALL_READ_TEST_ALL_DSET_NAME); + goto error; + } - /* Update file_state */ - for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) - for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) - file_state[i][j] = buf_all[i][j]; + fspace_id_arr[i] = fspace_id; + dtype_id_arr[i] = DATASET_SMALL_READ_TEST_ALL_DSET_DTYPE; - /* Generate points to read */ - DATASET_IO_POINT_GEN_POINTS(points, i, j); + if (NULL == (read_buf_arr[i] = malloc(data_size))) + TEST_ERROR; + } - /* Select points */ - if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_IO_POINT_NPOINTS, points) < 0) + if (H5Dread_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, fspace_id_arr, fspace_id_arr, + H5P_DEFAULT, read_buf_arr) < 0) { + H5_FAILED(); + printf(" couldn't read from dataset '%s'\n", DATASET_SMALL_READ_TEST_ALL_DSET_NAME); + goto error; + } + + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + free(read_buf_arr[i]); + read_buf_arr[i] = NULL; + } + if (H5Sclose(fspace_id) < 0) + TEST_ERROR; + for (i = 0; i < DATASET_MULTI_COUNT; i++) + if (H5Dclose(dset_id_arr[i]) < 0) TEST_ERROR; + if (H5Gclose(group_id) < 0) + TEST_ERROR; + if (H5Gclose(container_group) < 0) + TEST_ERROR; + if (H5Fclose(file_id) < 0) + TEST_ERROR; - /* Wipe read buffer */ - memset(buf_point, 0, sizeof(buf_point)); + PASSED(); - /* Read points to "all" memory buffer */ - if (H5Dread(dset_id, H5T_NATIVE_INT, mspace_id_all, fspace_id, H5P_DEFAULT, buf_point) < 0) - FAIL_PUTS_ERROR("Failed to read points from dataset to all memory buffer"); + return 0; - /* Verify data */ - for (i = 0; i < DATASET_IO_POINT_NPOINTS; i++) - if (buf_point[i] != file_state[points[2 * i]][points[2 * i + 1]]) - FAIL_PUTS_ERROR("Incorrect data read from points to all memory buffer"); +error: + H5E_BEGIN_TRY + { + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + free(read_buf_arr[i]); + read_buf_arr[i] = NULL; + H5Dclose(dset_id_arr[i]); + } + H5Sclose(fspace_id); + H5Gclose(group_id); + H5Gclose(container_group); + H5Fclose(file_id); + } + H5E_END_TRY; - /* Generate points to write */ - DATASET_IO_POINT_GEN_POINTS(points, i, j); + return 1; +} - /* Select points */ - if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_IO_POINT_NPOINTS, points) < 0) - TEST_ERROR; +/* + * A test to check that a small amount of data can be + * read back from datasets using hyperslab selections. + */ +static int +test_read_multi_dataset_small_hyperslab(void) +{ + hsize_t start[DATASET_SMALL_READ_TEST_HYPERSLAB_DSET_SPACE_RANK]; + hsize_t stride[DATASET_SMALL_READ_TEST_HYPERSLAB_DSET_SPACE_RANK]; + hsize_t count[DATASET_SMALL_READ_TEST_HYPERSLAB_DSET_SPACE_RANK]; + hsize_t block[DATASET_SMALL_READ_TEST_HYPERSLAB_DSET_SPACE_RANK]; + hsize_t dims[DATASET_SMALL_READ_TEST_HYPERSLAB_DSET_SPACE_RANK] = {10, 5, 3}; + size_t i, data_size; + hid_t file_id = H5I_INVALID_HID; + hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID; + hid_t dset_id_arr[DATASET_MULTI_COUNT]; + hid_t mspace_id = H5I_INVALID_HID, fspace_id = H5I_INVALID_HID; + hid_t mspace_id_arr[DATASET_MULTI_COUNT]; + hid_t fspace_id_arr[DATASET_MULTI_COUNT]; + hid_t dtype_arr[DATASET_MULTI_COUNT]; + void *read_buf_arr[DATASET_MULTI_COUNT]; - /* Fill write buffer */ - for (i = 0; i < DATASET_IO_POINT_NPOINTS; i++) - buf_point[i] = rand(); + TESTING("small multi read from datasets with a hyperslab selection"); - /* Write points from "all" memory buffer */ - if (H5Dwrite(dset_id, H5T_NATIVE_INT, mspace_id_all, fspace_id, H5P_DEFAULT, buf_point) < 0) - FAIL_PUTS_ERROR("Failed to write points to dataset from all memory buffer"); + /* Make sure the connector supports the API functions being tested */ + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_FILE_BASIC) || !(vol_cap_flags_g & H5VL_CAP_FLAG_GROUP_BASIC) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_DATASET_BASIC)) { + SKIPPED(); + printf(" API functions for basic file, group, or dataset aren't supported with this connector\n"); + return 0; + } - /* Update file state */ - for (i = 0; i < DATASET_IO_POINT_NPOINTS; i++) - file_state[points[2 * i]][points[2 * i + 1]] = buf_point[i]; + /* Prevent uninitialized memory usage on test failure */ + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + read_buf_arr[i] = NULL; + dset_id_arr[i] = H5I_INVALID_HID; + } - /* Wipe read buffer */ - memset(buf_all, 0, sizeof(buf_all)); + if ((file_id = H5Fopen(H5_api_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open file '%s'\n", H5_api_test_filename); + goto error; + } - /* Read entire dataset */ - if (H5Dread(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_all) < 0) - FAIL_PUTS_ERROR("Failed to read entire dataset"); + if ((container_group = H5Gopen2(file_id, DATASET_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open container group '%s'\n", DATASET_TEST_GROUP_NAME); + goto error; + } - /* Verify data */ - for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) - for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) - if (buf_all[i][j] != file_state[i][j]) - FAIL_PUTS_ERROR("Incorrect data found after writing from all memory buffer to points"); + if ((group_id = H5Gcreate2(container_group, DATASET_SMALL_READ_MULTI_TEST_HYPERSLAB_GROUP_NAME, + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create container sub-group '%s'\n", + DATASET_SMALL_READ_TEST_HYPERSLAB_GROUP_NAME); + goto error; + } - PASSED(); + if ((fspace_id = H5Screate_simple(DATASET_SMALL_READ_TEST_HYPERSLAB_DSET_SPACE_RANK, dims, NULL)) < 0) + TEST_ERROR; + if ((mspace_id = H5Screate_simple(DATASET_SMALL_READ_TEST_HYPERSLAB_DSET_SPACE_RANK - 1, dims, NULL)) < 0) + TEST_ERROR; - if (do_chunk) - TESTING("point selection I/O with points in memory and file (same shape) with chunking"); - else - TESTING("point selection I/O with points in memory and file (same shape)"); + for (i = 0; i < DATASET_SMALL_READ_TEST_HYPERSLAB_DSET_SPACE_RANK; i++) { + start[i] = 0; + stride[i] = 1; + count[i] = dims[i]; + block[i] = 1; + } - /* Generate points to read */ - DATASET_IO_POINT_GEN_POINTS(points, i, j); + count[2] = 1; - /* Select points */ - if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_IO_POINT_NPOINTS, points) < 0) - TEST_ERROR; + if (H5Sselect_hyperslab(fspace_id, H5S_SELECT_SET, start, stride, count, block) < 0) + TEST_ERROR; - /* Wipe read buffer */ - memset(buf_all, 0, sizeof(buf_all)); + for (i = 0, data_size = 1; i < DATASET_SMALL_READ_TEST_HYPERSLAB_DSET_SPACE_RANK - 1; i++) + data_size *= dims[i]; + data_size *= DATASET_SMALL_READ_TEST_HYPERSLAB_DSET_DTYPESIZE; - /* Generate expected read buffer */ - memset(erbuf, 0, sizeof(erbuf)); - for (i = 0; i < DATASET_IO_POINT_NPOINTS; i++) - erbuf[points[2 * i]][points[2 * i + 1]] = file_state[points[2 * i]][points[2 * i + 1]]; + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + char dset_name[DSET_NAME_BUF_SIZE]; - /* Read data points->points */ - if (H5Dread(dset_id, H5T_NATIVE_INT, fspace_id, fspace_id, H5P_DEFAULT, buf_all) < 0) - FAIL_PUTS_ERROR("Failed to read points from dataset to points in memory buffer"); + if (DSET_NAME_BUF_SIZE <= snprintf(dset_name, DSET_NAME_BUF_SIZE, "%s%zu%c", + DATASET_SMALL_READ_TEST_HYPERSLAB_DSET_NAME, i, '\0')) + TEST_ERROR; - /* Verify data */ - for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) - for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) - if (buf_all[i][j] != erbuf[i][j]) - FAIL_PUTS_ERROR("Incorrect data found read from points in file to points in memory"); - - /* Generate points to write */ - DATASET_IO_POINT_GEN_POINTS(points, i, j); + if ((dset_id_arr[i] = H5Dcreate2(group_id, dset_name, DATASET_SMALL_READ_TEST_HYPERSLAB_DSET_DTYPE, + fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset '%s'\n", DATASET_SMALL_READ_TEST_HYPERSLAB_DSET_NAME); + goto error; + } - /* Select points */ - if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_IO_POINT_NPOINTS, points) < 0) + if (NULL == (read_buf_arr[i] = malloc(data_size))) TEST_ERROR; - /* Fill write buffer */ - for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) - for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) - buf_all[i][j] = rand(); - - /* Write data points->points */ - if (H5Dwrite(dset_id, H5T_NATIVE_INT, fspace_id, fspace_id, H5P_DEFAULT, buf_all) < 0) - FAIL_PUTS_ERROR("Failed to write from in memory to points in dataset"); - - /* Update file_state */ - for (i = 0; i < DATASET_IO_POINT_NPOINTS; i++) - file_state[points[2 * i]][points[2 * i + 1]] = buf_all[points[2 * i]][points[2 * i + 1]]; + mspace_id_arr[i] = mspace_id; + fspace_id_arr[i] = fspace_id; + dtype_arr[i] = DATASET_SMALL_READ_TEST_HYPERSLAB_DSET_DTYPE; + } - /* Wipe read buffer */ - memset(buf_all, 0, sizeof(buf_all)); + if (H5Dread_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_arr, mspace_id_arr, fspace_id_arr, H5P_DEFAULT, + read_buf_arr) < 0) { + H5_FAILED(); + printf(" couldn't read from dataset '%s'\n", DATASET_SMALL_READ_TEST_HYPERSLAB_DSET_NAME); + goto error; + } - /* Read entire dataset */ - if (H5Dread(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_all) < 0) - FAIL_PUTS_ERROR("Failed to read entire dataset"); + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + if (read_buf_arr[i]) { + free(read_buf_arr[i]); + read_buf_arr[i] = NULL; + } + if (H5Dclose(dset_id_arr[i]) < 0) + TEST_ERROR; + } - /* Verify data */ - for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) - for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) - if (buf_all[i][j] != file_state[i][j]) - FAIL_PUTS_ERROR( - "Incorrect data found after writing from points in memory to points in dataset"); + if (H5Sclose(mspace_id) < 0) + TEST_ERROR; + if (H5Sclose(fspace_id) < 0) + TEST_ERROR; + if (H5Gclose(group_id) < 0) + TEST_ERROR; + if (H5Gclose(container_group) < 0) + TEST_ERROR; + if (H5Fclose(file_id) < 0) + TEST_ERROR; - PASSED(); + PASSED(); - if (do_chunk) - TESTING("point selection I/O with points in memory and file (different shape) with chunking"); - else - TESTING("point selection I/O with points in memory and file (different shape)"); + return 0; - /* Generate points to read */ - DATASET_IO_POINT_GEN_POINTS(points, i, j); - DATASET_IO_POINT_GEN_POINTS(points2, i, j); +error: + H5E_BEGIN_TRY + { + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + if (read_buf_arr[i]) { + free(read_buf_arr[i]); + read_buf_arr[i] = NULL; + } + H5Dclose(dset_id_arr[i]); + } + H5Sclose(mspace_id); + H5Sclose(fspace_id); + H5Gclose(group_id); + H5Gclose(container_group); + H5Fclose(file_id); + } + H5E_END_TRY; - /* Select points */ - if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_IO_POINT_NPOINTS, points) < 0) - TEST_ERROR; - if (H5Sselect_elements(mspace_id_full, H5S_SELECT_SET, DATASET_IO_POINT_NPOINTS, points2) < 0) - TEST_ERROR; + return 1; +} - /* Wipe read buffer */ - memset(buf_all, 0, sizeof(buf_all)); +/* + * A test to check that a small amount of data can be + * read back from datasets using point selections. + */ +static int +test_read_multi_dataset_small_point_selection(void) +{ + hsize_t points[DATASET_SMALL_READ_TEST_POINT_SELECTION_NUM_POINTS * + DATASET_SMALL_READ_TEST_POINT_SELECTION_DSET_SPACE_RANK]; + hsize_t dims[DATASET_SMALL_READ_TEST_POINT_SELECTION_DSET_SPACE_RANK] = {10, 10, 10}; + hsize_t mspace_dims[] = {DATASET_SMALL_READ_TEST_POINT_SELECTION_NUM_POINTS}; + size_t i, data_size; + hid_t file_id = H5I_INVALID_HID; + hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID; + hid_t fspace_id = H5I_INVALID_HID, mspace_id = H5I_INVALID_HID; + hid_t dset_id_arr[DATASET_MULTI_COUNT]; + hid_t mspace_id_arr[DATASET_MULTI_COUNT], fspace_id_arr[DATASET_MULTI_COUNT]; + hid_t dtype_arr[DATASET_MULTI_COUNT]; + void *data[DATASET_MULTI_COUNT]; - /* Generate expected read buffer */ - memset(erbuf, 0, sizeof(erbuf)); - for (i = 0; i < DATASET_IO_POINT_NPOINTS; i++) - erbuf[points2[2 * i]][points2[2 * i + 1]] = file_state[points[2 * i]][points[2 * i + 1]]; + TESTING("small multi read from datasets with point selections"); - /* Read data points->points */ - if (H5Dread(dset_id, H5T_NATIVE_INT, mspace_id_full, fspace_id, H5P_DEFAULT, buf_all) < 0) - FAIL_PUTS_ERROR("Failed to read points from dataset to points in memory buffer"); + /* Make sure the connector supports the API functions being tested */ + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_FILE_BASIC) || !(vol_cap_flags_g & H5VL_CAP_FLAG_GROUP_BASIC) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_DATASET_BASIC)) { + SKIPPED(); + printf(" API functions for basic file, group, or dataset aren't supported with this connector\n"); + return 0; + } - /* Verify data */ - for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) - for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) - if (buf_all[i][j] != erbuf[i][j]) - FAIL_PUTS_ERROR( - "Incorrect data found after reading from points in file to points in memory"); + /* Prevent uninitialized memory usage on test failure */ + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + data[i] = NULL; + dset_id_arr[i] = H5I_INVALID_HID; + } - /* Generate points to write */ - DATASET_IO_POINT_GEN_POINTS(points, i, j); - DATASET_IO_POINT_GEN_POINTS(points2, i, j); + if ((file_id = H5Fopen(H5_api_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open file '%s'\n", H5_api_test_filename); + goto error; + } - /* Select points */ - if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_IO_POINT_NPOINTS, points) < 0) - TEST_ERROR; - if (H5Sselect_elements(mspace_id_full, H5S_SELECT_SET, DATASET_IO_POINT_NPOINTS, points2) < 0) - TEST_ERROR; + if ((container_group = H5Gopen2(file_id, DATASET_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open container group '%s'\n", DATASET_TEST_GROUP_NAME); + goto error; + } - /* Fill write buffer */ - for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) - for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) - buf_all[i][j] = rand(); + if ((group_id = H5Gcreate2(container_group, DATASET_SMALL_READ_MULTI_TEST_POINT_SELECTION_GROUP_NAME, + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create container sub-group '%s'\n", + DATASET_SMALL_READ_TEST_POINT_SELECTION_GROUP_NAME); + goto error; + } - /* Write data points->points */ - if (H5Dwrite(dset_id, H5T_NATIVE_INT, mspace_id_full, fspace_id, H5P_DEFAULT, buf_all) < 0) - FAIL_PUTS_ERROR("Failed to write from points in memory to points in dataset"); + if ((fspace_id = H5Screate_simple(DATASET_SMALL_READ_TEST_POINT_SELECTION_DSET_SPACE_RANK, dims, NULL)) < + 0) + TEST_ERROR; + if ((mspace_id = H5Screate_simple(1, mspace_dims, NULL)) < 0) + TEST_ERROR; - /* Update file_state */ - for (i = 0; i < DATASET_IO_POINT_NPOINTS; i++) - file_state[points[2 * i]][points[2 * i + 1]] = buf_all[points2[2 * i]][points2[2 * i + 1]]; + data_size = DATASET_SMALL_READ_TEST_POINT_SELECTION_NUM_POINTS * + DATASET_SMALL_READ_TEST_POINT_SELECTION_DSET_DTYPESIZE; - /* Wipe read buffer */ - memset(buf_all, 0, sizeof(buf_all)); + for (i = 0; i < DATASET_SMALL_READ_TEST_POINT_SELECTION_NUM_POINTS; i++) { + size_t j; - /* Read entire dataset */ - if (H5Dread(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_all) < 0) - FAIL_PUTS_ERROR("Failed to read entire dataset"); + for (j = 0; j < DATASET_SMALL_READ_TEST_POINT_SELECTION_DSET_SPACE_RANK; j++) + points[(i * DATASET_SMALL_READ_TEST_POINT_SELECTION_DSET_SPACE_RANK) + j] = i; + } - /* Verify data */ - for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) - for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) - if (buf_all[i][j] != file_state[i][j]) - FAIL_PUTS_ERROR( - "Incorrect data found after writing from points in memory to points in dataset"); + if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_SMALL_READ_TEST_POINT_SELECTION_NUM_POINTS, + points) < 0) { + H5_FAILED(); + printf(" couldn't select points\n"); + goto error; + } - PASSED(); + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + char dset_name[DSET_NAME_BUF_SIZE]; - if (do_chunk) - TESTING("point selection I/O with hyperslab in memory and points in file with chunking"); - else - TESTING("point selection I/O with hyperslab in memory and points in file"); + if (DSET_NAME_BUF_SIZE <= snprintf(dset_name, DSET_NAME_BUF_SIZE, "%s%zu%c", + DATASET_SMALL_READ_TEST_HYPERSLAB_DSET_NAME, i, '\0')) + TEST_ERROR; - /* Generate points to read */ - DATASET_IO_POINT_GEN_POINTS(points, i, j); + if ((dset_id_arr[i] = + H5Dcreate2(group_id, dset_name, DATASET_SMALL_READ_TEST_POINT_SELECTION_DSET_DTYPE, + fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset '%s'\n", DATASET_SMALL_READ_TEST_POINT_SELECTION_DSET_NAME); + goto error; + } - /* Select points */ - if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_IO_POINT_NPOINTS, points) < 0) + if (NULL == (data[i] = malloc(data_size))) TEST_ERROR; - /* Select hyperslab */ - if (H5Sselect_hyperslab(mspace_id_full, H5S_SELECT_SET, start, stride, count, block) < 0) - TEST_ERROR; + dtype_arr[i] = DATASET_SMALL_READ_TEST_POINT_SELECTION_DSET_DTYPE; + mspace_id_arr[i] = mspace_id; + fspace_id_arr[i] = fspace_id; + } - /* Wipe read buffer */ - memset(buf_all, 0, sizeof(buf_all)); + if (H5Dread_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_arr, mspace_id_arr, fspace_id_arr, H5P_DEFAULT, + data) < 0) { + H5_FAILED(); + printf(" couldn't read from dataset '%s'\n", DATASET_SMALL_READ_TEST_POINT_SELECTION_DSET_NAME); + goto error; + } - /* Generate expected read buffer */ - memset(erbuf, 0, sizeof(erbuf)); - for (i = 0; i < DATASET_IO_POINT_NPOINTS; i++) - erbuf[start[0] + (stride[0] * ((hsize_t)i / block[1]))][start[1] + ((hsize_t)i % block[1])] = - file_state[points[2 * i]][points[2 * i + 1]]; + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + if (data[i]) { + free(data[i]); + data[i] = NULL; + } + if (H5Dclose(dset_id_arr[i]) < 0) + TEST_ERROR; + } - /* Read data points->hslab */ - if (H5Dread(dset_id, H5T_NATIVE_INT, mspace_id_full, fspace_id, H5P_DEFAULT, buf_all) < 0) - FAIL_PUTS_ERROR("Failed to read points from dataset to hyperslab in memory buffer"); + if (H5Sclose(mspace_id) < 0) + TEST_ERROR; + if (H5Sclose(fspace_id) < 0) + TEST_ERROR; + if (H5Gclose(group_id) < 0) + TEST_ERROR; + if (H5Gclose(container_group) < 0) + TEST_ERROR; + if (H5Fclose(file_id) < 0) + TEST_ERROR; - /* Verify data */ - for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) - for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) - if (buf_all[i][j] != erbuf[i][j]) - FAIL_PUTS_ERROR( - "Incorrect data found after reading from points in file to hyperslab in memory"); + PASSED(); - /* Generate points to write */ - DATASET_IO_POINT_GEN_POINTS(points, i, j); + return 0; - /* Select points */ - if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_IO_POINT_NPOINTS, points) < 0) - TEST_ERROR; +error: + H5E_BEGIN_TRY + { + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + if (data[i]) { + free(data[i]); + data[i] = NULL; + } + H5Dclose(dset_id_arr[i]); + } + H5Sclose(mspace_id); + H5Sclose(fspace_id); + H5Gclose(group_id); + H5Gclose(container_group); + H5Fclose(file_id); + } + H5E_END_TRY; - /* Fill write buffer */ - for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) - for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) - buf_all[i][j] = rand(); + return 1; +} - /* Write data hlsab->points */ - if (H5Dwrite(dset_id, H5T_NATIVE_INT, mspace_id_full, fspace_id, H5P_DEFAULT, buf_all) < 0) - FAIL_PUTS_ERROR("Failed to write from hyperslab in memory to points in dataset"); +/* + * Tests point selection I/O with different patterns + */ +#define DATASET_IO_POINT_DIM_0 6 +#define DATASET_IO_POINT_DIM_1 9 +#define DATASET_IO_POINT_CDIM_0 4 +#define DATASET_IO_POINT_CDIM_1 3 +#define DATASET_IO_POINT_NPOINTS 10 +#define DATASET_IO_POINT_GEN_POINTS(POINTS, I, J) \ + { \ + for ((I) = 0; (I) < DATASET_IO_POINT_NPOINTS; (I)++) \ + do { \ + (POINTS)[2 * (I)] = (hsize_t)(rand() % DATASET_IO_POINT_DIM_0); \ + (POINTS)[2 * (I) + 1] = (hsize_t)(rand() % DATASET_IO_POINT_DIM_1); \ + for ((J) = 0; ((J) < (I)) && (((POINTS)[2 * (I)] != (POINTS)[2 * (J)]) || \ + ((POINTS)[2 * (I) + 1] != (POINTS)[2 * (J) + 1])); \ + (J)++) \ + ; \ + } while ((J) < (I)); \ + } +static int +test_dataset_io_point_selections(void) +{ + hid_t file_id = H5I_INVALID_HID; + hid_t dset_id = H5I_INVALID_HID; + hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID; + hid_t mspace_id_full = H5I_INVALID_HID, mspace_id_all = H5I_INVALID_HID, fspace_id = H5I_INVALID_HID; + hid_t dcpl_id_chunk = H5I_INVALID_HID; + hsize_t dims[2] = {DATASET_IO_POINT_DIM_0, DATASET_IO_POINT_DIM_1}; + hsize_t cdims[2] = {DATASET_IO_POINT_CDIM_0, DATASET_IO_POINT_CDIM_1}; + hsize_t points[DATASET_IO_POINT_NPOINTS * 2]; + hsize_t points2[DATASET_IO_POINT_NPOINTS * 2]; + hsize_t npoints = DATASET_IO_POINT_NPOINTS; + hsize_t start[2] = {1, 2}; + hsize_t stride[2] = {2, 5}; + hsize_t count[2] = {2, 1}; + hsize_t block[2] = {1, 5}; + int buf_all[DATASET_IO_POINT_DIM_0][DATASET_IO_POINT_DIM_1]; + int file_state[DATASET_IO_POINT_DIM_0][DATASET_IO_POINT_DIM_1]; + int erbuf[DATASET_IO_POINT_DIM_0][DATASET_IO_POINT_DIM_1]; + int buf_point[DATASET_IO_POINT_NPOINTS]; + bool do_chunk; + int i, j; + + TESTING("point selection I/O with all selection in memory and points in file"); + + /* Make sure the connector supports the API functions being tested */ + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_FILE_BASIC) || !(vol_cap_flags_g & H5VL_CAP_FLAG_GROUP_BASIC) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_DATASET_BASIC)) { + SKIPPED(); + printf(" API functions for basic file, group, or dataset aren't supported with this connector\n"); + return 0; + } + + /* Create dataspaces and DCPL */ + if ((mspace_id_full = H5Screate_simple(2, dims, NULL)) < 0) + TEST_ERROR; + if ((mspace_id_all = H5Screate_simple(1, &npoints, NULL)) < 0) + TEST_ERROR; + if ((fspace_id = H5Screate_simple(2, dims, NULL)) < 0) + TEST_ERROR; + if ((dcpl_id_chunk = H5Pcreate(H5P_DATASET_CREATE)) < 0) + TEST_ERROR; + + /* Enable chunking on chunk DCPL */ + if (H5Pset_chunk(dcpl_id_chunk, 2, cdims) < 0) + TEST_ERROR; + + /* Open file */ + if ((file_id = H5Fopen(H5_api_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) + TEST_ERROR; + + /* Open container group */ + if ((container_group = H5Gopen2(file_id, DATASET_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) + TEST_ERROR; + + /* Create group */ + if ((group_id = H5Gcreate2(container_group, DATASET_IO_POINT_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, + H5P_DEFAULT)) < 0) + TEST_ERROR; + + /* Perform with and without chunking */ + for (do_chunk = false;; do_chunk = true) { + if (do_chunk) { + TESTING("point selection I/O with all selection in memory and points in file with chunking"); + + /* Create chunked dataset */ + if ((dset_id = H5Dcreate2(group_id, DATASET_IO_POINT_DSET_NAME_CHUNK, H5T_NATIVE_INT, fspace_id, + H5P_DEFAULT, dcpl_id_chunk, H5P_DEFAULT)) < 0) + TEST_ERROR; + } /* end if */ + else + /* Create non-chunked dataset */ + if ((dset_id = H5Dcreate2(group_id, DATASET_IO_POINT_DSET_NAME_NOCHUNK, H5T_NATIVE_INT, fspace_id, + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; + + /* Fill write buffer */ + for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) + for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) + buf_all[i][j] = rand(); + + /* Write data */ + if (H5Dwrite(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_all) < 0) + FAIL_PUTS_ERROR("Failed to write entire dataset"); /* Update file_state */ + for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) + for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) + file_state[i][j] = buf_all[i][j]; + + /* Generate points to read */ + DATASET_IO_POINT_GEN_POINTS(points, i, j); + + /* Select points */ + if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_IO_POINT_NPOINTS, points) < 0) + TEST_ERROR; + + /* Wipe read buffer */ + memset(buf_point, 0, sizeof(buf_point)); + + /* Read points to "all" memory buffer */ + if (H5Dread(dset_id, H5T_NATIVE_INT, mspace_id_all, fspace_id, H5P_DEFAULT, buf_point) < 0) + FAIL_PUTS_ERROR("Failed to read points from dataset to all memory buffer"); + + /* Verify data */ for (i = 0; i < DATASET_IO_POINT_NPOINTS; i++) - file_state[points[2 * i]][points[2 * i + 1]] = - buf_all[start[0] + (stride[0] * ((hsize_t)i / block[1]))][start[1] + ((hsize_t)i % block[1])]; + if (buf_point[i] != file_state[points[2 * i]][points[2 * i + 1]]) + FAIL_PUTS_ERROR("Incorrect data read from points to all memory buffer"); + + /* Generate points to write */ + DATASET_IO_POINT_GEN_POINTS(points, i, j); + + /* Select points */ + if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_IO_POINT_NPOINTS, points) < 0) + TEST_ERROR; + + /* Fill write buffer */ + for (i = 0; i < DATASET_IO_POINT_NPOINTS; i++) + buf_point[i] = rand(); + + /* Write points from "all" memory buffer */ + if (H5Dwrite(dset_id, H5T_NATIVE_INT, mspace_id_all, fspace_id, H5P_DEFAULT, buf_point) < 0) + FAIL_PUTS_ERROR("Failed to write points to dataset from all memory buffer"); + + /* Update file state */ + for (i = 0; i < DATASET_IO_POINT_NPOINTS; i++) + file_state[points[2 * i]][points[2 * i + 1]] = buf_point[i]; + + /* Wipe read buffer */ + memset(buf_all, 0, sizeof(buf_all)); + + /* Read entire dataset */ + if (H5Dread(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_all) < 0) + FAIL_PUTS_ERROR("Failed to read entire dataset"); + + /* Verify data */ + for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) + for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) + if (buf_all[i][j] != file_state[i][j]) + FAIL_PUTS_ERROR("Incorrect data found after writing from all memory buffer to points"); + + PASSED(); + + if (do_chunk) + TESTING("point selection I/O with points in memory and file (same shape) with chunking"); + else + TESTING("point selection I/O with points in memory and file (same shape)"); + + /* Generate points to read */ + DATASET_IO_POINT_GEN_POINTS(points, i, j); + + /* Select points */ + if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_IO_POINT_NPOINTS, points) < 0) + TEST_ERROR; + + /* Wipe read buffer */ + memset(buf_all, 0, sizeof(buf_all)); + + /* Generate expected read buffer */ + memset(erbuf, 0, sizeof(erbuf)); + for (i = 0; i < DATASET_IO_POINT_NPOINTS; i++) + erbuf[points[2 * i]][points[2 * i + 1]] = file_state[points[2 * i]][points[2 * i + 1]]; + + /* Read data points->points */ + if (H5Dread(dset_id, H5T_NATIVE_INT, fspace_id, fspace_id, H5P_DEFAULT, buf_all) < 0) + FAIL_PUTS_ERROR("Failed to read points from dataset to points in memory buffer"); + + /* Verify data */ + for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) + for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) + if (buf_all[i][j] != erbuf[i][j]) + FAIL_PUTS_ERROR("Incorrect data found read from points in file to points in memory"); + + /* Generate points to write */ + DATASET_IO_POINT_GEN_POINTS(points, i, j); + + /* Select points */ + if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_IO_POINT_NPOINTS, points) < 0) + TEST_ERROR; + + /* Fill write buffer */ + for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) + for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) + buf_all[i][j] = rand(); + + /* Write data points->points */ + if (H5Dwrite(dset_id, H5T_NATIVE_INT, fspace_id, fspace_id, H5P_DEFAULT, buf_all) < 0) + FAIL_PUTS_ERROR("Failed to write from in memory to points in dataset"); + + /* Update file_state */ + for (i = 0; i < DATASET_IO_POINT_NPOINTS; i++) + file_state[points[2 * i]][points[2 * i + 1]] = buf_all[points[2 * i]][points[2 * i + 1]]; + + /* Wipe read buffer */ + memset(buf_all, 0, sizeof(buf_all)); + + /* Read entire dataset */ + if (H5Dread(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_all) < 0) + FAIL_PUTS_ERROR("Failed to read entire dataset"); + + /* Verify data */ + for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) + for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) + if (buf_all[i][j] != file_state[i][j]) + FAIL_PUTS_ERROR( + "Incorrect data found after writing from points in memory to points in dataset"); + + PASSED(); + + if (do_chunk) + TESTING("point selection I/O with points in memory and file (different shape) with chunking"); + else + TESTING("point selection I/O with points in memory and file (different shape)"); + + /* Generate points to read */ + DATASET_IO_POINT_GEN_POINTS(points, i, j); + DATASET_IO_POINT_GEN_POINTS(points2, i, j); + + /* Select points */ + if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_IO_POINT_NPOINTS, points) < 0) + TEST_ERROR; + if (H5Sselect_elements(mspace_id_full, H5S_SELECT_SET, DATASET_IO_POINT_NPOINTS, points2) < 0) + TEST_ERROR; + + /* Wipe read buffer */ + memset(buf_all, 0, sizeof(buf_all)); + + /* Generate expected read buffer */ + memset(erbuf, 0, sizeof(erbuf)); + for (i = 0; i < DATASET_IO_POINT_NPOINTS; i++) + erbuf[points2[2 * i]][points2[2 * i + 1]] = file_state[points[2 * i]][points[2 * i + 1]]; + + /* Read data points->points */ + if (H5Dread(dset_id, H5T_NATIVE_INT, mspace_id_full, fspace_id, H5P_DEFAULT, buf_all) < 0) + FAIL_PUTS_ERROR("Failed to read points from dataset to points in memory buffer"); + + /* Verify data */ + for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) + for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) + if (buf_all[i][j] != erbuf[i][j]) + FAIL_PUTS_ERROR( + "Incorrect data found after reading from points in file to points in memory"); + + /* Generate points to write */ + DATASET_IO_POINT_GEN_POINTS(points, i, j); + DATASET_IO_POINT_GEN_POINTS(points2, i, j); + + /* Select points */ + if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_IO_POINT_NPOINTS, points) < 0) + TEST_ERROR; + if (H5Sselect_elements(mspace_id_full, H5S_SELECT_SET, DATASET_IO_POINT_NPOINTS, points2) < 0) + TEST_ERROR; + + /* Fill write buffer */ + for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) + for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) + buf_all[i][j] = rand(); + + /* Write data points->points */ + if (H5Dwrite(dset_id, H5T_NATIVE_INT, mspace_id_full, fspace_id, H5P_DEFAULT, buf_all) < 0) + FAIL_PUTS_ERROR("Failed to write from points in memory to points in dataset"); + + /* Update file_state */ + for (i = 0; i < DATASET_IO_POINT_NPOINTS; i++) + file_state[points[2 * i]][points[2 * i + 1]] = buf_all[points2[2 * i]][points2[2 * i + 1]]; + + /* Wipe read buffer */ + memset(buf_all, 0, sizeof(buf_all)); + + /* Read entire dataset */ + if (H5Dread(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_all) < 0) + FAIL_PUTS_ERROR("Failed to read entire dataset"); + + /* Verify data */ + for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) + for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) + if (buf_all[i][j] != file_state[i][j]) + FAIL_PUTS_ERROR( + "Incorrect data found after writing from points in memory to points in dataset"); + + PASSED(); + + if (do_chunk) + TESTING("point selection I/O with hyperslab in memory and points in file with chunking"); + else + TESTING("point selection I/O with hyperslab in memory and points in file"); + + /* Generate points to read */ + DATASET_IO_POINT_GEN_POINTS(points, i, j); + + /* Select points */ + if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_IO_POINT_NPOINTS, points) < 0) + TEST_ERROR; + + /* Select hyperslab */ + if (H5Sselect_hyperslab(mspace_id_full, H5S_SELECT_SET, start, stride, count, block) < 0) + TEST_ERROR; + + /* Wipe read buffer */ + memset(buf_all, 0, sizeof(buf_all)); + + /* Generate expected read buffer */ + memset(erbuf, 0, sizeof(erbuf)); + for (i = 0; i < DATASET_IO_POINT_NPOINTS; i++) + erbuf[start[0] + (stride[0] * ((hsize_t)i / block[1]))][start[1] + ((hsize_t)i % block[1])] = + file_state[points[2 * i]][points[2 * i + 1]]; + + /* Read data points->hslab */ + if (H5Dread(dset_id, H5T_NATIVE_INT, mspace_id_full, fspace_id, H5P_DEFAULT, buf_all) < 0) + FAIL_PUTS_ERROR("Failed to read points from dataset to hyperslab in memory buffer"); + + /* Verify data */ + for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) + for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) + if (buf_all[i][j] != erbuf[i][j]) + FAIL_PUTS_ERROR( + "Incorrect data found after reading from points in file to hyperslab in memory"); + + /* Generate points to write */ + DATASET_IO_POINT_GEN_POINTS(points, i, j); + + /* Select points */ + if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_IO_POINT_NPOINTS, points) < 0) + TEST_ERROR; + + /* Fill write buffer */ + for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) + for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) + buf_all[i][j] = rand(); + + /* Write data hlsab->points */ + if (H5Dwrite(dset_id, H5T_NATIVE_INT, mspace_id_full, fspace_id, H5P_DEFAULT, buf_all) < 0) + FAIL_PUTS_ERROR("Failed to write from hyperslab in memory to points in dataset"); + + /* Update file_state */ + for (i = 0; i < DATASET_IO_POINT_NPOINTS; i++) + file_state[points[2 * i]][points[2 * i + 1]] = + buf_all[start[0] + (stride[0] * ((hsize_t)i / block[1]))][start[1] + ((hsize_t)i % block[1])]; + + /* Wipe read buffer */ + memset(buf_all, 0, sizeof(buf_all)); + + /* Read entire dataset */ + if (H5Dread(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_all) < 0) + FAIL_PUTS_ERROR("Failed to read entire dataset"); + + /* Verify data */ + for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) + for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) + if (buf_all[i][j] != file_state[i][j]) + FAIL_PUTS_ERROR( + "Incorrect data found after writing from hyperslab in memory to points in dataset"); + + PASSED(); + + if (do_chunk) + TESTING("point selection I/O with points in memory and hyperslab in file with chunking"); + else + TESTING("point selection I/O with points in memory and hyperslab in file"); + + /* Generate points to read */ + DATASET_IO_POINT_GEN_POINTS(points, i, j); + + /* Select points */ + if (H5Sselect_elements(mspace_id_full, H5S_SELECT_SET, DATASET_IO_POINT_NPOINTS, points) < 0) + TEST_ERROR; + + /* Select hyperslab */ + if (H5Sselect_hyperslab(fspace_id, H5S_SELECT_SET, start, stride, count, block) < 0) + TEST_ERROR; + + /* Wipe read buffer */ + memset(buf_all, 0, sizeof(buf_all)); + + /* Generate expected read buffer */ + memset(erbuf, 0, sizeof(erbuf)); + for (i = 0; i < DATASET_IO_POINT_NPOINTS; i++) + erbuf[points[2 * i]][points[2 * i + 1]] = + file_state[start[0] + (stride[0] * ((hsize_t)i / block[1]))] + [start[1] + ((hsize_t)i % block[1])]; + + /* Read data hslab->points */ + if (H5Dread(dset_id, H5T_NATIVE_INT, mspace_id_full, fspace_id, H5P_DEFAULT, buf_all) < 0) + FAIL_PUTS_ERROR("Failed to read hyperslab from dataset to points in memory buffer"); + + /* Verify data */ + for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) + for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) + if (buf_all[i][j] != erbuf[i][j]) + FAIL_PUTS_ERROR( + "Incorrect data found after reading from hyperslab in file to points in memory"); + + /* Generate points to write */ + DATASET_IO_POINT_GEN_POINTS(points, i, j); + + /* Select points */ + if (H5Sselect_elements(mspace_id_full, H5S_SELECT_SET, DATASET_IO_POINT_NPOINTS, points) < 0) + TEST_ERROR; + + /* Fill write buffer */ + for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) + for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) + buf_all[i][j] = rand(); + + /* Write data points->hslab */ + if (H5Dwrite(dset_id, H5T_NATIVE_INT, mspace_id_full, fspace_id, H5P_DEFAULT, buf_all) < 0) + FAIL_PUTS_ERROR("Failed to write from points in memory to hyperslab in dataset"); + + /* Update file_state */ + for (i = 0; i < DATASET_IO_POINT_NPOINTS; i++) + file_state[start[0] + (stride[0] * ((hsize_t)i / block[1]))][start[1] + ((hsize_t)i % block[1])] = + buf_all[points[2 * i]][points[2 * i + 1]]; + + /* Wipe read buffer */ + memset(buf_all, 0, sizeof(buf_all)); + + /* Read entire dataset */ + if (H5Dread(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_all) < 0) + FAIL_PUTS_ERROR("Failed to read entire dataset"); + + /* Verify data */ + for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) + for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) + if (buf_all[i][j] != file_state[i][j]) + FAIL_PUTS_ERROR( + "Incorrect data found after writing from points in memory to hyperslab in dataset"); + + if (!do_chunk) + PASSED(); + + /* Close dataset */ + if (H5Dclose(dset_id) < 0) + TEST_ERROR; + + /* Exit after chunked run */ + if (do_chunk) + break; + } /* end for */ + + /* Close */ + if (H5Gclose(group_id) < 0) + TEST_ERROR; + if (H5Gclose(container_group) < 0) + TEST_ERROR; + if (H5Fclose(file_id) < 0) + TEST_ERROR; + if (H5Pclose(dcpl_id_chunk) < 0) + TEST_ERROR; + if (H5Sclose(mspace_id_full) < 0) + TEST_ERROR; + if (H5Sclose(mspace_id_all) < 0) + TEST_ERROR; + if (H5Sclose(fspace_id) < 0) + TEST_ERROR; + + PASSED(); + + return 0; + +error: + H5E_BEGIN_TRY + { + H5Sclose(fspace_id); + H5Sclose(mspace_id_full); + H5Sclose(mspace_id_all); + H5Pclose(dcpl_id_chunk); + H5Dclose(dset_id); + H5Gclose(group_id); + H5Gclose(container_group); + H5Fclose(file_id); + } + H5E_END_TRY + + return 1; +} /* end test_dataset_io_point_selections() */ + +/* + * A test to check that data can't be read from a + * dataset when H5Dread is passed invalid parameters. + */ +static int +test_read_dataset_invalid_params(void) +{ + hsize_t dims[DATASET_READ_INVALID_PARAMS_TEST_DSET_SPACE_RANK] = {10, 5, 3}; + herr_t err_ret = -1; + size_t i, data_size; + hid_t file_id = H5I_INVALID_HID; + hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID; + hid_t dset_id = H5I_INVALID_HID; + hid_t fspace_id = H5I_INVALID_HID; + void *read_buf = NULL; + + TESTING_MULTIPART("H5Dread with invalid parameters"); + + /* Make sure the connector supports the API functions being tested */ + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_FILE_BASIC) || !(vol_cap_flags_g & H5VL_CAP_FLAG_GROUP_BASIC) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_DATASET_BASIC)) { + SKIPPED(); + printf(" API functions for basic file, group, or dataset aren't supported with this connector\n"); + return 0; + } + + TESTING_2("test setup"); + + if ((file_id = H5Fopen(H5_api_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open file '%s'\n", H5_api_test_filename); + goto error; + } + + if ((container_group = H5Gopen2(file_id, DATASET_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open container group '%s'\n", DATASET_TEST_GROUP_NAME); + goto error; + } + + if ((group_id = H5Gcreate2(container_group, DATASET_READ_INVALID_PARAMS_TEST_GROUP_NAME, H5P_DEFAULT, + H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create container sub-group '%s'\n", DATASET_READ_INVALID_PARAMS_TEST_GROUP_NAME); + goto error; + } + + if ((fspace_id = H5Screate_simple(DATASET_READ_INVALID_PARAMS_TEST_DSET_SPACE_RANK, dims, NULL)) < 0) + TEST_ERROR; + + if ((dset_id = H5Dcreate2(group_id, DATASET_READ_INVALID_PARAMS_TEST_DSET_NAME, + DATASET_READ_INVALID_PARAMS_TEST_DSET_DTYPE, fspace_id, H5P_DEFAULT, + H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset '%s'\n", DATASET_READ_INVALID_PARAMS_TEST_DSET_NAME); + goto error; + } + + for (i = 0, data_size = 1; i < DATASET_READ_INVALID_PARAMS_TEST_DSET_SPACE_RANK; i++) + data_size *= dims[i]; + data_size *= DATASET_READ_INVALID_PARAMS_TEST_DSET_DTYPESIZE; + + if (NULL == (read_buf = malloc(data_size))) + TEST_ERROR; + + PASSED(); + + BEGIN_MULTIPART + { + PART_BEGIN(H5Dread_invalid_dset_id) + { + TESTING_2("H5Dread with an invalid dataset ID"); + + H5E_BEGIN_TRY + { + err_ret = H5Dread(H5I_INVALID_HID, DATASET_READ_INVALID_PARAMS_TEST_DSET_DTYPE, H5S_ALL, + H5S_ALL, H5P_DEFAULT, read_buf); + } + H5E_END_TRY + + if (err_ret >= 0) { + H5_FAILED(); + printf(" read from dataset using H5Dread with an invalid dataset ID!\n"); + PART_ERROR(H5Dread_invalid_dset_id); + } + + PASSED(); + } + PART_END(H5Dread_invalid_dset_id); + + PART_BEGIN(H5Dread_invalid_datatype) + { + TESTING_2("H5Dread with an invalid memory datatype"); + + H5E_BEGIN_TRY + { + err_ret = H5Dread(dset_id, H5I_INVALID_HID, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_buf); + } + H5E_END_TRY + + if (err_ret >= 0) { + H5_FAILED(); + printf(" read from dataset using H5Dread with an invalid memory datatype!\n"); + PART_ERROR(H5Dread_invalid_datatype); + } + + PASSED(); + } + PART_END(H5Dread_invalid_datatype); + + PART_BEGIN(H5Dread_invalid_mem_dataspace) + { + TESTING_2("H5Dread with an invalid memory dataspace"); + + H5E_BEGIN_TRY + { + err_ret = H5Dread(dset_id, DATASET_READ_INVALID_PARAMS_TEST_DSET_DTYPE, H5I_INVALID_HID, + H5S_ALL, H5P_DEFAULT, read_buf); + } + H5E_END_TRY + + if (err_ret >= 0) { + H5_FAILED(); + printf(" read from dataset using H5Dread with an invalid memory dataspace!\n"); + PART_ERROR(H5Dread_invalid_mem_dataspace); + } + + PASSED(); + } + PART_END(H5Dread_invalid_mem_dataspace); + + PART_BEGIN(H5Dread_invalid_file_dataspace) + { + TESTING_2("H5Dread with an invalid file dataspace"); + + H5E_BEGIN_TRY + { + err_ret = H5Dread(dset_id, DATASET_READ_INVALID_PARAMS_TEST_DSET_DTYPE, H5S_ALL, + H5I_INVALID_HID, H5P_DEFAULT, read_buf); + } + H5E_END_TRY + + if (err_ret >= 0) { + H5_FAILED(); + printf(" read from dataset using H5Dread with an invalid file dataspace!\n"); + PART_ERROR(H5Dread_invalid_file_dataspace); + } + + PASSED(); + } + PART_END(H5Dread_invalid_file_dataspace); + + PART_BEGIN(H5Dread_invalid_dxpl) + { + TESTING_2("H5Dread with an invalid DXPL"); + + H5E_BEGIN_TRY + { + err_ret = H5Dread(dset_id, DATASET_READ_INVALID_PARAMS_TEST_DSET_DTYPE, H5S_ALL, H5S_ALL, + H5I_INVALID_HID, read_buf); + } + H5E_END_TRY + + if (err_ret >= 0) { + H5_FAILED(); + printf(" read from dataset using H5Dread with an invalid DXPL!\n"); + PART_ERROR(H5Dread_invalid_dxpl); + } + + PASSED(); + } + PART_END(H5Dread_invalid_dxpl); + + PART_BEGIN(H5Dread_invalid_data_buf) + { + TESTING_2("H5Dread with an invalid data buffer"); + + H5E_BEGIN_TRY + { + err_ret = H5Dread(dset_id, DATASET_READ_INVALID_PARAMS_TEST_DSET_DTYPE, H5S_ALL, H5S_ALL, + H5P_DEFAULT, NULL); + } + H5E_END_TRY + + if (err_ret >= 0) { + H5_FAILED(); + printf(" read from dataset using H5Dread with an invalid data buffer!\n"); + PART_ERROR(H5Dread_invalid_data_buf); + } + + PASSED(); + } + PART_END(H5Dread_invalid_data_buf); + } + END_MULTIPART; + + TESTING_2("test cleanup"); + + if (read_buf) { + free(read_buf); + read_buf = NULL; + } + + if (H5Sclose(fspace_id) < 0) + TEST_ERROR; + if (H5Dclose(dset_id) < 0) + TEST_ERROR; + if (H5Gclose(group_id) < 0) + TEST_ERROR; + if (H5Gclose(container_group) < 0) + TEST_ERROR; + if (H5Fclose(file_id) < 0) + TEST_ERROR; + + PASSED(); + + return 0; + +error: + H5E_BEGIN_TRY + { + if (read_buf) + free(read_buf); + H5Sclose(fspace_id); + H5Dclose(dset_id); + H5Gclose(group_id); + H5Gclose(container_group); + H5Fclose(file_id); + } + H5E_END_TRY + + return 1; +} + +/* + * A test to check that a small write can be + * made to a dataset using an H5S_ALL selection. + */ +static int +test_write_dataset_small_all(void) +{ + hssize_t space_npoints; + hsize_t dims[DATASET_SMALL_WRITE_TEST_ALL_DSET_SPACE_RANK] = {10, 5, 3}; + size_t i; + hid_t file_id = H5I_INVALID_HID; + hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID; + hid_t dset_id = H5I_INVALID_HID; + hid_t fspace_id = H5I_INVALID_HID; + void *data = NULL; + + TESTING("small write to dataset with H5S_ALL"); + + /* Make sure the connector supports the API functions being tested */ + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_FILE_BASIC) || !(vol_cap_flags_g & H5VL_CAP_FLAG_GROUP_BASIC) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_DATASET_BASIC) || !(vol_cap_flags_g & H5VL_CAP_FLAG_DATASET_MORE)) { + SKIPPED(); + printf(" API functions for basic file, group, or dataset aren't supported with this connector\n"); + return 0; + } + + if ((file_id = H5Fopen(H5_api_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open file '%s'\n", H5_api_test_filename); + goto error; + } + + if ((container_group = H5Gopen2(file_id, DATASET_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open container group '%s'\n", DATASET_TEST_GROUP_NAME); + goto error; + } + + if ((group_id = H5Gcreate2(container_group, DATASET_SMALL_WRITE_TEST_ALL_GROUP_NAME, H5P_DEFAULT, + H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create container sub-group '%s'\n", DATASET_SMALL_WRITE_TEST_ALL_GROUP_NAME); + goto error; + } + + if ((fspace_id = H5Screate_simple(DATASET_SMALL_WRITE_TEST_ALL_DSET_SPACE_RANK, dims, NULL)) < 0) + TEST_ERROR; + + if ((dset_id = H5Dcreate2(group_id, DATASET_SMALL_WRITE_TEST_ALL_DSET_NAME, + DATASET_SMALL_WRITE_TEST_ALL_DSET_DTYPE, fspace_id, H5P_DEFAULT, H5P_DEFAULT, + H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset '%s'\n", DATASET_SMALL_WRITE_TEST_ALL_DSET_NAME); + goto error; + } + + /* Close the dataset and dataspace to ensure that writing works correctly in this manner */ + if (H5Dclose(dset_id) < 0) + TEST_ERROR; + if (H5Sclose(fspace_id) < 0) + TEST_ERROR; + + if ((dset_id = H5Dopen2(group_id, DATASET_SMALL_WRITE_TEST_ALL_DSET_NAME, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open dataset '%s'\n", DATASET_SMALL_WRITE_TEST_ALL_DSET_NAME); + goto error; + } + + if ((fspace_id = H5Dget_space(dset_id)) < 0) { + H5_FAILED(); + printf(" couldn't get dataset dataspace\n"); + goto error; + } + + if ((space_npoints = H5Sget_simple_extent_npoints(fspace_id)) < 0) { + H5_FAILED(); + printf(" couldn't get dataspace num points\n"); + goto error; + } + + if (NULL == (data = malloc((hsize_t)space_npoints * DATASET_SMALL_WRITE_TEST_ALL_DSET_DTYPESIZE))) + TEST_ERROR; + + for (i = 0; i < (hsize_t)space_npoints; i++) + ((int *)data)[i] = (int)i; + + if (H5Dwrite(dset_id, DATASET_SMALL_WRITE_TEST_ALL_DSET_DTYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, data) < 0) { + H5_FAILED(); + printf(" couldn't write to dataset '%s'\n", DATASET_SMALL_WRITE_TEST_ALL_DSET_NAME); + goto error; + } + + if (data) { + free(data); + data = NULL; + } + + if (H5Sclose(fspace_id) < 0) + TEST_ERROR; + if (H5Dclose(dset_id) < 0) + TEST_ERROR; + if (H5Gclose(group_id) < 0) + TEST_ERROR; + if (H5Gclose(container_group) < 0) + TEST_ERROR; + if (H5Fclose(file_id) < 0) + TEST_ERROR; + + PASSED(); + + return 0; + +error: + H5E_BEGIN_TRY + { + if (data) + free(data); + H5Sclose(fspace_id); + H5Dclose(dset_id); + H5Gclose(group_id); + H5Gclose(container_group); + H5Fclose(file_id); + } + H5E_END_TRY + + return 1; +} + +/* + * A test to check that a small write can be made + * to a dataset using a hyperslab selection. + */ +static int +test_write_dataset_small_hyperslab(void) +{ + hsize_t start[DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_SPACE_RANK]; + hsize_t stride[DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_SPACE_RANK]; + hsize_t count[DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_SPACE_RANK]; + hsize_t block[DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_SPACE_RANK]; + hsize_t dims[DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_SPACE_RANK] = {10, 5, 3}; + size_t i, data_size; + hid_t file_id = H5I_INVALID_HID; + hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID; + hid_t dset_id = H5I_INVALID_HID; + hid_t mspace_id = H5I_INVALID_HID, fspace_id = H5I_INVALID_HID; + void *data = NULL; + + TESTING("small write to dataset with a hyperslab selection"); + + /* Make sure the connector supports the API functions being tested */ + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_FILE_BASIC) || !(vol_cap_flags_g & H5VL_CAP_FLAG_GROUP_BASIC) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_DATASET_BASIC)) { + SKIPPED(); + printf(" API functions for basic file, group, or dataset aren't supported with this connector\n"); + return 0; + } + + if ((file_id = H5Fopen(H5_api_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open file '%s'\n", H5_api_test_filename); + goto error; + } + + if ((container_group = H5Gopen2(file_id, DATASET_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open container group '%s'\n", DATASET_TEST_GROUP_NAME); + goto error; + } + + if ((group_id = H5Gcreate2(container_group, DATASET_SMALL_WRITE_TEST_HYPERSLAB_GROUP_NAME, H5P_DEFAULT, + H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create container sub-group '%s'\n", + DATASET_SMALL_WRITE_TEST_HYPERSLAB_GROUP_NAME); + goto error; + } + + if ((fspace_id = H5Screate_simple(DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_SPACE_RANK, dims, NULL)) < 0) + TEST_ERROR; + if ((mspace_id = H5Screate_simple(DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_SPACE_RANK - 1, dims, NULL)) < + 0) + TEST_ERROR; + + if ((dset_id = H5Dcreate2(group_id, DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_NAME, + DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_DTYPE, fspace_id, H5P_DEFAULT, + H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset '%s'\n", DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_NAME); + goto error; + } + + for (i = 0, data_size = 1; i < DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_SPACE_RANK - 1; i++) + data_size *= dims[i]; + data_size *= DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_DTYPESIZE; + + if (NULL == (data = malloc(data_size))) + TEST_ERROR; + + for (i = 0; i < data_size / DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_DTYPESIZE; i++) + ((int *)data)[i] = (int)i; + + for (i = 0; i < DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_SPACE_RANK; i++) { + start[i] = 0; + stride[i] = 1; + count[i] = dims[i]; + block[i] = 1; + } + + count[2] = 1; + + if (H5Sselect_hyperslab(fspace_id, H5S_SELECT_SET, start, stride, count, block) < 0) + TEST_ERROR; - /* Wipe read buffer */ - memset(buf_all, 0, sizeof(buf_all)); + if (H5Dwrite(dset_id, DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_DTYPE, mspace_id, fspace_id, H5P_DEFAULT, + data) < 0) { + H5_FAILED(); + printf(" couldn't write to dataset '%s'\n", DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_NAME); + goto error; + } - /* Read entire dataset */ - if (H5Dread(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_all) < 0) - FAIL_PUTS_ERROR("Failed to read entire dataset"); + if (data) { + free(data); + data = NULL; + } - /* Verify data */ - for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) - for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) - if (buf_all[i][j] != file_state[i][j]) - FAIL_PUTS_ERROR( - "Incorrect data found after writing from hyperslab in memory to points in dataset"); + if (H5Sclose(mspace_id) < 0) + TEST_ERROR; + if (H5Sclose(fspace_id) < 0) + TEST_ERROR; + if (H5Dclose(dset_id) < 0) + TEST_ERROR; + if (H5Gclose(group_id) < 0) + TEST_ERROR; + if (H5Gclose(container_group) < 0) + TEST_ERROR; + if (H5Fclose(file_id) < 0) + TEST_ERROR; - PASSED(); + PASSED(); - if (do_chunk) - TESTING("point selection I/O with points in memory and hyperslab in file with chunking"); - else - TESTING("point selection I/O with points in memory and hyperslab in file"); + return 0; - /* Generate points to read */ - DATASET_IO_POINT_GEN_POINTS(points, i, j); +error: + H5E_BEGIN_TRY + { + if (data) + free(data); + H5Sclose(mspace_id); + H5Sclose(fspace_id); + H5Dclose(dset_id); + H5Gclose(group_id); + H5Gclose(container_group); + H5Fclose(file_id); + } + H5E_END_TRY - /* Select points */ - if (H5Sselect_elements(mspace_id_full, H5S_SELECT_SET, DATASET_IO_POINT_NPOINTS, points) < 0) - TEST_ERROR; + return 1; +} - /* Select hyperslab */ - if (H5Sselect_hyperslab(fspace_id, H5S_SELECT_SET, start, stride, count, block) < 0) - TEST_ERROR; +/* + * A test to check that a small write can be made + * to a dataset using a point selection. + */ +static int +test_write_dataset_small_point_selection(void) +{ + hsize_t points[DATASET_SMALL_WRITE_TEST_POINT_SELECTION_NUM_POINTS * + DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_SPACE_RANK]; + hsize_t dims[DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_SPACE_RANK] = {10, 10, 10}; + hsize_t mdims[] = {DATASET_SMALL_WRITE_TEST_POINT_SELECTION_NUM_POINTS}; + size_t i, data_size; + hid_t file_id = H5I_INVALID_HID; + hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID; + hid_t dset_id = H5I_INVALID_HID; + hid_t fspace_id = H5I_INVALID_HID; + hid_t mspace_id = H5I_INVALID_HID; + void *data = NULL; - /* Wipe read buffer */ - memset(buf_all, 0, sizeof(buf_all)); + TESTING("small write to dataset with a point selection"); - /* Generate expected read buffer */ - memset(erbuf, 0, sizeof(erbuf)); - for (i = 0; i < DATASET_IO_POINT_NPOINTS; i++) - erbuf[points[2 * i]][points[2 * i + 1]] = - file_state[start[0] + (stride[0] * ((hsize_t)i / block[1]))] - [start[1] + ((hsize_t)i % block[1])]; + /* Make sure the connector supports the API functions being tested */ + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_FILE_BASIC) || !(vol_cap_flags_g & H5VL_CAP_FLAG_GROUP_BASIC) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_DATASET_BASIC)) { + SKIPPED(); + printf(" API functions for basic file, group, or dataset aren't supported with this connector\n"); + return 0; + } - /* Read data hslab->points */ - if (H5Dread(dset_id, H5T_NATIVE_INT, mspace_id_full, fspace_id, H5P_DEFAULT, buf_all) < 0) - FAIL_PUTS_ERROR("Failed to read hyperslab from dataset to points in memory buffer"); + if ((file_id = H5Fopen(H5_api_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open file '%s'\n", H5_api_test_filename); + goto error; + } - /* Verify data */ - for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) - for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) - if (buf_all[i][j] != erbuf[i][j]) - FAIL_PUTS_ERROR( - "Incorrect data found after reading from hyperslab in file to points in memory"); + if ((container_group = H5Gopen2(file_id, DATASET_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open container group '%s'\n", DATASET_TEST_GROUP_NAME); + goto error; + } - /* Generate points to write */ - DATASET_IO_POINT_GEN_POINTS(points, i, j); + if ((group_id = H5Gcreate2(container_group, DATASET_SMALL_WRITE_TEST_POINT_SELECTION_GROUP_NAME, + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create container sub-group '%s'\n", + DATASET_SMALL_WRITE_TEST_POINT_SELECTION_GROUP_NAME); + goto error; + } - /* Select points */ - if (H5Sselect_elements(mspace_id_full, H5S_SELECT_SET, DATASET_IO_POINT_NPOINTS, points) < 0) - TEST_ERROR; + if ((fspace_id = H5Screate_simple(DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_SPACE_RANK, dims, NULL)) < + 0) + TEST_ERROR; + if ((mspace_id = H5Screate_simple(1, mdims, NULL)) < 0) + TEST_ERROR; - /* Fill write buffer */ - for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) - for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) - buf_all[i][j] = rand(); + if ((dset_id = H5Dcreate2(group_id, DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_NAME, + DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_DTYPE, fspace_id, H5P_DEFAULT, + H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset '%s'\n", DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_NAME); + goto error; + } - /* Write data points->hslab */ - if (H5Dwrite(dset_id, H5T_NATIVE_INT, mspace_id_full, fspace_id, H5P_DEFAULT, buf_all) < 0) - FAIL_PUTS_ERROR("Failed to write from points in memory to hyperslab in dataset"); + data_size = DATASET_SMALL_WRITE_TEST_POINT_SELECTION_NUM_POINTS * + DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_DTYPESIZE; - /* Update file_state */ - for (i = 0; i < DATASET_IO_POINT_NPOINTS; i++) - file_state[start[0] + (stride[0] * ((hsize_t)i / block[1]))][start[1] + ((hsize_t)i % block[1])] = - buf_all[points[2 * i]][points[2 * i + 1]]; + if (NULL == (data = malloc(data_size))) + TEST_ERROR; - /* Wipe read buffer */ - memset(buf_all, 0, sizeof(buf_all)); + for (i = 0; i < data_size / DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_DTYPESIZE; i++) + ((int *)data)[i] = (int)i; - /* Read entire dataset */ - if (H5Dread(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_all) < 0) - FAIL_PUTS_ERROR("Failed to read entire dataset"); + for (i = 0; i < DATASET_SMALL_WRITE_TEST_POINT_SELECTION_NUM_POINTS; i++) { + size_t j; - /* Verify data */ - for (i = 0; i < DATASET_IO_POINT_DIM_0; i++) - for (j = 0; j < DATASET_IO_POINT_DIM_1; j++) - if (buf_all[i][j] != file_state[i][j]) - FAIL_PUTS_ERROR( - "Incorrect data found after writing from points in memory to hyperslab in dataset"); + for (j = 0; j < DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_SPACE_RANK; j++) + points[(i * DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_SPACE_RANK) + j] = i; + } - if (!do_chunk) - PASSED(); + if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_SMALL_WRITE_TEST_POINT_SELECTION_NUM_POINTS, + points) < 0) { + H5_FAILED(); + printf(" couldn't select points\n"); + goto error; + } - /* Close dataset */ - if (H5Dclose(dset_id) < 0) - TEST_ERROR; + if (H5Dwrite(dset_id, DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_DTYPE, mspace_id, fspace_id, + H5P_DEFAULT, data) < 0) { + H5_FAILED(); + printf(" couldn't write to dataset '%s'\n", DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_NAME); + goto error; + } - /* Exit after chunked run */ - if (do_chunk) - break; - } /* end for */ + if (data) { + free(data); + data = NULL; + } - /* Close */ - if (H5Gclose(group_id) < 0) - TEST_ERROR; - if (H5Gclose(container_group) < 0) + if (H5Sclose(mspace_id) < 0) TEST_ERROR; - if (H5Fclose(file_id) < 0) + if (H5Sclose(fspace_id) < 0) TEST_ERROR; - if (H5Pclose(dcpl_id_chunk) < 0) + if (H5Dclose(dset_id) < 0) TEST_ERROR; - if (H5Sclose(mspace_id_full) < 0) + if (H5Gclose(group_id) < 0) TEST_ERROR; - if (H5Sclose(mspace_id_all) < 0) + if (H5Gclose(container_group) < 0) TEST_ERROR; - if (H5Sclose(fspace_id) < 0) + if (H5Fclose(file_id) < 0) TEST_ERROR; PASSED(); @@ -4893,10 +5965,10 @@ test_dataset_io_point_selections(void) error: H5E_BEGIN_TRY { + if (data) + free(data); + H5Sclose(mspace_id); H5Sclose(fspace_id); - H5Sclose(mspace_id_full); - H5Sclose(mspace_id_all); - H5Pclose(dcpl_id_chunk); H5Dclose(dset_id); H5Gclose(group_id); H5Gclose(container_group); @@ -4905,31 +5977,41 @@ error: H5E_END_TRY return 1; -} /* end test_dataset_io_point_selections() */ +} /* - * A test to check that data can't be read from a - * dataset when H5Dread is passed invalid parameters. + * A test to ensure that data is read back correctly from + * a dataset after it has been written. */ static int -test_read_dataset_invalid_params(void) +test_write_dataset_data_verification(void) { - hsize_t dims[DATASET_READ_INVALID_PARAMS_TEST_DSET_SPACE_RANK] = {10, 5, 3}; - herr_t err_ret = -1; - size_t i, data_size; - hid_t file_id = H5I_INVALID_HID; - hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID; - hid_t dset_id = H5I_INVALID_HID; - hid_t fspace_id = H5I_INVALID_HID; - void *read_buf = NULL; + hssize_t space_npoints; + hsize_t dims[DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK] = {10, 10, 10}; + hsize_t start[DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK]; + hsize_t stride[DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK]; + hsize_t count[DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK]; + hsize_t block[DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK]; + hsize_t + points[DATASET_DATA_VERIFY_WRITE_TEST_NUM_POINTS * DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK]; + size_t i, data_size; + hid_t file_id = H5I_INVALID_HID; + hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID; + hid_t dset_id = H5I_INVALID_HID; + hid_t fspace_id = H5I_INVALID_HID; + hid_t mspace_id = H5I_INVALID_HID; + void *data = NULL; + void *write_buf = NULL; + void *read_buf = NULL; - TESTING_MULTIPART("H5Dread with invalid parameters"); + TESTING_MULTIPART("verification of dataset data using H5Dwrite then H5Dread"); /* Make sure the connector supports the API functions being tested */ if (!(vol_cap_flags_g & H5VL_CAP_FLAG_FILE_BASIC) || !(vol_cap_flags_g & H5VL_CAP_FLAG_GROUP_BASIC) || - !(vol_cap_flags_g & H5VL_CAP_FLAG_DATASET_BASIC)) { + !(vol_cap_flags_g & H5VL_CAP_FLAG_DATASET_BASIC) || !(vol_cap_flags_g & H5VL_CAP_FLAG_DATASET_MORE)) { SKIPPED(); - printf(" API functions for basic file, group, or dataset aren't supported with this connector\n"); + printf(" API functions for basic file, group, basic or more dataset aren't supported with this " + "connector\n"); return 0; } @@ -4947,164 +6029,430 @@ test_read_dataset_invalid_params(void) goto error; } - if ((group_id = H5Gcreate2(container_group, DATASET_READ_INVALID_PARAMS_TEST_GROUP_NAME, H5P_DEFAULT, + if ((group_id = H5Gcreate2(container_group, DATASET_DATA_VERIFY_WRITE_TEST_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { H5_FAILED(); - printf(" couldn't create container sub-group '%s'\n", DATASET_READ_INVALID_PARAMS_TEST_GROUP_NAME); + printf(" couldn't create container sub-group '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_GROUP_NAME); goto error; } - if ((fspace_id = H5Screate_simple(DATASET_READ_INVALID_PARAMS_TEST_DSET_SPACE_RANK, dims, NULL)) < 0) + if ((fspace_id = H5Screate_simple(DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK, dims, NULL)) < 0) TEST_ERROR; - if ((dset_id = H5Dcreate2(group_id, DATASET_READ_INVALID_PARAMS_TEST_DSET_NAME, - DATASET_READ_INVALID_PARAMS_TEST_DSET_DTYPE, fspace_id, H5P_DEFAULT, - H5P_DEFAULT, H5P_DEFAULT)) < 0) { + if ((dset_id = H5Dcreate2(group_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME, + DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE, fspace_id, H5P_DEFAULT, H5P_DEFAULT, + H5P_DEFAULT)) < 0) { H5_FAILED(); - printf(" couldn't create dataset '%s'\n", DATASET_READ_INVALID_PARAMS_TEST_DSET_NAME); + printf(" couldn't create dataset '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME); goto error; } - for (i = 0, data_size = 1; i < DATASET_READ_INVALID_PARAMS_TEST_DSET_SPACE_RANK; i++) + for (i = 0, data_size = 1; i < DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK; i++) data_size *= dims[i]; - data_size *= DATASET_READ_INVALID_PARAMS_TEST_DSET_DTYPESIZE; + data_size *= DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; - if (NULL == (read_buf = malloc(data_size))) + if (NULL == (data = malloc(data_size))) TEST_ERROR; + for (i = 0; i < data_size / DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; i++) + ((int *)data)[i] = (int)i; + PASSED(); BEGIN_MULTIPART { - PART_BEGIN(H5Dread_invalid_dset_id) + PART_BEGIN(H5Dwrite_all_read) { - TESTING_2("H5Dread with an invalid dataset ID"); + TESTING_2("H5Dwrite using H5S_ALL then H5Dread"); + + if (H5Dwrite(dset_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, + data) < 0) { + H5_FAILED(); + printf(" couldn't write to dataset '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_all_read); + } + + if (data) { + free(data); + data = NULL; + } + + if (fspace_id >= 0) { + H5E_BEGIN_TRY + { + H5Sclose(fspace_id); + } + H5E_END_TRY + fspace_id = H5I_INVALID_HID; + } + if (dset_id >= 0) { + H5E_BEGIN_TRY + { + H5Dclose(dset_id); + } + H5E_END_TRY + dset_id = H5I_INVALID_HID; + } + + if ((dset_id = H5Dopen2(group_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open dataset '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_all_read); + } + + if ((fspace_id = H5Dget_space(dset_id)) < 0) { + H5_FAILED(); + printf(" couldn't get dataset dataspace\n"); + PART_ERROR(H5Dwrite_all_read); + } + + if ((space_npoints = H5Sget_simple_extent_npoints(fspace_id)) < 0) { + H5_FAILED(); + printf(" couldn't get dataspace num points\n"); + PART_ERROR(H5Dwrite_all_read); + } + + if (NULL == + (data = malloc((hsize_t)space_npoints * DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE))) { + H5_FAILED(); + printf(" couldn't allocate buffer for dataset read\n"); + PART_ERROR(H5Dwrite_all_read); + } + + if (H5Dread(dset_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, + data) < 0) { + H5_FAILED(); + printf(" couldn't read from dataset '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_all_read); + } + + for (i = 0; i < (hsize_t)space_npoints; i++) + if (((int *)data)[i] != (int)i) { + H5_FAILED(); + printf(" H5S_ALL selection data verification failed\n"); + PART_ERROR(H5Dwrite_all_read); + } + + if (data) { + free(data); + data = NULL; + } + + PASSED(); + } + PART_END(H5Dwrite_all_read); + + PART_BEGIN(H5Dwrite_hyperslab_read) + { + TESTING_2("H5Dwrite using hyperslab selection then H5Dread"); + + data_size = dims[1] * 2 * DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; + + if (NULL == (write_buf = malloc(data_size))) { + H5_FAILED(); + printf(" couldn't allocate buffer for dataset write\n"); + PART_ERROR(H5Dwrite_hyperslab_read); + } + + for (i = 0; i < data_size / DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; i++) + ((int *)write_buf)[i] = 56; + + for (i = 0, data_size = 1; i < DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK; i++) + data_size *= dims[i]; + data_size *= DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; + + if (NULL == (data = malloc(data_size))) { + H5_FAILED(); + printf(" couldn't allocate buffer for dataset data verification\n"); + PART_ERROR(H5Dwrite_hyperslab_read); + } + + if (H5Dread(dset_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, + data) < 0) { + H5_FAILED(); + printf(" couldn't read from dataset '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_hyperslab_read); + } + + for (i = 0; i < 2; i++) { + size_t j; + + for (j = 0; j < dims[1]; j++) + ((int *)data)[(i * dims[1] * dims[2]) + (j * dims[2])] = 56; + } + + /* Write to first two rows of dataset */ + start[0] = start[1] = start[2] = 0; + stride[0] = stride[1] = stride[2] = 1; + count[0] = 2; + count[1] = dims[1]; + count[2] = 1; + block[0] = block[1] = block[2] = 1; + + if (H5Sselect_hyperslab(fspace_id, H5S_SELECT_SET, start, stride, count, block) < 0) { + H5_FAILED(); + printf(" couldn't select hyperslab for dataset write\n"); + PART_ERROR(H5Dwrite_hyperslab_read); + } - H5E_BEGIN_TRY { - err_ret = H5Dread(H5I_INVALID_HID, DATASET_READ_INVALID_PARAMS_TEST_DSET_DTYPE, H5S_ALL, - H5S_ALL, H5P_DEFAULT, read_buf); + hsize_t mdims[] = {(hsize_t)2 * dims[1]}; + + if ((mspace_id = H5Screate_simple(1, mdims, NULL)) < 0) { + H5_FAILED(); + printf(" couldn't create memory dataspace\n"); + PART_ERROR(H5Dwrite_hyperslab_read); + } } - H5E_END_TRY - if (err_ret >= 0) { + if (H5Dwrite(dset_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE, mspace_id, fspace_id, + H5P_DEFAULT, write_buf) < 0) { H5_FAILED(); - printf(" read from dataset using H5Dread with an invalid dataset ID!\n"); - PART_ERROR(H5Dread_invalid_dset_id); + printf(" couldn't write to dataset '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_hyperslab_read); + } + + if (mspace_id >= 0) { + H5E_BEGIN_TRY + { + H5Sclose(mspace_id); + } + H5E_END_TRY + mspace_id = H5I_INVALID_HID; + } + if (fspace_id >= 0) { + H5E_BEGIN_TRY + { + H5Sclose(fspace_id); + } + H5E_END_TRY + fspace_id = H5I_INVALID_HID; + } + if (dset_id >= 0) { + H5E_BEGIN_TRY + { + H5Dclose(dset_id); + } + H5E_END_TRY + dset_id = H5I_INVALID_HID; + } + + if ((dset_id = H5Dopen2(group_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open dataset '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_hyperslab_read); + } + + if ((fspace_id = H5Dget_space(dset_id)) < 0) { + H5_FAILED(); + printf(" couldn't get dataset dataspace\n"); + PART_ERROR(H5Dwrite_hyperslab_read); + } + + if ((space_npoints = H5Sget_simple_extent_npoints(fspace_id)) < 0) { + H5_FAILED(); + printf(" couldn't get dataspace num points\n"); + PART_ERROR(H5Dwrite_hyperslab_read); + } + + if (NULL == + (read_buf = malloc((hsize_t)space_npoints * DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE))) { + H5_FAILED(); + printf(" couldn't allocate buffer for dataset read\n"); + PART_ERROR(H5Dwrite_hyperslab_read); + } + + if (H5Dread(dset_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, + read_buf) < 0) { + H5_FAILED(); + printf(" couldn't read from dataset '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_hyperslab_read); + } + + if (memcmp(data, read_buf, data_size)) { + H5_FAILED(); + printf(" hyperslab selection data verification failed\n"); + PART_ERROR(H5Dwrite_hyperslab_read); + } + + if (data) { + free(data); + data = NULL; + } + + if (write_buf) { + free(write_buf); + write_buf = NULL; + } + + if (read_buf) { + free(read_buf); + read_buf = NULL; } PASSED(); } - PART_END(H5Dread_invalid_dset_id); + PART_END(H5Dwrite_hyperslab_read); - PART_BEGIN(H5Dread_invalid_datatype) + PART_BEGIN(H5Dwrite_point_sel_read) { - TESTING_2("H5Dread with an invalid memory datatype"); + TESTING_2("H5Dwrite using point selection then H5Dread"); - H5E_BEGIN_TRY - { - err_ret = H5Dread(dset_id, H5I_INVALID_HID, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_buf); - } - H5E_END_TRY + data_size = + DATASET_DATA_VERIFY_WRITE_TEST_NUM_POINTS * DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; - if (err_ret >= 0) { + if (NULL == (write_buf = malloc(data_size))) { H5_FAILED(); - printf(" read from dataset using H5Dread with an invalid memory datatype!\n"); - PART_ERROR(H5Dread_invalid_datatype); + printf(" couldn't allocate buffer for dataset write\n"); + PART_ERROR(H5Dwrite_point_sel_read); } - PASSED(); - } - PART_END(H5Dread_invalid_datatype); + for (i = 0; i < data_size / DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; i++) + ((int *)write_buf)[i] = 13; - PART_BEGIN(H5Dread_invalid_mem_dataspace) - { - TESTING_2("H5Dread with an invalid memory dataspace"); + for (i = 0, data_size = 1; i < DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK; i++) + data_size *= dims[i]; + data_size *= DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; - H5E_BEGIN_TRY - { - err_ret = H5Dread(dset_id, DATASET_READ_INVALID_PARAMS_TEST_DSET_DTYPE, H5I_INVALID_HID, - H5S_ALL, H5P_DEFAULT, read_buf); + if (NULL == (data = malloc(data_size))) { + H5_FAILED(); + printf(" couldn't allocate buffer for dataset data verification\n"); + PART_ERROR(H5Dwrite_point_sel_read); } - H5E_END_TRY - if (err_ret >= 0) { + if (H5Dread(dset_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, + data) < 0) { H5_FAILED(); - printf(" read from dataset using H5Dread with an invalid memory dataspace!\n"); - PART_ERROR(H5Dread_invalid_mem_dataspace); + printf(" couldn't read from dataset '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_point_sel_read); } - PASSED(); - } - PART_END(H5Dread_invalid_mem_dataspace); + for (i = 0; i < dims[0]; i++) { + size_t j; - PART_BEGIN(H5Dread_invalid_file_dataspace) - { - TESTING_2("H5Dread with an invalid file dataspace"); + for (j = 0; j < dims[1]; j++) { + size_t k; - H5E_BEGIN_TRY - { - err_ret = H5Dread(dset_id, DATASET_READ_INVALID_PARAMS_TEST_DSET_DTYPE, H5S_ALL, - H5I_INVALID_HID, H5P_DEFAULT, read_buf); + for (k = 0; k < dims[2]; k++) { + if (i == j && j == k) + ((int *)data)[(i * dims[1] * dims[2]) + (j * dims[2]) + k] = 13; + } + } } - H5E_END_TRY - if (err_ret >= 0) { + /* Select a series of 10 points in the dataset */ + for (i = 0; i < DATASET_DATA_VERIFY_WRITE_TEST_NUM_POINTS; i++) { + size_t j; + + for (j = 0; j < DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK; j++) + points[(i * DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK) + j] = i; + } + + if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_DATA_VERIFY_WRITE_TEST_NUM_POINTS, + points) < 0) { H5_FAILED(); - printf(" read from dataset using H5Dread with an invalid file dataspace!\n"); - PART_ERROR(H5Dread_invalid_file_dataspace); + printf(" couldn't select elements in dataspace\n"); + PART_ERROR(H5Dwrite_point_sel_read); } - PASSED(); - } - PART_END(H5Dread_invalid_file_dataspace); + { + hsize_t mdims[] = {(hsize_t)DATASET_DATA_VERIFY_WRITE_TEST_NUM_POINTS}; - PART_BEGIN(H5Dread_invalid_dxpl) - { - TESTING_2("H5Dread with an invalid DXPL"); + if ((mspace_id = H5Screate_simple(1, mdims, NULL)) < 0) { + H5_FAILED(); + printf(" couldn't create memory dataspace\n"); + PART_ERROR(H5Dwrite_point_sel_read); + } + } - H5E_BEGIN_TRY - { - err_ret = H5Dread(dset_id, DATASET_READ_INVALID_PARAMS_TEST_DSET_DTYPE, H5S_ALL, H5S_ALL, - H5I_INVALID_HID, read_buf); + if (H5Dwrite(dset_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE, mspace_id, fspace_id, + H5P_DEFAULT, write_buf) < 0) { + H5_FAILED(); + printf(" couldn't write to dataset '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_point_sel_read); } - H5E_END_TRY - if (err_ret >= 0) { + if (mspace_id >= 0) { + H5E_BEGIN_TRY + { + H5Sclose(mspace_id); + } + H5E_END_TRY + mspace_id = H5I_INVALID_HID; + } + if (fspace_id >= 0) { + H5E_BEGIN_TRY + { + H5Sclose(fspace_id); + } + H5E_END_TRY + fspace_id = H5I_INVALID_HID; + } + if (dset_id >= 0) { + H5E_BEGIN_TRY + { + H5Dclose(dset_id); + } + H5E_END_TRY + dset_id = H5I_INVALID_HID; + } + + if ((dset_id = H5Dopen2(group_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME, H5P_DEFAULT)) < 0) { H5_FAILED(); - printf(" read from dataset using H5Dread with an invalid DXPL!\n"); - PART_ERROR(H5Dread_invalid_dxpl); + printf(" couldn't open dataset '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_point_sel_read); } - PASSED(); - } - PART_END(H5Dread_invalid_dxpl); + if ((fspace_id = H5Dget_space(dset_id)) < 0) { + H5_FAILED(); + printf(" couldn't get dataset dataspace\n"); + PART_ERROR(H5Dwrite_point_sel_read); + } - PART_BEGIN(H5Dread_invalid_data_buf) - { - TESTING_2("H5Dread with an invalid data buffer"); + if ((space_npoints = H5Sget_simple_extent_npoints(fspace_id)) < 0) { + H5_FAILED(); + printf(" couldn't get dataspace num points\n"); + PART_ERROR(H5Dwrite_point_sel_read); + } - H5E_BEGIN_TRY - { - err_ret = H5Dread(dset_id, DATASET_READ_INVALID_PARAMS_TEST_DSET_DTYPE, H5S_ALL, H5S_ALL, - H5P_DEFAULT, NULL); + if (NULL == + (read_buf = malloc((hsize_t)space_npoints * DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE))) { + H5_FAILED(); + printf(" couldn't allocate buffer for dataset read\n"); + PART_ERROR(H5Dwrite_point_sel_read); } - H5E_END_TRY - if (err_ret >= 0) { + if (H5Dread(dset_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, + read_buf) < 0) { H5_FAILED(); - printf(" read from dataset using H5Dread with an invalid data buffer!\n"); - PART_ERROR(H5Dread_invalid_data_buf); + printf(" couldn't read from dataset '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_point_sel_read); + } + + if (memcmp(data, read_buf, data_size)) { + H5_FAILED(); + printf(" point selection data verification failed\n"); + PART_ERROR(H5Dwrite_point_sel_read); } PASSED(); } - PART_END(H5Dread_invalid_data_buf); + PART_END(H5Dwrite_point_sel_read); } END_MULTIPART; TESTING_2("test cleanup"); + if (data) { + free(data); + data = NULL; + } + + if (write_buf) { + free(write_buf); + write_buf = NULL; + } + if (read_buf) { free(read_buf); read_buf = NULL; @@ -5128,8 +6476,13 @@ test_read_dataset_invalid_params(void) error: H5E_BEGIN_TRY { + if (data) + free(data); + if (write_buf) + free(write_buf); if (read_buf) free(read_buf); + H5Sclose(mspace_id); H5Sclose(fspace_id); H5Dclose(dset_id); H5Gclose(group_id); @@ -5142,26 +6495,33 @@ error: } /* - * A test to check that a small write can be + * A test to check that a small multi write can be * made to a dataset using an H5S_ALL selection. */ static int -test_write_dataset_small_all(void) +test_write_multi_dataset_small_all(void) { hssize_t space_npoints; hsize_t dims[DATASET_SMALL_WRITE_TEST_ALL_DSET_SPACE_RANK] = {10, 5, 3}; size_t i; hid_t file_id = H5I_INVALID_HID; hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID; - hid_t dset_id = H5I_INVALID_HID; - hid_t fspace_id = H5I_INVALID_HID; - void *data = NULL; + hid_t dset_id_arr[DATASET_MULTI_COUNT]; + hid_t fspace_id = H5I_INVALID_HID, fspace_id_arr[DATASET_MULTI_COUNT]; + hid_t dtype_id_arr[DATASET_MULTI_COUNT]; + void *data[DATASET_MULTI_COUNT]; - TESTING("small write to dataset with H5S_ALL"); + TESTING("small multi write to datasets with H5S_ALL"); + + /* Prevent uninitialized memory usage on test failure */ + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + dset_id_arr[i] = H5I_INVALID_HID; + data[i] = NULL; + } /* Make sure the connector supports the API functions being tested */ if (!(vol_cap_flags_g & H5VL_CAP_FLAG_FILE_BASIC) || !(vol_cap_flags_g & H5VL_CAP_FLAG_GROUP_BASIC) || - !(vol_cap_flags_g & H5VL_CAP_FLAG_DATASET_BASIC) || !(vol_cap_flags_g & H5VL_CAP_FLAG_DATASET_MORE)) { + !(vol_cap_flags_g & H5VL_CAP_FLAG_DATASET_BASIC)) { SKIPPED(); printf(" API functions for basic file, group, or dataset aren't supported with this connector\n"); return 0; @@ -5179,69 +6539,89 @@ test_write_dataset_small_all(void) goto error; } - if ((group_id = H5Gcreate2(container_group, DATASET_SMALL_WRITE_TEST_ALL_GROUP_NAME, H5P_DEFAULT, + if ((group_id = H5Gcreate2(container_group, DATASET_SMALL_WRITE_MULTI_TEST_ALL_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { H5_FAILED(); - printf(" couldn't create container sub-group '%s'\n", DATASET_SMALL_WRITE_TEST_ALL_GROUP_NAME); + printf(" couldn't create container sub-group '%s'\n", + DATASET_SMALL_WRITE_MULTI_TEST_ALL_GROUP_NAME); goto error; } if ((fspace_id = H5Screate_simple(DATASET_SMALL_WRITE_TEST_ALL_DSET_SPACE_RANK, dims, NULL)) < 0) TEST_ERROR; - if ((dset_id = H5Dcreate2(group_id, DATASET_SMALL_WRITE_TEST_ALL_DSET_NAME, - DATASET_SMALL_WRITE_TEST_ALL_DSET_DTYPE, fspace_id, H5P_DEFAULT, H5P_DEFAULT, - H5P_DEFAULT)) < 0) { - H5_FAILED(); - printf(" couldn't create dataset '%s'\n", DATASET_SMALL_WRITE_TEST_ALL_DSET_NAME); - goto error; + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + char dset_name[DSET_NAME_BUF_SIZE]; + + if (DSET_NAME_BUF_SIZE <= snprintf(dset_name, DSET_NAME_BUF_SIZE, "%s%zu%c", + DATASET_SMALL_WRITE_MULTI_TEST_ALL_DSET_NAME, i, '\0')) + TEST_ERROR; + + if ((dset_id_arr[i] = H5Dcreate2(group_id, dset_name, DATASET_SMALL_WRITE_TEST_ALL_DSET_DTYPE, + fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset '%s'\n", DATASET_SMALL_WRITE_MULTI_TEST_ALL_DSET_NAME); + goto error; + } + + /* Close the dataset and dataspace to ensure that writing works correctly in this manner */ + if (H5Dclose(dset_id_arr[i]) < 0) + TEST_ERROR; } - /* Close the dataset and dataspace to ensure that writing works correctly in this manner */ - if (H5Dclose(dset_id) < 0) - TEST_ERROR; if (H5Sclose(fspace_id) < 0) TEST_ERROR; - if ((dset_id = H5Dopen2(group_id, DATASET_SMALL_WRITE_TEST_ALL_DSET_NAME, H5P_DEFAULT)) < 0) { - H5_FAILED(); - printf(" couldn't open dataset '%s'\n", DATASET_SMALL_WRITE_TEST_ALL_DSET_NAME); - goto error; - } + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + char dset_name[DSET_NAME_BUF_SIZE]; - if ((fspace_id = H5Dget_space(dset_id)) < 0) { - H5_FAILED(); - printf(" couldn't get dataset dataspace\n"); - goto error; - } + if (DSET_NAME_BUF_SIZE <= snprintf(dset_name, DSET_NAME_BUF_SIZE, "%s%zu%c", + DATASET_SMALL_WRITE_MULTI_TEST_ALL_DSET_NAME, i, '\0')) + TEST_ERROR; - if ((space_npoints = H5Sget_simple_extent_npoints(fspace_id)) < 0) { - H5_FAILED(); - printf(" couldn't get dataspace num points\n"); - goto error; - } + if ((dset_id_arr[i] = H5Dopen2(group_id, dset_name, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open dataset '%s'\n", dset_name); + goto error; + } - if (NULL == (data = malloc((hsize_t)space_npoints * DATASET_SMALL_WRITE_TEST_ALL_DSET_DTYPESIZE))) - TEST_ERROR; + if ((fspace_id = H5Dget_space(dset_id_arr[i])) < 0) { + H5_FAILED(); + printf(" couldn't get dataset dataspace\n"); + goto error; + } - for (i = 0; i < (hsize_t)space_npoints; i++) - ((int *)data)[i] = (int)i; + if ((space_npoints = H5Sget_simple_extent_npoints(fspace_id)) < 0) { + H5_FAILED(); + printf(" couldn't get dataspace num points\n"); + goto error; + } + + dtype_id_arr[i] = DATASET_SMALL_WRITE_TEST_ALL_DSET_DTYPE; + fspace_id_arr[i] = H5S_ALL; + + if (NULL == (data[i] = malloc((hsize_t)space_npoints * DATASET_SMALL_WRITE_TEST_ALL_DSET_DTYPESIZE))) + TEST_ERROR; - if (H5Dwrite(dset_id, DATASET_SMALL_WRITE_TEST_ALL_DSET_DTYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, data) < 0) { + for (size_t j = 0; j < (size_t)space_npoints; j++) + ((int **)data)[i][j] = (int)i; + } + + if (H5Dwrite_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, fspace_id_arr, fspace_id_arr, + H5P_DEFAULT, (const void **)data) < 0) { H5_FAILED(); - printf(" couldn't write to dataset '%s'\n", DATASET_SMALL_WRITE_TEST_ALL_DSET_NAME); + printf(" couldn't write to dataset '%s'\n", DATASET_SMALL_WRITE_MULTI_TEST_ALL_DSET_NAME); goto error; } - if (data) { - free(data); - data = NULL; + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + free(data[i]); + data[i] = NULL; + if (H5Dclose(dset_id_arr[i]) < 0) + TEST_ERROR; } - if (H5Sclose(fspace_id) < 0) TEST_ERROR; - if (H5Dclose(dset_id) < 0) - TEST_ERROR; if (H5Gclose(group_id) < 0) TEST_ERROR; if (H5Gclose(container_group) < 0) @@ -5256,25 +6636,28 @@ test_write_dataset_small_all(void) error: H5E_BEGIN_TRY { - if (data) - free(data); + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + if (data[i]) + free(data[i]); + H5Dclose(dset_id_arr[i]); + } + H5Sclose(fspace_id); - H5Dclose(dset_id); H5Gclose(group_id); H5Gclose(container_group); H5Fclose(file_id); } - H5E_END_TRY + H5E_END_TRY; return 1; } /* - * A test to check that a small write can be made + * A test to check that a small multi write can be made * to a dataset using a hyperslab selection. */ static int -test_write_dataset_small_hyperslab(void) +test_write_multi_dataset_small_hyperslab(void) { hsize_t start[DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_SPACE_RANK]; hsize_t stride[DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_SPACE_RANK]; @@ -5284,11 +6667,13 @@ test_write_dataset_small_hyperslab(void) size_t i, data_size; hid_t file_id = H5I_INVALID_HID; hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID; - hid_t dset_id = H5I_INVALID_HID; + hid_t dset_id_arr[DATASET_MULTI_COUNT]; hid_t mspace_id = H5I_INVALID_HID, fspace_id = H5I_INVALID_HID; - void *data = NULL; + hid_t mspace_id_arr[DATASET_MULTI_COUNT], fspace_id_arr[DATASET_MULTI_COUNT]; + hid_t dtype_id_arr[DATASET_MULTI_COUNT]; + void *data[DATASET_MULTI_COUNT]; - TESTING("small write to dataset with a hyperslab selection"); + TESTING("small multi write to datasets with hyperslab selections"); /* Make sure the connector supports the API functions being tested */ if (!(vol_cap_flags_g & H5VL_CAP_FLAG_FILE_BASIC) || !(vol_cap_flags_g & H5VL_CAP_FLAG_GROUP_BASIC) || @@ -5298,6 +6683,11 @@ test_write_dataset_small_hyperslab(void) return 0; } + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + dset_id_arr[i] = H5I_INVALID_HID; + data[i] = NULL; + } + if ((file_id = H5Fopen(H5_api_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) { H5_FAILED(); printf(" couldn't open file '%s'\n", H5_api_test_filename); @@ -5310,11 +6700,11 @@ test_write_dataset_small_hyperslab(void) goto error; } - if ((group_id = H5Gcreate2(container_group, DATASET_SMALL_WRITE_TEST_HYPERSLAB_GROUP_NAME, H5P_DEFAULT, - H5P_DEFAULT, H5P_DEFAULT)) < 0) { + if ((group_id = H5Gcreate2(container_group, DATASET_SMALL_WRITE_MULTI_TEST_HYPERSLAB_GROUP_NAME, + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { H5_FAILED(); printf(" couldn't create container sub-group '%s'\n", - DATASET_SMALL_WRITE_TEST_HYPERSLAB_GROUP_NAME); + DATASET_SMALL_WRITE_MULTI_TEST_HYPERSLAB_GROUP_NAME); goto error; } @@ -5324,23 +6714,30 @@ test_write_dataset_small_hyperslab(void) 0) TEST_ERROR; - if ((dset_id = H5Dcreate2(group_id, DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_NAME, - DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_DTYPE, fspace_id, H5P_DEFAULT, - H5P_DEFAULT, H5P_DEFAULT)) < 0) { - H5_FAILED(); - printf(" couldn't create dataset '%s'\n", DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_NAME); - goto error; - } - for (i = 0, data_size = 1; i < DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_SPACE_RANK - 1; i++) data_size *= dims[i]; data_size *= DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_DTYPESIZE; - if (NULL == (data = malloc(data_size))) - TEST_ERROR; + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + char dset_name[DSET_NAME_BUF_SIZE]; - for (i = 0; i < data_size / DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_DTYPESIZE; i++) - ((int *)data)[i] = (int)i; + if (DSET_NAME_BUF_SIZE <= snprintf(dset_name, DSET_NAME_BUF_SIZE, "%s%zu%c", + DATASET_SMALL_WRITE_MULTI_TEST_HYPERSLAB_DSET_NAME, i, '\0')) + TEST_ERROR; + + if ((dset_id_arr[i] = H5Dcreate2(group_id, dset_name, DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_DTYPE, + fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset '%s'\n", dset_name); + goto error; + } + + if (NULL == (data[i] = malloc(data_size))) + TEST_ERROR; + + for (size_t j = 0; j < data_size / DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_DTYPESIZE; j++) + ((int **)data)[i][j] = (int)i; + } for (i = 0; i < DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_SPACE_RANK; i++) { start[i] = 0; @@ -5354,24 +6751,32 @@ test_write_dataset_small_hyperslab(void) if (H5Sselect_hyperslab(fspace_id, H5S_SELECT_SET, start, stride, count, block) < 0) TEST_ERROR; - if (H5Dwrite(dset_id, DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_DTYPE, mspace_id, fspace_id, H5P_DEFAULT, - data) < 0) { + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + dtype_id_arr[i] = DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_DTYPE; + mspace_id_arr[i] = mspace_id; + fspace_id_arr[i] = fspace_id; + } + + if (H5Dwrite_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, mspace_id_arr, fspace_id_arr, + H5P_DEFAULT, (const void **)data) < 0) { H5_FAILED(); - printf(" couldn't write to dataset '%s'\n", DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_NAME); + printf(" couldn't write to dataset '%s'\n", DATASET_SMALL_WRITE_MULTI_TEST_HYPERSLAB_DSET_NAME); goto error; } - if (data) { - free(data); - data = NULL; + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + if (data[i]) { + free(data[i]); + data[i] = NULL; + } + if (H5Dclose(dset_id_arr[i]) < 0) + TEST_ERROR; } if (H5Sclose(mspace_id) < 0) TEST_ERROR; if (H5Sclose(fspace_id) < 0) TEST_ERROR; - if (H5Dclose(dset_id) < 0) - TEST_ERROR; if (H5Gclose(group_id) < 0) TEST_ERROR; if (H5Gclose(container_group) < 0) @@ -5386,26 +6791,30 @@ test_write_dataset_small_hyperslab(void) error: H5E_BEGIN_TRY { - if (data) - free(data); + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + if (data[i]) { + free(data[i]); + data[i] = NULL; + } + H5Dclose(dset_id_arr[i]); + } H5Sclose(mspace_id); H5Sclose(fspace_id); - H5Dclose(dset_id); H5Gclose(group_id); H5Gclose(container_group); H5Fclose(file_id); } - H5E_END_TRY + H5E_END_TRY; return 1; } /* - * A test to check that a small write can be made + * A test to check that a small multi write can be made * to a dataset using a point selection. */ static int -test_write_dataset_small_point_selection(void) +test_write_multi_dataset_small_point_selection(void) { hsize_t points[DATASET_SMALL_WRITE_TEST_POINT_SELECTION_NUM_POINTS * DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_SPACE_RANK]; @@ -5414,12 +6823,13 @@ test_write_dataset_small_point_selection(void) size_t i, data_size; hid_t file_id = H5I_INVALID_HID; hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID; - hid_t dset_id = H5I_INVALID_HID; - hid_t fspace_id = H5I_INVALID_HID; - hid_t mspace_id = H5I_INVALID_HID; - void *data = NULL; + hid_t dset_id_arr[DATASET_MULTI_COUNT]; + hid_t fspace_id = H5I_INVALID_HID, fspace_id_arr[DATASET_MULTI_COUNT]; + hid_t mspace_id = H5I_INVALID_HID, mspace_id_arr[DATASET_MULTI_COUNT]; + hid_t dtype_id_arr[DATASET_MULTI_COUNT]; + void *data[DATASET_MULTI_COUNT]; - TESTING("small write to dataset with a point selection"); + TESTING("small multi write to datasets with point selections"); /* Make sure the connector supports the API functions being tested */ if (!(vol_cap_flags_g & H5VL_CAP_FLAG_FILE_BASIC) || !(vol_cap_flags_g & H5VL_CAP_FLAG_GROUP_BASIC) || @@ -5429,6 +6839,11 @@ test_write_dataset_small_point_selection(void) return 0; } + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + data[i] = NULL; + dset_id_arr[i] = H5I_INVALID_HID; + } + if ((file_id = H5Fopen(H5_api_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) { H5_FAILED(); printf(" couldn't open file '%s'\n", H5_api_test_filename); @@ -5441,11 +6856,11 @@ test_write_dataset_small_point_selection(void) goto error; } - if ((group_id = H5Gcreate2(container_group, DATASET_SMALL_WRITE_TEST_POINT_SELECTION_GROUP_NAME, + if ((group_id = H5Gcreate2(container_group, DATASET_SMALL_WRITE_MULTI_TEST_POINT_SELECTION_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { H5_FAILED(); printf(" couldn't create container sub-group '%s'\n", - DATASET_SMALL_WRITE_TEST_POINT_SELECTION_GROUP_NAME); + DATASET_SMALL_WRITE_MULTI_TEST_POINT_SELECTION_GROUP_NAME); goto error; } @@ -5455,22 +6870,30 @@ test_write_dataset_small_point_selection(void) if ((mspace_id = H5Screate_simple(1, mdims, NULL)) < 0) TEST_ERROR; - if ((dset_id = H5Dcreate2(group_id, DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_NAME, - DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_DTYPE, fspace_id, H5P_DEFAULT, - H5P_DEFAULT, H5P_DEFAULT)) < 0) { - H5_FAILED(); - printf(" couldn't create dataset '%s'\n", DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_NAME); - goto error; - } - data_size = DATASET_SMALL_WRITE_TEST_POINT_SELECTION_NUM_POINTS * DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_DTYPESIZE; - if (NULL == (data = malloc(data_size))) - TEST_ERROR; + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + char dset_name[DSET_NAME_BUF_SIZE]; - for (i = 0; i < data_size / DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_DTYPESIZE; i++) - ((int *)data)[i] = (int)i; + if (DSET_NAME_BUF_SIZE <= snprintf(dset_name, DSET_NAME_BUF_SIZE, "%s%zu%c", + DATASET_SMALL_WRITE_MULTI_TEST_POINT_SELECTION_DSET_NAME, i, '\0')) + TEST_ERROR; + + if ((dset_id_arr[i] = + H5Dcreate2(group_id, dset_name, DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_DTYPE, + fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset '%s'\n", dset_name); + goto error; + } + + if (NULL == (data[i] = malloc(data_size))) + TEST_ERROR; + + for (size_t j = 0; j < data_size / DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_DTYPESIZE; j++) + ((int **)data)[i][j] = (int)i; + } for (i = 0; i < DATASET_SMALL_WRITE_TEST_POINT_SELECTION_NUM_POINTS; i++) { size_t j; @@ -5486,24 +6909,33 @@ test_write_dataset_small_point_selection(void) goto error; } - if (H5Dwrite(dset_id, DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_DTYPE, mspace_id, fspace_id, - H5P_DEFAULT, data) < 0) { + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + dtype_id_arr[i] = DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_DTYPE; + mspace_id_arr[i] = mspace_id; + fspace_id_arr[i] = fspace_id; + } + + if (H5Dwrite_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, mspace_id_arr, fspace_id_arr, + H5P_DEFAULT, (const void **)data) < 0) { H5_FAILED(); - printf(" couldn't write to dataset '%s'\n", DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_NAME); + printf(" couldn't write to multiple datasets\n"); goto error; } - if (data) { - free(data); - data = NULL; + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + if (data[i]) { + free(data[i]); + data[i] = NULL; + } + + if (H5Dclose(dset_id_arr[i]) < 0) + TEST_ERROR; } if (H5Sclose(mspace_id) < 0) TEST_ERROR; if (H5Sclose(fspace_id) < 0) TEST_ERROR; - if (H5Dclose(dset_id) < 0) - TEST_ERROR; if (H5Gclose(group_id) < 0) TEST_ERROR; if (H5Gclose(container_group) < 0) @@ -5518,28 +6950,32 @@ test_write_dataset_small_point_selection(void) error: H5E_BEGIN_TRY { - if (data) - free(data); + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + if (data[i]) + free(data[i]); + + H5Dclose(dset_id_arr[i]); + } + H5Sclose(mspace_id); H5Sclose(fspace_id); - H5Dclose(dset_id); H5Gclose(group_id); H5Gclose(container_group); H5Fclose(file_id); } - H5E_END_TRY + H5E_END_TRY; return 1; } /* * A test to ensure that data is read back correctly from - * a dataset after it has been written. + * multiple datasets after it has been written. */ static int -test_write_dataset_data_verification(void) +test_write_multi_dataset_data_verification(void) { - hssize_t space_npoints; + hssize_t space_npoints[DATASET_MULTI_COUNT]; hsize_t dims[DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK] = {10, 10, 10}; hsize_t start[DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK]; hsize_t stride[DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK]; @@ -5550,18 +6986,21 @@ test_write_dataset_data_verification(void) size_t i, data_size; hid_t file_id = H5I_INVALID_HID; hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID; - hid_t dset_id = H5I_INVALID_HID; - hid_t fspace_id = H5I_INVALID_HID; - hid_t mspace_id = H5I_INVALID_HID; - void *data = NULL; - void *write_buf = NULL; - void *read_buf = NULL; - - TESTING_MULTIPART("verification of dataset data using H5Dwrite then H5Dread"); + hid_t dset_id_arr[DATASET_MULTI_COUNT]; + hid_t dtype_id_arr[DATASET_MULTI_COUNT]; + hid_t fspace_id = H5I_INVALID_HID, fspace_id_arr[DATASET_MULTI_COUNT]; + hid_t mspace_id = H5I_INVALID_HID, mspace_id_arr[DATASET_MULTI_COUNT]; + hid_t select_all_arr[DATASET_MULTI_COUNT]; + void *data[DATASET_MULTI_COUNT]; + void *write_buf[DATASET_MULTI_COUNT]; + void *read_buf[DATASET_MULTI_COUNT]; + char dset_names[DATASET_MULTI_COUNT][DSET_NAME_BUF_SIZE]; + + TESTING_MULTIPART("verification of datasets' data using H5Dwrite_multi then H5Dread_multi"); /* Make sure the connector supports the API functions being tested */ if (!(vol_cap_flags_g & H5VL_CAP_FLAG_FILE_BASIC) || !(vol_cap_flags_g & H5VL_CAP_FLAG_GROUP_BASIC) || - !(vol_cap_flags_g & H5VL_CAP_FLAG_DATASET_BASIC) || !(vol_cap_flags_g & H5VL_CAP_FLAG_DATASET_MORE)) { + !(vol_cap_flags_g & H5VL_CAP_FLAG_DATASET_BASIC)) { SKIPPED(); printf(" API functions for basic file, group, basic or more dataset aren't supported with this " "connector\n"); @@ -5570,6 +7009,13 @@ test_write_dataset_data_verification(void) TESTING_2("test setup"); + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + select_all_arr[i] = H5S_ALL; + read_buf[i] = NULL; + write_buf[i] = NULL; + data[i] = NULL; + } + if ((file_id = H5Fopen(H5_api_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) { H5_FAILED(); printf(" couldn't open file '%s'\n", H5_api_test_filename); @@ -5582,52 +7028,77 @@ test_write_dataset_data_verification(void) goto error; } - if ((group_id = H5Gcreate2(container_group, DATASET_DATA_VERIFY_WRITE_TEST_GROUP_NAME, H5P_DEFAULT, + if ((group_id = H5Gcreate2(container_group, DATASET_DATA_VERIFY_WRITE_MULTI_TEST_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { H5_FAILED(); - printf(" couldn't create container sub-group '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_GROUP_NAME); + printf(" couldn't create container sub-group '%s'\n", + DATASET_DATA_VERIFY_WRITE_MULTI_TEST_GROUP_NAME); goto error; } if ((fspace_id = H5Screate_simple(DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK, dims, NULL)) < 0) TEST_ERROR; - if ((dset_id = H5Dcreate2(group_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME, - DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE, fspace_id, H5P_DEFAULT, H5P_DEFAULT, - H5P_DEFAULT)) < 0) { - H5_FAILED(); - printf(" couldn't create dataset '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME); - goto error; - } - for (i = 0, data_size = 1; i < DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK; i++) data_size *= dims[i]; data_size *= DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; - if (NULL == (data = malloc(data_size))) - TEST_ERROR; + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + if (DSET_NAME_BUF_SIZE <= snprintf(dset_names[i], DSET_NAME_BUF_SIZE, "%s%zu%c", + DATASET_DATA_VERIFY_WRITE_MULTI_TEST_DSET_NAME, i, '\0')) + TEST_ERROR; - for (i = 0; i < data_size / DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; i++) - ((int *)data)[i] = (int)i; + if ((dset_id_arr[i] = H5Dcreate2(group_id, dset_names[i], DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE, + fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset '%s'\n", dset_names[i]); + goto error; + } + + if (NULL == (data[i] = malloc(data_size))) + TEST_ERROR; + + dtype_id_arr[i] = DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE; + + for (size_t j = 0; j < data_size / DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; j++) + ((int **)data)[i][j] = (int)j; + } PASSED(); BEGIN_MULTIPART { - PART_BEGIN(H5Dwrite_all_read) + PART_BEGIN(H5Dwrite_multi_all_read) { - TESTING_2("H5Dwrite using H5S_ALL then H5Dread"); + TESTING_2("H5Dwrite_multi using H5S_ALL then H5Dread_multi"); - if (H5Dwrite(dset_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, - data) < 0) { + if (H5Dwrite_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, select_all_arr, select_all_arr, + H5P_DEFAULT, (const void **)data) < 0) { H5_FAILED(); - printf(" couldn't write to dataset '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME); - PART_ERROR(H5Dwrite_all_read); + printf(" couldn't write to datasets"); + PART_ERROR(H5Dwrite_multi_all_read); } - if (data) { - free(data); - data = NULL; + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + if (data[i]) { + free(data[i]); + data[i] = NULL; + } + + if (dset_id_arr[i] >= 0) { + H5E_BEGIN_TRY + { + H5Dclose(dset_id_arr[i]); + } + H5E_END_TRY; + dset_id_arr[i] = H5I_INVALID_HID; + } + + if ((dset_id_arr[i] = H5Dopen2(group_id, dset_names[i], H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open dataset '%s'\n", dset_names[i]); + PART_ERROR(H5Dwrite_multi_all_read); + } } if (fspace_id >= 0) { @@ -5635,103 +7106,109 @@ test_write_dataset_data_verification(void) { H5Sclose(fspace_id); } - H5E_END_TRY + H5E_END_TRY; fspace_id = H5I_INVALID_HID; } - if (dset_id >= 0) { - H5E_BEGIN_TRY - { - H5Dclose(dset_id); - } - H5E_END_TRY - dset_id = H5I_INVALID_HID; - } - if ((dset_id = H5Dopen2(group_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME, H5P_DEFAULT)) < 0) { - H5_FAILED(); - printf(" couldn't open dataset '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME); - PART_ERROR(H5Dwrite_all_read); - } + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + if ((fspace_id_arr[i] = H5Dget_space(dset_id_arr[i])) < 0) { + H5_FAILED(); + printf(" couldn't get dataset dataspace\n"); + PART_ERROR(H5Dwrite_multi_all_read); + } - if ((fspace_id = H5Dget_space(dset_id)) < 0) { - H5_FAILED(); - printf(" couldn't get dataset dataspace\n"); - PART_ERROR(H5Dwrite_all_read); - } + if ((space_npoints[i] = H5Sget_simple_extent_npoints(fspace_id_arr[i])) < 0) { + H5_FAILED(); + printf(" couldn't get dataspace num points\n"); + PART_ERROR(H5Dwrite_multi_all_read); + } - if ((space_npoints = H5Sget_simple_extent_npoints(fspace_id)) < 0) { - H5_FAILED(); - printf(" couldn't get dataspace num points\n"); - PART_ERROR(H5Dwrite_all_read); + if (NULL == (data[i] = malloc((hsize_t)space_npoints[i] * + DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE))) { + H5_FAILED(); + printf(" couldn't allocate buffer for dataset read\n"); + PART_ERROR(H5Dwrite_multi_all_read); + } } - if (NULL == - (data = malloc((hsize_t)space_npoints * DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE))) { + if (H5Dread_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, select_all_arr, select_all_arr, + H5P_DEFAULT, data) < 0) { H5_FAILED(); - printf(" couldn't allocate buffer for dataset read\n"); - PART_ERROR(H5Dwrite_all_read); + printf(" couldn't read from datasets\n"); + PART_ERROR(H5Dwrite_multi_all_read); } - if (H5Dread(dset_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, - data) < 0) { - H5_FAILED(); - printf(" couldn't read from dataset '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME); - PART_ERROR(H5Dwrite_all_read); - } + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + for (size_t j = 0; j < (hsize_t)space_npoints[i]; j++) + if (((int **)data)[i][j] != (int)j) { + H5_FAILED(); + printf(" H5S_ALL selection data verification failed\n"); + PART_ERROR(H5Dwrite_multi_all_read); + } - for (i = 0; i < (hsize_t)space_npoints; i++) - if (((int *)data)[i] != (int)i) { - H5_FAILED(); - printf(" H5S_ALL selection data verification failed\n"); - PART_ERROR(H5Dwrite_all_read); + if (data[i]) { + free(data[i]); + data[i] = NULL; } - - if (data) { - free(data); - data = NULL; } PASSED(); } - PART_END(H5Dwrite_all_read); - - PART_BEGIN(H5Dwrite_hyperslab_read) - { - TESTING_2("H5Dwrite using hyperslab selection then H5Dread"); - - data_size = dims[1] * 2 * DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; + PART_END(H5Dwrite_multi_all_read); - if (NULL == (write_buf = malloc(data_size))) { - H5_FAILED(); - printf(" couldn't allocate buffer for dataset write\n"); - PART_ERROR(H5Dwrite_hyperslab_read); + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + if (data[i]) { + free(data[i]); + data[i] = NULL; } + } - for (i = 0; i < data_size / DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; i++) - ((int *)write_buf)[i] = 56; + PART_BEGIN(H5Dwrite_multi_hyperslab_read) + { + TESTING_2("H5Dwrite_multi using hyperslab selection then H5Dread_multi"); - for (i = 0, data_size = 1; i < DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK; i++) - data_size *= dims[i]; - data_size *= DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + data_size = dims[1] * 2 * DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; - if (NULL == (data = malloc(data_size))) { - H5_FAILED(); - printf(" couldn't allocate buffer for dataset data verification\n"); - PART_ERROR(H5Dwrite_hyperslab_read); + if (NULL == (write_buf[i] = malloc(data_size))) { + H5_FAILED(); + printf(" couldn't allocate buffer for dataset write\n"); + PART_ERROR(H5Dwrite_multi_hyperslab_read); + } + + for (size_t j = 0; j < data_size / DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; j++) { + ((int *)write_buf[i])[j] = 56; + } + + data_size = 1; + for (size_t j = 0; j < DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK; j++) + data_size *= dims[j]; + data_size *= DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; + + if (NULL == (data[i] = malloc(data_size))) { + H5_FAILED(); + printf(" couldn't allocate buffer for datasets' data verification\n"); + PART_ERROR(H5Dwrite_multi_hyperslab_read); + } } - if (H5Dread(dset_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, - data) < 0) { + if (H5Dread_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, select_all_arr, select_all_arr, + H5P_DEFAULT, data) < 0) { H5_FAILED(); - printf(" couldn't read from dataset '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME); - PART_ERROR(H5Dwrite_hyperslab_read); + printf(" couldn't read from datasets\n"); + PART_ERROR(H5Dwrite_multi_hyperslab_read); } - for (i = 0; i < 2; i++) { - size_t j; + /* Reference data for verification */ + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + for (size_t j = 0; j < 2; j++) { + size_t k; - for (j = 0; j < dims[1]; j++) - ((int *)data)[(i * dims[1] * dims[2]) + (j * dims[2])] = 56; + for (k = 0; k < dims[1]; k++) { + size_t index = (j * dims[1] * dims[2]) + (k * dims[2]); + ((int **)data)[i][index] = (int)56; + } + } } /* Write to first two rows of dataset */ @@ -5742,27 +7219,29 @@ test_write_dataset_data_verification(void) count[2] = 1; block[0] = block[1] = block[2] = 1; - if (H5Sselect_hyperslab(fspace_id, H5S_SELECT_SET, start, stride, count, block) < 0) { - H5_FAILED(); - printf(" couldn't select hyperslab for dataset write\n"); - PART_ERROR(H5Dwrite_hyperslab_read); - } + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + if (H5Sselect_hyperslab(fspace_id_arr[i], H5S_SELECT_SET, start, stride, count, block) < 0) { + H5_FAILED(); + printf(" couldn't select hyperslab for dataset write\n"); + PART_ERROR(H5Dwrite_multi_hyperslab_read); + } - { - hsize_t mdims[] = {(hsize_t)2 * dims[1]}; + { + hsize_t mdims[] = {(hsize_t)2 * dims[1]}; - if ((mspace_id = H5Screate_simple(1, mdims, NULL)) < 0) { - H5_FAILED(); - printf(" couldn't create memory dataspace\n"); - PART_ERROR(H5Dwrite_hyperslab_read); + if ((mspace_id_arr[i] = H5Screate_simple(1, mdims, NULL)) < 0) { + H5_FAILED(); + printf(" couldn't create memory dataspace\n"); + PART_ERROR(H5Dwrite_multi_hyperslab_read); + } } } - if (H5Dwrite(dset_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE, mspace_id, fspace_id, - H5P_DEFAULT, write_buf) < 0) { + if (H5Dwrite_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, mspace_id_arr, fspace_id_arr, + H5P_DEFAULT, (const void **)write_buf) < 0) { H5_FAILED(); - printf(" couldn't write to dataset '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME); - PART_ERROR(H5Dwrite_hyperslab_read); + printf(" couldn't write to datasets\n"); + PART_ERROR(H5Dwrite_multi_hyperslab_read); } if (mspace_id >= 0) { @@ -5770,7 +7249,7 @@ test_write_dataset_data_verification(void) { H5Sclose(mspace_id); } - H5E_END_TRY + H5E_END_TRY; mspace_id = H5I_INVALID_HID; } if (fspace_id >= 0) { @@ -5778,119 +7257,133 @@ test_write_dataset_data_verification(void) { H5Sclose(fspace_id); } - H5E_END_TRY + H5E_END_TRY; fspace_id = H5I_INVALID_HID; } - if (dset_id >= 0) { - H5E_BEGIN_TRY - { - H5Dclose(dset_id); + + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + if (dset_id_arr[i] >= 0) { + H5E_BEGIN_TRY + { + H5Dclose(dset_id_arr[i]); + } + H5E_END_TRY; + dset_id_arr[i] = H5I_INVALID_HID; } - H5E_END_TRY - dset_id = H5I_INVALID_HID; - } - if ((dset_id = H5Dopen2(group_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME, H5P_DEFAULT)) < 0) { - H5_FAILED(); - printf(" couldn't open dataset '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME); - PART_ERROR(H5Dwrite_hyperslab_read); - } + if ((dset_id_arr[i] = H5Dopen2(group_id, dset_names[i], H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open dataset '%s'\n", dset_names[i]); + PART_ERROR(H5Dwrite_multi_hyperslab_read); + } - if ((fspace_id = H5Dget_space(dset_id)) < 0) { - H5_FAILED(); - printf(" couldn't get dataset dataspace\n"); - PART_ERROR(H5Dwrite_hyperslab_read); - } + if ((fspace_id_arr[i] = H5Dget_space(dset_id_arr[i])) < 0) { + H5_FAILED(); + printf(" couldn't get dataset dataspace\n"); + PART_ERROR(H5Dwrite_multi_hyperslab_read); + } - if ((space_npoints = H5Sget_simple_extent_npoints(fspace_id)) < 0) { - H5_FAILED(); - printf(" couldn't get dataspace num points\n"); - PART_ERROR(H5Dwrite_hyperslab_read); - } + if ((space_npoints[i] = H5Sget_simple_extent_npoints(fspace_id_arr[i])) < 0) { + H5_FAILED(); + printf(" couldn't get dataspace num points\n"); + PART_ERROR(H5Dwrite_multi_hyperslab_read); + } - if (NULL == - (read_buf = malloc((hsize_t)space_npoints * DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE))) { - H5_FAILED(); - printf(" couldn't allocate buffer for dataset read\n"); - PART_ERROR(H5Dwrite_hyperslab_read); + if (NULL == (read_buf[i] = malloc((hsize_t)space_npoints[i] * + DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE))) { + H5_FAILED(); + printf(" couldn't allocate buffer for dataset read\n"); + PART_ERROR(H5Dwrite_multi_hyperslab_read); + } } - if (H5Dread(dset_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, - read_buf) < 0) { + if (H5Dread_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, select_all_arr, select_all_arr, + H5P_DEFAULT, read_buf) < 0) { H5_FAILED(); - printf(" couldn't read from dataset '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME); - PART_ERROR(H5Dwrite_hyperslab_read); + printf(" couldn't read from datasets\n"); + PART_ERROR(H5Dwrite_multi_hyperslab_read); } - if (memcmp(data, read_buf, data_size)) { - H5_FAILED(); - printf(" hyperslab selection data verification failed\n"); - PART_ERROR(H5Dwrite_hyperslab_read); - } + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + if (memcmp(data[i], read_buf[i], data_size)) { + H5_FAILED(); + printf(" hyperslab selection data verification failed\n"); + PART_ERROR(H5Dwrite_multi_hyperslab_read); + } - if (data) { - free(data); - data = NULL; + if (data[i]) { + free(data[i]); + data[i] = NULL; + } + + if (write_buf[i]) { + free(write_buf[i]); + write_buf[i] = NULL; + } + + if (read_buf[i]) { + free(read_buf[i]); + read_buf[i] = NULL; + } } - if (write_buf) { - free(write_buf); - write_buf = NULL; + PASSED(); + } + PART_END(H5Dwrite_multi_hyperslab_read); + + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + if (data[i]) { + free(data[i]); + data[i] = NULL; } - if (read_buf) { - free(read_buf); - read_buf = NULL; + if (write_buf[i]) { + free(write_buf[i]); + write_buf[i] = NULL; } - PASSED(); + if (read_buf[i]) { + free(read_buf[i]); + read_buf[i] = NULL; + } } - PART_END(H5Dwrite_hyperslab_read); - PART_BEGIN(H5Dwrite_point_sel_read) + PART_BEGIN(H5Dwrite_multi_point_sel_read) { - TESTING_2("H5Dwrite using point selection then H5Dread"); + TESTING_2("H5Dwrite_multi using point selection then H5Dread_multi"); data_size = DATASET_DATA_VERIFY_WRITE_TEST_NUM_POINTS * DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; - if (NULL == (write_buf = malloc(data_size))) { - H5_FAILED(); - printf(" couldn't allocate buffer for dataset write\n"); - PART_ERROR(H5Dwrite_point_sel_read); - } + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + if (NULL == (write_buf[i] = malloc(data_size))) { + H5_FAILED(); + printf(" couldn't allocate buffer for dataset write\n"); + PART_ERROR(H5Dwrite_multi_point_sel_read); + } - for (i = 0; i < data_size / DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; i++) - ((int *)write_buf)[i] = 13; + for (size_t j = 0; j < data_size / DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; j++) + ((int **)write_buf)[i][j] = 13; - for (i = 0, data_size = 1; i < DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK; i++) - data_size *= dims[i]; - data_size *= DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; + data_size = 1; - if (NULL == (data = malloc(data_size))) { - H5_FAILED(); - printf(" couldn't allocate buffer for dataset data verification\n"); - PART_ERROR(H5Dwrite_point_sel_read); - } + for (size_t j = 0; j < DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK; j++) + data_size *= dims[j]; + data_size *= DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; - if (H5Dread(dset_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, - data) < 0) { - H5_FAILED(); - printf(" couldn't read from dataset '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME); - PART_ERROR(H5Dwrite_point_sel_read); + if (NULL == (data[i] = malloc(data_size))) { + H5_FAILED(); + printf(" couldn't allocate buffer for dataset data verification\n"); + PART_ERROR(H5Dwrite_multi_point_sel_read); + } } - for (i = 0; i < dims[0]; i++) { - size_t j; - - for (j = 0; j < dims[1]; j++) { - size_t k; - - for (k = 0; k < dims[2]; k++) { - if (i == j && j == k) - ((int *)data)[(i * dims[1] * dims[2]) + (j * dims[2]) + k] = 13; - } - } + if (H5Dread_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, select_all_arr, select_all_arr, + H5P_DEFAULT, data) < 0) { + H5_FAILED(); + printf(" couldn't read from dataset '%s'\n", + DATASET_DATA_VERIFY_WRITE_MULTI_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_multi_point_sel_read); } /* Select a series of 10 points in the dataset */ @@ -5901,28 +7394,30 @@ test_write_dataset_data_verification(void) points[(i * DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK) + j] = i; } - if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_DATA_VERIFY_WRITE_TEST_NUM_POINTS, - points) < 0) { - H5_FAILED(); - printf(" couldn't select elements in dataspace\n"); - PART_ERROR(H5Dwrite_point_sel_read); - } + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + if (H5Sselect_elements(fspace_id_arr[i], H5S_SELECT_SET, + DATASET_DATA_VERIFY_WRITE_TEST_NUM_POINTS, points) < 0) { + H5_FAILED(); + printf(" couldn't select elements in dataspace\n"); + PART_ERROR(H5Dwrite_multi_point_sel_read); + } - { - hsize_t mdims[] = {(hsize_t)DATASET_DATA_VERIFY_WRITE_TEST_NUM_POINTS}; + { + hsize_t mdims[] = {(hsize_t)DATASET_DATA_VERIFY_WRITE_TEST_NUM_POINTS}; - if ((mspace_id = H5Screate_simple(1, mdims, NULL)) < 0) { - H5_FAILED(); - printf(" couldn't create memory dataspace\n"); - PART_ERROR(H5Dwrite_point_sel_read); + if ((mspace_id_arr[i] = H5Screate_simple(1, mdims, NULL)) < 0) { + H5_FAILED(); + printf(" couldn't create memory dataspace\n"); + PART_ERROR(H5Dwrite_multi_point_sel_read); + } } } - if (H5Dwrite(dset_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE, mspace_id, fspace_id, - H5P_DEFAULT, write_buf) < 0) { + if (H5Dwrite_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, mspace_id_arr, fspace_id_arr, + H5P_DEFAULT, (const void **)write_buf) < 0) { H5_FAILED(); - printf(" couldn't write to dataset '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME); - PART_ERROR(H5Dwrite_point_sel_read); + printf(" couldn't write to datasets\n"); + PART_ERROR(H5Dwrite_multi_point_sel_read); } if (mspace_id >= 0) { @@ -5930,7 +7425,7 @@ test_write_dataset_data_verification(void) { H5Sclose(mspace_id); } - H5E_END_TRY + H5E_END_TRY; mspace_id = H5I_INVALID_HID; } if (fspace_id >= 0) { @@ -5938,83 +7433,105 @@ test_write_dataset_data_verification(void) { H5Sclose(fspace_id); } - H5E_END_TRY + H5E_END_TRY; fspace_id = H5I_INVALID_HID; } - if (dset_id >= 0) { - H5E_BEGIN_TRY - { - H5Dclose(dset_id); + + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + if (dset_id_arr[i] >= 0) { + H5E_BEGIN_TRY + { + H5Dclose(dset_id_arr[i]); + } + H5E_END_TRY; + dset_id_arr[i] = H5I_INVALID_HID; } - H5E_END_TRY - dset_id = H5I_INVALID_HID; - } - if ((dset_id = H5Dopen2(group_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME, H5P_DEFAULT)) < 0) { - H5_FAILED(); - printf(" couldn't open dataset '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME); - PART_ERROR(H5Dwrite_point_sel_read); - } + if ((dset_id_arr[i] = H5Dopen2(group_id, dset_names[i], H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open dataset '%s'\n", dset_names[i]); + PART_ERROR(H5Dwrite_multi_point_sel_read); + } - if ((fspace_id = H5Dget_space(dset_id)) < 0) { - H5_FAILED(); - printf(" couldn't get dataset dataspace\n"); - PART_ERROR(H5Dwrite_point_sel_read); - } + if ((fspace_id = H5Dget_space(dset_id_arr[i])) < 0) { + H5_FAILED(); + printf(" couldn't get dataset dataspace\n"); + PART_ERROR(H5Dwrite_multi_point_sel_read); + } - if ((space_npoints = H5Sget_simple_extent_npoints(fspace_id)) < 0) { - H5_FAILED(); - printf(" couldn't get dataspace num points\n"); - PART_ERROR(H5Dwrite_point_sel_read); - } + if ((space_npoints[i] = H5Sget_simple_extent_npoints(fspace_id)) < 0) { + H5_FAILED(); + printf(" couldn't get dataspace num points\n"); + PART_ERROR(H5Dwrite_multi_point_sel_read); + } - if (NULL == - (read_buf = malloc((hsize_t)space_npoints * DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE))) { - H5_FAILED(); - printf(" couldn't allocate buffer for dataset read\n"); - PART_ERROR(H5Dwrite_point_sel_read); + if (NULL == (read_buf[i] = malloc((hsize_t)space_npoints[i] * + DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE))) { + H5_FAILED(); + printf(" couldn't allocate buffer for dataset read\n"); + PART_ERROR(H5Dwrite_multi_point_sel_read); + } } - if (H5Dread(dset_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, - read_buf) < 0) { + if (H5Dread_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, select_all_arr, select_all_arr, + H5P_DEFAULT, read_buf) < 0) { H5_FAILED(); - printf(" couldn't read from dataset '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME); - PART_ERROR(H5Dwrite_point_sel_read); + printf(" couldn't read from dataset '%s'\n", + DATASET_DATA_VERIFY_WRITE_MULTI_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_multi_point_sel_read); } - if (memcmp(data, read_buf, data_size)) { - H5_FAILED(); - printf(" point selection data verification failed\n"); - PART_ERROR(H5Dwrite_point_sel_read); + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + for (size_t j = 0; j < dims[0]; j++) { + size_t k; + + for (k = 0; k < dims[1]; k++) { + size_t l; + + for (l = 0; l < dims[2]; l++) { + if (j == k && k == l) + ((int **)data)[i][(j * dims[1] * dims[2]) + (k * dims[2]) + l] = 13; + } + } + } + + if (memcmp(data[i], read_buf[i], data_size)) { + H5_FAILED(); + printf(" point selection data verification failed\n"); + PART_ERROR(H5Dwrite_multi_point_sel_read); + } } PASSED(); } - PART_END(H5Dwrite_point_sel_read); + PART_END(H5Dwrite_multi_point_sel_read); } END_MULTIPART; TESTING_2("test cleanup"); - if (data) { - free(data); - data = NULL; - } + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + if (data[i]) { + free(data[i]); + data[i] = NULL; + } - if (write_buf) { - free(write_buf); - write_buf = NULL; - } + if (write_buf[i]) { + free(write_buf[i]); + write_buf[i] = NULL; + } - if (read_buf) { - free(read_buf); - read_buf = NULL; + if (read_buf[i]) { + free(read_buf[i]); + read_buf[i] = NULL; + } + + if (H5Dclose(dset_id_arr[i]) < 0) + TEST_ERROR; } if (H5Sclose(fspace_id) < 0) TEST_ERROR; - if (H5Dclose(dset_id) < 0) - TEST_ERROR; if (H5Gclose(group_id) < 0) TEST_ERROR; if (H5Gclose(container_group) < 0) @@ -6029,20 +7546,24 @@ test_write_dataset_data_verification(void) error: H5E_BEGIN_TRY { - if (data) - free(data); - if (write_buf) - free(write_buf); - if (read_buf) - free(read_buf); + for (i = 0; i < DATASET_MULTI_COUNT; i++) { + if (data[i]) + free(data[i]); + if (write_buf[i]) + free(write_buf[i]); + if (read_buf[i]) + free(read_buf[i]); + + H5Dclose(dset_id_arr[i]); + } + H5Sclose(mspace_id); H5Sclose(fspace_id); - H5Dclose(dset_id); H5Gclose(group_id); H5Gclose(container_group); H5Fclose(file_id); } - H5E_END_TRY + H5E_END_TRY; return 1; } diff --git a/test/API/H5_api_dataset_test.h b/test/API/H5_api_dataset_test.h index 5d18c4d..bba3073 100644 --- a/test/API/H5_api_dataset_test.h +++ b/test/API/H5_api_dataset_test.h @@ -145,6 +145,12 @@ int H5_api_dataset_test(void); #define DATASET_SMALL_READ_TEST_POINT_SELECTION_GROUP_NAME "dataset_small_read_point_selection_test" #define DATASET_SMALL_READ_TEST_POINT_SELECTION_DSET_NAME "dataset_small_read_point_selection_dset" +#define DATASET_MULTI_COUNT 10 +#define DATASET_SMALL_READ_MULTI_TEST_ALL_GROUP_NAME "dataset_small_read_multi_all_test" +#define DATASET_SMALL_READ_MULTI_TEST_HYPERSLAB_GROUP_NAME "dataset_small_read_multi_hyperslab_test" +#define DATASET_SMALL_READ_MULTI_TEST_POINT_SELECTION_GROUP_NAME \ + "dataset_small_read_multi_point_selection_test" + #define DATASET_IO_POINT_GROUP_NAME "dataset_io_point_selection_test" #define DATASET_IO_POINT_DSET_NAME_NOCHUNK "dataset_io_point_selection_dset_nochunk" #define DATASET_IO_POINT_DSET_NAME_CHUNK "dataset_io_point_selection_dset_chunk" @@ -181,6 +187,20 @@ int H5_api_dataset_test(void); #define DATASET_DATA_VERIFY_WRITE_TEST_GROUP_NAME "dataset_data_write_verification_test" #define DATASET_DATA_VERIFY_WRITE_TEST_DSET_NAME "dataset_data_write_verification_dset" +#define DATASET_SMALL_WRITE_MULTI_TEST_ALL_GROUP_NAME "dataset_small_write_multi_all_test" +#define DATASET_SMALL_WRITE_MULTI_TEST_ALL_DSET_NAME "dataset_small_write_multi_all_dset" + +#define DATASET_SMALL_WRITE_MULTI_TEST_HYPERSLAB_GROUP_NAME "dataset_small_write_multi_hyperslab_test" +#define DATASET_SMALL_WRITE_MULTI_TEST_HYPERSLAB_DSET_NAME "dataset_small_write_multi_hyperslab_dset" + +#define DATASET_SMALL_WRITE_MULTI_TEST_POINT_SELECTION_GROUP_NAME \ + "dataset_small_write_multi_point_selection_test" +#define DATASET_SMALL_WRITE_MULTI_TEST_POINT_SELECTION_DSET_NAME \ + "dataset_small_write_multi_point_selection_dset" + +#define DATASET_DATA_VERIFY_WRITE_MULTI_TEST_GROUP_NAME "dataset_data_write_multi_verification_test" +#define DATASET_DATA_VERIFY_WRITE_MULTI_TEST_DSET_NAME "dataset_data_write_multi_verification_dset" + #define DATASET_WRITE_INVALID_PARAMS_TEST_DSET_SPACE_RANK 3 #define DATASET_WRITE_INVALID_PARAMS_TEST_DSET_DTYPESIZE sizeof(int) #define DATASET_WRITE_INVALID_PARAMS_TEST_DSET_DTYPE H5T_NATIVE_INT -- cgit v0.12