From d5a9006c353b66ddd6348daff3e610953de60ba8 Mon Sep 17 00:00:00 2001 From: mattjala <124107509+mattjala@users.noreply.github.com> Date: Fri, 5 Jan 2024 20:44:27 -0600 Subject: [PATCH 01/12] Add H5Dread/write_multi to API tests (#3919) --- test/API/H5_api_dataset_test.c | 3236 +++++++++++++++++++++++--------- test/API/H5_api_dataset_test.h | 20 + test/h5test.h | 98 +- 3 files changed, 2451 insertions(+), 903 deletions(-) diff --git a/test/API/H5_api_dataset_test.c b/test/API/H5_api_dataset_test.c index cc2162eea8a..f97e3ea96e7 100644 --- a/test/API/H5_api_dataset_test.c +++ b/test/API/H5_api_dataset_test.c @@ -50,12 +50,19 @@ static void test_get_dataset_offset_invalid_params(void); static void test_read_dataset_small_all(void); static void test_read_dataset_small_hyperslab(void); static void test_read_dataset_small_point_selection(void); +static void test_read_multi_dataset_small_all(void); +static void test_read_multi_dataset_small_hyperslab(void); +static void test_read_multi_dataset_small_point_selection(void); static void test_dataset_io_point_selections(void); static void test_read_dataset_invalid_params(void); static void test_write_dataset_small_all(void); static void test_write_dataset_small_hyperslab(void); static void test_write_dataset_small_point_selection(void); static void test_write_dataset_data_verification(void); +static void test_write_multi_dataset_small_all(void); +static void test_write_multi_dataset_small_hyperslab(void); +static void test_write_multi_dataset_small_point_selection(void); +static void test_write_multi_dataset_data_verification(void); static void test_write_dataset_invalid_params(void); static void test_dataset_builtin_type_conversion(void); static void test_dataset_compound_partial_io(void); @@ -4317,50 +4324,24 @@ test_read_dataset_small_point_selection(void) } /* - * 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 void -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]; - hbool_t 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) || @@ -4370,426 +4351,1510 @@ test_dataset_io_point_selections(void) return; } - /* 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; - /* 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; +} - /* 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 void +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; + } - /* 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; - /* 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; +} - /* 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 void +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; + } - /* 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; - /* 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; +} - /* 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 void +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]; + hbool_t 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; + } + + /* 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; + +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; +} /* 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 void +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; + } + + 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; + +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; +} + +/* + * A test to check that a small write can be + * made to a dataset using an H5S_ALL selection. + */ +static void +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; + } + + 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; + +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; +} + +/* + * A test to check that a small write can be made + * to a dataset using a hyperslab selection. + */ +static void +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; + } + + 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; - /* 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; +} - /* 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 void +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; + } - /* 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(); @@ -4799,10 +5864,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); @@ -4811,31 +5876,41 @@ test_dataset_io_point_selections(void) H5E_END_TRY return; -} /* 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 void -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; } @@ -4853,164 +5928,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; @@ -5034,8 +6375,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); @@ -5048,26 +6394,33 @@ test_read_dataset_invalid_params(void) } /* - * 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 void -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; @@ -5085,69 +6438,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) @@ -5162,25 +6535,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; } /* - * 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 void -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]; @@ -5190,11 +6566,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) || @@ -5204,6 +6582,11 @@ test_write_dataset_small_hyperslab(void) return; } + 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); @@ -5216,11 +6599,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; } @@ -5230,23 +6613,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; @@ -5260,24 +6650,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) @@ -5292,26 +6690,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; } /* - * 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 void -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]; @@ -5320,12 +6722,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) || @@ -5335,6 +6738,11 @@ test_write_dataset_small_point_selection(void) return; } + 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); @@ -5347,11 +6755,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; } @@ -5361,22 +6769,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; @@ -5392,24 +6808,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) @@ -5424,28 +6849,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; } /* * 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 void -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]; @@ -5456,18 +6885,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"); @@ -5476,6 +6908,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); @@ -5488,52 +6927,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) { @@ -5541,103 +7005,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 */ @@ -5648,27 +7118,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) { @@ -5676,7 +7148,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) { @@ -5684,119 +7156,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 */ @@ -5807,28 +7293,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) { @@ -5836,7 +7324,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) { @@ -5844,83 +7332,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) @@ -5935,20 +7445,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; } @@ -10932,6 +12446,12 @@ H5_api_dataset_test_add(void) "small read from dataset with a hyperslab selection", NULL, testframe_flags); AddTest("test_read_dataset_small_point_selection", test_read_dataset_small_point_selection, NULL, "small read from dataset with a point selection", NULL, testframe_flags); + AddTest("test_read_multi_dataset_small_all", test_read_multi_dataset_small_all, NULL, + "small read from multiple datasets with H5S_ALL using H5Dread_multi", NULL, testframe_flags); + AddTest("test_read_multi_dataset_small_hyperslab", test_read_multi_dataset_small_hyperslab, NULL, + "small read from multiple datasets with hyperslab selection using H5Dread_multi", NULL, testframe_flags); + AddTest("test_read_multi_dataset_small_point_selection", test_read_multi_dataset_small_point_selection, NULL, + "small read from multiple datasets with point selection using H5Dread_multi", NULL, testframe_flags); AddTest("test_dataset_io_point_selections", test_dataset_io_point_selections, NULL, "point selection I/O with all selection in memory and points in file", NULL, testframe_flags); AddTest("test_read_dataset_invalid_params", test_read_dataset_invalid_params, NULL, @@ -10944,6 +12464,14 @@ H5_api_dataset_test_add(void) "small write to dataset with a point selection", NULL, testframe_flags); AddTest("test_write_dataset_data_verification", test_write_dataset_data_verification, NULL, "verification of dataset data using H5Dwrite then H5Dread", NULL, testframe_flags); + AddTest("test_write_multi_dataset_small_all", test_write_multi_dataset_small_all, NULL, + "small write to multiple datasets with H5S_ALL using H5Dwrite_multi", NULL, testframe_flags); + AddTest("test_write_multi_dataset_small_hyperslab", test_write_multi_dataset_small_hyperslab, NULL, + "small write to multiple datasets with hyperslab selection using H5Dwrite_multi", NULL, testframe_flags); + AddTest("test_write_multi_dataset_small_point_selection", test_write_multi_dataset_small_point_selection, NULL, + "small write to multiple datasets with point selection using H5Dwrite_multi", NULL, testframe_flags); + AddTest("test_write_multi_dataset_data_verification", test_write_multi_dataset_data_verification, NULL, + "verification of dataset data using H5Dwrite_multi then H5Dread_multi", NULL, testframe_flags); AddTest("test_write_dataset_invalid_params", test_write_dataset_invalid_params, NULL, "H5Dwrite with invalid parameters", NULL, testframe_flags); AddTest("test_dataset_builtin_type_conversion", test_dataset_builtin_type_conversion, NULL, diff --git a/test/API/H5_api_dataset_test.h b/test/API/H5_api_dataset_test.h index 552ecad5f7b..875852844f7 100644 --- a/test/API/H5_api_dataset_test.h +++ b/test/API/H5_api_dataset_test.h @@ -145,6 +145,12 @@ void H5_api_dataset_test_add(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 @@ void H5_api_dataset_test_add(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 diff --git a/test/h5test.h b/test/h5test.h index bc2018e985e..aedc0c83a65 100644 --- a/test/h5test.h +++ b/test/h5test.h @@ -144,88 +144,88 @@ extern pthread_key_t test_thread_info_key_g; #define TESTING(WHAT) \ do { \ if (IS_MAIN_TEST_THREAD) { \ - printf("Testing %-62s", WHAT); \ - fflush(stdout); \ - } \ - INCR_TEST_STAT(n_tests_run_g); \ + printf("Testing %-62s", WHAT); \ + fflush(stdout); \ + } \ + INCR_TEST_STAT(n_tests_run_g); \ } while (0) #define TESTING_2(WHAT) \ do { \ if (IS_MAIN_TEST_THREAD) { \ - printf(" Testing %-60s", WHAT); \ - fflush(stdout); \ - } \ - INCR_TEST_STAT(n_tests_run_g); \ + printf(" Testing %-60s", WHAT); \ + fflush(stdout); \ + } \ + INCR_TEST_STAT(n_tests_run_g); \ } while (0) #define PASSED() \ do { \ if (IS_MAIN_TEST_THREAD) { \ - HDputs(" PASSED"); \ - fflush(stdout); \ - } \ - INCR_TEST_STAT(n_tests_passed_g); \ + HDputs(" PASSED"); \ + fflush(stdout); \ + } \ + INCR_TEST_STAT(n_tests_passed_g); \ } while (0) #define H5_FAILED() \ do { \ if (IS_MAIN_TEST_THREAD) { \ - HDputs("*FAILED*"); \ - fflush(stdout); \ - } \ - INCR_TEST_STAT(n_tests_failed_g); \ + HDputs("*FAILED*"); \ + fflush(stdout); \ + } \ + INCR_TEST_STAT(n_tests_failed_g); \ } while (0) #define H5_WARNING() \ do { \ if (IS_MAIN_TEST_THREAD) { \ - HDputs("*WARNING*"); \ - fflush(stdout); \ - } \ + HDputs("*WARNING*"); \ + fflush(stdout); \ + } \ } while (0) #define SKIPPED() \ do { \ if (IS_MAIN_TEST_THREAD) { \ - HDputs(" -SKIP-"); \ - fflush(stdout); \ - } \ - INCR_TEST_STAT(n_tests_skipped_g); \ + HDputs(" -SKIP-"); \ + fflush(stdout); \ + } \ + INCR_TEST_STAT(n_tests_skipped_g); \ } while (0) #define PUTS_ERROR(s) \ do { \ if (IS_MAIN_TEST_THREAD) { \ - HDputs(s); \ - AT(); \ - } \ + HDputs(s); \ + AT(); \ + } \ goto error; \ } while (0) #define TEST_ERROR \ do { \ if (IS_MAIN_TEST_THREAD) { \ - H5_FAILED(); \ - AT(); \ - } \ + H5_FAILED(); \ + AT(); \ + } \ goto error; \ } while (0) #define STACK_ERROR \ - do { \ - if (IS_MAIN_TEST_THREAD) \ - H5Eprint2(H5E_DEFAULT, stdout); \ + do { \ + if (IS_MAIN_TEST_THREAD) \ + H5Eprint2(H5E_DEFAULT, stdout); \ goto error; \ } while (0) #define FAIL_STACK_ERROR \ do { \ if (IS_MAIN_TEST_THREAD) { \ - H5_FAILED(); \ - AT(); \ - H5Eprint2(H5E_DEFAULT, stdout); \ - } \ + H5_FAILED(); \ + AT(); \ + H5Eprint2(H5E_DEFAULT, stdout); \ + } \ goto error; \ } while (0) #define FAIL_PUTS_ERROR(s) \ do { \ if (IS_MAIN_TEST_THREAD) { \ - H5_FAILED(); \ - AT(); \ - HDputs(s); \ - } \ + H5_FAILED(); \ + AT(); \ + HDputs(s); \ + } \ goto error; \ } while (0) /* @@ -234,10 +234,10 @@ extern pthread_key_t test_thread_info_key_g; #define TESTING_MULTIPART(WHAT) \ do { \ if (IS_MAIN_TEST_THREAD) { \ - printf("Testing %-62s", WHAT); \ - HDputs(""); \ - fflush(stdout); \ - } \ + printf("Testing %-62s", WHAT); \ + HDputs(""); \ + fflush(stdout); \ + } \ } while (0) /* @@ -268,16 +268,16 @@ extern pthread_key_t test_thread_info_key_g; part_##part_name##_end: #define PART_ERROR(part_name) \ do { \ - INCR_TEST_STAT(n_tests_failed_g); \ + INCR_TEST_STAT(n_tests_failed_g); \ part_nerrors++; \ goto part_##part_name##_end; \ } while (0) #define PART_TEST_ERROR(part_name) \ do { \ if (IS_MAIN_TEST_THREAD) { \ - H5_FAILED(); \ - AT(); \ - } \ + H5_FAILED(); \ + AT(); \ + } \ part_nerrors++; \ goto part_##part_name##_end; \ } while (0) @@ -455,4 +455,4 @@ H5TEST_DLL herr_t h5_wait_message(const char *file); #ifdef __cplusplus } #endif -#endif \ No newline at end of file +#endif From c42353ab3bb057a816afbfcf4ffa77a62427ff6c Mon Sep 17 00:00:00 2001 From: Jordan Henderson Date: Mon, 9 Dec 2024 16:10:08 -0600 Subject: [PATCH 02/12] Fix some API test warnings --- test/API/H5_api_dataset_test.c | 133 ++++++++++++++++++--------------- test/API/H5_api_dataset_test.h | 2 +- test/API/H5_api_test.c | 5 +- 3 files changed, 75 insertions(+), 65 deletions(-) diff --git a/test/API/H5_api_dataset_test.c b/test/API/H5_api_dataset_test.c index f97e3ea96e7..0a6e78c8b6a 100644 --- a/test/API/H5_api_dataset_test.c +++ b/test/API/H5_api_dataset_test.c @@ -6400,15 +6400,16 @@ test_write_dataset_data_verification(void) static 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_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]; + 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_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]; + const void *data_c[DATASET_MULTI_COUNT]; TESTING("small multi write to datasets with H5S_ALL"); @@ -6501,13 +6502,14 @@ test_write_multi_dataset_small_all(void) if (NULL == (data[i] = malloc((hsize_t)space_npoints * DATASET_SMALL_WRITE_TEST_ALL_DSET_DTYPESIZE))) TEST_ERROR; + data_c[i] = data[i]; 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) { + H5P_DEFAULT, data_c) < 0) { H5_FAILED(); printf(" couldn't write to dataset '%s'\n", DATASET_SMALL_WRITE_MULTI_TEST_ALL_DSET_NAME); goto error; @@ -6558,19 +6560,20 @@ test_write_multi_dataset_small_all(void) static 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]; - 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_arr[DATASET_MULTI_COUNT]; - hid_t mspace_id = H5I_INVALID_HID, fspace_id = H5I_INVALID_HID; - 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]; + 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_arr[DATASET_MULTI_COUNT]; + hid_t mspace_id = H5I_INVALID_HID, fspace_id = H5I_INVALID_HID; + 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]; + const void *data_c[DATASET_MULTI_COUNT]; TESTING("small multi write to datasets with hyperslab selections"); @@ -6633,6 +6636,7 @@ test_write_multi_dataset_small_hyperslab(void) if (NULL == (data[i] = malloc(data_size))) TEST_ERROR; + data_c[i] = data[i]; for (size_t j = 0; j < data_size / DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_DTYPESIZE; j++) ((int **)data)[i][j] = (int)i; @@ -6657,7 +6661,7 @@ test_write_multi_dataset_small_hyperslab(void) } if (H5Dwrite_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, mspace_id_arr, fspace_id_arr, - H5P_DEFAULT, (const void **)data) < 0) { + H5P_DEFAULT, data_c) < 0) { H5_FAILED(); printf(" couldn't write to dataset '%s'\n", DATASET_SMALL_WRITE_MULTI_TEST_HYPERSLAB_DSET_NAME); goto error; @@ -6715,18 +6719,19 @@ test_write_multi_dataset_small_hyperslab(void) static 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]; - 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_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]; + 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_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]; + const void *data_c[DATASET_MULTI_COUNT]; TESTING("small multi write to datasets with point selections"); @@ -6789,6 +6794,7 @@ test_write_multi_dataset_small_point_selection(void) if (NULL == (data[i] = malloc(data_size))) TEST_ERROR; + data_c[i] = data[i]; for (size_t j = 0; j < data_size / DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_DTYPESIZE; j++) ((int **)data)[i][j] = (int)i; @@ -6815,7 +6821,7 @@ test_write_multi_dataset_small_point_selection(void) } if (H5Dwrite_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, mspace_id_arr, fspace_id_arr, - H5P_DEFAULT, (const void **)data) < 0) { + H5P_DEFAULT, data_c) < 0) { H5_FAILED(); printf(" couldn't write to multiple datasets\n"); goto error; @@ -6874,26 +6880,28 @@ test_write_multi_dataset_small_point_selection(void) static void test_write_multi_dataset_data_verification(void) { - 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]; - 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_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]; + 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]; + 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_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]; + const void *data_c[DATASET_MULTI_COUNT]; + void *write_buf[DATASET_MULTI_COUNT]; + const void *write_buf_c[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"); @@ -6956,6 +6964,7 @@ test_write_multi_dataset_data_verification(void) if (NULL == (data[i] = malloc(data_size))) TEST_ERROR; + data_c[i] = data[i]; dtype_id_arr[i] = DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE; @@ -6972,7 +6981,7 @@ test_write_multi_dataset_data_verification(void) TESTING_2("H5Dwrite_multi using H5S_ALL then H5Dread_multi"); if (H5Dwrite_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, select_all_arr, select_all_arr, - H5P_DEFAULT, (const void **)data) < 0) { + H5P_DEFAULT, data_c) < 0) { H5_FAILED(); printf(" couldn't write to datasets"); PART_ERROR(H5Dwrite_multi_all_read); @@ -7075,6 +7084,8 @@ test_write_multi_dataset_data_verification(void) PART_ERROR(H5Dwrite_multi_hyperslab_read); } + write_buf_c[i] = write_buf[i]; + for (size_t j = 0; j < data_size / DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; j++) { ((int *)write_buf[i])[j] = 56; } @@ -7137,7 +7148,7 @@ test_write_multi_dataset_data_verification(void) } 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) { + H5P_DEFAULT, write_buf_c) < 0) { H5_FAILED(); printf(" couldn't write to datasets\n"); PART_ERROR(H5Dwrite_multi_hyperslab_read); @@ -7261,6 +7272,8 @@ test_write_multi_dataset_data_verification(void) PART_ERROR(H5Dwrite_multi_point_sel_read); } + write_buf_c[i] = write_buf[i]; + for (size_t j = 0; j < data_size / DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; j++) ((int **)write_buf)[i][j] = 13; @@ -7313,7 +7326,7 @@ test_write_multi_dataset_data_verification(void) } 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) { + H5P_DEFAULT, write_buf_c) < 0) { H5_FAILED(); printf(" couldn't write to datasets\n"); PART_ERROR(H5Dwrite_multi_point_sel_read); diff --git a/test/API/H5_api_dataset_test.h b/test/API/H5_api_dataset_test.h index 875852844f7..4c2901f646a 100644 --- a/test/API/H5_api_dataset_test.h +++ b/test/API/H5_api_dataset_test.h @@ -53,7 +53,7 @@ void H5_api_dataset_test_add(void); #define ZERO_DIM_DSET_TEST_DSET_NAME "zero_dim_dset" #define DATASET_MANY_CREATE_GROUP_NAME "group_for_many_datasets" -#define DSET_NAME_BUF_SIZE 64u +#define DSET_NAME_BUF_SIZE 64 #define DATASET_NUMB 100u #define DATASET_SHAPE_TEST_DSET_BASE_NAME "dataset_shape_test" diff --git a/test/API/H5_api_test.c b/test/API/H5_api_test.c index a67dc016327..b93b7aabafa 100644 --- a/test/API/H5_api_test.c +++ b/test/API/H5_api_test.c @@ -50,9 +50,6 @@ static int H5_api_test_create_containers(const char *filename, uint64_t vol_cap_ static int H5_api_test_create_single_container(const char *filename, uint64_t vol_cap_flags); static int H5_api_test_destroy_container_files(void); -/* Margin of runtime for each subtest allocated to cleanup */ -#define API_TEST_MARGIN 1 - /* X-macro to define the following for each test: * - enum type * - name @@ -594,4 +591,4 @@ H5_api_test_destroy_container_files(void) { free(filename); filename = NULL; return -1; -} \ No newline at end of file +} From d7a5743e4a7f1963463ea4eab1be5948d22be448 Mon Sep 17 00:00:00 2001 From: mattjala <124107509+mattjala@users.noreply.github.com> Date: Tue, 6 Feb 2024 14:57:50 -0600 Subject: [PATCH 03/12] Sync API tests with vol-tests (#3940) --- test/API/H5_api_attribute_test.c | 270 +++++ test/API/H5_api_attribute_test.h | 9 + test/API/H5_api_dataset_test.c | 1747 +++++++++++++++++++++++++----- test/API/H5_api_dataset_test.h | 38 + test/API/H5_api_object_test.c | 256 ++++- test/API/H5_api_object_test.h | 7 + 6 files changed, 2037 insertions(+), 290 deletions(-) diff --git a/test/API/H5_api_attribute_test.c b/test/API/H5_api_attribute_test.c index 8c53d1fefd8..47b74f999d1 100644 --- a/test/API/H5_api_attribute_test.c +++ b/test/API/H5_api_attribute_test.c @@ -52,6 +52,7 @@ static void test_attribute_iterate_datatype(void); static void test_attribute_iterate_index_saving(void); static void test_attribute_iterate_invalid_params(void); static void test_attribute_iterate_0_attributes(void); +static void test_attribute_string_encodings(void); static void test_delete_attribute(void); static void test_delete_attribute_invalid_params(void); static void test_attribute_exists(void); @@ -8303,6 +8304,273 @@ test_attribute_iterate_0_attributes(void) } +/* + * A test to check that attributes preserve data + * correctness for strings with ASCII or UTF-8 char sets + */ +static void +test_attribute_string_encodings(void) +{ + hid_t file_id = H5I_INVALID_HID; + hid_t container_group = H5I_INVALID_HID; + hid_t dset_id1 = H5I_INVALID_HID; + hid_t dset_id2 = H5I_INVALID_HID; + hid_t type_id1 = H5I_INVALID_HID; + hid_t type_id2 = H5I_INVALID_HID; + hid_t space_id = H5I_INVALID_HID; + hid_t attr_id1 = H5I_INVALID_HID; + hid_t attr_id2 = H5I_INVALID_HID; + hsize_t dims[ATTRIBUTE_STRING_ENCODINGS_RANK] = {ATTRIBUTE_STRING_ENCODINGS_EXTENT}; + size_t ascii_str_size = 0; + size_t utf8_str_size = 0; + char *write_buf = NULL; + char *read_buf = NULL; + + TESTING_MULTIPART("string encoding read/write correctness on attributes"); + + /* 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_ATTR_BASIC)) { + SKIPPED(); + printf(" API functions for basic file, group, basic or more dataset aren't supported with this " + "connector\n"); + return; + } + + TESTING_2("test setup"); + + ascii_str_size = strlen(ATTRIBUTE_STRING_ENCODINGS_ASCII_STRING); + utf8_str_size = strlen(ATTRIBUTE_STRING_ENCODINGS_UTF8_STRING); + + 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, ATTRIBUTE_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open container group '%s'\n", ATTRIBUTE_TEST_GROUP_NAME); + goto error; + } + + if ((space_id = H5Screate_simple(ATTRIBUTE_STRING_ENCODINGS_RANK, dims, NULL)) < 0) { + H5_FAILED(); + printf(" couldn't create dataspace\n"); + goto error; + } + + if ((type_id1 = H5Tcopy(H5T_C_S1)) < 0) { + H5_FAILED(); + printf(" couldn't copy builtin string datatype\n"); + goto error; + } + + if ((H5Tset_size(type_id1, ascii_str_size)) < 0) { + H5_FAILED(); + printf(" couldn't set size of string datatype\n"); + goto error; + } + + if ((H5Tset_cset(type_id1, H5T_CSET_ASCII)) < 0) { + H5_FAILED(); + printf(" couldn't set character set of string to ASCII\n"); + goto error; + } + + if ((dset_id1 = H5Dcreate(container_group, ATTRIBUTE_STRING_ENCODINGS_DSET_NAME1, type_id1, space_id, + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset with ascii string\n"); + goto error; + } + + if ((attr_id1 = H5Acreate(dset_id1, ATTRIBUTE_STRING_ENCODINGS_ATTR_NAME1, type_id1, space_id, + H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create attribute with ascii string\n"); + goto error; + } + + if ((type_id2 = H5Tcopy(H5T_C_S1)) < 0) { + H5_FAILED(); + printf(" couldn't copy builtin string datatype\n"); + goto error; + } + + if ((H5Tset_size(type_id2, utf8_str_size)) < 0) { + H5_FAILED(); + printf(" couldn't set size of string datatype\n"); + goto error; + } + + if ((H5Tset_cset(type_id2, H5T_CSET_UTF8)) < 0) { + H5_FAILED(); + printf(" couldn't set character set of string to UTF-8\n"); + goto error; + } + + if ((dset_id2 = H5Dcreate(container_group, ATTRIBUTE_STRING_ENCODINGS_DSET_NAME2, type_id2, space_id, + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset with UTF-8 string\n"); + goto error; + } + + if ((attr_id2 = H5Acreate(dset_id2, ATTRIBUTE_STRING_ENCODINGS_ATTR_NAME2, type_id2, space_id, + H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create attribute with ascii string\n"); + goto error; + } + + PASSED(); + + BEGIN_MULTIPART + { + PART_BEGIN(ASCII_cset) + { + TESTING_2("ASCII character set"); + if ((write_buf = calloc(1, ascii_str_size + 1)) == NULL) { + H5_FAILED(); + printf(" couldn't allocate memory for write buffer\n"); + PART_ERROR(ASCII_cset); + } + + memcpy(write_buf, ATTRIBUTE_STRING_ENCODINGS_ASCII_STRING, ascii_str_size); + + if ((read_buf = calloc(1, ascii_str_size + 1)) == NULL) { + H5_FAILED(); + printf(" couldn't allocate memory for read buffer\n"); + PART_ERROR(ASCII_cset); + } + + if (H5Awrite(attr_id1, type_id1, write_buf) < 0) { + H5_FAILED(); + printf(" couldn't write to attribute with ASCII string\n"); + PART_ERROR(ASCII_cset); + } + + if (H5Aread(attr_id1, type_id1, read_buf) < 0) { + H5_FAILED(); + printf(" couldn't read from attribute with ASCII string\n"); + PART_ERROR(ASCII_cset); + } + + if (strncmp(write_buf, read_buf, ascii_str_size)) { + H5_FAILED(); + printf(" incorrect data read from attribute with ASCII string\n"); + PART_ERROR(ASCII_cset); + } + + free(write_buf); + write_buf = NULL; + + free(read_buf); + read_buf = NULL; + + PASSED(); + } + PART_END(ASCII_cset); + + PART_BEGIN(UTF8_cset) + { + TESTING_2("UTF-8 character set"); + + if ((write_buf = calloc(1, utf8_str_size + 1)) == NULL) { + H5_FAILED(); + printf(" couldn't allocate memory for write buffer\n"); + PART_ERROR(UTF8_cset); + } + + memcpy(write_buf, ATTRIBUTE_STRING_ENCODINGS_UTF8_STRING, utf8_str_size); + + if ((read_buf = calloc(1, utf8_str_size + 1)) == NULL) { + H5_FAILED(); + printf(" couldn't allocate memory for read buffer\n"); + PART_ERROR(UTF8_cset); + } + + if (H5Awrite(attr_id2, type_id2, write_buf) < 0) { + H5_FAILED(); + printf(" couldn't write to attribute with UTF-8 string\n"); + PART_ERROR(UTF8_cset); + } + + if (H5Aread(attr_id2, type_id2, read_buf) < 0) { + H5_FAILED(); + printf(" couldn't read from attribute with UTF-8 string\n"); + PART_ERROR(UTF8_cset); + } + + if (strncmp(write_buf, read_buf, utf8_str_size)) { + H5_FAILED(); + printf(" incorrect data read from attribute with UTF-8 string\n"); + PART_ERROR(UTF8_cset); + } + + free(write_buf); + write_buf = NULL; + + free(read_buf); + read_buf = NULL; + + PASSED(); + } + PART_END(UTF8_cset); + + PASSED(); + } + END_MULTIPART; + + TESTING_2("test cleanup"); + + if (H5Fclose(file_id) < 0) + TEST_ERROR; + if (H5Gclose(container_group) < 0) + TEST_ERROR; + if (H5Dclose(dset_id1) < 0) + TEST_ERROR; + if (H5Dclose(dset_id2) < 0) + TEST_ERROR; + if (H5Tclose(type_id1) < 0) + TEST_ERROR; + if (H5Tclose(type_id2) < 0) + TEST_ERROR; + if (H5Aclose(attr_id1) < 0) + TEST_ERROR; + if (H5Aclose(attr_id2) < 0) + TEST_ERROR; + if (write_buf) + free(write_buf); + if (read_buf) + free(read_buf); + + PASSED(); + + return; + +error: + H5E_BEGIN_TRY + { + H5Fclose(file_id); + H5Gclose(container_group); + H5Dclose(dset_id1); + H5Dclose(dset_id2); + H5Tclose(type_id1); + H5Tclose(type_id2); + H5Aclose(attr_id1); + H5Aclose(attr_id2); + if (write_buf) + free(write_buf); + if (read_buf) + free(read_buf); + } + H5E_END_TRY; + + return; +} + /* * A test to check that an attribute can be deleted * using H5Adelete(_by_idx). @@ -11089,6 +11357,8 @@ H5_api_attribute_test_add(void) "attribute iteration with invalid parameters", NULL, testframe_flags); AddTest("test_attribute_iterate_0_attributes", test_attribute_iterate_0_attributes, NULL, "attribute iteration on object with 0 attributes", NULL, testframe_flags); + AddTest("test_attribute_string_encodings", test_attribute_string_encodings, NULL, + "attribute string encoding correctness", NULL, testframe_flags); AddTest("test_delete_attribute", test_delete_attribute, NULL, "attribute deletion", NULL, testframe_flags); AddTest("test_delete_attribute_invalid_params", test_delete_attribute_invalid_params, NULL, "attribute deletion with invalid parameters", NULL, testframe_flags); diff --git a/test/API/H5_api_attribute_test.h b/test/API/H5_api_attribute_test.h index 67cef76d1fb..c24eec8d484 100644 --- a/test/API/H5_api_attribute_test.h +++ b/test/API/H5_api_attribute_test.h @@ -156,6 +156,15 @@ void H5_api_attribute_test_add(void); #define ATTRIBUTE_ITERATE_TEST_0_ATTRIBUTES_SUBGROUP_NAME "attribute_iterate_test_0_attributes" #define ATTRIBUTE_ITERATE_TEST_0_ATTRIBUTES_DSET_NAME "attribute_iterate_dset" +#define ATTRIBUTE_STRING_ENCODINGS_RANK 1 +#define ATTRIBUTE_STRING_ENCODINGS_EXTENT 1 +#define ATTRIBUTE_STRING_ENCODINGS_DSET_NAME1 "encoding_dset1" +#define ATTRIBUTE_STRING_ENCODINGS_DSET_NAME2 "encoding_dset2" +#define ATTRIBUTE_STRING_ENCODINGS_ASCII_STRING "asciistr" +#define ATTRIBUTE_STRING_ENCODINGS_UTF8_STRING "αaααaaaα" +#define ATTRIBUTE_STRING_ENCODINGS_ATTR_NAME1 "encoding_attr1" +#define ATTRIBUTE_STRING_ENCODINGS_ATTR_NAME2 "encoding_attr2" + #define ATTRIBUTE_ITERATE_INVALID_PARAMS_TEST_ATTR_SPACE_RANK 1 #define ATTRIBUTE_ITERATE_INVALID_PARAMS_TEST_SUBGROUP_NAME "attribute_iterate_invalid_params_test" #define ATTRIBUTE_ITERATE_INVALID_PARAMS_TEST_ATTR_NAME "invalid_params_iter_attr1" diff --git a/test/API/H5_api_dataset_test.c b/test/API/H5_api_dataset_test.c index 0a6e78c8b6a..2258acc10f7 100644 --- a/test/API/H5_api_dataset_test.c +++ b/test/API/H5_api_dataset_test.c @@ -64,7 +64,9 @@ static void test_write_multi_dataset_small_hyperslab(void); static void test_write_multi_dataset_small_point_selection(void); static void test_write_multi_dataset_data_verification(void); static void test_write_dataset_invalid_params(void); +static void test_dataset_string_encodings(void); static void test_dataset_builtin_type_conversion(void); +static void test_dataset_real_to_int_conversion(void); static void test_dataset_compound_partial_io(void); static void test_dataset_set_extent_chunked_unlimited(void); static void test_dataset_set_extent_chunked_fixed(void); @@ -103,6 +105,9 @@ print_dataset_test_header(void) printf("**********************************************\n\n"); } +size_t filter(unsigned int flags, size_t H5_ATTR_UNUSED cd_nelmts, + const unsigned int H5_ATTR_UNUSED cd_values[], size_t nbytes, size_t H5_ATTR_UNUSED *buf_size, + void H5_ATTR_UNUSED **buf); /* * A test to check that a dataset can be * created under the root group. @@ -1978,6 +1983,22 @@ test_create_dataset_array_types(void) return; } +size_t +filter(unsigned int flags, size_t H5_ATTR_UNUSED cd_nelmts, const unsigned int H5_ATTR_UNUSED cd_values[], + size_t nbytes, size_t H5_ATTR_UNUSED *buf_size, void H5_ATTR_UNUSED **buf) +{ + buf_size = 0; + + if (flags & H5Z_FLAG_REVERSE) { + /* No-op */ + } + else { + /* No-op */ + } + + return nbytes; +} + /* * A test to check the functionality of the different * dataset creation properties. @@ -1993,6 +2014,13 @@ test_create_dataset_creation_properties(void) hid_t dset_id = H5I_INVALID_HID, dcpl_id = H5I_INVALID_HID; hid_t dset_dtype = H5I_INVALID_HID, compact_dtype = H5I_INVALID_HID; hid_t fspace_id = H5I_INVALID_HID, compact_fspace_id = H5I_INVALID_HID; + void *read_buf = NULL; + unsigned int filter_params[DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_NUM_PARAMS] = {1, 2, 3}; + unsigned int filter_params_out[DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_NUM_PARAMS]; + char ud_filter_name[strlen(DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_NAME)]; + int nfilters = 0; + H5Z_filter_t retrieved_filter_id = H5I_INVALID_HID; + size_t num_filter_params = DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_NUM_PARAMS; TESTING_MULTIPART("dataset creation properties"); @@ -2326,6 +2354,276 @@ test_create_dataset_creation_properties(void) } PART_END(DCPL_fill_time_property_test); + PART_BEGIN(DCPL_fill_value_test) + { + TESTING_2("fill values"); + + int int_fill_value = DATASET_FILL_VALUE_TEST_INT_FILL_VALUE; + double double_fill_value = DATASET_FILL_VALUE_TEST_DOUBLE_FILL_VALUE; + + void *val = NULL; + size_t num_elems = 1; + hid_t type_id = H5I_INVALID_HID; + + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_FILL_VALUES)) { + SKIPPED(); + printf(" dataset fill values are not supported by this VOL connector\n"); + PART_EMPTY(DCPL_fill_value_test); + } + + /* Integer Fill Value */ + if ((dcpl_id = H5Pcreate(H5P_DATASET_CREATE)) < 0) { + H5_FAILED(); + printf(" couldn't create DCPL\n"); + PART_ERROR(DCPL_fill_value_test); + } + + if (H5Pset_fill_value(dcpl_id, DATASET_FILL_VALUE_TEST_INT_TYPE, (const void *)&int_fill_value) < + 0) { + H5_FAILED(); + printf(" couldn't set integer fill value in property list"); + PART_ERROR(DCPL_fill_value_test); + } + + if ((dset_id = + H5Dcreate(group_id, DATASET_FILL_VALUE_TEST_DSET_NAME1, DATASET_FILL_VALUE_TEST_INT_TYPE, + fspace_id, H5P_DEFAULT, dcpl_id, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset with integer fill value"); + PART_ERROR(DCPL_fill_value_test); + } + + if ((H5Sget_simple_extent_dims(fspace_id, dims, NULL)) < 0) { + H5_FAILED(); + printf(" couldn't get dataspace dimensions"); + PART_ERROR(DCPL_fill_value_test); + } + + for (i = 0; i < DATASET_CREATION_PROPERTIES_TEST_SHAPE_RANK; i++) + num_elems *= (size_t)dims[i]; + + if ((read_buf = calloc(num_elems, sizeof(DATASET_FILL_VALUE_TEST_INT_TYPE))) == NULL) { + H5_FAILED(); + printf(" couldn't allocate memory for read buffer"); + PART_ERROR(DCPL_fill_value_test); + } + + if (H5Dread(dset_id, DATASET_FILL_VALUE_TEST_INT_TYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_buf) < + 0) { + H5_FAILED(); + printf(" couldn't read from dataset"); + PART_ERROR(DCPL_fill_value_test); + } + + for (i = 0; i < num_elems; i++) { + val = (int *)(read_buf) + i; + + if (*(int *)val != DATASET_FILL_VALUE_TEST_INT_FILL_VALUE) { + H5_FAILED(); + printf(" incorrect value read from dataset"); + PART_ERROR(DCPL_fill_value_test); + } + } + + if (H5Dclose(dset_id) < 0) { + H5_FAILED(); + printf(" couldn't close integer fill value dataset"); + PART_ERROR(DCPL_fill_value_test); + } + + if (H5Pclose(dcpl_id) < 0) { + H5_FAILED(); + printf(" couldn't close dcpl"); + PART_ERROR(DCPL_fill_value_test); + } + + /* Re-open integer dataset */ + if ((dset_id = H5Dopen2(group_id, DATASET_FILL_VALUE_TEST_DSET_NAME1, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open integer fill value dataset"); + PART_ERROR(DCPL_fill_value_test); + } + + if (H5Dclose(dset_id) < 0) { + H5_FAILED(); + printf(" couldn't close opened integer fill value dataset"); + PART_ERROR(DCPL_fill_value_test); + } + + free(read_buf); + read_buf = NULL; + + /* Double fill value */ + if ((dcpl_id = H5Pcreate(H5P_DATASET_CREATE)) == H5I_INVALID_HID) { + H5_FAILED(); + printf(" couldn't create dcpl"); + PART_ERROR(DCPL_fill_value_test); + } + + if ((H5Pset_fill_value(dcpl_id, DATASET_FILL_VALUE_TEST_DOUBLE_TYPE, + (const void *)&double_fill_value)) < 0) { + H5_FAILED(); + printf(" couldn't set double fill value in property list"); + PART_ERROR(DCPL_fill_value_test); + } + + if ((dset_id = H5Dcreate2(group_id, DATASET_FILL_VALUE_TEST_DSET_NAME2, + DATASET_FILL_VALUE_TEST_DOUBLE_TYPE, fspace_id, H5P_DEFAULT, dcpl_id, + H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset with double fill value"); + PART_ERROR(DCPL_fill_value_test); + } + + if ((read_buf = calloc(num_elems, sizeof(DATASET_FILL_VALUE_TEST_DOUBLE_TYPE))) == NULL) { + H5_FAILED(); + printf(" couldn't allocate memory for read buffer"); + PART_ERROR(DCPL_fill_value_test); + } + + if (H5Dread(dset_id, DATASET_FILL_VALUE_TEST_DOUBLE_TYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, + read_buf) < 0) { + H5_FAILED(); + printf(" couldn't read from dataset"); + PART_ERROR(DCPL_fill_value_test); + } + + for (i = 0; i < num_elems; i++) { + val = (double *)(read_buf) + i; + + if (!(H5_DBL_REL_EQUAL(*(double *)val, DATASET_FILL_VALUE_TEST_DOUBLE_FILL_VALUE, + 0.0000001))) { + H5_FAILED(); + printf(" incorrect value read from dataset"); + PART_ERROR(DCPL_fill_value_test); + } + } + + if (H5Dclose(dset_id) < 0) { + H5_FAILED(); + printf(" couldn't close double fill value dataset"); + PART_ERROR(DCPL_fill_value_test); + } + + if (H5Pclose(dcpl_id) < 0) { + H5_FAILED(); + printf(" couldn't close dcpl"); + PART_ERROR(DCPL_fill_value_test); + } + + /* Re-open double dataset */ + if ((dset_id = H5Dopen2(group_id, DATASET_FILL_VALUE_TEST_DSET_NAME2, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open double fill value dataset"); + PART_ERROR(DCPL_fill_value_test); + } + + if (H5Dclose(dset_id) < 0) { + H5_FAILED(); + printf(" couldn't close opened double fill value dataset"); + PART_ERROR(DCPL_fill_value_test); + } + + free(read_buf); + read_buf = NULL; + + /* Fixed-length string fill value */ + if ((dcpl_id = H5Pcreate(H5P_DATASET_CREATE)) == H5I_INVALID_HID) { + H5_FAILED(); + printf(" couldn't create dcpl"); + PART_ERROR(DCPL_fill_value_test); + } + + if ((type_id = H5Tcopy(H5T_C_S1)) < 0) { + H5_FAILED(); + printf(" couldn't copy string datatype"); + PART_ERROR(DCPL_fill_value_test); + } + + if ((H5Tset_size(type_id, DATASET_FILL_VALUE_TEST_STRING_SIZE)) < 0) { + H5_FAILED(); + printf(" couldn't set size of string datatype"); + PART_ERROR(DCPL_fill_value_test); + } + + if ((H5Pset_fill_value(dcpl_id, type_id, + (const void *)DATASET_FILL_VALUE_TEST_STRING_FILL_VALUE)) < 0) { + H5_FAILED(); + printf(" couldn't set string fill value in property list"); + PART_ERROR(DCPL_fill_value_test); + } + + if ((dset_id = H5Dcreate2(group_id, DATASET_FILL_VALUE_TEST_DSET_NAME3, type_id, fspace_id, + H5P_DEFAULT, dcpl_id, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset with string fill value"); + PART_ERROR(DCPL_fill_value_test); + } + + if ((read_buf = calloc(num_elems, DATASET_FILL_VALUE_TEST_STRING_SIZE)) == NULL) { + H5_FAILED(); + printf(" couldn't allocate memory for read buffer"); + PART_ERROR(DCPL_fill_value_test); + } + + if (H5Dread(dset_id, type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_buf) < 0) { + H5_FAILED(); + printf(" couldn't read from dataset"); + PART_ERROR(DCPL_fill_value_test); + } + + for (i = 0; i < num_elems; i++) { + char val_str[DATASET_FILL_VALUE_TEST_STRING_SIZE + 1]; + + memcpy(val_str, ((char *)read_buf) + i * DATASET_FILL_VALUE_TEST_STRING_SIZE, + DATASET_FILL_VALUE_TEST_STRING_SIZE); + val_str[DATASET_FILL_VALUE_TEST_STRING_SIZE] = '\0'; + + if (strcmp(val_str, DATASET_FILL_VALUE_TEST_STRING_FILL_VALUE)) { + H5_FAILED(); + printf(" incorrect value read from string dataset"); + PART_ERROR(DCPL_fill_value_test); + } + } + + if (H5Dclose(dset_id) < 0) { + H5_FAILED(); + printf(" couldn't close string fill value dataset"); + PART_ERROR(DCPL_fill_value_test); + } + + if (H5Pclose(dcpl_id) < 0) { + H5_FAILED(); + printf(" couldn't close dcpl"); + PART_ERROR(DCPL_fill_value_test); + } + + if (H5Tclose(type_id) < 0) { + H5_FAILED(); + printf(" couldn't close string type"); + PART_ERROR(DCPL_fill_value_test); + } + + free(read_buf); + read_buf = NULL; + + /* Re-open string dataset */ + if ((dset_id = H5Dopen2(group_id, DATASET_FILL_VALUE_TEST_DSET_NAME3, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open string fill value dataset"); + PART_ERROR(DCPL_fill_value_test); + } + + if (H5Dclose(dset_id) < 0) { + H5_FAILED(); + printf(" couldn't close opened string fill value dataset"); + PART_ERROR(DCPL_fill_value_test); + } + + PASSED(); + } + PART_END(DCPL_fill_value_test); + /* Test filters */ PART_BEGIN(DCPL_filters_test) { @@ -2426,6 +2724,120 @@ test_create_dataset_creation_properties(void) } PART_END(DCPL_filters_test); + /* Test a user-defined filter */ + PART_BEGIN(DCPL_user_defined_filter_test) + { + TESTING_2("user-defined dataset filters"); + /* Create user-defined filter and register with library */ + const H5Z_class2_t filter_cls[1] = { + {H5Z_CLASS_T_VERS, DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_ID, 1, 1, + DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_NAME, NULL, NULL, &filter}}; + + if (H5Zregister((const void *)&filter_cls) < 0) { + H5_FAILED(); + printf(" couldn't register filter\n"); + PART_ERROR(DCPL_user_defined_filter_test); + } + + if ((dcpl_id = H5Pcreate(H5P_DATASET_CREATE)) < 0) { + H5_FAILED(); + printf(" couldn't create DCPL\n"); + PART_ERROR(DCPL_user_defined_filter_test); + } + + if (H5Pset_chunk(dcpl_id, DATASET_CREATION_PROPERTIES_TEST_SHAPE_RANK, chunk_dims) < 0) { + H5_FAILED(); + printf(" couldn't set chunking on DCPL\n"); + PART_ERROR(DCPL_user_defined_filter_test); + } + + /* Set user-defined filter on the DCPL */ + if (H5Pset_filter(dcpl_id, (H5Z_filter_t)DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_ID, + H5Z_FLAG_MANDATORY, 3, filter_params) < 0) { + H5_FAILED(); + printf(" couldn't set user-defined filter on DCPL\n"); + PART_ERROR(DCPL_user_defined_filter_test); + } + + /* Use a simple datatype, as not all filters support all datatypes. */ + if ((dset_id = H5Dcreate2(group_id, DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_DSET_NAME, + H5T_NATIVE_INT, fspace_id, H5P_DEFAULT, dcpl_id, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset '%s'\n", + DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_DSET_NAME); + PART_ERROR(DCPL_user_defined_filter_test); + } + + 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_CREATION_PROPERTIES_TEST_UD_FILTER_DSET_NAME, + H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open dataset '%s'\n", + DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_DSET_NAME); + PART_ERROR(DCPL_user_defined_filter_test); + } + + if (dcpl_id >= 0) { + H5E_BEGIN_TRY + { + H5Pclose(dcpl_id); + } + H5E_END_TRY; + dcpl_id = H5I_INVALID_HID; + } + + /* Test that parameters are preserved in the DCPL */ + memset(filter_params_out, 0, + sizeof(unsigned int) * DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_NUM_PARAMS); + + if ((dcpl_id = H5Dget_create_plist(dset_id)) < 0) { + H5_FAILED(); + printf(" couldn't retrieve DCPL\n"); + PART_ERROR(DCPL_user_defined_filter_test); + } + + if ((nfilters = H5Pget_nfilters(dcpl_id)) != 1) { + H5_FAILED(); + printf(" retrieved incorrect number of filters from DCPL\n"); + PART_ERROR(DCPL_user_defined_filter_test); + } + + if ((retrieved_filter_id = H5Pget_filter2( + dcpl_id, 0, H5Z_FLAG_MANDATORY, &num_filter_params, filter_params_out, + strlen(DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_NAME), ud_filter_name, NULL)) < 0) { + H5_FAILED(); + printf(" retrieved incorrect user-defined filter ID\n"); + PART_ERROR(DCPL_user_defined_filter_test); + } + + for (i = 0; i < DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_NUM_PARAMS; i++) + if (filter_params[i] != filter_params_out[i]) { + H5_FAILED(); + printf(" retrieved incorrect parameter value from DCPL\n"); + PART_ERROR(DCPL_user_defined_filter_test); + } + + if (dset_id >= 0) { + H5E_BEGIN_TRY + { + H5Dclose(dset_id); + } + H5E_END_TRY; + dset_id = H5I_INVALID_HID; + } + + PASSED(); + } + PART_END(DCPL_user_defined_filter_test) + /* Test the dataset storage layout property */ PART_BEGIN(DCPL_storage_layout_test) { @@ -2625,6 +3037,11 @@ test_create_dataset_creation_properties(void) TESTING_2("test cleanup"); + if (read_buf) { + free(read_buf); + read_buf = NULL; + } + if (H5Sclose(compact_fspace_id) < 0) TEST_ERROR; if (H5Sclose(fspace_id) < 0) @@ -2647,6 +3064,10 @@ test_create_dataset_creation_properties(void) error: H5E_BEGIN_TRY { + if (read_buf) { + free(read_buf); + } + H5Sclose(compact_fspace_id); H5Sclose(fspace_id); H5Tclose(compact_dtype); @@ -4620,7 +5041,7 @@ test_read_multi_dataset_small_point_selection(void) 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]; + void *read_buf[DATASET_MULTI_COUNT]; TESTING("small multi read from datasets with point selections"); @@ -4634,7 +5055,7 @@ test_read_multi_dataset_small_point_selection(void) /* Prevent uninitialized memory usage on test failure */ for (i = 0; i < DATASET_MULTI_COUNT; i++) { - data[i] = NULL; + read_buf[i] = NULL; dset_id_arr[i] = H5I_INVALID_HID; } @@ -4696,7 +5117,7 @@ test_read_multi_dataset_small_point_selection(void) goto error; } - if (NULL == (data[i] = malloc(data_size))) + if (NULL == (read_buf[i] = malloc(data_size))) TEST_ERROR; dtype_arr[i] = DATASET_SMALL_READ_TEST_POINT_SELECTION_DSET_DTYPE; @@ -4705,16 +5126,16 @@ test_read_multi_dataset_small_point_selection(void) } if (H5Dread_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_arr, mspace_id_arr, fspace_id_arr, H5P_DEFAULT, - data) < 0) { + read_buf) < 0) { H5_FAILED(); printf(" couldn't read from dataset '%s'\n", DATASET_SMALL_READ_TEST_POINT_SELECTION_DSET_NAME); goto error; } for (i = 0; i < DATASET_MULTI_COUNT; i++) { - if (data[i]) { - free(data[i]); - data[i] = NULL; + if (read_buf[i]) { + free(read_buf[i]); + read_buf[i] = NULL; } if (H5Dclose(dset_id_arr[i]) < 0) TEST_ERROR; @@ -4739,9 +5160,9 @@ test_read_multi_dataset_small_point_selection(void) H5E_BEGIN_TRY { for (i = 0; i < DATASET_MULTI_COUNT; i++) { - if (data[i]) { - free(data[i]); - data[i] = NULL; + if (read_buf[i]) { + free(read_buf[i]); + read_buf[i] = NULL; } H5Dclose(dset_id_arr[i]); } @@ -6408,15 +6829,16 @@ test_write_multi_dataset_small_all(void) 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]; - const void *data_c[DATASET_MULTI_COUNT]; + const void *write_buf[DATASET_MULTI_COUNT]; + void *wbuf_temp[DATASET_MULTI_COUNT]; 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; + write_buf[i] = NULL; + wbuf_temp[i] = NULL; } /* Make sure the connector supports the API functions being tested */ @@ -6500,24 +6922,26 @@ test_write_multi_dataset_small_all(void) 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))) + if (NULL == + (wbuf_temp[i] = malloc((hsize_t)space_npoints * DATASET_SMALL_WRITE_TEST_ALL_DSET_DTYPESIZE))) TEST_ERROR; - data_c[i] = data[i]; for (size_t j = 0; j < (size_t)space_npoints; j++) - ((int **)data)[i][j] = (int)i; + ((int **)wbuf_temp)[i][j] = (int)i; + + write_buf[i] = wbuf_temp[i]; } if (H5Dwrite_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, fspace_id_arr, fspace_id_arr, - H5P_DEFAULT, data_c) < 0) { + H5P_DEFAULT, write_buf) < 0) { H5_FAILED(); printf(" couldn't write to dataset '%s'\n", DATASET_SMALL_WRITE_MULTI_TEST_ALL_DSET_NAME); goto error; } for (i = 0; i < DATASET_MULTI_COUNT; i++) { - free(data[i]); - data[i] = NULL; + free(wbuf_temp[i]); + wbuf_temp[i] = NULL; if (H5Dclose(dset_id_arr[i]) < 0) TEST_ERROR; } @@ -6538,8 +6962,8 @@ test_write_multi_dataset_small_all(void) H5E_BEGIN_TRY { for (i = 0; i < DATASET_MULTI_COUNT; i++) { - if (data[i]) - free(data[i]); + if (wbuf_temp[i]) + free(wbuf_temp[i]); H5Dclose(dset_id_arr[i]); } @@ -6572,8 +6996,8 @@ test_write_multi_dataset_small_hyperslab(void) hid_t mspace_id = H5I_INVALID_HID, fspace_id = H5I_INVALID_HID; 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]; - const void *data_c[DATASET_MULTI_COUNT]; + const void *write_buf[DATASET_MULTI_COUNT]; + void *wbuf_temp[DATASET_MULTI_COUNT]; TESTING("small multi write to datasets with hyperslab selections"); @@ -6587,7 +7011,8 @@ test_write_multi_dataset_small_hyperslab(void) for (i = 0; i < DATASET_MULTI_COUNT; i++) { dset_id_arr[i] = H5I_INVALID_HID; - data[i] = NULL; + write_buf[i] = NULL; + wbuf_temp[i] = NULL; } if ((file_id = H5Fopen(H5_API_TEST_FILENAME, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) { @@ -6634,12 +7059,13 @@ test_write_multi_dataset_small_hyperslab(void) goto error; } - if (NULL == (data[i] = malloc(data_size))) + if (NULL == (wbuf_temp[i] = malloc(data_size))) TEST_ERROR; - data_c[i] = data[i]; for (size_t j = 0; j < data_size / DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_DTYPESIZE; j++) - ((int **)data)[i][j] = (int)i; + ((int **)wbuf_temp)[i][j] = (int)i; + + write_buf[i] = (const void *)wbuf_temp[i]; } for (i = 0; i < DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_SPACE_RANK; i++) { @@ -6661,16 +7087,16 @@ test_write_multi_dataset_small_hyperslab(void) } if (H5Dwrite_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, mspace_id_arr, fspace_id_arr, - H5P_DEFAULT, data_c) < 0) { + H5P_DEFAULT, write_buf) < 0) { H5_FAILED(); printf(" couldn't write to dataset '%s'\n", DATASET_SMALL_WRITE_MULTI_TEST_HYPERSLAB_DSET_NAME); goto error; } for (i = 0; i < DATASET_MULTI_COUNT; i++) { - if (data[i]) { - free(data[i]); - data[i] = NULL; + if (wbuf_temp[i]) { + free(wbuf_temp[i]); + wbuf_temp[i] = NULL; } if (H5Dclose(dset_id_arr[i]) < 0) TEST_ERROR; @@ -6695,9 +7121,9 @@ test_write_multi_dataset_small_hyperslab(void) H5E_BEGIN_TRY { for (i = 0; i < DATASET_MULTI_COUNT; i++) { - if (data[i]) { - free(data[i]); - data[i] = NULL; + if (wbuf_temp[i]) { + free(wbuf_temp[i]); + wbuf_temp[i] = NULL; } H5Dclose(dset_id_arr[i]); } @@ -6720,7 +7146,7 @@ static 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]; + 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; @@ -6730,8 +7156,8 @@ test_write_multi_dataset_small_point_selection(void) 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]; - const void *data_c[DATASET_MULTI_COUNT]; + const void *write_buf[DATASET_MULTI_COUNT]; + void *wbuf_temp[DATASET_MULTI_COUNT]; TESTING("small multi write to datasets with point selections"); @@ -6744,7 +7170,8 @@ test_write_multi_dataset_small_point_selection(void) } for (i = 0; i < DATASET_MULTI_COUNT; i++) { - data[i] = NULL; + write_buf[i] = NULL; + wbuf_temp[i] = NULL; dset_id_arr[i] = H5I_INVALID_HID; } @@ -6792,12 +7219,13 @@ test_write_multi_dataset_small_point_selection(void) goto error; } - if (NULL == (data[i] = malloc(data_size))) + if (NULL == (wbuf_temp[i] = malloc(data_size))) TEST_ERROR; - data_c[i] = data[i]; for (size_t j = 0; j < data_size / DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_DTYPESIZE; j++) - ((int **)data)[i][j] = (int)i; + ((int **)wbuf_temp)[i][j] = (int)i; + + write_buf[i] = (const void *)wbuf_temp[i]; } for (i = 0; i < DATASET_SMALL_WRITE_TEST_POINT_SELECTION_NUM_POINTS; i++) { @@ -6821,16 +7249,16 @@ test_write_multi_dataset_small_point_selection(void) } if (H5Dwrite_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, mspace_id_arr, fspace_id_arr, - H5P_DEFAULT, data_c) < 0) { + H5P_DEFAULT, write_buf) < 0) { H5_FAILED(); printf(" couldn't write to multiple datasets\n"); goto error; } for (i = 0; i < DATASET_MULTI_COUNT; i++) { - if (data[i]) { - free(data[i]); - data[i] = NULL; + if (wbuf_temp[i]) { + free(wbuf_temp[i]); + wbuf_temp[i] = NULL; } if (H5Dclose(dset_id_arr[i]) < 0) @@ -6856,8 +7284,8 @@ test_write_multi_dataset_small_point_selection(void) H5E_BEGIN_TRY { for (i = 0; i < DATASET_MULTI_COUNT; i++) { - if (data[i]) - free(data[i]); + if (wbuf_temp[i]) + free(wbuf_temp[i]); H5Dclose(dset_id_arr[i]); } @@ -6880,26 +7308,25 @@ test_write_multi_dataset_small_point_selection(void) static void test_write_multi_dataset_data_verification(void) { - 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]; - 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_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]; - const void *data_c[DATASET_MULTI_COUNT]; - void *write_buf[DATASET_MULTI_COUNT]; - const void *write_buf_c[DATASET_MULTI_COUNT]; + 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]; + 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_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]; + const void *write_buf[DATASET_MULTI_COUNT]; + void *wbuf_temp[DATASET_MULTI_COUNT]; void *read_buf[DATASET_MULTI_COUNT]; char dset_names[DATASET_MULTI_COUNT][DSET_NAME_BUF_SIZE]; @@ -6920,6 +7347,7 @@ test_write_multi_dataset_data_verification(void) select_all_arr[i] = H5S_ALL; read_buf[i] = NULL; write_buf[i] = NULL; + wbuf_temp[i] = NULL; data[i] = NULL; } @@ -6964,12 +7392,13 @@ test_write_multi_dataset_data_verification(void) if (NULL == (data[i] = malloc(data_size))) TEST_ERROR; - data_c[i] = data[i]; 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; + + write_buf[i] = (const void *)data[i]; } PASSED(); @@ -6981,7 +7410,7 @@ test_write_multi_dataset_data_verification(void) TESTING_2("H5Dwrite_multi using H5S_ALL then H5Dread_multi"); if (H5Dwrite_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, select_all_arr, select_all_arr, - H5P_DEFAULT, data_c) < 0) { + H5P_DEFAULT, write_buf) < 0) { H5_FAILED(); printf(" couldn't write to datasets"); PART_ERROR(H5Dwrite_multi_all_read); @@ -7078,16 +7507,14 @@ test_write_multi_dataset_data_verification(void) for (i = 0; i < DATASET_MULTI_COUNT; i++) { data_size = dims[1] * 2 * DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; - if (NULL == (write_buf[i] = malloc(data_size))) { + if (NULL == (wbuf_temp[i] = malloc(data_size))) { H5_FAILED(); printf(" couldn't allocate buffer for dataset write\n"); PART_ERROR(H5Dwrite_multi_hyperslab_read); } - write_buf_c[i] = write_buf[i]; - for (size_t j = 0; j < data_size / DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; j++) { - ((int *)write_buf[i])[j] = 56; + ((int *)wbuf_temp[i])[j] = 56; } data_size = 1; @@ -7100,6 +7527,8 @@ test_write_multi_dataset_data_verification(void) printf(" couldn't allocate buffer for datasets' data verification\n"); PART_ERROR(H5Dwrite_multi_hyperslab_read); } + + write_buf[i] = (const void *)wbuf_temp[i]; } if (H5Dread_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, select_all_arr, select_all_arr, @@ -7148,7 +7577,7 @@ test_write_multi_dataset_data_verification(void) } if (H5Dwrite_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, mspace_id_arr, fspace_id_arr, - H5P_DEFAULT, write_buf_c) < 0) { + H5P_DEFAULT, write_buf) < 0) { H5_FAILED(); printf(" couldn't write to datasets\n"); PART_ERROR(H5Dwrite_multi_hyperslab_read); @@ -7226,9 +7655,9 @@ test_write_multi_dataset_data_verification(void) data[i] = NULL; } - if (write_buf[i]) { - free(write_buf[i]); - write_buf[i] = NULL; + if (wbuf_temp[i]) { + free(wbuf_temp[i]); + wbuf_temp[i] = NULL; } if (read_buf[i]) { @@ -7242,14 +7671,9 @@ test_write_multi_dataset_data_verification(void) PART_END(H5Dwrite_multi_hyperslab_read); for (i = 0; i < DATASET_MULTI_COUNT; i++) { - if (data[i]) { - free(data[i]); - data[i] = NULL; - } - - if (write_buf[i]) { - free(write_buf[i]); - write_buf[i] = NULL; + if (wbuf_temp[i]) { + free(wbuf_temp[i]); + wbuf_temp[i] = NULL; } if (read_buf[i]) { @@ -7266,16 +7690,16 @@ test_write_multi_dataset_data_verification(void) DATASET_DATA_VERIFY_WRITE_TEST_NUM_POINTS * DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; for (i = 0; i < DATASET_MULTI_COUNT; i++) { - if (NULL == (write_buf[i] = malloc(data_size))) { + if (NULL == (wbuf_temp[i] = malloc(data_size))) { H5_FAILED(); printf(" couldn't allocate buffer for dataset write\n"); PART_ERROR(H5Dwrite_multi_point_sel_read); } - write_buf_c[i] = write_buf[i]; - for (size_t j = 0; j < data_size / DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; j++) - ((int **)write_buf)[i][j] = 13; + ((int **)wbuf_temp)[i][j] = 13; + + write_buf[i] = (const void *)wbuf_temp[i]; data_size = 1; @@ -7326,7 +7750,7 @@ test_write_multi_dataset_data_verification(void) } if (H5Dwrite_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, mspace_id_arr, fspace_id_arr, - H5P_DEFAULT, write_buf_c) < 0) { + H5P_DEFAULT, write_buf) < 0) { H5_FAILED(); printf(" couldn't write to datasets\n"); PART_ERROR(H5Dwrite_multi_point_sel_read); @@ -7428,9 +7852,9 @@ test_write_multi_dataset_data_verification(void) data[i] = NULL; } - if (write_buf[i]) { - free(write_buf[i]); - write_buf[i] = NULL; + if (wbuf_temp[i]) { + free(wbuf_temp[i]); + wbuf_temp[i] = NULL; } if (read_buf[i]) { @@ -7461,8 +7885,8 @@ test_write_multi_dataset_data_verification(void) for (i = 0; i < DATASET_MULTI_COUNT; i++) { if (data[i]) free(data[i]); - if (write_buf[i]) - free(write_buf[i]); + if (wbuf_temp[i]) + free(wbuf_temp[i]); if (read_buf[i]) free(read_buf[i]); @@ -7606,80 +8030,849 @@ test_write_dataset_invalid_params(void) err_ret = H5Dwrite(dset_id, DATASET_WRITE_INVALID_PARAMS_TEST_DSET_DTYPE, H5I_INVALID_HID, H5S_ALL, H5P_DEFAULT, data); } - H5E_END_TRY + H5E_END_TRY + + if (err_ret >= 0) { + H5_FAILED(); + printf(" wrote to dataset using H5Dwrite with an invalid memory dataspace!\n"); + PART_ERROR(H5Dwrite_invalid_mem_dataspace); + } + + PASSED(); + } + PART_END(H5Dwrite_invalid_mem_dataspace); + + PART_BEGIN(H5Dwrite_invalid_file_dataspace) + { + TESTING_2("H5Dwrite with an invalid file dataspace"); + + H5E_BEGIN_TRY + { + err_ret = H5Dwrite(dset_id, DATASET_WRITE_INVALID_PARAMS_TEST_DSET_DTYPE, H5S_ALL, + H5I_INVALID_HID, H5P_DEFAULT, data); + } + H5E_END_TRY + + if (err_ret >= 0) { + H5_FAILED(); + printf(" wrote to dataset using H5Dwrite with an invalid file dataspace!\n"); + PART_ERROR(H5Dwrite_invalid_file_dataspace); + } + + PASSED(); + } + PART_END(H5Dwrite_invalid_file_dataspace); + + PART_BEGIN(H5Dwrite_invalid_dxpl) + { + TESTING_2("H5Dwrite with an invalid DXPL"); + + H5E_BEGIN_TRY + { + err_ret = H5Dwrite(dset_id, DATASET_WRITE_INVALID_PARAMS_TEST_DSET_DTYPE, H5S_ALL, H5S_ALL, + H5I_INVALID_HID, data); + } + H5E_END_TRY + + if (err_ret >= 0) { + H5_FAILED(); + printf(" wrote to dataset using H5Dwrite with an invalid DXPL!\n"); + PART_ERROR(H5Dwrite_invalid_dxpl); + } + + PASSED(); + } + PART_END(H5Dwrite_invalid_dxpl); + + PART_BEGIN(H5Dwrite_invalid_data_buf) + { + TESTING_2("H5Dwrite with an invalid data buffer"); + + H5E_BEGIN_TRY + { + err_ret = H5Dwrite(dset_id, DATASET_WRITE_INVALID_PARAMS_TEST_DSET_DTYPE, H5S_ALL, H5S_ALL, + H5P_DEFAULT, NULL); + } + H5E_END_TRY + + if (err_ret >= 0) { + H5_FAILED(); + printf(" wrote to dataset using H5Dwrite with an invalid data buffer!\n"); + PART_ERROR(H5Dwrite_invalid_data_buf); + } + + PASSED(); + } + PART_END(H5Dwrite_invalid_data_buf); + } + END_MULTIPART; + + TESTING_2("test cleanup"); + + 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; + +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; +} + +/* + * A test to ensure that strings of any encoding + * can be written to and read from a dataset + */ +static void +test_dataset_string_encodings(void) +{ + hid_t file_id = H5I_INVALID_HID; + hid_t container_group = H5I_INVALID_HID; + hid_t dset_id1 = H5I_INVALID_HID; + hid_t dset_id2 = H5I_INVALID_HID; + hid_t type_id1 = H5I_INVALID_HID; + hid_t type_id2 = H5I_INVALID_HID; + hid_t space_id = H5I_INVALID_HID; + hsize_t dims[DATASET_STRING_ENCODINGS_RANK] = {DATASET_STRING_ENCODINGS_EXTENT}; + size_t ascii_str_size = 0; + size_t utf8_str_size = 0; + char *write_buf = NULL; + char *read_buf = NULL; + + TESTING_MULTIPART("string encoding read/write correctness on datasets"); + + /* 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_ATTR_BASIC)) { + SKIPPED(); + printf(" API functions for basic file, group, basic or more dataset aren't supported with this " + "connector\n"); + return; + } + + TESTING_2("test setup"); + + ascii_str_size = strlen(DATASET_STRING_ENCODINGS_ASCII_STRING); + utf8_str_size = strlen(DATASET_STRING_ENCODINGS_UTF8_STRING); + + 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 ((space_id = H5Screate_simple(DATASET_STRING_ENCODINGS_RANK, dims, NULL)) < 0) { + H5_FAILED(); + printf(" couldn't create dataspace\n"); + goto error; + } + + if ((type_id1 = H5Tcopy(H5T_C_S1)) < 0) { + H5_FAILED(); + printf(" couldn't copy builtin string datatype\n"); + goto error; + } + + if ((H5Tset_size(type_id1, ascii_str_size)) < 0) { + H5_FAILED(); + printf(" couldn't set size of string datatype\n"); + goto error; + } + + if ((H5Tset_cset(type_id1, H5T_CSET_ASCII)) < 0) { + H5_FAILED(); + printf(" couldn't set character set of string to ASCII\n"); + goto error; + } + + if ((dset_id1 = H5Dcreate(container_group, DATASET_STRING_ENCODINGS_DSET_NAME1, type_id1, space_id, + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset with ascii string\n"); + goto error; + } + + if ((type_id2 = H5Tcopy(H5T_C_S1)) < 0) { + H5_FAILED(); + printf(" couldn't copy builtin string datatype\n"); + goto error; + } + + if ((H5Tset_size(type_id2, utf8_str_size)) < 0) { + H5_FAILED(); + printf(" couldn't set size of string datatype\n"); + goto error; + } + + if ((H5Tset_cset(type_id2, H5T_CSET_UTF8)) < 0) { + H5_FAILED(); + printf(" couldn't set character set of string to UTF-8\n"); + goto error; + } + + if ((dset_id2 = H5Dcreate(container_group, DATASET_STRING_ENCODINGS_DSET_NAME2, type_id2, space_id, + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset with UTF-8 string\n"); + goto error; + } + + PASSED(); + + BEGIN_MULTIPART + { + PART_BEGIN(ASCII_cset) + { + TESTING_2("ASCII character set"); + /* Dataset with ASCII string datatype */ + if ((write_buf = calloc(1, ascii_str_size + 1)) == NULL) { + H5_FAILED(); + printf(" couldn't allocate memory for write buffer\n"); + PART_ERROR(ASCII_cset); + } + + memcpy(write_buf, DATASET_STRING_ENCODINGS_ASCII_STRING, ascii_str_size); + + if ((H5Dwrite(dset_id1, type_id1, H5S_ALL, H5S_ALL, H5P_DEFAULT, write_buf)) < 0) { + H5_FAILED(); + printf(" couldn't write to dataset with ASCII string\n"); + PART_ERROR(ASCII_cset); + } + + if ((read_buf = calloc(1, ascii_str_size + 1)) == NULL) { + H5_FAILED(); + printf(" couldn't allocate memory for read buffer\n"); + PART_ERROR(ASCII_cset); + } + + if ((H5Dread(dset_id1, type_id1, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_buf)) < 0) { + H5_FAILED(); + printf(" couldn't read from dataset with ASCII string\n"); + PART_ERROR(ASCII_cset); + } + + if (strncmp(write_buf, read_buf, ascii_str_size)) { + H5_FAILED(); + printf(" incorrect data read from dataset with ASCII string\n"); + PART_ERROR(ASCII_cset); + } + + free(write_buf); + write_buf = NULL; + + free(read_buf); + read_buf = NULL; + + PASSED(); + } + PART_END(ASCII_cset); + + PART_BEGIN(UTF8_cset) + { + TESTING_2("UTF-8 character set"); + /* Dataset with UTF-8 string datatype */ + if ((write_buf = calloc(1, utf8_str_size + 1)) == NULL) { + H5_FAILED(); + printf(" couldn't allocate memory for write buffer\n"); + PART_ERROR(UTF8_cset); + } + + memcpy(write_buf, DATASET_STRING_ENCODINGS_UTF8_STRING, utf8_str_size); + + if ((H5Dwrite(dset_id2, type_id2, H5S_ALL, H5S_ALL, H5P_DEFAULT, write_buf)) < 0) { + H5_FAILED(); + printf(" couldn't write to dataset with ASCII string\n"); + PART_ERROR(UTF8_cset); + } + + if ((read_buf = calloc(1, utf8_str_size + 1)) == NULL) { + H5_FAILED(); + printf(" couldn't allocate memory for read buffer\n"); + PART_ERROR(UTF8_cset); + } + + if ((H5Dread(dset_id2, type_id2, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_buf)) < 0) { + H5_FAILED(); + printf(" couldn't read from dataset with ASCII string\n"); + PART_ERROR(UTF8_cset); + } + + if (strncmp(write_buf, read_buf, utf8_str_size)) { + H5_FAILED(); + printf(" incorrect data read from dataset with ASCII string\n"); + PART_ERROR(UTF8_cset); + } + + free(write_buf); + write_buf = NULL; + + free(read_buf); + read_buf = NULL; + + PASSED(); + } + PART_END(UTF8_cset); + + PASSED(); + } + END_MULTIPART; + + TESTING_2("test cleanup"); + + if (H5Fclose(file_id) < 0) + TEST_ERROR; + if (H5Gclose(container_group) < 0) + TEST_ERROR; + if (H5Dclose(dset_id1) < 0) + TEST_ERROR; + if (H5Dclose(dset_id2) < 0) + TEST_ERROR; + if (H5Tclose(type_id1) < 0) + TEST_ERROR; + if (H5Tclose(type_id2) < 0) + TEST_ERROR; + if (write_buf) + free(write_buf); + if (read_buf) + free(read_buf); + + PASSED(); + + return; + +error: + H5E_BEGIN_TRY + { + H5Fclose(file_id); + H5Gclose(container_group); + H5Dclose(dset_id1); + H5Dclose(dset_id2); + H5Tclose(type_id1); + H5Tclose(type_id2); + if (write_buf) + free(write_buf); + if (read_buf) + free(read_buf); + } + H5E_END_TRY; + + return; +} + +/* + * A test to ensure that data is read back correctly from a dataset after it has + * been written, using type conversion with builtin types. + */ +static void +test_dataset_builtin_type_conversion(void) +{ + hssize_t space_npoints; + hsize_t dims[DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK] = {10, 10, 10}; + hsize_t start[DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK]; + hsize_t stride[DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK]; + hsize_t count[DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK]; + hsize_t block[DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK]; + hsize_t points[DATASET_DATA_BUILTIN_CONVERSION_TEST_NUM_POINTS * + DATASET_DATA_BUILTIN_CONVERSION_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; + hid_t file_type_id = H5I_INVALID_HID; + H5T_order_t native_order; + void *data = NULL; + void *write_buf = NULL; + void *read_buf = NULL; + + TESTING_MULTIPART( + "verification of dataset data using H5Dwrite then H5Dread with type conversion of builtin types"); + + /* 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, basic or more dataset aren't supported with this " + "connector\n"); + return; + } + + TESTING_2("test setup"); + + if ((native_order = H5Tget_order(DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE)) < 0) { + H5_FAILED(); + printf(" couldn't get native byte order\n"); + goto error; + } + if (native_order == H5T_ORDER_LE) + file_type_id = H5T_STD_I32BE; + else + file_type_id = H5T_STD_I32LE; + + 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_DATA_BUILTIN_CONVERSION_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); + goto error; + } + + if ((fspace_id = H5Screate_simple(DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK, dims, NULL)) < 0) + TEST_ERROR; + + if ((dset_id = H5Dcreate2(group_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME, file_type_id, + fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset '%s'\n", DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + goto error; + } + + for (i = 0, data_size = 1; i < DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK; i++) + data_size *= dims[i]; + data_size *= DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; + + if (NULL == (data = malloc(data_size))) + TEST_ERROR; + + for (i = 0; i < data_size / DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; i++) + ((int *)data)[i] = (int)i; + + PASSED(); + + BEGIN_MULTIPART + { + PART_BEGIN(H5Dwrite_all_read) + { + TESTING_2("H5Dwrite then H5Dread with H5S_ALL selection"); + + if (H5Dwrite(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, H5S_ALL, H5S_ALL, + H5P_DEFAULT, data) < 0) { + H5_FAILED(); + printf(" couldn't write to dataset '%s'\n", + DATASET_DATA_BUILTIN_CONVERSION_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_BUILTIN_CONVERSION_TEST_DSET_NAME, H5P_DEFAULT)) < + 0) { + H5_FAILED(); + printf(" couldn't open dataset '%s'\n", DATASET_DATA_BUILTIN_CONVERSION_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_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE))) { + H5_FAILED(); + printf(" couldn't allocate buffer for dataset read\n"); + PART_ERROR(H5Dwrite_all_read); + } + + if (H5Dread(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, H5S_ALL, H5S_ALL, + H5P_DEFAULT, data) < 0) { + H5_FAILED(); + printf(" couldn't read from dataset '%s'\n", + DATASET_DATA_BUILTIN_CONVERSION_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_BUILTIN_CONVERSION_TEST_MEM_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_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; i++) + ((int *)write_buf)[i] = 56; + + for (i = 0, data_size = 1; i < DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK; i++) + data_size *= dims[i]; + data_size *= DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_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_BUILTIN_CONVERSION_TEST_MEM_DTYPE, H5S_ALL, H5S_ALL, + H5P_DEFAULT, data) < 0) { + H5_FAILED(); + printf(" couldn't read from dataset '%s'\n", + DATASET_DATA_BUILTIN_CONVERSION_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); + } + + { + 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 (H5Dwrite(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, mspace_id, fspace_id, + H5P_DEFAULT, write_buf) < 0) { + H5_FAILED(); + printf(" couldn't write to dataset '%s'\n", + DATASET_DATA_BUILTIN_CONVERSION_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_BUILTIN_CONVERSION_TEST_DSET_NAME, H5P_DEFAULT)) < + 0) { + H5_FAILED(); + printf(" couldn't open dataset '%s'\n", DATASET_DATA_BUILTIN_CONVERSION_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_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE))) { + H5_FAILED(); + printf(" couldn't allocate buffer for dataset read\n"); + PART_ERROR(H5Dwrite_hyperslab_read); + } + + if (H5Dread(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, H5S_ALL, H5S_ALL, + H5P_DEFAULT, read_buf) < 0) { + H5_FAILED(); + printf(" couldn't read from dataset '%s'\n", + DATASET_DATA_BUILTIN_CONVERSION_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(H5Dwrite_hyperslab_read); + + PART_BEGIN(H5Dwrite_point_sel_read) + { + TESTING_2("H5Dwrite using point selection then H5Dread"); + + data_size = DATASET_DATA_BUILTIN_CONVERSION_TEST_NUM_POINTS * + DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_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 < data_size / DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; i++) + ((int *)write_buf)[i] = 13; + + for (i = 0, data_size = 1; i < DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK; i++) + data_size *= dims[i]; + data_size *= DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; + + if (NULL == (data = malloc(data_size))) { + H5_FAILED(); + printf(" couldn't allocate buffer for dataset data verification\n"); + PART_ERROR(H5Dwrite_point_sel_read); + } + + if (H5Dread(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, H5S_ALL, H5S_ALL, + H5P_DEFAULT, data) < 0) { + H5_FAILED(); + printf(" couldn't read from dataset '%s'\n", + DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_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; + } + } + } + + /* Select a series of 10 points in the dataset */ + for (i = 0; i < DATASET_DATA_BUILTIN_CONVERSION_TEST_NUM_POINTS; i++) { + size_t j; + + for (j = 0; j < DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK; j++) + points[(i * DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK) + j] = i; + } + + if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_DATA_BUILTIN_CONVERSION_TEST_NUM_POINTS, + points) < 0) { + H5_FAILED(); + printf(" couldn't select elements in dataspace\n"); + PART_ERROR(H5Dwrite_point_sel_read); + } + + { + hsize_t mdims[] = {(hsize_t)DATASET_DATA_BUILTIN_CONVERSION_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 (H5Dwrite(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, mspace_id, fspace_id, + H5P_DEFAULT, write_buf) < 0) { + H5_FAILED(); + printf(" couldn't write to dataset '%s'\n", + DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_point_sel_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 (err_ret >= 0) { + if ((dset_id = H5Dopen2(group_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME, H5P_DEFAULT)) < + 0) { H5_FAILED(); - printf(" wrote to dataset using H5Dwrite with an invalid memory dataspace!\n"); - PART_ERROR(H5Dwrite_invalid_mem_dataspace); - } - - PASSED(); - } - PART_END(H5Dwrite_invalid_mem_dataspace); - - PART_BEGIN(H5Dwrite_invalid_file_dataspace) - { - TESTING_2("H5Dwrite with an invalid file dataspace"); - - H5E_BEGIN_TRY - { - err_ret = H5Dwrite(dset_id, DATASET_WRITE_INVALID_PARAMS_TEST_DSET_DTYPE, H5S_ALL, - H5I_INVALID_HID, H5P_DEFAULT, data); + printf(" couldn't open dataset '%s'\n", DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_point_sel_read); } - H5E_END_TRY - if (err_ret >= 0) { + if ((fspace_id = H5Dget_space(dset_id)) < 0) { H5_FAILED(); - printf(" wrote to dataset using H5Dwrite with an invalid file dataspace!\n"); - PART_ERROR(H5Dwrite_invalid_file_dataspace); + printf(" couldn't get dataset dataspace\n"); + PART_ERROR(H5Dwrite_point_sel_read); } - PASSED(); - } - PART_END(H5Dwrite_invalid_file_dataspace); - - PART_BEGIN(H5Dwrite_invalid_dxpl) - { - TESTING_2("H5Dwrite with an invalid DXPL"); - - H5E_BEGIN_TRY - { - err_ret = H5Dwrite(dset_id, DATASET_WRITE_INVALID_PARAMS_TEST_DSET_DTYPE, H5S_ALL, H5S_ALL, - H5I_INVALID_HID, data); + 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_END_TRY - if (err_ret >= 0) { + if (NULL == (read_buf = malloc((hsize_t)space_npoints * + DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE))) { H5_FAILED(); - printf(" wrote to dataset using H5Dwrite with an invalid DXPL!\n"); - PART_ERROR(H5Dwrite_invalid_dxpl); + printf(" couldn't allocate buffer for dataset read\n"); + PART_ERROR(H5Dwrite_point_sel_read); } - PASSED(); - } - PART_END(H5Dwrite_invalid_dxpl); - - PART_BEGIN(H5Dwrite_invalid_data_buf) - { - TESTING_2("H5Dwrite with an invalid data buffer"); - - H5E_BEGIN_TRY - { - err_ret = H5Dwrite(dset_id, DATASET_WRITE_INVALID_PARAMS_TEST_DSET_DTYPE, H5S_ALL, H5S_ALL, - H5P_DEFAULT, NULL); + if (H5Dread(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, H5S_ALL, H5S_ALL, + H5P_DEFAULT, read_buf) < 0) { + H5_FAILED(); + printf(" couldn't read from dataset '%s'\n", + DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_point_sel_read); } - H5E_END_TRY - if (err_ret >= 0) { + if (memcmp(data, read_buf, data_size)) { H5_FAILED(); - printf(" wrote to dataset using H5Dwrite with an invalid data buffer!\n"); - PART_ERROR(H5Dwrite_invalid_data_buf); + printf(" point selection data verification failed\n"); + PART_ERROR(H5Dwrite_point_sel_read); } PASSED(); } - PART_END(H5Dwrite_invalid_data_buf); + PART_END(H5Dwrite_point_sel_read); } END_MULTIPART; @@ -7690,6 +8883,16 @@ test_write_dataset_invalid_params(void) data = NULL; } + if (write_buf) { + free(write_buf); + write_buf = NULL; + } + + if (read_buf) { + free(read_buf); + read_buf = NULL; + } + if (H5Sclose(fspace_id) < 0) TEST_ERROR; if (H5Dclose(dset_id) < 0) @@ -7710,6 +8913,11 @@ test_write_dataset_invalid_params(void) { 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); @@ -7721,39 +8929,34 @@ test_write_dataset_invalid_params(void) return; } -/* - * A test to ensure that data is read back correctly from a dataset after it has - * been written, using type conversion with builtin types. - */ static void -test_dataset_builtin_type_conversion(void) +test_dataset_real_to_int_conversion(void) { - hssize_t space_npoints; - hsize_t dims[DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK] = {10, 10, 10}; - hsize_t start[DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK]; - hsize_t stride[DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK]; - hsize_t count[DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK]; - hsize_t block[DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK]; - hsize_t points[DATASET_DATA_BUILTIN_CONVERSION_TEST_NUM_POINTS * - DATASET_DATA_BUILTIN_CONVERSION_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; - hid_t file_type_id = H5I_INVALID_HID; - H5T_order_t native_order; - void *data = NULL; - void *write_buf = NULL; - void *read_buf = NULL; + hssize_t space_npoints; + hsize_t dims[DATASET_DATA_REAL_CONVERSION_TEST_DSET_SPACE_RANK] = {10, 10, 10}; + hsize_t start[DATASET_DATA_REAL_CONVERSION_TEST_DSET_SPACE_RANK]; + hsize_t stride[DATASET_DATA_REAL_CONVERSION_TEST_DSET_SPACE_RANK]; + hsize_t count[DATASET_DATA_REAL_CONVERSION_TEST_DSET_SPACE_RANK]; + hsize_t block[DATASET_DATA_REAL_CONVERSION_TEST_DSET_SPACE_RANK]; + hsize_t points[DATASET_DATA_REAL_CONVERSION_TEST_NUM_POINTS * + DATASET_DATA_REAL_CONVERSION_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; + hid_t real_type_id = DATASET_DATA_REAL_CONVERSION_TEST_REAL_TYPE; + void *data = NULL; + void *write_buf = NULL; + void *read_buf = NULL; TESTING_MULTIPART( - "verification of dataset data using H5Dwrite then H5Dread with type conversion of builtin types"); + "verification of dataset data using H5Dwrite then H5Dread with real <-> integer type conversion"); /* 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"); @@ -7762,16 +8965,6 @@ test_dataset_builtin_type_conversion(void) TESTING_2("test setup"); - if ((native_order = H5Tget_order(DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE)) < 0) { - H5_FAILED(); - printf(" couldn't get native byte order\n"); - goto error; - } - if (native_order == H5T_ORDER_LE) - file_type_id = H5T_STD_I32BE; - else - file_type_id = H5T_STD_I32LE; - 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); @@ -7784,31 +8977,32 @@ test_dataset_builtin_type_conversion(void) goto error; } - if ((group_id = H5Gcreate2(container_group, DATASET_DATA_BUILTIN_CONVERSION_TEST_GROUP_NAME, H5P_DEFAULT, + if ((group_id = H5Gcreate2(container_group, DATASET_DATA_REAL_CONVERSION_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_REAL_CONVERSION_TEST_GROUP_NAME); goto error; } - if ((fspace_id = H5Screate_simple(DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK, dims, NULL)) < 0) + if ((fspace_id = H5Screate_simple(DATASET_DATA_REAL_CONVERSION_TEST_DSET_SPACE_RANK, dims, NULL)) < 0) TEST_ERROR; - if ((dset_id = H5Dcreate2(group_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME, file_type_id, - fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { + if ((dset_id = H5Dcreate2(group_id, DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME, real_type_id, fspace_id, + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { H5_FAILED(); - printf(" couldn't create dataset '%s'\n", DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + printf(" couldn't create dataset '%s'\n", DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME); goto error; } - for (i = 0, data_size = 1; i < DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK; i++) + for (i = 0, data_size = 1; i < DATASET_DATA_REAL_CONVERSION_TEST_DSET_SPACE_RANK; i++) data_size *= dims[i]; - data_size *= DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; + data_size *= DATASET_DATA_REAL_CONVERSION_TEST_INT_DTYPESIZE; if (NULL == (data = malloc(data_size))) TEST_ERROR; - for (i = 0; i < data_size / DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; i++) + for (i = 0; i < data_size / DATASET_DATA_REAL_CONVERSION_TEST_INT_DTYPESIZE; i++) ((int *)data)[i] = (int)i; PASSED(); @@ -7817,13 +9011,12 @@ test_dataset_builtin_type_conversion(void) { PART_BEGIN(H5Dwrite_all_read) { - TESTING_2("H5Dwrite then H5Dread with H5S_ALL selection"); + TESTING_2("write then read int from real dataset with H5S_ALL selection"); - if (H5Dwrite(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, H5S_ALL, H5S_ALL, - H5P_DEFAULT, data) < 0) { + if (H5Dwrite(dset_id, DATASET_DATA_REAL_CONVERSION_TEST_INT_TYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, + data) < 0) { H5_FAILED(); - printf(" couldn't write to dataset '%s'\n", - DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + printf(" couldn't write to dataset '%s'\n", DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME); PART_ERROR(H5Dwrite_all_read); } @@ -7837,7 +9030,7 @@ test_dataset_builtin_type_conversion(void) { H5Sclose(fspace_id); } - H5E_END_TRY + H5E_END_TRY; fspace_id = H5I_INVALID_HID; } if (dset_id >= 0) { @@ -7845,14 +9038,14 @@ test_dataset_builtin_type_conversion(void) { H5Dclose(dset_id); } - H5E_END_TRY + H5E_END_TRY; dset_id = H5I_INVALID_HID; } - if ((dset_id = H5Dopen2(group_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME, H5P_DEFAULT)) < + if ((dset_id = H5Dopen2(group_id, DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME, H5P_DEFAULT)) < 0) { H5_FAILED(); - printf(" couldn't open dataset '%s'\n", DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + printf(" couldn't open dataset '%s'\n", DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME); PART_ERROR(H5Dwrite_all_read); } @@ -7868,18 +9061,17 @@ test_dataset_builtin_type_conversion(void) PART_ERROR(H5Dwrite_all_read); } - if (NULL == (data = malloc((hsize_t)space_npoints * - DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE))) { + if (NULL == + (data = malloc((hsize_t)space_npoints * DATASET_DATA_REAL_CONVERSION_TEST_INT_DTYPESIZE))) { H5_FAILED(); printf(" couldn't allocate buffer for dataset read\n"); PART_ERROR(H5Dwrite_all_read); } - if (H5Dread(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, H5S_ALL, H5S_ALL, - H5P_DEFAULT, data) < 0) { + if (H5Dread(dset_id, DATASET_DATA_REAL_CONVERSION_TEST_INT_TYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, + data) < 0) { H5_FAILED(); - printf(" couldn't read from dataset '%s'\n", - DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + printf(" couldn't read from dataset '%s'\n", DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME); PART_ERROR(H5Dwrite_all_read); } @@ -7899,11 +9091,26 @@ test_dataset_builtin_type_conversion(void) } PART_END(H5Dwrite_all_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; + } + PART_BEGIN(H5Dwrite_hyperslab_read) { - TESTING_2("H5Dwrite using hyperslab selection then H5Dread"); + TESTING_2("write then read int from real dataset with hyperslab selection"); - data_size = dims[1] * 2 * DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; + data_size = dims[1] * 2 * DATASET_DATA_REAL_CONVERSION_TEST_INT_DTYPESIZE; if (NULL == (write_buf = malloc(data_size))) { H5_FAILED(); @@ -7911,26 +9118,21 @@ test_dataset_builtin_type_conversion(void) PART_ERROR(H5Dwrite_hyperslab_read); } - for (i = 0; i < data_size / DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; i++) + for (i = 0; i < data_size / DATASET_DATA_REAL_CONVERSION_TEST_INT_DTYPESIZE; i++) ((int *)write_buf)[i] = 56; - for (i = 0, data_size = 1; i < DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK; i++) + for (i = 0, data_size = 1; i < DATASET_DATA_REAL_CONVERSION_TEST_DSET_SPACE_RANK; i++) data_size *= dims[i]; - data_size *= DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; + data_size *= DATASET_DATA_REAL_CONVERSION_TEST_INT_DTYPESIZE; - if (NULL == (data = malloc(data_size))) { + if (NULL == (data = calloc(1, 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_BUILTIN_CONVERSION_TEST_MEM_DTYPE, H5S_ALL, H5S_ALL, - H5P_DEFAULT, data) < 0) { - H5_FAILED(); - printf(" couldn't read from dataset '%s'\n", - DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); - PART_ERROR(H5Dwrite_hyperslab_read); - } + for (i = 0; i < dims[0] * dims[1] * dims[2]; i++) + ((int *)data)[i] = (int)i; for (i = 0; i < 2; i++) { size_t j; @@ -7963,11 +9165,10 @@ test_dataset_builtin_type_conversion(void) } } - if (H5Dwrite(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, mspace_id, fspace_id, + if (H5Dwrite(dset_id, DATASET_DATA_REAL_CONVERSION_TEST_INT_TYPE, mspace_id, fspace_id, H5P_DEFAULT, write_buf) < 0) { H5_FAILED(); - printf(" couldn't write to dataset '%s'\n", - DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + printf(" couldn't write to dataset '%s'\n", DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME); PART_ERROR(H5Dwrite_hyperslab_read); } @@ -7976,7 +9177,7 @@ test_dataset_builtin_type_conversion(void) { H5Sclose(mspace_id); } - H5E_END_TRY + H5E_END_TRY; mspace_id = H5I_INVALID_HID; } if (fspace_id >= 0) { @@ -7984,7 +9185,7 @@ test_dataset_builtin_type_conversion(void) { H5Sclose(fspace_id); } - H5E_END_TRY + H5E_END_TRY; fspace_id = H5I_INVALID_HID; } if (dset_id >= 0) { @@ -7992,14 +9193,14 @@ test_dataset_builtin_type_conversion(void) { H5Dclose(dset_id); } - H5E_END_TRY + H5E_END_TRY; dset_id = H5I_INVALID_HID; } - if ((dset_id = H5Dopen2(group_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME, H5P_DEFAULT)) < + if ((dset_id = H5Dopen2(group_id, DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME, H5P_DEFAULT)) < 0) { H5_FAILED(); - printf(" couldn't open dataset '%s'\n", DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + printf(" couldn't open dataset '%s'\n", DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME); PART_ERROR(H5Dwrite_hyperslab_read); } @@ -8016,17 +9217,16 @@ test_dataset_builtin_type_conversion(void) } if (NULL == (read_buf = malloc((hsize_t)space_npoints * - DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE))) { + DATASET_DATA_REAL_CONVERSION_TEST_INT_DTYPESIZE))) { H5_FAILED(); printf(" couldn't allocate buffer for dataset read\n"); PART_ERROR(H5Dwrite_hyperslab_read); } - if (H5Dread(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, H5S_ALL, H5S_ALL, - H5P_DEFAULT, read_buf) < 0) { + if (H5Dread(dset_id, DATASET_DATA_REAL_CONVERSION_TEST_INT_TYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, + read_buf) < 0) { H5_FAILED(); - printf(" couldn't read from dataset '%s'\n", - DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + printf(" couldn't read from dataset '%s'\n", DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME); PART_ERROR(H5Dwrite_hyperslab_read); } @@ -8055,12 +9255,27 @@ test_dataset_builtin_type_conversion(void) } PART_END(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; + } + PART_BEGIN(H5Dwrite_point_sel_read) { - TESTING_2("H5Dwrite using point selection then H5Dread"); + TESTING_2("write then read int from real dataset with point selection"); - data_size = DATASET_DATA_BUILTIN_CONVERSION_TEST_NUM_POINTS * - DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; + data_size = DATASET_DATA_REAL_CONVERSION_TEST_NUM_POINTS * + DATASET_DATA_REAL_CONVERSION_TEST_INT_DTYPESIZE; if (NULL == (write_buf = malloc(data_size))) { H5_FAILED(); @@ -8068,12 +9283,12 @@ test_dataset_builtin_type_conversion(void) PART_ERROR(H5Dwrite_point_sel_read); } - for (i = 0; i < data_size / DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; i++) + for (i = 0; i < data_size / DATASET_DATA_REAL_CONVERSION_TEST_INT_DTYPESIZE; i++) ((int *)write_buf)[i] = 13; - for (i = 0, data_size = 1; i < DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK; i++) + for (i = 0, data_size = 1; i < DATASET_DATA_REAL_CONVERSION_TEST_DSET_SPACE_RANK; i++) data_size *= dims[i]; - data_size *= DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; + data_size *= DATASET_DATA_REAL_CONVERSION_TEST_INT_DTYPESIZE; if (NULL == (data = malloc(data_size))) { H5_FAILED(); @@ -8081,11 +9296,10 @@ test_dataset_builtin_type_conversion(void) PART_ERROR(H5Dwrite_point_sel_read); } - if (H5Dread(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, H5S_ALL, H5S_ALL, - H5P_DEFAULT, data) < 0) { + if (H5Dread(dset_id, DATASET_DATA_REAL_CONVERSION_TEST_INT_TYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, + data) < 0) { H5_FAILED(); - printf(" couldn't read from dataset '%s'\n", - DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + printf(" couldn't read from dataset '%s'\n", DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME); PART_ERROR(H5Dwrite_point_sel_read); } @@ -8103,14 +9317,14 @@ test_dataset_builtin_type_conversion(void) } /* Select a series of 10 points in the dataset */ - for (i = 0; i < DATASET_DATA_BUILTIN_CONVERSION_TEST_NUM_POINTS; i++) { + for (i = 0; i < DATASET_DATA_REAL_CONVERSION_TEST_NUM_POINTS; i++) { size_t j; - for (j = 0; j < DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK; j++) - points[(i * DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK) + j] = i; + for (j = 0; j < DATASET_DATA_REAL_CONVERSION_TEST_DSET_SPACE_RANK; j++) + points[(i * DATASET_DATA_REAL_CONVERSION_TEST_DSET_SPACE_RANK) + j] = i; } - if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_DATA_BUILTIN_CONVERSION_TEST_NUM_POINTS, + if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_DATA_REAL_CONVERSION_TEST_NUM_POINTS, points) < 0) { H5_FAILED(); printf(" couldn't select elements in dataspace\n"); @@ -8118,7 +9332,7 @@ test_dataset_builtin_type_conversion(void) } { - hsize_t mdims[] = {(hsize_t)DATASET_DATA_BUILTIN_CONVERSION_TEST_NUM_POINTS}; + hsize_t mdims[] = {(hsize_t)DATASET_DATA_REAL_CONVERSION_TEST_NUM_POINTS}; if ((mspace_id = H5Screate_simple(1, mdims, NULL)) < 0) { H5_FAILED(); @@ -8127,11 +9341,10 @@ test_dataset_builtin_type_conversion(void) } } - if (H5Dwrite(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, mspace_id, fspace_id, + if (H5Dwrite(dset_id, DATASET_DATA_REAL_CONVERSION_TEST_INT_TYPE, mspace_id, fspace_id, H5P_DEFAULT, write_buf) < 0) { H5_FAILED(); - printf(" couldn't write to dataset '%s'\n", - DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + printf(" couldn't write to dataset '%s'\n", DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME); PART_ERROR(H5Dwrite_point_sel_read); } @@ -8140,7 +9353,7 @@ test_dataset_builtin_type_conversion(void) { H5Sclose(mspace_id); } - H5E_END_TRY + H5E_END_TRY; mspace_id = H5I_INVALID_HID; } if (fspace_id >= 0) { @@ -8148,7 +9361,7 @@ test_dataset_builtin_type_conversion(void) { H5Sclose(fspace_id); } - H5E_END_TRY + H5E_END_TRY; fspace_id = H5I_INVALID_HID; } if (dset_id >= 0) { @@ -8156,14 +9369,14 @@ test_dataset_builtin_type_conversion(void) { H5Dclose(dset_id); } - H5E_END_TRY + H5E_END_TRY; dset_id = H5I_INVALID_HID; } - if ((dset_id = H5Dopen2(group_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME, H5P_DEFAULT)) < + if ((dset_id = H5Dopen2(group_id, DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME, H5P_DEFAULT)) < 0) { H5_FAILED(); - printf(" couldn't open dataset '%s'\n", DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + printf(" couldn't open dataset '%s'\n", DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME); PART_ERROR(H5Dwrite_point_sel_read); } @@ -8180,17 +9393,16 @@ test_dataset_builtin_type_conversion(void) } if (NULL == (read_buf = malloc((hsize_t)space_npoints * - DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE))) { + DATASET_DATA_REAL_CONVERSION_TEST_INT_DTYPESIZE))) { H5_FAILED(); printf(" couldn't allocate buffer for dataset read\n"); PART_ERROR(H5Dwrite_point_sel_read); } - if (H5Dread(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, H5S_ALL, H5S_ALL, - H5P_DEFAULT, read_buf) < 0) { + if (H5Dread(dset_id, DATASET_DATA_REAL_CONVERSION_TEST_INT_TYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, + read_buf) < 0) { H5_FAILED(); - printf(" couldn't read from dataset '%s'\n", - DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + printf(" couldn't read from dataset '%s'\n", DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME); PART_ERROR(H5Dwrite_point_sel_read); } @@ -8254,7 +9466,7 @@ test_dataset_builtin_type_conversion(void) H5Gclose(container_group); H5Fclose(file_id); } - H5E_END_TRY + H5E_END_TRY; return; } @@ -12469,6 +13681,8 @@ H5_api_dataset_test_add(void) "point selection I/O with all selection in memory and points in file", NULL, testframe_flags); AddTest("test_read_dataset_invalid_params", test_read_dataset_invalid_params, NULL, "H5Dread with invalid parameters", NULL, testframe_flags); + AddTest("test_dataset_string_encodings", test_dataset_string_encodings, NULL, + "dataset string encoding correctness", NULL, testframe_flags); AddTest("test_write_dataset_small_all", test_write_dataset_small_all, NULL, "small write to dataset with H5S_ALL", NULL, testframe_flags); AddTest("test_write_dataset_small_hyperslab", test_write_dataset_small_hyperslab, NULL, @@ -12490,6 +13704,9 @@ H5_api_dataset_test_add(void) AddTest("test_dataset_builtin_type_conversion", test_dataset_builtin_type_conversion, NULL, "verification of dataset data using H5Dwrite then H5Dread with type conversion of builtin types", NULL, testframe_flags); + AddTest("test_dataset_real_to_int_conversion", test_dataset_real_to_int_conversion, NULL, + "verification of dataset data using H5Dwrite then H5Dread with real <-> integer type conversion", + NULL, testframe_flags); AddTest("test_dataset_compound_partial_io", test_dataset_compound_partial_io, NULL, "verification of dataset data using H5Dwrite then H5Dread with partial element compound type I/O", NULL, testframe_flags); diff --git a/test/API/H5_api_dataset_test.h b/test/API/H5_api_dataset_test.h index 4c2901f646a..61f7c977de5 100644 --- a/test/API/H5_api_dataset_test.h +++ b/test/API/H5_api_dataset_test.h @@ -42,6 +42,13 @@ void H5_api_dataset_test_add(void); #define DATASET_CREATE_ANONYMOUS_INVALID_PARAMS_GROUP_NAME "anon_dset_creation_invalid_params_test" #define DATASET_CREATE_ANONYMOUS_INVALID_PARAMS_SPACE_RANK 2 +#define DATASET_STRING_ENCODINGS_RANK 1 +#define DATASET_STRING_ENCODINGS_EXTENT 1 +#define DATASET_STRING_ENCODINGS_DSET_NAME1 "encoding_dset1" +#define DATASET_STRING_ENCODINGS_DSET_NAME2 "encoding_dset2" +#define DATASET_STRING_ENCODINGS_ASCII_STRING "asciistr" +#define DATASET_STRING_ENCODINGS_UTF8_STRING "αaααaaaα" + #define DATASET_CREATE_NULL_DATASPACE_TEST_SUBGROUP_NAME "dataset_with_null_space_test" #define DATASET_CREATE_NULL_DATASPACE_TEST_DSET_NAME "dataset_with_null_space" @@ -106,6 +113,10 @@ void H5_api_dataset_test_add(void); #define DATASET_CREATION_PROPERTIES_TEST_MAX_COMPACT 12 #define DATASET_CREATION_PROPERTIES_TEST_MIN_DENSE 8 #define DATASET_CREATION_PROPERTIES_TEST_SHAPE_RANK 3 +#define DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_ID 32004 +#define DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_NAME "lz4" +#define DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_DSET_NAME "ud_filter_test" +#define DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_NUM_PARAMS 3 #define DATASET_OPEN_INVALID_PARAMS_SPACE_RANK 2 #define DATASET_OPEN_INVALID_PARAMS_GROUP_NAME "dataset_open_test" @@ -126,6 +137,24 @@ void H5_api_dataset_test_add(void); #define DATASET_PROPERTY_LIST_TEST_DSET_NAME3 "property_list_test_dataset3" #define DATASET_PROPERTY_LIST_TEST_DSET_NAME4 "property_list_test_dataset4" +#define DATASET_STORAGE_SIZE_TEST_ALL_DSET_SPACE_RANK 2 +#define DATASET_STORAGE_SIZE_TEST_ALL_DSET_EXTENT 10 +#define DATASET_STORAGE_SIZE_TEST_GROUP_NAME "dataset_get_storage_size_test" +#define DATASET_STORAGE_SIZE_TEST_DSET_CONTIGUOUS_NAME "dataset_contiguous" +#define DATASET_STORAGE_SIZE_TEST_DSET_CHUNKED_NAME "dataset_chunked" +#define DATASET_STORAGE_SIZE_TEST_DSET_FILTERED_NAME "dataset_filtered" +#define DATASET_STORAGE_SIZE_TEST_TYPE H5T_NATIVE_INT + +#define DATASET_FILL_VALUE_TEST_DSET_NAME1 "dataset_fill_value_test_dataset1" +#define DATASET_FILL_VALUE_TEST_DSET_NAME2 "dataset_fill_value_test_dataset2" +#define DATASET_FILL_VALUE_TEST_DSET_NAME3 "dataset_fill_value_test_dataset3" +#define DATASET_FILL_VALUE_TEST_INT_TYPE H5T_NATIVE_INT +#define DATASET_FILL_VALUE_TEST_INT_FILL_VALUE 1 +#define DATASET_FILL_VALUE_TEST_DOUBLE_TYPE H5T_NATIVE_DOUBLE +#define DATASET_FILL_VALUE_TEST_DOUBLE_FILL_VALUE 2.002 +#define DATASET_FILL_VALUE_TEST_STRING_FILL_VALUE "abcdefgh" +#define DATASET_FILL_VALUE_TEST_STRING_SIZE 8 /* No null terminator for fixed length string*/ + #define DATASET_SMALL_READ_TEST_ALL_DSET_SPACE_RANK 3 #define DATASET_SMALL_READ_TEST_ALL_DSET_DTYPESIZE sizeof(int) #define DATASET_SMALL_READ_TEST_ALL_DSET_DTYPE H5T_NATIVE_INT @@ -214,6 +243,15 @@ void H5_api_dataset_test_add(void); #define DATASET_DATA_BUILTIN_CONVERSION_TEST_GROUP_NAME "dataset_builtin_conversion_verification_test" #define DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME "dataset_builtin_conversion_verification_dset" +#define DATASET_DATA_REAL_CONVERSION_TEST_DSET_SPACE_RANK 3 +#define DATASET_DATA_REAL_CONVERSION_TEST_NUM_POINTS 10 +#define DATASET_DATA_REAL_CONVERSION_TEST_GROUP_NAME "dataset_real_conversion_verification_test" +#define DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME "dataset_real_conversion_verification_dset" +#define DATASET_DATA_REAL_CONVERSION_TEST_INT_DTYPESIZE sizeof(int) +#define DATASET_DATA_REAL_CONVERSION_TEST_INT_TYPE H5T_NATIVE_INT +#define DATASET_DATA_REAL_CONVERSION_TEST_REAL_DTYPESIZE sizeof(double) +#define DATASET_DATA_REAL_CONVERSION_TEST_REAL_TYPE H5T_NATIVE_DOUBLE + #define DATASET_COMPOUND_PARTIAL_IO_DSET_DIMS 10 #define DATASET_DATA_COMPOUND_PARTIAL_IO_TEST_GROUP_NAME "dataset_compound_partial_io_test" #define DATASET_DATA_COMPOUND_PARTIAL_IO_TEST_DSET_NAME "dataset_compound_partial_io_test" diff --git a/test/API/H5_api_object_test.c b/test/API/H5_api_object_test.c index a0d65363164..e1d6ca8b6e2 100644 --- a/test/API/H5_api_object_test.c +++ b/test/API/H5_api_object_test.c @@ -52,6 +52,8 @@ static herr_t object_copy_soft_link_expand_callback(hid_t group, const char *nam void *op_data); static herr_t object_visit_callback(hid_t o_id, const char *name, const H5O_info2_t *object_info, void *op_data); +static herr_t object_visit_simple_callback(hid_t o_id, const char *name, const H5O_info2_t *object_info, + void *op_data); static herr_t object_visit_dset_callback(hid_t o_id, const char *name, const H5O_info2_t *object_info, void *op_data); static herr_t object_visit_dtype_callback(hid_t o_id, const char *name, const H5O_info2_t *object_info, @@ -5032,15 +5034,23 @@ test_object_comments_invalid_params(void) static void test_object_visit(void) { - size_t i; - hid_t file_id = H5I_INVALID_HID; - hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID; - hid_t group_id2 = H5I_INVALID_HID; - hid_t gcpl_id = H5I_INVALID_HID; - hid_t type_id = H5I_INVALID_HID; - hid_t dset_id = H5I_INVALID_HID; - hid_t dset_dtype = H5I_INVALID_HID; - hid_t fspace_id = H5I_INVALID_HID; + size_t i; + hid_t file_id = H5I_INVALID_HID; + hid_t file_id2 = H5I_INVALID_HID; + hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID; + hid_t group_id2 = H5I_INVALID_HID; + hid_t gcpl_id = H5I_INVALID_HID; + hid_t type_id = H5I_INVALID_HID; + hid_t dset_id = H5I_INVALID_HID; + hid_t dset_dtype = H5I_INVALID_HID; + hid_t fspace_id = H5I_INVALID_HID; + hid_t attr_id = H5I_INVALID_HID; + hid_t group_id3 = H5I_INVALID_HID; + hid_t group_id4 = H5I_INVALID_HID; + hid_t group_id5 = H5I_INVALID_HID; + hssize_t num_elems = 0; + size_t elem_size = 0; + char visit_filename[H5_API_TEST_FILENAME_MAX_LENGTH]; TESTING_MULTIPART("object visiting"); @@ -5063,6 +5073,15 @@ test_object_visit(void) goto error; } + snprintf(visit_filename, H5_API_TEST_FILENAME_MAX_LENGTH, "%s%s", test_path_prefix, + OBJECT_VISIT_TEST_FILE_NAME); + + if ((file_id2 = H5Fcreate(visit_filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open file '%s'\n", OBJECT_VISIT_TEST_FILE_NAME); + goto error; + } + if ((container_group = H5Gopen2(file_id, OBJECT_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) { H5_FAILED(); printf(" couldn't open container group '%s'\n", OBJECT_TEST_GROUP_NAME); @@ -5090,11 +5109,29 @@ test_object_visit(void) goto error; } - if ((fspace_id = generate_random_dataspace(OBJECT_VISIT_TEST_SPACE_RANK, NULL, NULL, FALSE)) < 0) - TEST_ERROR; + /* Make sure not to generate too much data for an attribute to hold */ + do { + if (fspace_id != H5I_INVALID_HID) + H5Sclose(fspace_id); - if ((dset_dtype = generate_random_datatype(H5T_NO_CLASS, FALSE)) < 0) - TEST_ERROR; + if (dset_dtype != H5I_INVALID_HID) + H5Tclose(dset_dtype); + + if ((fspace_id = generate_random_dataspace(OBJECT_VISIT_TEST_SPACE_RANK, NULL, NULL, FALSE)) < 0) { + TEST_ERROR; + } + + if ((dset_dtype = generate_random_datatype(H5T_NO_CLASS, FALSE)) < 0) { + TEST_ERROR; + } + + if ((num_elems = H5Sget_simple_extent_npoints(fspace_id)) < 0) + TEST_ERROR; + + if ((elem_size = H5Tget_size(dset_dtype)) == 0) + TEST_ERROR; + + } while (((long unsigned int)num_elems * elem_size) > OBJECT_VISIT_TEST_TOTAL_DATA_SIZE_LIMIT); if ((type_id = generate_random_datatype(H5T_NO_CLASS, FALSE)) < 0) { H5_FAILED(); @@ -5102,6 +5139,14 @@ test_object_visit(void) goto error; } + if ((attr_id = H5Acreate2(group_id, OBJECT_VISIT_TEST_ATTR_NAME, dset_dtype, fspace_id, H5P_DEFAULT, + H5P_DEFAULT)) == H5I_INVALID_HID) { + H5_FAILED(); + printf(" couldn't create attribute '%s' on group '%s'\n", OBJECT_VISIT_TEST_ATTR_NAME, + OBJECT_VISIT_TEST_SUBGROUP_NAME); + goto error; + } + if ((group_id2 = H5Gcreate2(group_id, OBJECT_VISIT_TEST_GROUP_NAME, H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0) { H5_FAILED(); @@ -5109,6 +5154,27 @@ test_object_visit(void) goto error; } + if ((group_id3 = H5Gcreate2(file_id2, OBJECT_VISIT_TEST_GROUP_NAME_PARENT, H5P_DEFAULT, gcpl_id, + H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create group '%s'\n", OBJECT_VISIT_TEST_GROUP_NAME_PARENT); + goto error; + } + + if ((group_id4 = H5Gcreate2(group_id3, OBJECT_VISIT_TEST_GROUP_NAME_CHILD, H5P_DEFAULT, gcpl_id, + H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create group '%s'\n", OBJECT_VISIT_TEST_GROUP_NAME_CHILD); + goto error; + } + + if ((group_id5 = H5Gcreate2(group_id4, OBJECT_VISIT_TEST_GROUP_NAME_GRANDCHILD, H5P_DEFAULT, gcpl_id, + H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create group '%s'\n", OBJECT_VISIT_TEST_GROUP_NAME_GRANDCHILD); + goto error; + } + if ((dset_id = H5Dcreate2(group_id, OBJECT_VISIT_TEST_DSET_NAME, dset_dtype, fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { H5_FAILED(); @@ -5241,16 +5307,49 @@ test_object_visit(void) } PART_END(H5Ovisit_create_order_decreasing); + PART_BEGIN(H5Ovisit_group) + { + TESTING_2("H5Ovisit on a group"); + + i = 0; + + if (H5Ovisit3(group_id3, H5_INDEX_CRT_ORDER, H5_ITER_INC, object_visit_simple_callback, &i, + H5O_INFO_ALL) < 0) { + H5_FAILED(); + printf(" H5Ovisit on a group failed!\n"); + PART_ERROR(H5Ovisit_group); + } + + if (i != OBJECT_VISIT_TEST_SUBGROUP_LAYERS) { + H5_FAILED(); + printf(" some objects were not visited!\n"); + PART_ERROR(H5Ovisit_group); + } + + PASSED(); + } + PART_END(H5Ovisit_group); + PART_BEGIN(H5Ovisit_file) { TESTING_2("H5Ovisit on a file ID"); - /* - * XXX: - */ + i = 0; + + if (H5Ovisit3(file_id2, H5_INDEX_CRT_ORDER, H5_ITER_INC, object_visit_simple_callback, &i, + H5O_INFO_ALL) < 0) { + H5_FAILED(); + printf(" H5Ovisit on a file ID failed!\n"); + PART_ERROR(H5Ovisit_file); + } - SKIPPED(); - PART_EMPTY(H5Ovisit_file); + if (i != OBJECT_VISIT_TEST_NUM_OBJS_VISITED) { + H5_FAILED(); + printf(" some objects were not visited!\n"); + PART_ERROR(H5Ovisit_file); + } + + PASSED(); } PART_END(H5Ovisit_file); @@ -5284,6 +5383,30 @@ test_object_visit(void) } PART_END(H5Ovisit_dtype); + PART_BEGIN(H5Ovisit_attr) + { + TESTING_2("H5Ovisit on an attribute"); + + i = 0; + + if (H5Ovisit3(attr_id, H5_INDEX_CRT_ORDER, H5_ITER_INC, object_visit_simple_callback, &i, + H5O_INFO_ALL) < 0) { + H5_FAILED(); + printf(" H5Ovisit on an attribute failed!\n"); + PART_ERROR(H5Ovisit_attr); + } + + /* Should have same effect as calling H5Ovisit on group_id */ + if (i != OBJECT_VISIT_TEST_NUM_OBJS_VISITED) { + H5_FAILED(); + printf(" some objects were not visited!\n"); + PART_ERROR(H5Ovisit_attr); + } + + PASSED(); + } + PART_END(H5Ovisit_attr); + PART_BEGIN(H5Ovisit_by_name_obj_name_increasing) { TESTING_2("H5Ovisit_by_name by object name in increasing order"); @@ -5464,12 +5587,22 @@ test_object_visit(void) { TESTING_2("H5Ovisit_by_name on a file ID"); - /* - * XXX: - */ + i = 0; + + if (H5Ovisit_by_name3(file_id2, "/", H5_INDEX_CRT_ORDER, H5_ITER_INC, + object_visit_simple_callback, &i, H5O_INFO_ALL, H5P_DEFAULT) < 0) { + H5_FAILED(); + printf(" H5Ovisit on a file ID failed!\n"); + PART_ERROR(H5Ovisit_by_name_file); + } - SKIPPED(); - PART_EMPTY(H5Ovisit_by_name_file); + if (i != OBJECT_VISIT_TEST_NUM_OBJS_VISITED) { + H5_FAILED(); + printf(" some objects were not visited!\n"); + PART_ERROR(H5Ovisit_by_name_file); + } + + PASSED(); } PART_END(H5Ovisit_by_name_file); @@ -5503,6 +5636,29 @@ test_object_visit(void) } PART_END(H5Ovisit_by_name_dtype); + PART_BEGIN(H5Ovisit_by_name_attr) + { + TESTING_2("H5Ovisit_by_name on an attribute"); + + i = 0; + + if (H5Ovisit_by_name(attr_id, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, object_visit_simple_callback, + &i, H5O_INFO_ALL, H5P_DEFAULT) < 0) { + H5_FAILED(); + printf(" H5Ovisit_by_name on an attribute failed!\n"); + PART_ERROR(H5Ovisit_by_name_attr); + } + + /* Should have same effect as calling H5Ovisit on group_id */ + if (i != OBJECT_VISIT_TEST_NUM_OBJS_VISITED) { + H5_FAILED(); + printf(" some objects were not visited!\n"); + PART_ERROR(H5Ovisit_by_name_attr); + } + + PASSED(); + } + PART_END(H5Ovisit_by_name_attr); } END_MULTIPART; @@ -5520,12 +5676,25 @@ test_object_visit(void) TEST_ERROR; if (H5Gclose(group_id2) < 0) TEST_ERROR; + if (H5Gclose(group_id3) < 0) + TEST_ERROR; + if (H5Gclose(group_id4) < 0) + TEST_ERROR; + if (H5Gclose(group_id5) < 0) + TEST_ERROR; + if (H5Aclose(attr_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; + if (H5Fclose(file_id2) < 0) + TEST_ERROR; + if (remove_test_file(NULL, visit_filename) < 0) + TEST_ERROR; + PASSED(); return; @@ -5539,11 +5708,17 @@ test_object_visit(void) H5Dclose(dset_id); H5Pclose(gcpl_id); H5Gclose(group_id2); + H5Gclose(group_id3); + H5Gclose(group_id4); + H5Gclose(group_id5); + H5Aclose(attr_id); H5Gclose(group_id); H5Gclose(container_group); H5Fclose(file_id); + H5Fclose(file_id2); + remove_test_file(NULL, visit_filename); } - H5E_END_TRY + H5E_END_TRY; return; } @@ -7051,6 +7226,29 @@ object_visit_callback(hid_t o_id, const char *name, const H5O_info2_t *object_in return ret_val; } +/* + * H5Ovisit callback to count the number of visited objects + */ +static herr_t +object_visit_simple_callback(hid_t o_id, const char *name, const H5O_info2_t *object_info, void *op_data) +{ + size_t *i = (size_t *)op_data; + herr_t ret_val = 0; + + UNUSED(o_id); + UNUSED(object_info); + + if (name) + goto done; + + ret_val = -1; + +done: + (*i)++; + + return ret_val; +} + /* * H5Ovisit callback for visiting a singular dataset. */ @@ -7112,7 +7310,15 @@ object_visit_soft_link_callback(hid_t o_id, const char *name, const H5O_info2_t UNUSED(o_id); - if (!HDstrncmp(name, ".", strlen(".") + 1) && (counter_val <= 5)) { + if (!strcmp(name, OBJECT_VISIT_TEST_GROUP_NAME_PARENT) || + !strcmp(name, OBJECT_VISIT_TEST_GROUP_NAME_PARENT "/" OBJECT_VISIT_TEST_GROUP_NAME_CHILD) || + !strcmp(name, OBJECT_VISIT_TEST_GROUP_NAME_PARENT "/" OBJECT_VISIT_TEST_GROUP_NAME_CHILD + "/" OBJECT_VISIT_TEST_GROUP_NAME_GRANDCHILD)) { + (*i)--; + goto done; + } + + if (!strncmp(name, ".", strlen(".") + 1) && (counter_val <= 5)) { if (H5O_TYPE_GROUP == object_info->type) goto done; else diff --git a/test/API/H5_api_object_test.h b/test/API/H5_api_object_test.h index ab238914058..60832db7537 100644 --- a/test/API/H5_api_object_test.h +++ b/test/API/H5_api_object_test.h @@ -127,6 +127,13 @@ void H5_api_object_test_add(void); #define OBJECT_VISIT_TEST_GROUP_NAME "object_visit_test_group" #define OBJECT_VISIT_TEST_DSET_NAME "object_visit_test_dset" #define OBJECT_VISIT_TEST_TYPE_NAME "object_visit_test_type" +#define OBJECT_VISIT_TEST_ATTR_NAME "object_visit_test_attr" +#define OBJECT_VISIT_TEST_FILE_NAME "object_visit_test_file" +#define OBJECT_VISIT_TEST_SUBGROUP_LAYERS 3 +#define OBJECT_VISIT_TEST_GROUP_NAME_PARENT "object_visit_test_group_parent" +#define OBJECT_VISIT_TEST_GROUP_NAME_CHILD "object_visit_test_group_child" +#define OBJECT_VISIT_TEST_GROUP_NAME_GRANDCHILD "object_visit_test_group_grandchild" +#define OBJECT_VISIT_TEST_TOTAL_DATA_SIZE_LIMIT 32000 #define OBJECT_VISIT_SOFT_LINK_TEST_NUM_OBJS_VISITED 1 #define OBJECT_VISIT_SOFT_LINK_TEST_SUBGROUP_NAME "object_visit_soft_link" From 79cf83be3162d00d762d2c408bacf43df352243b Mon Sep 17 00:00:00 2001 From: jhendersonHDF Date: Fri, 9 Feb 2024 11:05:54 -0600 Subject: [PATCH 04/12] Fix build issue and some warnings in H5_api_dataset_test.c (#3998) --- test/API/H5_api_dataset_test.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/test/API/H5_api_dataset_test.c b/test/API/H5_api_dataset_test.c index 2258acc10f7..53950ad9452 100644 --- a/test/API/H5_api_dataset_test.c +++ b/test/API/H5_api_dataset_test.c @@ -1984,18 +1984,11 @@ test_create_dataset_array_types(void) } size_t -filter(unsigned int flags, size_t H5_ATTR_UNUSED cd_nelmts, const unsigned int H5_ATTR_UNUSED cd_values[], - size_t nbytes, size_t H5_ATTR_UNUSED *buf_size, void H5_ATTR_UNUSED **buf) +filter(unsigned int H5_ATTR_UNUSED flags, size_t H5_ATTR_UNUSED cd_nelmts, + const unsigned int H5_ATTR_UNUSED cd_values[], size_t nbytes, size_t H5_ATTR_UNUSED *buf_size, + void H5_ATTR_UNUSED **buf) { - buf_size = 0; - - if (flags & H5Z_FLAG_REVERSE) { - /* No-op */ - } - else { - /* No-op */ - } - + *buf_size = 0; return nbytes; } @@ -2017,7 +2010,7 @@ test_create_dataset_creation_properties(void) void *read_buf = NULL; unsigned int filter_params[DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_NUM_PARAMS] = {1, 2, 3}; unsigned int filter_params_out[DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_NUM_PARAMS]; - char ud_filter_name[strlen(DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_NAME)]; + char ud_filter_name[sizeof(DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_NAME)]; int nfilters = 0; H5Z_filter_t retrieved_filter_id = H5I_INVALID_HID; size_t num_filter_params = DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_NUM_PARAMS; From ce47cfcf117750e8012641b5ce02adf09a220623 Mon Sep 17 00:00:00 2001 From: mattjala <124107509+mattjala@users.noreply.github.com> Date: Wed, 14 Feb 2024 11:15:01 -0600 Subject: [PATCH 05/12] Add compound subset ops on attributes to API tests (#4005) * Add partial compound io on attributes to API tests --- test/API/H5_api_attribute_test.c | 266 +++++++++++++++++++++++++++++++ test/API/H5_api_attribute_test.h | 4 + 2 files changed, 270 insertions(+) diff --git a/test/API/H5_api_attribute_test.c b/test/API/H5_api_attribute_test.c index 47b74f999d1..3979c5bd2f0 100644 --- a/test/API/H5_api_attribute_test.c +++ b/test/API/H5_api_attribute_test.c @@ -52,6 +52,7 @@ static void test_attribute_iterate_datatype(void); static void test_attribute_iterate_index_saving(void); static void test_attribute_iterate_invalid_params(void); static void test_attribute_iterate_0_attributes(void); +static void test_attribute_compound_subset(void); static void test_attribute_string_encodings(void); static void test_delete_attribute(void); static void test_delete_attribute_invalid_params(void); @@ -8303,6 +8304,268 @@ test_attribute_iterate_0_attributes(void) return; } +/* A compound type for test_attribute_compound_subset */ +typedef struct attribute_compound_io_t { + int a; + int b; +} attribute_compound_io_t; + +/* + * A test to ensure that data is read back correctly from a attribute after it has + * been written, using subsets of compound datatypes + */ +static void +test_attribute_compound_subset(void) +{ + hsize_t dims[1] = {ATTRIBUTE_COMPOUND_IO_ATTR_DIMS}; + size_t i; + hid_t file_id = H5I_INVALID_HID; + hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID; + hid_t attr_id = H5I_INVALID_HID; + hid_t space_id = H5I_INVALID_HID; + hid_t full_type_id = H5I_INVALID_HID; + hid_t a_type_id = H5I_INVALID_HID; + hid_t b_type_id = H5I_INVALID_HID; + attribute_compound_io_t wbuf[ATTRIBUTE_COMPOUND_IO_ATTR_DIMS]; + attribute_compound_io_t rbuf[ATTRIBUTE_COMPOUND_IO_ATTR_DIMS]; + attribute_compound_io_t fbuf[ATTRIBUTE_COMPOUND_IO_ATTR_DIMS]; + attribute_compound_io_t erbuf[ATTRIBUTE_COMPOUND_IO_ATTR_DIMS]; + + TESTING_MULTIPART( + "verification of attribute data using H5Awrite then H5Aread with compound type subsets"); + + /* 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_ATTR_BASIC)) { + SKIPPED(); + printf( + " API functions for basic file, group, or attribute aren't supported with this connector\n"); + return; + } + + 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, ATTRIBUTE_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open container group '%s'\n", ATTRIBUTE_TEST_GROUP_NAME); + goto error; + } + + if ((group_id = H5Gcreate2(container_group, ATTRIBUTE_COMPOUND_IO_TEST_GROUP_NAME, H5P_DEFAULT, + H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create container sub-group '%s'\n", ATTRIBUTE_COMPOUND_IO_TEST_GROUP_NAME); + goto error; + } + + if ((space_id = H5Screate_simple(1, dims, NULL)) < 0) + TEST_ERROR; + + if ((full_type_id = H5Tcreate(H5T_COMPOUND, sizeof(attribute_compound_io_t))) < 0) + TEST_ERROR; + if (H5Tinsert(full_type_id, "a", HOFFSET(attribute_compound_io_t, a), H5T_NATIVE_INT) < 0) + TEST_ERROR; + if (H5Tinsert(full_type_id, "b", HOFFSET(attribute_compound_io_t, b), H5T_NATIVE_INT) < 0) + TEST_ERROR; + + if ((a_type_id = H5Tcreate(H5T_COMPOUND, sizeof(attribute_compound_io_t))) < 0) + TEST_ERROR; + if (H5Tinsert(a_type_id, "a", HOFFSET(attribute_compound_io_t, a), H5T_NATIVE_INT) < 0) + TEST_ERROR; + + if ((b_type_id = H5Tcreate(H5T_COMPOUND, sizeof(attribute_compound_io_t))) < 0) + TEST_ERROR; + if (H5Tinsert(b_type_id, "b", HOFFSET(attribute_compound_io_t, b), H5T_NATIVE_INT) < 0) + TEST_ERROR; + + if ((attr_id = H5Acreate2(group_id, ATTRIBUTE_COMPOUND_IO_TEST_ATTR_NAME, full_type_id, space_id, + H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create attribute '%s'\n", ATTRIBUTE_COMPOUND_IO_TEST_ATTR_NAME); + goto error; + } + + PASSED(); + + BEGIN_MULTIPART + { + PART_BEGIN(write_full_read_full) + { + TESTING_2("H5Awrite then H5Aread with all compound members"); + + /* Initialize wbuf */ + for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) { + wbuf[i].a = (int)(2 * i); + wbuf[i].b = (int)(2 * i + 1); + } + + /* Write data */ + if (H5Awrite(attr_id, full_type_id, wbuf) < 0) + PART_TEST_ERROR(write_full_read_full); + + /* Update fbuf to match file state */ + for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) { + fbuf[i].a = wbuf[i].a; + fbuf[i].b = wbuf[i].b; + } + + /* Initialize rbuf to -1 */ + for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) { + rbuf[i].a = -1; + rbuf[i].b = -1; + } + + /* Set erbuf (simply match file state since we're reading the whole + * thing) */ + for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) { + erbuf[i].a = fbuf[i].a; + erbuf[i].b = fbuf[i].b; + } + + /* Read data */ + if (H5Aread(attr_id, full_type_id, rbuf) < 0) + PART_TEST_ERROR(write_full_read_full); + + /* Verify data */ + for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) { + if (rbuf[i].a != erbuf[i].a) + PART_TEST_ERROR(write_full_read_full); + if (rbuf[i].b != erbuf[i].b) + PART_TEST_ERROR(write_full_read_full); + } + + PASSED(); + } + PART_END(write_full_read_full); + + PART_BEGIN(read_a) + { + TESTING_2("H5Aread with compound member a"); + + /* Initialize rbuf to -1 */ + for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) { + rbuf[i].a = -1; + rbuf[i].b = -1; + } + + /* Set erbuf (element a comes from the file, element b in untouched) + */ + for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) { + erbuf[i].a = fbuf[i].a; + erbuf[i].b = rbuf[i].b; + } + + /* Read data */ + if (H5Aread(attr_id, a_type_id, rbuf) < 0) + PART_TEST_ERROR(read_a); + + /* Verify data */ + for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) { + if (rbuf[i].a != erbuf[i].a) + PART_TEST_ERROR(read_a); + if (rbuf[i].b != erbuf[i].b) + PART_TEST_ERROR(read_a); + } + + PASSED(); + } + PART_END(read_a); + + PART_BEGIN(write_b_read_full) + { + TESTING_2("H5Awrite with compound member b then H5Aread with all compound members"); + + /* Initialize wbuf */ + for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) { + wbuf[i].a = (int)(2 * ATTRIBUTE_COMPOUND_IO_ATTR_DIMS + 2 * i); + wbuf[i].b = (int)(2 * ATTRIBUTE_COMPOUND_IO_ATTR_DIMS + 2 * i + 1); + } + + /* Write data */ + if (H5Awrite(attr_id, b_type_id, wbuf) < 0) + PART_TEST_ERROR(write_b_read_full); + + /* Update fbuf to match file state - only element b was updated */ + for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) { + fbuf[i].b = wbuf[i].b; + } + + /* Initialize rbuf to -1 */ + for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) { + rbuf[i].a = -1; + rbuf[i].b = -1; + } + + /* Set erbuf (simply match file state since we're reading the whole + * thing) */ + for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) { + erbuf[i].a = fbuf[i].a; + erbuf[i].b = fbuf[i].b; + } + + /* Read data */ + if (H5Aread(attr_id, full_type_id, rbuf) < 0) + PART_TEST_ERROR(write_b_read_full); + + /* Verify data */ + for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) { + if (rbuf[i].a != erbuf[i].a) + PART_TEST_ERROR(write_b_read_full); + if (rbuf[i].b != erbuf[i].b) + PART_TEST_ERROR(write_b_read_full); + } + + PASSED(); + } + PART_END(write_b_read_full); + } + END_MULTIPART; + + TESTING_2("test cleanup"); + + if (H5Sclose(space_id) < 0) + TEST_ERROR; + if (H5Aclose(attr_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; + if (H5Tclose(full_type_id) < 0) + TEST_ERROR; + if (H5Tclose(a_type_id) < 0) + TEST_ERROR; + if (H5Tclose(b_type_id) < 0) + TEST_ERROR; + + PASSED(); + + return; + +error: + H5E_BEGIN_TRY + { + H5Sclose(space_id); + H5Aclose(attr_id); + H5Gclose(group_id); + H5Gclose(container_group); + H5Fclose(file_id); + H5Tclose(full_type_id); + H5Tclose(a_type_id); + H5Tclose(b_type_id); + } + H5E_END_TRY; + + return; +} /* * A test to check that attributes preserve data @@ -11357,6 +11620,9 @@ H5_api_attribute_test_add(void) "attribute iteration with invalid parameters", NULL, testframe_flags); AddTest("test_attribute_iterate_0_attributes", test_attribute_iterate_0_attributes, NULL, "attribute iteration on object with 0 attributes", NULL, testframe_flags); + AddTest("test_attribute_compound_subset", test_attribute_compound_subset, NULL, + "verification of attribute data using H5Awrite then H5Aread with compound type subsets", + NULL, testframe_flags); AddTest("test_attribute_string_encodings", test_attribute_string_encodings, NULL, "attribute string encoding correctness", NULL, testframe_flags); AddTest("test_delete_attribute", test_delete_attribute, NULL, "attribute deletion", NULL, testframe_flags); diff --git a/test/API/H5_api_attribute_test.h b/test/API/H5_api_attribute_test.h index c24eec8d484..9baba1ceee5 100644 --- a/test/API/H5_api_attribute_test.h +++ b/test/API/H5_api_attribute_test.h @@ -156,6 +156,10 @@ void H5_api_attribute_test_add(void); #define ATTRIBUTE_ITERATE_TEST_0_ATTRIBUTES_SUBGROUP_NAME "attribute_iterate_test_0_attributes" #define ATTRIBUTE_ITERATE_TEST_0_ATTRIBUTES_DSET_NAME "attribute_iterate_dset" +#define ATTRIBUTE_COMPOUND_IO_ATTR_DIMS 10 +#define ATTRIBUTE_COMPOUND_IO_TEST_GROUP_NAME "attribute_compound_io_test_group" +#define ATTRIBUTE_COMPOUND_IO_TEST_ATTR_NAME "attribute_compound_io_test_attr" + #define ATTRIBUTE_STRING_ENCODINGS_RANK 1 #define ATTRIBUTE_STRING_ENCODINGS_EXTENT 1 #define ATTRIBUTE_STRING_ENCODINGS_DSET_NAME1 "encoding_dset1" From aa6d4f49870022f8659d2a14c0e4faa7b8a988b1 Mon Sep 17 00:00:00 2001 From: mattjala <124107509+mattjala@users.noreply.github.com> Date: Wed, 21 Feb 2024 13:52:39 -0600 Subject: [PATCH 06/12] Test vlen sequence IO in API tests (#4027) --- test/API/H5_api_dataset_test.c | 484 +++++++++++++++++++++++++++++++++ test/API/H5_api_dataset_test.h | 5 + 2 files changed, 489 insertions(+) diff --git a/test/API/H5_api_dataset_test.c b/test/API/H5_api_dataset_test.c index 53950ad9452..138a3836e02 100644 --- a/test/API/H5_api_dataset_test.c +++ b/test/API/H5_api_dataset_test.c @@ -68,6 +68,7 @@ static void test_dataset_string_encodings(void); static void test_dataset_builtin_type_conversion(void); static void test_dataset_real_to_int_conversion(void); static void test_dataset_compound_partial_io(void); +static void test_dataset_vlen_io(void); static void test_dataset_set_extent_chunked_unlimited(void); static void test_dataset_set_extent_chunked_fixed(void); static void test_dataset_set_extent_data(void); @@ -9726,6 +9727,486 @@ test_dataset_compound_partial_io(void) return; } +/* A test to check that vlen sequences can be written and read back + * with basic parent types and selections */ +static void +test_dataset_vlen_io(void) +{ + hid_t file_id = H5I_INVALID_HID; + hid_t container_group = H5I_INVALID_HID; + hid_t space_id = H5I_INVALID_HID; + hid_t dset_int = H5I_INVALID_HID; + hid_t dset_float = H5I_INVALID_HID; + hid_t dset_string = H5I_INVALID_HID; + hid_t vlen_int = H5I_INVALID_HID; + hid_t vlen_float = H5I_INVALID_HID; + hid_t vlen_string = H5I_INVALID_HID; + hid_t str_base_type = H5I_INVALID_HID; + + hsize_t dims[1] = {DATASET_VLEN_IO_DSET_DIMS}; + hsize_t point_coords[DATASET_VLEN_IO_DSET_DIMS / 2]; + + hvl_t wbuf[DATASET_VLEN_IO_DSET_DIMS]; + hvl_t rbuf[DATASET_VLEN_IO_DSET_DIMS]; + + TESTING_MULTIPART( + "verification of dataset data with H5Dwrite and then H5D read with variable length sequence data"); + + /* 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; + } + + 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 ((space_id = H5Screate_simple(1, dims, NULL)) < 0) { + H5_FAILED(); + printf(" couldn't create dataspace"); + goto error; + } + + if ((vlen_int = H5Tvlen_create(H5T_NATIVE_INT)) < 0) { + H5_FAILED(); + printf(" couldn't create vlen integer sequence"); + goto error; + } + + if ((vlen_float = H5Tvlen_create(H5T_NATIVE_FLOAT)) < 0) { + H5_FAILED(); + printf(" couldn't create vlen float sequence"); + goto error; + } + + if ((str_base_type = H5Tcopy(H5T_C_S1)) < 0) + TEST_ERROR; + + if ((H5Tset_size(str_base_type, DATASET_VLEN_IO_STR_LEN)) < 0) + TEST_ERROR; + + if ((vlen_string = H5Tvlen_create(str_base_type)) < 0) { + H5_FAILED(); + printf(" couldn't create vlen string sequence"); + goto error; + } + + if ((dset_int = H5Dcreate2(file_id, DATASET_VLEN_IO_DSET_NAME "_int", vlen_int, space_id, H5P_DEFAULT, + H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset with vlen integer sequence datatype"); + goto error; + } + + if ((dset_float = H5Dcreate2(file_id, DATASET_VLEN_IO_DSET_NAME "_float", vlen_float, space_id, + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset with vlen float sequence datatype"); + goto error; + } + + if ((dset_string = H5Dcreate2(file_id, DATASET_VLEN_IO_DSET_NAME "_string", vlen_string, space_id, + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset with vlen string sequence datatype"); + goto error; + } + + memset(wbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); + memset(rbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); + + PASSED(); + + BEGIN_MULTIPART + { + PART_BEGIN(rw_all_int) + { + TESTING_2("write and read entire dataspace with integer sequence"); + /* Set up write buffer */ + for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS; i++) { + if ((wbuf[i].p = calloc(i + 1, sizeof(int) * (i + 1))) == NULL) + PART_TEST_ERROR(rw_all_int); + + for (size_t j = 0; j < i + 1; j++) { + ((int *)wbuf[i].p)[j] = (int)(i * j + 1); + } + + wbuf[i].len = i + 1; + } + + /* Perform write */ + if ((H5Dwrite(dset_int, vlen_int, space_id, H5S_ALL, H5P_DEFAULT, (const void *)wbuf)) < 0) + PART_TEST_ERROR(rw_all_int); + + /* Perform read */ + if ((H5Dread(dset_int, vlen_int, space_id, H5S_ALL, H5P_DEFAULT, (void *)rbuf)) < 0) + PART_TEST_ERROR(rw_all_int); + + /* Verify data */ + for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS; i++) { + if (!rbuf[i].p) + PART_TEST_ERROR(rw_all_int); + + if (rbuf[i].len != wbuf[i].len) + PART_TEST_ERROR(rw_all_int); + + for (size_t j = 0; j < i + 1; j++) + if (((int *)rbuf[i].p)[j] != ((int *)wbuf[i].p)[j]) + PART_TEST_ERROR(rw_all_int); + } + + PASSED(); + + /* Reset buffers */ + + if (H5Treclaim(vlen_int, space_id, H5P_DEFAULT, rbuf) < 0) + PART_TEST_ERROR(rw_all_int); + + if (H5Treclaim(vlen_int, space_id, H5P_DEFAULT, wbuf) < 0) + PART_TEST_ERROR(rw_all_int); + + memset(wbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); + memset(rbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); + } + PART_END(rw_all_int) + { + TESTING_2("write and read entire dataspace with float sequence"); + /* Set up write buffer */ + for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS; i++) { + if ((wbuf[i].p = calloc(i + 1, sizeof(float) * (i + 1))) == NULL) + PART_TEST_ERROR(rw_all_float); + + for (size_t j = 0; j < i + 1; j++) { + ((float *)wbuf[i].p)[j] = (float)(i * j + 1); + } + + wbuf[i].len = i + 1; + } + + /* Perform write */ + if ((H5Dwrite(dset_float, vlen_float, space_id, H5S_ALL, H5P_DEFAULT, (const void *)wbuf)) < 0) + PART_TEST_ERROR(rw_all_float); + + /* Perform read */ + if ((H5Dread(dset_float, vlen_float, space_id, H5S_ALL, H5P_DEFAULT, (void *)rbuf)) < 0) + PART_TEST_ERROR(rw_all_float); + + /* Verify data */ + for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS; i++) { + if (!rbuf[i].p) + PART_TEST_ERROR(rw_all_float); + + if (rbuf[i].len != wbuf[i].len) + PART_TEST_ERROR(rw_all_float); + + for (size_t j = 0; j < i + 1; j++) { + float expected = ((float *)wbuf[i].p)[j]; + float actual = ((float *)rbuf[i].p)[j]; + + if (!(H5_DBL_REL_EQUAL(expected, actual, 0.001))) + PART_TEST_ERROR(rw_all_float); + } + } + + PASSED(); + + /* Reset buffers */ + + if (H5Treclaim(vlen_float, space_id, H5P_DEFAULT, rbuf) < 0) + PART_TEST_ERROR(rw_all_float); + + if (H5Treclaim(vlen_float, space_id, H5P_DEFAULT, wbuf) < 0) + PART_TEST_ERROR(rw_all_float); + + memset(wbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); + memset(rbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); + PART_BEGIN(rw_all_float) + } + PART_END(rw_all_float); + + PART_BEGIN(rw_all_string) + { + TESTING_2("write and read entire dataspace with string sequence"); + /* Set up write buffer */ + for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS; i++) { + if ((wbuf[i].p = calloc(i + 1, DATASET_VLEN_IO_STR_LEN * (i + 1))) == NULL) + PART_TEST_ERROR(rw_all_string); + + for (size_t j = 0; j < i + 1; j++) { + char *str_ptr = ((char *)wbuf[i].p) + DATASET_VLEN_IO_STR_LEN * j; + memcpy(str_ptr, DATASET_VLEN_IO_STR_VALUE, DATASET_VLEN_IO_STR_LEN); + } + + wbuf[i].len = i + 1; + } + + /* Perform write */ + if ((H5Dwrite(dset_string, vlen_string, space_id, H5S_ALL, H5P_DEFAULT, (const void *)wbuf)) < 0) + PART_TEST_ERROR(rw_all_string); + + /* Perform read */ + if ((H5Dread(dset_string, vlen_string, space_id, H5S_ALL, H5P_DEFAULT, (void *)rbuf)) < 0) + PART_TEST_ERROR(rw_all_string); + + /* Verify data */ + for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS; i++) { + if (!rbuf[i].p) + PART_TEST_ERROR(rw_all_string); + + if (rbuf[i].len != wbuf[i].len) + PART_TEST_ERROR(rw_all_string); + + for (size_t j = 0; j < i + 1; j++) { + char str_buf[DATASET_VLEN_IO_STR_LEN + 1]; + char *str_ptr = (char *)rbuf[i].p + DATASET_VLEN_IO_STR_LEN * j; + memcpy(str_buf, str_ptr, DATASET_VLEN_IO_STR_LEN); + str_buf[DATASET_VLEN_IO_STR_LEN] = '\0'; + + if (strcmp(str_buf, DATASET_VLEN_IO_STR_VALUE)) + PART_TEST_ERROR(rw_all_string); + } + } + + PASSED(); + + /* Reset buffers */ + + if (H5Treclaim(vlen_string, space_id, H5P_DEFAULT, rbuf) < 0) + PART_TEST_ERROR(rw_all_string); + + if (H5Treclaim(vlen_string, space_id, H5P_DEFAULT, wbuf) < 0) + PART_TEST_ERROR(rw_all_string); + + memset(wbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); + memset(rbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); + } + PART_END(rw_all_string); + + PART_BEGIN(rw_point_selection) + { + /* Select even-indexed points */ + for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS / 2; i++) + point_coords[i] = i * 2; + + /* Select points on dataspace */ + if (H5Sselect_elements(space_id, H5S_SELECT_SET, DATASET_VLEN_IO_DSET_DIMS / 2, + (const hsize_t *)point_coords) < 0) + PART_TEST_ERROR(rw_point_selection); + + /* Set up write buffer */ + for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS; i++) { + if ((wbuf[i].p = calloc(i + 1, sizeof(int) * (i + 1))) == NULL) + PART_TEST_ERROR(rw_point_selection); + + for (size_t j = 0; j < i + 1; j++) { + ((int *)wbuf[i].p)[j] = (int)(i * j + 1); + } + + wbuf[i].len = i + 1; + } + + /* Perform write */ + if ((H5Dwrite(dset_int, vlen_int, space_id, space_id, H5P_DEFAULT, (const void *)wbuf)) < 0) + PART_TEST_ERROR(rw_point_selection); + + /* Perform read */ + if ((H5Dread(dset_int, vlen_int, space_id, space_id, H5P_DEFAULT, (void *)rbuf)) < 0) + PART_TEST_ERROR(rw_point_selection); + + /* Verify data */ + for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS; i++) { + if (i % 2 == 0) { + if (!rbuf[i].p) + PART_TEST_ERROR(rw_point_selection); + + if (rbuf[i].len != wbuf[i].len) + PART_TEST_ERROR(rw_point_selection); + + for (size_t j = 0; j < i + 1; j++) + if (((int *)rbuf[i].p)[j] != ((int *)wbuf[i].p)[j]) + PART_TEST_ERROR(rw_point_selection); + } + else { + /* Odd positions in buffer should still read 0 */ + if (rbuf[i].p) + PART_TEST_ERROR(rw_point_selection); + if (rbuf[i].len) + PART_TEST_ERROR(rw_point_selection); + } + } + + PASSED(); + + /* Reset buffers */ + + if (H5Treclaim(vlen_int, space_id, H5P_DEFAULT, rbuf) < 0) + PART_TEST_ERROR(rw_point_selection); + + if (H5Treclaim(vlen_int, space_id, H5P_DEFAULT, wbuf) < 0) + PART_TEST_ERROR(rw_point_selection); + + memset(wbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); + memset(rbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); + } + PART_END(rw_point_selection); + + PART_BEGIN(rw_hyperslab_selection) + { + /* Select hyperslab of every 3rd element */ + const hsize_t start[1] = {0}; + const hsize_t stride[1] = {3}; + const hsize_t count[1] = {1 + (DATASET_VLEN_IO_DSET_DIMS / stride[0])}; + const hsize_t block[1] = {1}; + + if ((H5Sselect_hyperslab(space_id, H5S_SELECT_SET, start, stride, count, block)) < 0) + PART_TEST_ERROR(rw_hyperslab_selection); + + /* Set up write buffer */ + for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS; i++) { + if ((wbuf[i].p = calloc(i + 1, sizeof(int) * (i + 1))) == NULL) + PART_TEST_ERROR(rw_hyperslab_selection); + + for (size_t j = 0; j < i + 1; j++) { + ((int *)wbuf[i].p)[j] = (int)(i * j + 1); + } + + wbuf[i].len = i + 1; + } + + /* Perform write */ + if ((H5Dwrite(dset_int, vlen_int, space_id, space_id, H5P_DEFAULT, (const void *)wbuf)) < 0) + PART_TEST_ERROR(rw_hyperslab_selection); + + /* Perform read */ + if ((H5Dread(dset_int, vlen_int, space_id, space_id, H5P_DEFAULT, (void *)rbuf)) < 0) + PART_TEST_ERROR(rw_hyperslab_selection); + + /* Verify data */ + for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS; i++) { + if (i % stride[0] == 0) { + if (!rbuf[i].p) + PART_TEST_ERROR(rw_hyperslab_selection); + + if (rbuf[i].len != wbuf[i].len) + PART_TEST_ERROR(rw_hyperslab_selection); + + for (size_t j = 0; j < i + 1; j++) + if (((int *)rbuf[i].p)[j] != ((int *)wbuf[i].p)[j]) + PART_TEST_ERROR(rw_hyperslab_selection); + } + else { + /* Unread positions should still be 0 */ + if (rbuf[i].p) + PART_TEST_ERROR(rw_hyperslab_selection); + if (rbuf[i].len) + PART_TEST_ERROR(rw_hyperslab_selection); + } + } + + PASSED(); + + /* Reset buffers */ + + if (H5Treclaim(vlen_int, space_id, H5P_DEFAULT, rbuf) < 0) + PART_TEST_ERROR(rw_hyperslab_selection); + + if (H5Treclaim(vlen_int, space_id, H5P_DEFAULT, wbuf) < 0) + PART_TEST_ERROR(rw_hyperslab_selection); + + memset(wbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); + memset(rbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); + } + PART_END(rw_hyperslab_selection); + } + END_MULTIPART; + + TESTING_2("test cleanup"); + + if (H5Fclose(file_id) < 0) + TEST_ERROR; + if (H5Gclose(container_group) < 0) + TEST_ERROR; + if (H5Dclose(dset_int) < 0) + TEST_ERROR; + if (H5Dclose(dset_float) < 0) + TEST_ERROR; + if (H5Dclose(dset_string) < 0) + TEST_ERROR; + if (H5Sclose(space_id) < 0) + TEST_ERROR; + /* In case of memory allocation error, not all hvl_t buffers in array may be allocated. + * Free one-by-one */ + for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS; i++) { + if (wbuf[i].p) { + free(wbuf[i].p); + wbuf[i].p = NULL; + } + } + + for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS; i++) { + if (rbuf[i].p) { + free(rbuf[i].p); + rbuf[i].p = NULL; + } + } + + if (H5Tclose(vlen_int) < 0) + TEST_ERROR; + if (H5Tclose(vlen_float) < 0) + TEST_ERROR; + if (H5Tclose(vlen_string) < 0) + TEST_ERROR; + + PASSED(); + + return; + +error: + + H5E_BEGIN_TRY + { + H5Fclose(file_id); + H5Gclose(container_group); + H5Dclose(dset_int); + H5Dclose(dset_float); + H5Dclose(dset_string); + H5Sclose(space_id); + for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS; i++) { + if (wbuf[i].p) { + free(wbuf[i].p); + wbuf[i].p = NULL; + } + } + + for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS; i++) { + if (rbuf[i].p) { + free(rbuf[i].p); + rbuf[i].p = NULL; + } + } + H5Tclose(vlen_int); + H5Tclose(vlen_float); + H5Tclose(vlen_string); + } + H5E_END_TRY + + return; +} + /* * A test to check that a chunked dataset's extent can be * changed by using H5Dset_extent. This test uses unlimited @@ -13703,6 +14184,9 @@ H5_api_dataset_test_add(void) AddTest("test_dataset_compound_partial_io", test_dataset_compound_partial_io, NULL, "verification of dataset data using H5Dwrite then H5Dread with partial element compound type I/O", NULL, testframe_flags); + AddTest("test_dataset_vlen_io", test_dataset_vlen_io, NULL, + "verification of dataset data with H5Dwrite and then H5D read with variable length sequence data", + NULL, testframe_flags); AddTest("test_dataset_set_extent_chunked_unlimited", test_dataset_set_extent_chunked_unlimited, NULL, "H5Dset_extent on chunked dataset with unlimited dimensions", NULL, testframe_flags); AddTest("test_dataset_set_extent_chunked_fixed", test_dataset_set_extent_chunked_fixed, NULL, diff --git a/test/API/H5_api_dataset_test.h b/test/API/H5_api_dataset_test.h index 61f7c977de5..63b1eb6b61f 100644 --- a/test/API/H5_api_dataset_test.h +++ b/test/API/H5_api_dataset_test.h @@ -256,6 +256,11 @@ void H5_api_dataset_test_add(void); #define DATASET_DATA_COMPOUND_PARTIAL_IO_TEST_GROUP_NAME "dataset_compound_partial_io_test" #define DATASET_DATA_COMPOUND_PARTIAL_IO_TEST_DSET_NAME "dataset_compound_partial_io_test" +#define DATASET_VLEN_IO_DSET_DIMS 100 +#define DATASET_VLEN_IO_DSET_NAME "vlen_dset" +#define DATASET_VLEN_IO_STR_LEN 8 +#define DATASET_VLEN_IO_STR_VALUE "abcdefgh" + #define DATASET_SET_EXTENT_CHUNKED_UNLIMITED_TEST_SPACE_RANK 2 #define DATASET_SET_EXTENT_CHUNKED_UNLIMITED_TEST_NUM_PASSES 3 #define DATASET_SET_EXTENT_CHUNKED_UNLIMITED_TEST_GROUP_NAME "set_extent_chunked_unlimited_test" From 4a6754faab5fd8b7bb2dc8a285cfa401585334c7 Mon Sep 17 00:00:00 2001 From: mattjala <124107509+mattjala@users.noreply.github.com> Date: Mon, 26 Feb 2024 14:27:51 -0600 Subject: [PATCH 07/12] Fix allocating too much memory in dset API test (#4041) --- test/API/H5_api_dataset_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/API/H5_api_dataset_test.c b/test/API/H5_api_dataset_test.c index 138a3836e02..4110dd714de 100644 --- a/test/API/H5_api_dataset_test.c +++ b/test/API/H5_api_dataset_test.c @@ -9943,7 +9943,7 @@ test_dataset_vlen_io(void) TESTING_2("write and read entire dataspace with string sequence"); /* Set up write buffer */ for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS; i++) { - if ((wbuf[i].p = calloc(i + 1, DATASET_VLEN_IO_STR_LEN * (i + 1))) == NULL) + if ((wbuf[i].p = calloc(i + 1, DATASET_VLEN_IO_STR_LEN)) == NULL) PART_TEST_ERROR(rw_all_string); for (size_t j = 0; j < i + 1; j++) { From cc8d305a3aff993155908d7f6dead4b8d6a94e76 Mon Sep 17 00:00:00 2001 From: mattjala <124107509+mattjala@users.noreply.github.com> Date: Mon, 4 Mar 2024 08:52:44 -0600 Subject: [PATCH 08/12] Fix VOL-compatibility issues in External Link API test (#4039) Fix link API tests with incorrect filename --- test/API/H5_api_link_test.c | 235 ++++++++++++++++++++++++++++++------ test/API/H5_api_link_test.h | 2 + 2 files changed, 199 insertions(+), 38 deletions(-) diff --git a/test/API/H5_api_link_test.c b/test/API/H5_api_link_test.c index 3f8ae2412dc..0f96b0c0b12 100644 --- a/test/API/H5_api_link_test.c +++ b/test/API/H5_api_link_test.c @@ -320,6 +320,7 @@ test_create_hard_link_many(void) hid_t file_id = H5I_INVALID_HID; hid_t container_group = H5I_INVALID_HID; hid_t group_id = H5I_INVALID_HID, group_id2 = H5I_INVALID_HID; + bool valid_name_matched = FALSE; char objname[HARD_LINK_TEST_GROUP_MANY_NAME_BUF_SIZE]; /* Object name */ TESTING("hard link creation of many links"); @@ -451,6 +452,7 @@ test_create_hard_link_many(void) HARD_LINK_TEST_GROUP_MANY_FINAL_NAME); goto error; } + /* Check name */ if (H5Iget_name(group_id2, objname, (size_t)HARD_LINK_TEST_GROUP_MANY_NAME_BUF_SIZE) < 0) { H5_FAILED(); @@ -458,9 +460,23 @@ test_create_hard_link_many(void) goto error; } - if (HDstrcmp(objname, "/" LINK_TEST_GROUP_NAME "/" HARD_LINK_TEST_GROUP_MANY_NAME "/hard21")) { + for (size_t i = 1; (i < HARD_LINK_TEST_GROUP_MANY_NUM_HARD_LINKS + 1 && !valid_name_matched); i++) { + char name_possibility[H5_API_TEST_FILENAME_MAX_LENGTH]; + + snprintf(name_possibility, H5_API_TEST_FILENAME_MAX_LENGTH, "%s%zu", + "/" LINK_TEST_GROUP_NAME "/" HARD_LINK_TEST_GROUP_MANY_NAME "/hard", i); + + valid_name_matched |= !strcmp(objname, name_possibility); + } + + valid_name_matched |= !strcmp(objname, "/" LINK_TEST_GROUP_NAME "/" HARD_LINK_TEST_GROUP_MANY_NAME + "/" HARD_LINK_TEST_GROUP_MANY_FINAL_NAME); + + if (!valid_name_matched) { H5_FAILED(); - printf(" wrong name of the object '%s'\n", objname); + printf(" H5Iget_name failed to retrieve a valid name for '%s'\n", + HARD_LINK_TEST_GROUP_MANY_FINAL_NAME); + goto error; } @@ -1506,7 +1522,8 @@ test_create_soft_link_long_name(void) static void test_create_soft_link_many(void) { - htri_t link_exists; + htri_t link_exists = FAIL; + bool valid_name_matched = FALSE; hid_t file_id = H5I_INVALID_HID; hid_t container_group = H5I_INVALID_HID; hid_t group_id = H5I_INVALID_HID; @@ -1660,9 +1677,23 @@ test_create_soft_link_many(void) goto error; } - if (HDstrcmp(objname, "/" LINK_TEST_GROUP_NAME "/" SOFT_LINK_TEST_GROUP_MANY_NAME "/soft16")) { + for (size_t i = 1; (i < SOFT_LINK_TEST_GROUP_MANY_NAME_SOFT_LINK_COUNT + 1 && !valid_name_matched); i++) { + char name_possibility[H5_API_TEST_FILENAME_MAX_LENGTH]; + + snprintf(name_possibility, H5_API_TEST_FILENAME_MAX_LENGTH, "%s%zu", + "/" LINK_TEST_GROUP_NAME "/" SOFT_LINK_TEST_GROUP_MANY_NAME "/soft", i); + + valid_name_matched |= !strcmp(objname, name_possibility); + } + + valid_name_matched |= !strcmp(objname, "/" LINK_TEST_GROUP_NAME "/" SOFT_LINK_TEST_GROUP_MANY_NAME + "/" SOFT_LINK_TEST_GROUP_MANY_FINAL_NAME); + + if (!valid_name_matched) { H5_FAILED(); - printf(" wrong name of the object '%s'\n", objname); + printf(" H5Iget_name failed to retrieve a valid name for '%s'\n", + "/" LINK_TEST_GROUP_NAME "/" SOFT_LINK_TEST_GROUP_MANY_NAME + "/" SOFT_LINK_TEST_GROUP_MANY_FINAL_NAME); goto error; } @@ -2440,9 +2471,10 @@ test_create_external_link_multi(void) PART_ERROR(H5Lcreate_external_final_file); } - if (HDstrcmp(objname, "/A/B/C")) { + if (strcmp(objname, "/A/B/C") && strcmp(objname, "/D/E/F") && strcmp(objname, "/G/H/I") && + strcmp(objname, "/" LINK_TEST_GROUP_NAME "/" EXTERNAL_LINK_TEST_MULTI_NAME "/ext_link")) { H5_FAILED(); - printf(" wrong name of the object '%s'\n", objname); + printf(" H5Iget_name failed to retrieve a valid name for the object '%s'\n", "/A/B/C"); PART_ERROR(H5Lcreate_external_final_file); } @@ -2510,9 +2542,13 @@ test_create_external_link_multi(void) PART_ERROR(H5Lcreate_external_object_created); } - if (HDstrcmp(objname, "/A/B/C/new_group")) { + if (strcmp(objname, "/A/B/C/new_group") && strcmp(objname, "/D/E/F/new_group") && + strcmp(objname, "/G/H/I/new_group") && + strcmp(objname, + "/" LINK_TEST_GROUP_NAME "/" EXTERNAL_LINK_TEST_MULTI_NAME "/ext_link/new_group")) { H5_FAILED(); - printf(" wrong name of the object '%s'\n", objname); + printf(" H5Iget_name was unable to retrieve a valid name for the object '%s'\n", + "/A/B/C/new_group"); PART_ERROR(H5Lcreate_external_object_created); } @@ -2582,11 +2618,12 @@ test_create_external_link_multi(void) static void test_create_external_link_ping_pong(void) { - hid_t file_id = H5I_INVALID_HID; - hid_t group_id = H5I_INVALID_HID; - hid_t group_id2 = H5I_INVALID_HID; - char *ext_link_filename1 = NULL; - char *ext_link_filename2 = NULL; + hid_t file_id = H5I_INVALID_HID; + hid_t group_id = H5I_INVALID_HID; + hid_t group_id2 = H5I_INVALID_HID; + bool valid_name_matched = false; + char *ext_link_filename1 = NULL; + char *ext_link_filename2 = NULL; char objname[EXTERNAL_LINK_TEST_MULTI_NAME_BUF_SIZE]; TESTING_MULTIPART("external link creation to an object in ping pong style"); @@ -2739,9 +2776,19 @@ test_create_external_link_ping_pong(void) PART_ERROR(H5Lcreate_external_verify); } - if (HDstrcmp(objname, "/final")) { + for (size_t i = 1; i < EXTERNAL_LINK_TEST_PING_PONG_NUM_LINKS + 1 && !valid_name_matched; i++) { + char name_possibility[H5_API_TEST_FILENAME_MAX_LENGTH]; + + snprintf(name_possibility, H5_API_TEST_FILENAME_MAX_LENGTH, "%s%zu", "/link", i); + + valid_name_matched |= !strcmp(name_possibility, objname); + } + + valid_name_matched |= !strcmp(objname, "/final"); + + if (!valid_name_matched) { H5_FAILED(); - printf(" wrong name of the object '%s'\n", objname); + printf(" H5Iget_name was unable to retrieve a valid name for the object '%s'\n", "/final"); PART_ERROR(H5Lcreate_external_verify); } @@ -2799,9 +2846,20 @@ test_create_external_link_ping_pong(void) PART_ERROR(H5Lcreate_external_verify_again); } - if (HDstrcmp(objname, "/final/new_group")) { + for (size_t i = 1; i < EXTERNAL_LINK_TEST_PING_PONG_NUM_LINKS + 1 && !valid_name_matched; i++) { + char name_possibility[H5_API_TEST_FILENAME_MAX_LENGTH]; + + snprintf(name_possibility, H5_API_TEST_FILENAME_MAX_LENGTH, "%s%zu%s", "/link", i, + "/new_group"); + + valid_name_matched |= !strcmp(objname, name_possibility); + } + + valid_name_matched |= !strcmp(objname, "/final/new_group"); + + if (!valid_name_matched) { H5_FAILED(); - printf(" wrong name of the object '%s'\n", objname); + printf(" H5Iget_name was unable to find a valid name for '%s'\n", "/final/new_group"); PART_ERROR(H5Lcreate_external_verify_again); } @@ -6853,6 +6911,8 @@ test_delete_link(void) TEST_ERROR; if (H5Fclose(file_id) < 0) TEST_ERROR; + if (H5Fclose(ext_file_id) < 0) + TEST_ERROR; if (remove_test_file(NULL, ext_link_filename) < 0) TEST_ERROR; free(ext_link_filename); @@ -8657,6 +8717,8 @@ test_copy_link(void) TEST_ERROR; if (H5Fclose(file_id) < 0) TEST_ERROR; + if (H5Fclose(ext_file_id) < 0) + TEST_ERROR; if (remove_test_file(NULL, ext_link_filename) < 0) TEST_ERROR; free(ext_link_filename); @@ -9038,6 +9100,8 @@ test_copy_link_invalid_params(void) TEST_ERROR; if (H5Fclose(file_id) < 0) TEST_ERROR; + if (H5Fclose(ext_file_id) < 0) + TEST_ERROR; if (remove_test_file(NULL, ext_link_filename) < 0) TEST_ERROR; free(ext_link_filename); @@ -10501,6 +10565,8 @@ test_move_link(void) TEST_ERROR; if (H5Fclose(file_id) < 0) TEST_ERROR; + if (H5Fclose(ext_file_id) < 0) + TEST_ERROR; if (remove_test_file(NULL, ext_link_filename) < 0) TEST_ERROR; free(ext_link_filename); @@ -11294,6 +11360,8 @@ test_move_link_invalid_params(void) TEST_ERROR; if (H5Fclose(file_id) < 0) TEST_ERROR; + if (H5Fclose(ext_file_id) < 0) + TEST_ERROR; if (remove_test_file(NULL, ext_link_filename) < 0) TEST_ERROR; free(ext_link_filename); @@ -13352,6 +13420,8 @@ test_get_link_val(void) TEST_ERROR; if (H5Fclose(file_id) < 0) TEST_ERROR; + if (H5Fclose(ext_file_id) < 0) + TEST_ERROR; if (remove_test_file(NULL, ext_link_filename) < 0) TEST_ERROR; free(ext_link_filename); @@ -19265,6 +19335,14 @@ test_link_iterate_hard_links(void) { TESTING_2("H5Literate2 by link name in increasing order"); + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_EXTERNAL_LINKS) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_UD_LINKS)) { + SKIPPED(); + printf(" API functions for external or user-defined link aren't supported with this " + "connector\n"); + PART_EMPTY(H5Literate_link_name_increasing); + } + i = 0; /* Test basic link iteration capability using both index types and both index orders */ @@ -19990,6 +20068,12 @@ test_link_iterate_external_links(void) { TESTING_2("H5Literate2 by link name in increasing order"); + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_EXTERNAL_LINKS)) { + SKIPPED(); + printf(" external link API is not supported with this VOL connector\n"); + PART_EMPTY(H5Literate_link_name_increasing); + } + i = 0; /* Test basic link iteration capability using both index types and both index orders */ @@ -20014,6 +20098,12 @@ test_link_iterate_external_links(void) { TESTING_2("H5Literate2 by link name in decreasing order"); + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_EXTERNAL_LINKS)) { + SKIPPED(); + printf(" external link API is not supported with this VOL connector\n"); + PART_EMPTY(H5Literate_link_name_decreasing); + } + /* Reset the counter to the appropriate value for the next test */ i = LINK_ITER_EXT_LINKS_TEST_NUM_LINKS; @@ -20038,9 +20128,11 @@ test_link_iterate_external_links(void) { TESTING_2("H5Literate2 by creation order in increasing order"); - if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER)) { + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_EXTERNAL_LINKS)) { SKIPPED(); - printf(" creation order tracking isn't supported with this VOL connector\n"); + printf(" creation order tracking or the external link API aren't supported with this VOL " + "connector\n"); PART_EMPTY(H5Literate_link_creation_increasing); } @@ -20068,9 +20160,11 @@ test_link_iterate_external_links(void) { TESTING_2("H5Literate2 by creation order in decreasing order"); - if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER)) { + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_EXTERNAL_LINKS)) { SKIPPED(); - printf(" creation order tracking isn't supported with this VOL connector\n"); + printf(" creation order tracking or the external link API aren't supported with this VOL " + "connector\n"); PART_EMPTY(H5Literate_link_creation_decreasing); } @@ -20098,6 +20192,12 @@ test_link_iterate_external_links(void) { TESTING_2("H5Literate_by_name2 by link name in increasing order"); + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_EXTERNAL_LINKS)) { + SKIPPED(); + printf(" the external link API is not supported with this VOL connector\n"); + PART_EMPTY(H5Literate_by_name_link_name_increasing); + } + /* Reset the counter to the appropriate value for the next test */ i = 0; @@ -20123,6 +20223,13 @@ test_link_iterate_external_links(void) { TESTING_2("H5Literate_by_name2 by link name in decreasing order"); + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_EXTERNAL_LINKS)) { + SKIPPED(); + printf(" creation order tracking or the external link API aren't supported with this VOL " + "connector\n"); + PART_EMPTY(H5Literate_by_name_creation_decreasing); + } + /* Reset the counter to the appropriate value for the next test */ i = LINK_ITER_EXT_LINKS_TEST_NUM_LINKS; @@ -20148,9 +20255,11 @@ test_link_iterate_external_links(void) { TESTING_2("H5Literate_by_name2 by creation order in increasing order"); - if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER)) { + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_EXTERNAL_LINKS)) { SKIPPED(); - printf(" creation order tracking isn't supported with this VOL connector\n"); + printf(" creation order tracking or the external link API aren't supported with this VOL " + "connector\n"); PART_EMPTY(H5Literate_by_name_creation_increasing); } @@ -20180,9 +20289,11 @@ test_link_iterate_external_links(void) { TESTING_2("H5Literate_by_name2 by creation order in decreasing order"); - if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER)) { + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_EXTERNAL_LINKS)) { SKIPPED(); - printf(" creation order tracking isn't supported with this VOL connector\n"); + printf(" creation order tracking or the external link API are not supported with this VOL " + "connector\n"); PART_EMPTY(H5Literate_by_name_creation_decreasing); } @@ -20434,6 +20545,14 @@ test_link_iterate_mixed_links(void) { TESTING_2("H5Literate2 by link name in increasing order"); + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_EXTERNAL_LINKS) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_UD_LINKS)) { + SKIPPED(); + printf(" creation order tracking, external links, or user-defined links aren't supported " + "with this VOL connector\n"); + PART_EMPTY(H5Literate_link_name_increasing); + } + i = 0; /* Test basic link iteration capability using both index types and both index orders */ @@ -20457,6 +20576,14 @@ test_link_iterate_mixed_links(void) { TESTING_2("H5Literate2 by link name in decreasing order"); + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_EXTERNAL_LINKS) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_UD_LINKS)) { + SKIPPED(); + printf(" creation order tracking, external links, or user-defined links aren't supported " + "with this VOL connector\n"); + PART_EMPTY(H5Literate_link_name_decreasing); + } + /* Reset the counter to the appropriate value for the next test */ i = LINK_ITER_MIXED_LINKS_TEST_NUM_LINKS; @@ -20480,9 +20607,12 @@ test_link_iterate_mixed_links(void) { TESTING_2("H5Literate2 by creation order in increasing order"); - if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER)) { + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_EXTERNAL_LINKS) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_UD_LINKS)) { SKIPPED(); - printf(" creation order tracking isn't supported with this VOL connector\n"); + printf(" creation order tracking, external links, or user-defined links aren't supported " + "with this VOL connector\n"); PART_EMPTY(H5Literate_link_creation_increasing); } @@ -20510,9 +20640,12 @@ test_link_iterate_mixed_links(void) { TESTING_2("H5Literate2 by creation order in decreasing order"); - if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER)) { + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_EXTERNAL_LINKS) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_UD_LINKS)) { SKIPPED(); - printf(" creation order tracking isn't supported with this VOL connector\n"); + printf(" creation order tracking, external links, or user-defined links aren't supported " + "with this VOL connector\n"); PART_EMPTY(H5Literate_link_creation_decreasing); } @@ -20540,6 +20673,13 @@ test_link_iterate_mixed_links(void) { TESTING_2("H5Literate_by_name2 by link name in increasing order"); + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_EXTERNAL_LINKS) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_UD_LINKS)) { + SKIPPED(); + printf(" external links or user-defined links aren't supported with this VOL connector\n"); + PART_EMPTY(H5Literate_by_name_link_name_increasing); + } + i = 0; if (H5Literate_by_name2( @@ -20564,6 +20704,13 @@ test_link_iterate_mixed_links(void) { TESTING_2("H5Literate_by_name2 by link name in decreasing order"); + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_EXTERNAL_LINKS) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_UD_LINKS)) { + SKIPPED(); + printf(" external links or user-defined links aren't supported with this VOL connector\n"); + PART_EMPTY(H5Literate_by_name_link_name_decreasing); + } + /* Reset the counter to the appropriate value for the next test */ i = LINK_ITER_MIXED_LINKS_TEST_NUM_LINKS; @@ -20589,9 +20736,12 @@ test_link_iterate_mixed_links(void) { TESTING_2("H5Literate_by_name2 by creation order in increasing order"); - if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER)) { + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_EXTERNAL_LINKS) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_UD_LINKS)) { SKIPPED(); - printf(" creation order tracking isn't supported with this VOL connector\n"); + printf(" creation order tracking, external links, or user-defined links aren't supported " + "with this VOL connector\n"); PART_EMPTY(H5Literate_by_name_creation_increasing); } @@ -20620,9 +20770,12 @@ test_link_iterate_mixed_links(void) { TESTING_2("H5Literate_by_name2 by creation order in decreasing order"); - if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER)) { + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_EXTERNAL_LINKS) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_UD_LINKS)) { SKIPPED(); - printf(" creation order tracking isn't supported with this VOL connector\n"); + printf(" creation order tracking, external links, or user-defined links aren't supported " + "with this VOL connector\n"); PART_EMPTY(H5Literate_by_name_creation_decreasing); } @@ -20651,9 +20804,12 @@ test_link_iterate_mixed_links(void) { TESTING_2("H5Literate2 index-saving capabilities in increasing order"); - if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER)) { + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_EXTERNAL_LINKS) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_UD_LINKS)) { SKIPPED(); - printf(" creation order tracking isn't supported with this VOL connector\n"); + printf(" creation order tracking, external links, or user-defined links aren't supported " + "with this VOL connector\n"); PART_EMPTY(H5Literate_index_saving_increasing); } @@ -20689,9 +20845,12 @@ test_link_iterate_mixed_links(void) { TESTING_2("H5Literate2 index-saving capabilities in decreasing order"); - if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER)) { + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_EXTERNAL_LINKS) || + !(vol_cap_flags_g & H5VL_CAP_FLAG_UD_LINKS)) { SKIPPED(); - printf(" creation order tracking isn't supported with this VOL connector\n"); + printf(" creation order tracking, external links, or user-defined links aren't supported " + "with this VOL connector\n"); PART_EMPTY(H5Literate_index_saving_decreasing); } diff --git a/test/API/H5_api_link_test.h b/test/API/H5_api_link_test.h index b5f8daf82c1..15815b191bc 100644 --- a/test/API/H5_api_link_test.h +++ b/test/API/H5_api_link_test.h @@ -32,6 +32,7 @@ void H5_api_link_test_add(void); #define HARD_LINK_TEST_GROUP_MANY_NAME "hard_link_many_name" #define HARD_LINK_TEST_GROUP_MANY_FINAL_NAME "hard_link_final" #define HARD_LINK_TEST_GROUP_MANY_NAME_BUF_SIZE 1024 +#define HARD_LINK_TEST_GROUP_MANY_NUM_HARD_LINKS 21 #define H5L_SAME_LOC_TEST_GROUP_NAME "h5l_same_loc_test_group" #define H5L_SAME_LOC_TEST_LINK_NAME1 "h5l_same_loc_test_link1" @@ -82,6 +83,7 @@ void H5_api_link_test_add(void); #define EXTERNAL_LINK_TEST_PING_PONG_NAME1 "ext_link_file_ping_pong_1.h5" #define EXTERNAL_LINK_TEST_PING_PONG_NAME2 "ext_link_file_ping_pong_2.h5" #define EXTERNAL_LINK_TEST_PING_PONG_NAME_BUF_SIZE 1024 +#define EXTERNAL_LINK_TEST_PING_PONG_NUM_LINKS 6 #define EXTERNAL_LINK_INVALID_PARAMS_TEST_GROUP_NAME "external_link_creation_invalid_params_test" #define EXTERNAL_LINK_INVALID_PARAMS_TEST_FILE_NAME "ext_link_invalid_params_file.h5" From dc27151d07e3cb3e41d26ab1623485eb043a0a6e Mon Sep 17 00:00:00 2001 From: mattjala <124107509+mattjala@users.noreply.github.com> Date: Thu, 7 Mar 2024 11:07:05 -0600 Subject: [PATCH 09/12] Close and reopen file during dset vlen IO API tests (#4050) - Close/reopen file and file objects to prevent cache from being used instead of actual I/O. - Moved vlen io test datasets under the dset container group instead of the root group - Moved the PASSED() invocation to after individual test cleanup in case an error occurs during H5Treclaim --- test/API/H5_api_dataset_test.c | 202 ++++++++++++++++++++++++++++++--- 1 file changed, 186 insertions(+), 16 deletions(-) diff --git a/test/API/H5_api_dataset_test.c b/test/API/H5_api_dataset_test.c index 4110dd714de..768ba490130 100644 --- a/test/API/H5_api_dataset_test.c +++ b/test/API/H5_api_dataset_test.c @@ -9805,27 +9805,49 @@ test_dataset_vlen_io(void) goto error; } - if ((dset_int = H5Dcreate2(file_id, DATASET_VLEN_IO_DSET_NAME "_int", vlen_int, space_id, H5P_DEFAULT, - H5P_DEFAULT, H5P_DEFAULT)) < 0) { + if ((dset_int = H5Dcreate2(container_group, DATASET_VLEN_IO_DSET_NAME "_int", vlen_int, space_id, + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { H5_FAILED(); printf(" couldn't create dataset with vlen integer sequence datatype"); goto error; } - if ((dset_float = H5Dcreate2(file_id, DATASET_VLEN_IO_DSET_NAME "_float", vlen_float, space_id, + if ((dset_float = H5Dcreate2(container_group, DATASET_VLEN_IO_DSET_NAME "_float", vlen_float, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { H5_FAILED(); printf(" couldn't create dataset with vlen float sequence datatype"); goto error; } - if ((dset_string = H5Dcreate2(file_id, DATASET_VLEN_IO_DSET_NAME "_string", vlen_string, space_id, + if ((dset_string = H5Dcreate2(container_group, DATASET_VLEN_IO_DSET_NAME "_string", vlen_string, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { H5_FAILED(); printf(" couldn't create dataset with vlen string sequence datatype"); goto error; } + /* Close datasets until individual tests */ + if (H5Dclose(dset_int) < 0) { + H5_FAILED(); + printf(" couldn't close dataset with vlen integer sequence datatype"); + } + + dset_int = H5I_INVALID_HID; + + if (H5Dclose(dset_float) < 0) { + H5_FAILED(); + printf(" couldn't close dataset with vlen float sequence datatype"); + } + + dset_float = H5I_INVALID_HID; + + if (H5Dclose(dset_string) < 0) { + H5_FAILED(); + printf(" couldn't close dataset with vlen string sequence datatype"); + } + + dset_string = H5I_INVALID_HID; + memset(wbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); memset(rbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); @@ -9848,10 +9870,39 @@ test_dataset_vlen_io(void) wbuf[i].len = i + 1; } + /* Open dataset */ + if ((dset_int = H5Dopen2(container_group, DATASET_VLEN_IO_DSET_NAME "_int", H5P_DEFAULT)) < 0) + PART_TEST_ERROR(rw_all_int); + /* Perform write */ if ((H5Dwrite(dset_int, vlen_int, space_id, H5S_ALL, H5P_DEFAULT, (const void *)wbuf)) < 0) PART_TEST_ERROR(rw_all_int); + /* Close and reopen file objects to flush cache */ + if (H5Dclose(dset_int) < 0) + PART_TEST_ERROR(rw_all_int); + + dset_int = H5I_INVALID_HID; + + if (H5Gclose(container_group) < 0) + PART_TEST_ERROR(rw_all_int); + + container_group = H5I_INVALID_HID; + + if (H5Fclose(file_id) < 0) + PART_TEST_ERROR(rw_all_int); + + file_id = H5I_INVALID_HID; + + if ((file_id = H5Fopen(H5_api_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) + PART_TEST_ERROR(rw_all_int); + + if ((container_group = H5Gopen(file_id, DATASET_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) + PART_TEST_ERROR(rw_all_int); + + if ((dset_int = H5Dopen2(container_group, DATASET_VLEN_IO_DSET_NAME "_int", H5P_DEFAULT)) < 0) + PART_TEST_ERROR(rw_all_int); + /* Perform read */ if ((H5Dread(dset_int, vlen_int, space_id, H5S_ALL, H5P_DEFAULT, (void *)rbuf)) < 0) PART_TEST_ERROR(rw_all_int); @@ -9869,10 +9920,13 @@ test_dataset_vlen_io(void) PART_TEST_ERROR(rw_all_int); } - PASSED(); + /* Close before use in selection tests */ + if (H5Dclose(dset_int) < 0) + PART_TEST_ERROR(rw_all_int); - /* Reset buffers */ + dset_int = H5I_INVALID_HID; + /* Reset buffers */ if (H5Treclaim(vlen_int, space_id, H5P_DEFAULT, rbuf) < 0) PART_TEST_ERROR(rw_all_int); @@ -9881,8 +9935,11 @@ test_dataset_vlen_io(void) memset(wbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); memset(rbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); + + PASSED(); } PART_END(rw_all_int) + PART_BEGIN(rw_all_float) { TESTING_2("write and read entire dataspace with float sequence"); /* Set up write buffer */ @@ -9897,10 +9954,39 @@ test_dataset_vlen_io(void) wbuf[i].len = i + 1; } + /* Open dataset */ + if ((dset_float = H5Dopen2(container_group, DATASET_VLEN_IO_DSET_NAME "_float", H5P_DEFAULT)) < 0) + PART_TEST_ERROR(rw_all_float); + /* Perform write */ if ((H5Dwrite(dset_float, vlen_float, space_id, H5S_ALL, H5P_DEFAULT, (const void *)wbuf)) < 0) PART_TEST_ERROR(rw_all_float); + /* Close and reopen file objects to flush cache */ + if (H5Dclose(dset_float) < 0) + PART_TEST_ERROR(rw_all_float); + + dset_float = H5I_INVALID_HID; + + if (H5Gclose(container_group) < 0) + PART_TEST_ERROR(rw_all_float); + + container_group = H5I_INVALID_HID; + + if (H5Fclose(file_id) < 0) + PART_TEST_ERROR(rw_all_float); + + file_id = H5I_INVALID_HID; + + if ((file_id = H5Fopen(H5_api_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) + PART_TEST_ERROR(rw_all_float); + + if ((container_group = H5Gopen2(file_id, DATASET_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) + PART_TEST_ERROR(rw_all_float); + + if ((dset_float = H5Dopen2(container_group, DATASET_VLEN_IO_DSET_NAME "_float", H5P_DEFAULT)) < 0) + PART_TEST_ERROR(rw_all_float); + /* Perform read */ if ((H5Dread(dset_float, vlen_float, space_id, H5S_ALL, H5P_DEFAULT, (void *)rbuf)) < 0) PART_TEST_ERROR(rw_all_float); @@ -9922,8 +10008,6 @@ test_dataset_vlen_io(void) } } - PASSED(); - /* Reset buffers */ if (H5Treclaim(vlen_float, space_id, H5P_DEFAULT, rbuf) < 0) @@ -9934,7 +10018,8 @@ test_dataset_vlen_io(void) memset(wbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); memset(rbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); - PART_BEGIN(rw_all_float) + + PASSED(); } PART_END(rw_all_float); @@ -9954,10 +10039,41 @@ test_dataset_vlen_io(void) wbuf[i].len = i + 1; } + /* Open the dataset */ + if ((dset_string = H5Dopen2(container_group, DATASET_VLEN_IO_DSET_NAME "_string", H5P_DEFAULT)) < + 0) + PART_TEST_ERROR(rw_all_string); + /* Perform write */ if ((H5Dwrite(dset_string, vlen_string, space_id, H5S_ALL, H5P_DEFAULT, (const void *)wbuf)) < 0) PART_TEST_ERROR(rw_all_string); + /* Close and reopen file objects to flush cache */ + if (H5Dclose(dset_string) < 0) + PART_TEST_ERROR(rw_all_string); + + dset_string = H5I_INVALID_HID; + + if (H5Gclose(container_group) < 0) + PART_TEST_ERROR(rw_all_string); + + container_group = H5I_INVALID_HID; + + if (H5Fclose(file_id) < 0) + PART_TEST_ERROR(rw_all_string); + + file_id = H5I_INVALID_HID; + + if ((file_id = H5Fopen(H5_api_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) + PART_TEST_ERROR(rw_all_string); + + if ((container_group = H5Gopen2(file_id, DATASET_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) + PART_TEST_ERROR(rw_all_string); + + if ((dset_string = H5Dopen2(container_group, DATASET_VLEN_IO_DSET_NAME "_string", H5P_DEFAULT)) < + 0) + PART_TEST_ERROR(rw_all_string); + /* Perform read */ if ((H5Dread(dset_string, vlen_string, space_id, H5S_ALL, H5P_DEFAULT, (void *)rbuf)) < 0) PART_TEST_ERROR(rw_all_string); @@ -9981,8 +10097,6 @@ test_dataset_vlen_io(void) } } - PASSED(); - /* Reset buffers */ if (H5Treclaim(vlen_string, space_id, H5P_DEFAULT, rbuf) < 0) @@ -9993,6 +10107,8 @@ test_dataset_vlen_io(void) memset(wbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); memset(rbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); + + PASSED(); } PART_END(rw_all_string); @@ -10019,10 +10135,36 @@ test_dataset_vlen_io(void) wbuf[i].len = i + 1; } + /* Open dataset */ + if ((dset_int = H5Dopen2(container_group, DATASET_VLEN_IO_DSET_NAME "_int", H5P_DEFAULT)) < 0) + PART_TEST_ERROR(rw_point_selection); + /* Perform write */ if ((H5Dwrite(dset_int, vlen_int, space_id, space_id, H5P_DEFAULT, (const void *)wbuf)) < 0) PART_TEST_ERROR(rw_point_selection); + /* Close and reopen file objects to flush cache */ + if (H5Dclose(dset_int) < 0) + PART_TEST_ERROR(rw_point_selection); + dset_int = H5I_INVALID_HID; + + if (H5Gclose(container_group) < 0) + PART_TEST_ERROR(rw_point_selection); + container_group = H5I_INVALID_HID; + + if (H5Fclose(file_id) < 0) + PART_TEST_ERROR(rw_point_selection); + file_id = H5I_INVALID_HID; + + if ((file_id = H5Fopen(H5_api_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) + PART_TEST_ERROR(rw_point_selection); + + if ((container_group = H5Gopen2(file_id, DATASET_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) + PART_TEST_ERROR(rw_point_selection); + + if ((dset_int = H5Dopen2(container_group, DATASET_VLEN_IO_DSET_NAME "_int", H5P_DEFAULT)) < 0) + PART_TEST_ERROR(rw_point_selection); + /* Perform read */ if ((H5Dread(dset_int, vlen_int, space_id, space_id, H5P_DEFAULT, (void *)rbuf)) < 0) PART_TEST_ERROR(rw_point_selection); @@ -10049,10 +10191,11 @@ test_dataset_vlen_io(void) } } - PASSED(); + if (H5Dclose(dset_int) < 0) + PART_TEST_ERROR(rw_point_selection); + dset_int = H5I_INVALID_HID; /* Reset buffers */ - if (H5Treclaim(vlen_int, space_id, H5P_DEFAULT, rbuf) < 0) PART_TEST_ERROR(rw_point_selection); @@ -10061,6 +10204,8 @@ test_dataset_vlen_io(void) memset(wbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); memset(rbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); + + PASSED(); } PART_END(rw_point_selection); @@ -10087,10 +10232,36 @@ test_dataset_vlen_io(void) wbuf[i].len = i + 1; } + /* Open dataset */ + if ((dset_int = H5Dopen2(container_group, DATASET_VLEN_IO_DSET_NAME "_int", H5P_DEFAULT)) < 0) + PART_TEST_ERROR(rw_hyperslab_selection); + /* Perform write */ if ((H5Dwrite(dset_int, vlen_int, space_id, space_id, H5P_DEFAULT, (const void *)wbuf)) < 0) PART_TEST_ERROR(rw_hyperslab_selection); + /* Close and reopen file objects to flush cache */ + if (H5Dclose(dset_int) < 0) + PART_TEST_ERROR(rw_hyperslab_selection); + dset_int = H5I_INVALID_HID; + + if (H5Gclose(container_group) < 0) + PART_TEST_ERROR(rw_hyperslab_selection); + container_group = H5I_INVALID_HID; + + if (H5Fclose(file_id) < 0) + PART_TEST_ERROR(rw_hyperslab_selection); + file_id = H5I_INVALID_HID; + + if ((file_id = H5Fopen(H5_api_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) + PART_TEST_ERROR(rw_hyperslab_selection); + + if ((container_group = H5Gopen2(file_id, DATASET_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) + PART_TEST_ERROR(rw_hyperslab_selection); + + if ((dset_int = H5Dopen2(container_group, DATASET_VLEN_IO_DSET_NAME "_int", H5P_DEFAULT)) < 0) + PART_TEST_ERROR(rw_hyperslab_selection); + /* Perform read */ if ((H5Dread(dset_int, vlen_int, space_id, space_id, H5P_DEFAULT, (void *)rbuf)) < 0) PART_TEST_ERROR(rw_hyperslab_selection); @@ -10117,10 +10288,7 @@ test_dataset_vlen_io(void) } } - PASSED(); - /* Reset buffers */ - if (H5Treclaim(vlen_int, space_id, H5P_DEFAULT, rbuf) < 0) PART_TEST_ERROR(rw_hyperslab_selection); @@ -10129,6 +10297,8 @@ test_dataset_vlen_io(void) memset(wbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); memset(rbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); + + PASSED(); } PART_END(rw_hyperslab_selection); } From 56ff8c6135c4e4fe2da7068aae32990358376f02 Mon Sep 17 00:00:00 2001 From: mattjala <124107509+mattjala@users.noreply.github.com> Date: Wed, 13 Mar 2024 14:55:51 -0500 Subject: [PATCH 10/12] Fix segfault in vlen io API test (#4130) --- test/API/H5_api_dataset_test.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/test/API/H5_api_dataset_test.c b/test/API/H5_api_dataset_test.c index 768ba490130..59203dd45ab 100644 --- a/test/API/H5_api_dataset_test.c +++ b/test/API/H5_api_dataset_test.c @@ -9749,6 +9749,9 @@ test_dataset_vlen_io(void) hvl_t wbuf[DATASET_VLEN_IO_DSET_DIMS]; hvl_t rbuf[DATASET_VLEN_IO_DSET_DIMS]; + memset(wbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); + memset(rbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); + TESTING_MULTIPART( "verification of dataset data with H5Dwrite and then H5D read with variable length sequence data"); @@ -9897,7 +9900,7 @@ test_dataset_vlen_io(void) if ((file_id = H5Fopen(H5_api_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) PART_TEST_ERROR(rw_all_int); - if ((container_group = H5Gopen(file_id, DATASET_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) + if ((container_group = H5Gopen2(file_id, DATASET_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) PART_TEST_ERROR(rw_all_int); if ((dset_int = H5Dopen2(container_group, DATASET_VLEN_IO_DSET_NAME "_int", H5P_DEFAULT)) < 0) @@ -10114,6 +10117,7 @@ test_dataset_vlen_io(void) PART_BEGIN(rw_point_selection) { + TESTING_2("write with point selection"); /* Select even-indexed points */ for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS / 2; i++) point_coords[i] = i * 2; @@ -10211,6 +10215,7 @@ test_dataset_vlen_io(void) PART_BEGIN(rw_hyperslab_selection) { + TESTING_2("write with hyperslab selection"); /* Select hyperslab of every 3rd element */ const hsize_t start[1] = {0}; const hsize_t stride[1] = {3}; @@ -10318,6 +10323,7 @@ test_dataset_vlen_io(void) TEST_ERROR; if (H5Sclose(space_id) < 0) TEST_ERROR; + /* In case of memory allocation error, not all hvl_t buffers in array may be allocated. * Free one-by-one */ for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS; i++) { @@ -10351,9 +10357,12 @@ test_dataset_vlen_io(void) { H5Fclose(file_id); H5Gclose(container_group); - H5Dclose(dset_int); - H5Dclose(dset_float); - H5Dclose(dset_string); + if (dset_int != H5I_INVALID_HID) + H5Dclose(dset_int); + if (dset_float != H5I_INVALID_HID) + H5Dclose(dset_float); + if (dset_string != H5I_INVALID_HID) + H5Dclose(dset_string); H5Sclose(space_id); for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS; i++) { if (wbuf[i].p) { From dadf97b2a103661ce16caf98534e1b73b56fb469 Mon Sep 17 00:00:00 2001 From: mattjala <124107509+mattjala@users.noreply.github.com> Date: Wed, 20 Mar 2024 12:50:40 -0500 Subject: [PATCH 11/12] Vlen IO API test fixes --- test/API/H5_api_dataset_test.c | 112 ++++++++++++++++----------------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/test/API/H5_api_dataset_test.c b/test/API/H5_api_dataset_test.c index 59203dd45ab..6374fda2d74 100644 --- a/test/API/H5_api_dataset_test.c +++ b/test/API/H5_api_dataset_test.c @@ -9851,9 +9851,6 @@ test_dataset_vlen_io(void) dset_string = H5I_INVALID_HID; - memset(wbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); - memset(rbuf, 0, sizeof(hvl_t) * DATASET_VLEN_IO_DSET_DIMS); - PASSED(); BEGIN_MULTIPART @@ -9881,6 +9878,9 @@ test_dataset_vlen_io(void) if ((H5Dwrite(dset_int, vlen_int, space_id, H5S_ALL, H5P_DEFAULT, (const void *)wbuf)) < 0) PART_TEST_ERROR(rw_all_int); + if (H5Dflush(dset_int) < 0) + PART_TEST_ERROR(rw_hyperslab_selection); + /* Close and reopen file objects to flush cache */ if (H5Dclose(dset_int) < 0) PART_TEST_ERROR(rw_all_int); @@ -9897,7 +9897,7 @@ test_dataset_vlen_io(void) file_id = H5I_INVALID_HID; - if ((file_id = H5Fopen(H5_api_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) + if ((file_id = H5Fopen(H5_API_TEST_FILENAME, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) PART_TEST_ERROR(rw_all_int); if ((container_group = H5Gopen2(file_id, DATASET_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) @@ -9910,6 +9910,11 @@ test_dataset_vlen_io(void) if ((H5Dread(dset_int, vlen_int, space_id, H5S_ALL, H5P_DEFAULT, (void *)rbuf)) < 0) PART_TEST_ERROR(rw_all_int); + /* Close to finalize read */ + if (H5Dclose(dset_int) < 0) + PART_TEST_ERROR(rw_all_int); + dset_int = H5I_INVALID_HID; + /* Verify data */ for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS; i++) { if (!rbuf[i].p) @@ -9923,12 +9928,6 @@ test_dataset_vlen_io(void) PART_TEST_ERROR(rw_all_int); } - /* Close before use in selection tests */ - if (H5Dclose(dset_int) < 0) - PART_TEST_ERROR(rw_all_int); - - dset_int = H5I_INVALID_HID; - /* Reset buffers */ if (H5Treclaim(vlen_int, space_id, H5P_DEFAULT, rbuf) < 0) PART_TEST_ERROR(rw_all_int); @@ -9965,6 +9964,9 @@ test_dataset_vlen_io(void) if ((H5Dwrite(dset_float, vlen_float, space_id, H5S_ALL, H5P_DEFAULT, (const void *)wbuf)) < 0) PART_TEST_ERROR(rw_all_float); + if (H5Dflush(dset_float) < 0) + PART_TEST_ERROR(rw_hyperslab_selection); + /* Close and reopen file objects to flush cache */ if (H5Dclose(dset_float) < 0) PART_TEST_ERROR(rw_all_float); @@ -9981,7 +9983,7 @@ test_dataset_vlen_io(void) file_id = H5I_INVALID_HID; - if ((file_id = H5Fopen(H5_api_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) + if ((file_id = H5Fopen(H5_API_TEST_FILENAME, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) PART_TEST_ERROR(rw_all_float); if ((container_group = H5Gopen2(file_id, DATASET_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) @@ -9994,6 +9996,11 @@ test_dataset_vlen_io(void) if ((H5Dread(dset_float, vlen_float, space_id, H5S_ALL, H5P_DEFAULT, (void *)rbuf)) < 0) PART_TEST_ERROR(rw_all_float); + /* Close to finalize read */ + if (H5Dclose(dset_float) < 0) + PART_TEST_ERROR(rw_all_float); + dset_float = H5I_INVALID_HID; + /* Verify data */ for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS; i++) { if (!rbuf[i].p) @@ -10012,7 +10019,6 @@ test_dataset_vlen_io(void) } /* Reset buffers */ - if (H5Treclaim(vlen_float, space_id, H5P_DEFAULT, rbuf) < 0) PART_TEST_ERROR(rw_all_float); @@ -10051,6 +10057,9 @@ test_dataset_vlen_io(void) if ((H5Dwrite(dset_string, vlen_string, space_id, H5S_ALL, H5P_DEFAULT, (const void *)wbuf)) < 0) PART_TEST_ERROR(rw_all_string); + if (H5Dflush(dset_string) < 0) + PART_TEST_ERROR(rw_hyperslab_selection); + /* Close and reopen file objects to flush cache */ if (H5Dclose(dset_string) < 0) PART_TEST_ERROR(rw_all_string); @@ -10067,7 +10076,7 @@ test_dataset_vlen_io(void) file_id = H5I_INVALID_HID; - if ((file_id = H5Fopen(H5_api_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) + if ((file_id = H5Fopen(H5_API_TEST_FILENAME, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) PART_TEST_ERROR(rw_all_string); if ((container_group = H5Gopen2(file_id, DATASET_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) @@ -10081,6 +10090,11 @@ test_dataset_vlen_io(void) if ((H5Dread(dset_string, vlen_string, space_id, H5S_ALL, H5P_DEFAULT, (void *)rbuf)) < 0) PART_TEST_ERROR(rw_all_string); + /* Close to finalize read */ + if (H5Dclose(dset_string) < 0) + PART_TEST_ERROR(rw_all_string); + dset_string = H5I_INVALID_HID; + /* Verify data */ for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS; i++) { if (!rbuf[i].p) @@ -10101,7 +10115,6 @@ test_dataset_vlen_io(void) } /* Reset buffers */ - if (H5Treclaim(vlen_string, space_id, H5P_DEFAULT, rbuf) < 0) PART_TEST_ERROR(rw_all_string); @@ -10147,6 +10160,9 @@ test_dataset_vlen_io(void) if ((H5Dwrite(dset_int, vlen_int, space_id, space_id, H5P_DEFAULT, (const void *)wbuf)) < 0) PART_TEST_ERROR(rw_point_selection); + if (H5Dflush(dset_int) < 0) + PART_TEST_ERROR(rw_hyperslab_selection); + /* Close and reopen file objects to flush cache */ if (H5Dclose(dset_int) < 0) PART_TEST_ERROR(rw_point_selection); @@ -10160,7 +10176,7 @@ test_dataset_vlen_io(void) PART_TEST_ERROR(rw_point_selection); file_id = H5I_INVALID_HID; - if ((file_id = H5Fopen(H5_api_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) + if ((file_id = H5Fopen(H5_API_TEST_FILENAME, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) PART_TEST_ERROR(rw_point_selection); if ((container_group = H5Gopen2(file_id, DATASET_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) @@ -10173,6 +10189,11 @@ test_dataset_vlen_io(void) if ((H5Dread(dset_int, vlen_int, space_id, space_id, H5P_DEFAULT, (void *)rbuf)) < 0) PART_TEST_ERROR(rw_point_selection); + /* Close to finalize read */ + if (H5Dclose(dset_int) < 0) + PART_TEST_ERROR(rw_point_selection); + dset_int = H5I_INVALID_HID; + /* Verify data */ for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS; i++) { if (i % 2 == 0) { @@ -10195,10 +10216,6 @@ test_dataset_vlen_io(void) } } - if (H5Dclose(dset_int) < 0) - PART_TEST_ERROR(rw_point_selection); - dset_int = H5I_INVALID_HID; - /* Reset buffers */ if (H5Treclaim(vlen_int, space_id, H5P_DEFAULT, rbuf) < 0) PART_TEST_ERROR(rw_point_selection); @@ -10245,6 +10262,9 @@ test_dataset_vlen_io(void) if ((H5Dwrite(dset_int, vlen_int, space_id, space_id, H5P_DEFAULT, (const void *)wbuf)) < 0) PART_TEST_ERROR(rw_hyperslab_selection); + if (H5Dflush(dset_int) < 0) + PART_TEST_ERROR(rw_hyperslab_selection); + /* Close and reopen file objects to flush cache */ if (H5Dclose(dset_int) < 0) PART_TEST_ERROR(rw_hyperslab_selection); @@ -10258,7 +10278,7 @@ test_dataset_vlen_io(void) PART_TEST_ERROR(rw_hyperslab_selection); file_id = H5I_INVALID_HID; - if ((file_id = H5Fopen(H5_api_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) + if ((file_id = H5Fopen(H5_API_TEST_FILENAME, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) PART_TEST_ERROR(rw_hyperslab_selection); if ((container_group = H5Gopen2(file_id, DATASET_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) @@ -10271,6 +10291,11 @@ test_dataset_vlen_io(void) if ((H5Dread(dset_int, vlen_int, space_id, space_id, H5P_DEFAULT, (void *)rbuf)) < 0) PART_TEST_ERROR(rw_hyperslab_selection); + /* Close to finalize read */ + if (H5Dclose(dset_int) < 0) + PART_TEST_ERROR(rw_hyperslab_selection); + dset_int = H5I_INVALID_HID; + /* Verify data */ for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS; i++) { if (i % stride[0] == 0) { @@ -10311,42 +10336,18 @@ test_dataset_vlen_io(void) TESTING_2("test cleanup"); - if (H5Fclose(file_id) < 0) - TEST_ERROR; - if (H5Gclose(container_group) < 0) - TEST_ERROR; - if (H5Dclose(dset_int) < 0) - TEST_ERROR; - if (H5Dclose(dset_float) < 0) - TEST_ERROR; - if (H5Dclose(dset_string) < 0) - TEST_ERROR; if (H5Sclose(space_id) < 0) TEST_ERROR; - - /* In case of memory allocation error, not all hvl_t buffers in array may be allocated. - * Free one-by-one */ - for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS; i++) { - if (wbuf[i].p) { - free(wbuf[i].p); - wbuf[i].p = NULL; - } - } - - for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS; i++) { - if (rbuf[i].p) { - free(rbuf[i].p); - rbuf[i].p = NULL; - } - } - if (H5Tclose(vlen_int) < 0) TEST_ERROR; if (H5Tclose(vlen_float) < 0) TEST_ERROR; if (H5Tclose(vlen_string) < 0) TEST_ERROR; - + if (H5Gclose(container_group) < 0) + TEST_ERROR; + if (H5Fclose(file_id) < 0) + TEST_ERROR; PASSED(); return; @@ -10355,15 +10356,12 @@ test_dataset_vlen_io(void) H5E_BEGIN_TRY { - H5Fclose(file_id); - H5Gclose(container_group); - if (dset_int != H5I_INVALID_HID) - H5Dclose(dset_int); - if (dset_float != H5I_INVALID_HID) - H5Dclose(dset_float); - if (dset_string != H5I_INVALID_HID) - H5Dclose(dset_string); + H5Dclose(dset_int); + H5Dclose(dset_float); + H5Dclose(dset_string); H5Sclose(space_id); + /* In case of memory allocation error, not all hvl_t buffers in array may be allocated. + * Free one-by-one */ for (size_t i = 0; i < DATASET_VLEN_IO_DSET_DIMS; i++) { if (wbuf[i].p) { free(wbuf[i].p); @@ -10380,6 +10378,8 @@ test_dataset_vlen_io(void) H5Tclose(vlen_int); H5Tclose(vlen_float); H5Tclose(vlen_string); + H5Gclose(container_group); + H5Fclose(file_id); } H5E_END_TRY From edd27afb5bf90e2c6aa7a31f687468ae3141e4e6 Mon Sep 17 00:00:00 2001 From: Scot Breitenfeld Date: Tue, 2 Jul 2024 09:25:15 -0500 Subject: [PATCH 12/12] Test fixes for log-based vol (#4618) * fixes to address failures in the log-based VOL * moved file cleanup to tests proper * skipped index API test if not supported --- test/API/H5_api_attribute_test.c | 8 ++-- test/API/H5_api_group_test.c | 40 ++++++++++-------- test/API/H5_api_link_test.c | 72 ++++++++++++++++++++++++++++++++ test/API/H5_api_object_test.c | 1 - 4 files changed, 97 insertions(+), 24 deletions(-) diff --git a/test/API/H5_api_attribute_test.c b/test/API/H5_api_attribute_test.c index 3979c5bd2f0..5aaab9de64a 100644 --- a/test/API/H5_api_attribute_test.c +++ b/test/API/H5_api_attribute_test.c @@ -8781,15 +8781,11 @@ test_attribute_string_encodings(void) PASSED(); } PART_END(UTF8_cset); - - PASSED(); } END_MULTIPART; TESTING_2("test cleanup"); - if (H5Fclose(file_id) < 0) - TEST_ERROR; if (H5Gclose(container_group) < 0) TEST_ERROR; if (H5Dclose(dset_id1) < 0) @@ -8804,6 +8800,8 @@ test_attribute_string_encodings(void) TEST_ERROR; if (H5Aclose(attr_id2) < 0) TEST_ERROR; + if (H5Fclose(file_id) < 0) + TEST_ERROR; if (write_buf) free(write_buf); if (read_buf) @@ -8816,7 +8814,6 @@ test_attribute_string_encodings(void) error: H5E_BEGIN_TRY { - H5Fclose(file_id); H5Gclose(container_group); H5Dclose(dset_id1); H5Dclose(dset_id2); @@ -8824,6 +8821,7 @@ test_attribute_string_encodings(void) H5Tclose(type_id2); H5Aclose(attr_id1); H5Aclose(attr_id2); + H5Fclose(file_id); if (write_buf) free(write_buf); if (read_buf) diff --git a/test/API/H5_api_group_test.c b/test/API/H5_api_group_test.c index 24832baf0cd..e8dd7ae0eb0 100644 --- a/test/API/H5_api_group_test.c +++ b/test/API/H5_api_group_test.c @@ -1462,15 +1462,17 @@ test_get_group_info(void) PART_ERROR(H5Gget_info); } - /* - * For the purpose of this test, the max creation order should match - * the number of links in the group. - */ - if (group_info.max_corder != GROUP_GET_INFO_TEST_GROUP_NUMB) { - H5_FAILED(); - printf(" group's max creation order '%lld' doesn't match expected value '%lld'\n", - (long long)group_info.max_corder, (long long)GROUP_GET_INFO_TEST_GROUP_NUMB); - PART_ERROR(H5Gget_info); + if (vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER) { + /* + * For the purpose of this test, the max creation order should match + * the number of links in the group. + */ + if (group_info.max_corder != GROUP_GET_INFO_TEST_GROUP_NUMB) { + H5_FAILED(); + printf(" group's max creation order '%lld' doesn't match expected value '%lld'\n", + (long long)group_info.max_corder, (long long)GROUP_GET_INFO_TEST_GROUP_NUMB); + PART_ERROR(H5Gget_info); + } } /* Ensure that the storage_type field is at least set to a meaningful value */ @@ -1515,15 +1517,17 @@ test_get_group_info(void) PART_ERROR(H5Gget_info_by_name); } - /* - * For the purpose of this test, the max creation order should match - * the number of links in the group. - */ - if (group_info.max_corder != GROUP_GET_INFO_TEST_GROUP_NUMB) { - H5_FAILED(); - printf(" group's max creation order '%lld' doesn't match expected value '%lld'\n", - (long long)group_info.max_corder, (long long)GROUP_GET_INFO_TEST_GROUP_NUMB); - PART_ERROR(H5Gget_info_by_name); + if (vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER) { + /* + * For the purpose of this test, the max creation order should match + * the number of links in the group. + */ + if (group_info.max_corder != GROUP_GET_INFO_TEST_GROUP_NUMB) { + H5_FAILED(); + printf(" group's max creation order '%lld' doesn't match expected value '%lld'\n", + (long long)group_info.max_corder, (long long)GROUP_GET_INFO_TEST_GROUP_NUMB); + PART_ERROR(H5Gget_info_by_name); + } } /* Ensure that the storage_type field is at least set to a meaningful value */ diff --git a/test/API/H5_api_link_test.c b/test/API/H5_api_link_test.c index 0f96b0c0b12..19947790509 100644 --- a/test/API/H5_api_link_test.c +++ b/test/API/H5_api_link_test.c @@ -3935,6 +3935,12 @@ test_delete_link(void) { TESTING_2("H5Ldelete_by_idx on hard link by creation order in increasing order"); + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_BY_IDX)) { + SKIPPED(); + printf(" by index isn't supported with this VOL connector\n"); + PART_EMPTY(H5Ldelete_by_idx_hard_crt_order_increasing); + } + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER)) { SKIPPED(); printf(" creation order tracking isn't supported with this VOL connector\n"); @@ -4168,6 +4174,12 @@ test_delete_link(void) { TESTING_2("H5Ldelete_by_idx on hard link by creation order in decreasing order"); + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_BY_IDX)) { + SKIPPED(); + printf(" by index isn't supported with this VOL connector\n"); + PART_EMPTY(H5Ldelete_by_idx_hard_crt_order_decreasing); + } + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER)) { SKIPPED(); printf(" creation order tracking isn't supported with this VOL connector\n"); @@ -4401,6 +4413,12 @@ test_delete_link(void) { TESTING_2("H5Ldelete_by_idx on hard link by alphabetical order in increasing order"); + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_BY_IDX)) { + SKIPPED(); + printf(" by index isn't supported with this VOL connector\n"); + PART_EMPTY(H5Ldelete_by_idx_hard_name_order_increasing); + } + if ((subgroup_id = H5Gcreate2(group_id, LINK_DELETE_TEST_SUBGROUP7_NAME, H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0) { H5_FAILED(); @@ -4628,6 +4646,12 @@ test_delete_link(void) { TESTING_2("H5Ldelete_by_idx on hard link by alphabetical order in decreasing order"); + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_BY_IDX)) { + SKIPPED(); + printf(" by index isn't supported with this VOL connector\n"); + PART_EMPTY(H5Ldelete_by_idx_hard_name_order_decreasing); + } + if ((subgroup_id = H5Gcreate2(group_id, LINK_DELETE_TEST_SUBGROUP8_NAME, H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0) { H5_FAILED(); @@ -4855,6 +4879,12 @@ test_delete_link(void) { TESTING_2("H5Ldelete_by_idx on soft link by creation order in increasing order"); + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_BY_IDX)) { + SKIPPED(); + printf(" by index isn't supported with this VOL connector\n"); + PART_EMPTY(H5Ldelete_by_idx_soft_crt_order_increasing); + } + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER)) { SKIPPED(); printf(" creation order tracking isn't supported with this VOL connector\n"); @@ -5091,6 +5121,12 @@ test_delete_link(void) { TESTING_2("H5Ldelete_by_idx on soft link by creation order in decreasing order"); + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_BY_IDX)) { + SKIPPED(); + printf(" by index isn't supported with this VOL connector\n"); + PART_EMPTY(H5Ldelete_by_idx_soft_crt_order_decreasing); + } + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER)) { SKIPPED(); printf(" creation order tracking isn't supported with this VOL connector\n"); @@ -5327,6 +5363,12 @@ test_delete_link(void) { TESTING_2("H5Ldelete_by_idx on soft link by alphabetical order in increasing order"); + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_BY_IDX)) { + SKIPPED(); + printf(" by index isn't supported with this VOL connector\n"); + PART_EMPTY(H5Ldelete_by_idx_soft_name_order_increasing); + } + if ((subgroup_id = H5Gcreate2(group_id, LINK_DELETE_TEST_SUBGROUP11_NAME, H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0) { H5_FAILED(); @@ -5557,6 +5599,12 @@ test_delete_link(void) { TESTING_2("H5Ldelete_by_idx on soft link by alphabetical order in decreasing order"); + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_BY_IDX)) { + SKIPPED(); + printf(" by index isn't supported with this VOL connector\n"); + PART_EMPTY(H5Ldelete_by_idx_soft_name_order_decreasing); + } + if ((subgroup_id = H5Gcreate2(group_id, LINK_DELETE_TEST_SUBGROUP12_NAME, H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0) { H5_FAILED(); @@ -5787,6 +5835,12 @@ test_delete_link(void) { TESTING_2("H5Ldelete_by_idx on external link by creation order in increasing order"); + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_BY_IDX)) { + SKIPPED(); + printf(" by index isn't supported with this VOL connector\n"); + PART_EMPTY(H5Ldelete_by_idx_external_crt_order_increasing); + } + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER)) { SKIPPED(); printf(" creation order tracking isn't supported with this VOL connector\n"); @@ -6051,6 +6105,12 @@ test_delete_link(void) { TESTING_2("H5Ldelete_by_idx on external link by creation order in decreasing order"); + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_BY_IDX)) { + SKIPPED(); + printf(" by index isn't supported with this VOL connector\n"); + PART_EMPTY(H5Ldelete_by_idx_external_crt_order_decreasing); + } + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_CREATION_ORDER)) { SKIPPED(); printf(" creation order tracking isn't supported with this VOL connector\n"); @@ -6315,6 +6375,12 @@ test_delete_link(void) { TESTING_2("H5Ldelete_by_idx on external link by alphabetical order in increasing order"); + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_BY_IDX)) { + SKIPPED(); + printf(" by index isn't supported with this VOL connector\n"); + PART_EMPTY(H5Ldelete_by_idx_external_name_order_increasing); + } + if ((subgroup_id = H5Gcreate2(group_id, LINK_DELETE_TEST_SUBGROUP15_NAME, H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0) { H5_FAILED(); @@ -6573,6 +6639,12 @@ test_delete_link(void) { TESTING_2("H5Ldelete_by_idx on external link by alphabetical order in decreasing order"); + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_BY_IDX)) { + SKIPPED(); + printf(" by index isn't supported with this VOL connector\n"); + PART_EMPTY(H5Ldelete_by_idx_external_name_order_decreasing); + } + if ((subgroup_id = H5Gcreate2(group_id, LINK_DELETE_TEST_SUBGROUP16_NAME, H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0) { H5_FAILED(); diff --git a/test/API/H5_api_object_test.c b/test/API/H5_api_object_test.c index e1d6ca8b6e2..2aa5c9deac9 100644 --- a/test/API/H5_api_object_test.c +++ b/test/API/H5_api_object_test.c @@ -4728,7 +4728,6 @@ test_object_copy_between_files(void) TEST_ERROR; if (H5Fclose(file_id) < 0) TEST_ERROR; - if (remove_test_file(NULL, obj_copy_filename) < 0) TEST_ERROR; free(obj_copy_filename);