diff options
author | Ray Lu <songyulu@hdfgroup.org> | 2022-03-22 02:01:35 (GMT) |
---|---|---|
committer | Ray Lu <songyulu@hdfgroup.org> | 2022-03-22 02:01:35 (GMT) |
commit | 89ba97bd90b1dd5bfc8a64f342576c0720e217b9 (patch) | |
tree | 7dcde056def4bb632420b2ec914530bf0639f144 /tools | |
parent | 79e92803c4a3f52ab162ae572f041fa86901e9d0 (diff) | |
download | hdf5-89ba97bd90b1dd5bfc8a64f342576c0720e217b9.zip hdf5-89ba97bd90b1dd5bfc8a64f342576c0720e217b9.tar.gz hdf5-89ba97bd90b1dd5bfc8a64f342576c0720e217b9.tar.bz2 |
Second round of commit.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/lib/h5diff.c | 17 | ||||
-rw-r--r-- | tools/lib/h5diff.h | 1 | ||||
-rw-r--r-- | tools/src/h5diff/h5diff_common.c | 65 | ||||
-rw-r--r-- | tools/src/h5diff/h5diff_main.c | 5 | ||||
-rw-r--r-- | tools/src/h5dump/h5dump.c | 8 | ||||
-rw-r--r-- | tools/test/h5diff/h5diffgentest.c | 713 | ||||
-rw-r--r-- | tools/test/h5diff/testh5diff.sh.in | 15 | ||||
-rw-r--r-- | tools/test/h5dump/h5dumpgentest.c | 702 | ||||
-rw-r--r-- | tools/test/h5dump/testh5dump.sh.in | 14 |
9 files changed, 1537 insertions, 3 deletions
diff --git a/tools/lib/h5diff.c b/tools/lib/h5diff.c index 0ad319e..b1e7acd 100644 --- a/tools/lib/h5diff.c +++ b/tools/lib/h5diff.c @@ -648,8 +648,15 @@ h5diff(const char *fname1, const char *fname2, const char *objname1, const char *------------------------------------------------------------------------- */ /* open file 1 */ + if (opts->vfd_info[0].name) { + if ((fapl1_id = h5tools_get_fapl(H5P_DEFAULT, NULL, &(opts->vfd_info[0]))) < 0) { + parallel_print("h5diff: unable to create fapl for input file\n"); + H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "unable to create input fapl\n"); + } + } + if (opts->custom_vol[0]) { - if ((fapl1_id = h5tools_get_fapl(H5P_DEFAULT, &(opts->vol_info[0]), NULL)) < 0) { + if ((fapl1_id = h5tools_get_fapl(fapl1_id, &(opts->vol_info[0]), NULL)) < 0) { parallel_print("h5diff: unable to create fapl for input file\n"); H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "unable to create input fapl\n"); } @@ -662,9 +669,15 @@ h5diff(const char *fname1, const char *fname2, const char *objname1, const char H5TOOLS_DEBUG("file1_id = %s", fname1); /* open file 2 */ + if (opts->vfd_info[1].name) { + if ((fapl2_id = h5tools_get_fapl(H5P_DEFAULT, NULL, &(opts->vfd_info[1]))) < 0) { + parallel_print("h5diff: unable to create fapl for output file\n"); + H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "unable to create output fapl\n"); + } + } if (opts->custom_vol[1]) { - if ((fapl2_id = h5tools_get_fapl(H5P_DEFAULT, &(opts->vol_info[1]), NULL)) < 0) { + if ((fapl2_id = h5tools_get_fapl(fapl2_id, &(opts->vol_info[1]), NULL)) < 0) { parallel_print("h5diff: unable to create fapl for output file\n"); H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "unable to create output fapl\n"); } diff --git a/tools/lib/h5diff.h b/tools/lib/h5diff.h index 7b41538..08a404c 100644 --- a/tools/lib/h5diff.h +++ b/tools/lib/h5diff.h @@ -89,6 +89,7 @@ typedef struct { char * obj_name[2]; /* name for object */ struct subset_t * sset[2]; /* subsetting parameters */ h5tools_vol_info_t vol_info[2]; /* VOL information for input file, output file */ + h5tools_vfd_info_t vfd_info[2]; /* VFD information for input file, output file */ hbool_t custom_vol[2]; /* Using a custom input, output VOL? */ } diff_opt_t; diff --git a/tools/src/h5diff/h5diff_common.c b/tools/src/h5diff/h5diff_common.c index b669087..8ec7cb6 100644 --- a/tools/src/h5diff/h5diff_common.c +++ b/tools/src/h5diff/h5diff_common.c @@ -48,8 +48,37 @@ static struct h5_long_options l_opts[] = {{"help", no_arg, 'h'}, {"vol-value-2", require_arg, '4'}, {"vol-name-2", require_arg, '5'}, {"vol-info-2", require_arg, '6'}, + {"vfd-name-1", require_arg, '7'}, + {"vfd-value-1", require_arg, '8'}, + {"vfd-name-2", require_arg, '9'}, + {"vfd-value-2", require_arg, '0'}, {NULL, 0, '\0'}}; +static H5FD_onion_fapl_info_t onion_fa_g_1 = { + H5FD_ONION_FAPL_INFO_VERSION_CURR, + H5P_DEFAULT, /* backing_fapl_id */ + 32, /* page_size */ + H5FD_ONION_STORE_TARGET_ONION, /* store_target */ + H5FD_ONION_FAPL_INFO_REVISION_ID_LATEST, + 0, /* force_write_open */ + 0, /* creation_flags */ + "indoor speaking voices", /* comment */ +}; + +static H5FD_onion_fapl_info_t onion_fa_g_2 = { + H5FD_ONION_FAPL_INFO_VERSION_CURR, + H5P_DEFAULT, /* backing_fapl_id */ + 32, /* page_size */ + H5FD_ONION_STORE_TARGET_ONION, /* store_target */ + H5FD_ONION_FAPL_INFO_REVISION_ID_LATEST, + 0, /* force_write_open */ + 0, /* creation_flags */ + "indoor speaking voices", /* comment */ +}; + +static const char *driver_name_g_1 = NULL; /* The driver to open the first file with. */ +static const char *driver_name_g_2 = NULL; /* The driver to open the second file with. */ + /*------------------------------------------------------------------------- * Function: check_options * @@ -432,9 +461,45 @@ parse_command_line(int argc, const char *argv[], const char **fname1, const char case '6': opts->vol_info[1].info_string = H5_optarg; break; + case '7': + driver_name_g_1 = HDstrdup(H5_optarg); + break; + case '8': + onion_fa_g_1.revision_id = (uint64_t)HDatol(H5_optarg); + break; + case '9': + driver_name_g_2 = HDstrdup(H5_optarg); + break; + case '0': + onion_fa_g_2.revision_id = (uint64_t)HDatol(H5_optarg); + + } } + /* Copy the VFD driver info for both the files */ + if (driver_name_g_1) { + if (!HDstrcmp(driver_name_g_1, "onion")) { + opts->vfd_info[0].name = HDstrdup(driver_name_g_1); + opts->vfd_info[0].info = HDmalloc(sizeof(H5FD_onion_fapl_info_t)); + HDmemcpy(opts->vfd_info[0].info, &onion_fa_g_1, sizeof(H5FD_onion_fapl_info_t)); + } + + if (driver_name_g_1) + HDfree(driver_name_g_1); + } /* driver name defined */ + + if (driver_name_g_2) { + if (!HDstrcmp(driver_name_g_2, "onion")) { + opts->vfd_info[1].name = HDstrdup(driver_name_g_2); + opts->vfd_info[1].info = HDmalloc(sizeof(H5FD_onion_fapl_info_t)); + HDmemcpy(opts->vfd_info[1].info, &onion_fa_g_2, sizeof(H5FD_onion_fapl_info_t)); + } + + if (driver_name_g_2) + HDfree(driver_name_g_2); + } /* driver name defined */ + /* check options */ check_options(opts); diff --git a/tools/src/h5diff/h5diff_main.c b/tools/src/h5diff/h5diff_main.c index a835953..ab70dba 100644 --- a/tools/src/h5diff/h5diff_main.c +++ b/tools/src/h5diff/h5diff_main.c @@ -131,6 +131,11 @@ main(int argc, const char *argv[]) HDfree(opts.sset[i]); opts.sset[i] = NULL; } + + if (opts.vfd_info[i].name) + HDfree((void *)opts.vfd_info[i].name); + if (opts.vfd_info[i].info) + HDfree((void *)opts.vfd_info[i].info); } h5diff_exit(ret); diff --git a/tools/src/h5dump/h5dump.c b/tools/src/h5dump/h5dump.c index 57c328a..3a2a563 100644 --- a/tools/src/h5dump/h5dump.c +++ b/tools/src/h5dump/h5dump.c @@ -952,7 +952,7 @@ parse_start: last_was_dset = TRUE; break; case 'f': - driver_name_g = H5_optarg; + driver_name_g = HDstrdup(H5_optarg); break; case 'g': dump_opts.display_all = 0; @@ -1639,11 +1639,17 @@ done: HDfree(prefix); prefix = NULL; } + if (fname) { HDfree(fname); fname = NULL; } + if (driver_name_g) { + HDfree(driver_name_g); + driver_name_g = NULL; + } + if (hand) free_handler(hand, argc); diff --git a/tools/test/h5diff/h5diffgentest.c b/tools/test/h5diff/h5diffgentest.c index 8b23e27..8ad196c 100644 --- a/tools/test/h5diff/h5diffgentest.c +++ b/tools/test/h5diff/h5diffgentest.c @@ -62,6 +62,10 @@ size_t H5TOOLS_MALLOCSIZE = (128 * 1024 * 1024); #define FILE20 "h5diff_dset_zero_dim_size2.h5" #define FILE21 "h5diff_dset_idx1.h5" #define FILE22 "h5diff_dset_idx2.h5" +#define FILE23 "h5diff_onion_dset_1d.h5" +#define FILE24 "h5diff_onion_objs.h5" +#define FILE25 "h5diff_onion_dset_ext.h5" + #define DANGLE_LINK_FILE1 "h5diff_danglelinks1.h5" #define DANGLE_LINK_FILE2 "h5diff_danglelinks2.h5" #define GRP_RECURSE_FILE1 "h5diff_grp_recurse1.h5" @@ -111,6 +115,11 @@ size_t H5TOOLS_MALLOCSIZE = (128 * 1024 * 1024); #define SPACE1_DIM1 0 #define SPACE1_DIM2 0 +/* For Onion VFD */ +#define ONION_TEST_FIXNAME_SIZE 1024 +#define ONION_TEST_PAGE_SIZE (uint32_t)32 +#define ONE_DIM_SIZE 16 + /* Error macros */ #define AT() HDprintf("ERROR at %s:%d in %s()...\n", __FILE__, __LINE__, __func__); #define PROGRAM_ERROR \ @@ -179,6 +188,11 @@ static void test_objs_nocomparables(const char *fname1, const char *fname2); static void test_objs_strings(const char *fname, const char *fname2); static void test_double_epsilon(const char *fname1, const char *fname2); +/* Generate the files for testing Onion VFD */ +static int test_onion_1d_dset(const char *fname); +static int test_onion_create_delete_objects(const char *fname); +static int test_onion_dset_extension(const char *fname); + /* called by test_attributes() and test_datasets() */ static void write_attr_strings(hid_t loc_id, const char *dset_name, hid_t fid, int make_diffs); static void write_attr_in(hid_t loc_id, const char *dset_name, hid_t fid, int make_diffs); @@ -298,9 +312,704 @@ main(void) /* double dataset and epsilion. HDFFV-10897 */ test_double_epsilon(DIFF_EPS1, DIFF_EPS2); + /* Generate the files for testing Onion VFD */ + test_onion_1d_dset(FILE23); + test_onion_create_delete_objects(FILE24); + test_onion_dset_extension(FILE25); + return EXIT_SUCCESS; } +/* Structure to collect the onion filepaths in one place. */ +struct onion_filepaths { + char *canon; + char *onion; + char *recovery; +}; + +/* Allocate and populate filepaths with h5_fixname'd strings as appropriate. + * Should be released with onion_filepaths_destroy() when done. + */ +static struct onion_filepaths * +onion_filepaths_init(const char *basename, H5FD_onion_fapl_info_t *fa_info) +{ + struct onion_filepaths *paths = NULL; + + paths = (struct onion_filepaths *)HDmalloc(sizeof(struct onion_filepaths)); + if (NULL == paths) + goto error; + paths->canon = NULL; + paths->onion = NULL; + paths->recovery = NULL; + + paths->canon = HDstrdup(basename); + + paths->onion = (char *)HDmalloc(sizeof(char) * ONION_TEST_FIXNAME_SIZE); + HDsnprintf(paths->onion, ONION_TEST_FIXNAME_SIZE, "%s.onion", paths->canon); + + paths->recovery = (char *)HDmalloc(sizeof(char) * ONION_TEST_FIXNAME_SIZE); + HDsnprintf(paths->recovery, ONION_TEST_FIXNAME_SIZE, "%s.onion.recovery", paths->canon); + + return paths; + +error: + if (paths != NULL) { + if (paths->canon != NULL) + HDfree(paths->canon); + if (paths->onion != NULL) + HDfree(paths->onion); + if (paths->recovery != NULL) + HDfree(paths->recovery); + } + return NULL; +} + +static void +onion_filepaths_destroy(struct onion_filepaths *s) +{ + HDfree(s->canon); + HDfree(s->onion); + HDfree(s->recovery); + HDfree(s); +} + +static int +test_onion_1d_dset(const char *fname) +{ + hid_t fapl_id = H5I_INVALID_HID; + struct onion_filepaths *paths = NULL; + H5FD_onion_fapl_info_t onion_info = { + H5FD_ONION_FAPL_INFO_VERSION_CURR, + H5I_INVALID_HID, /* backing_fapl_id */ + ONION_TEST_PAGE_SIZE, /* page_size */ + H5FD_ONION_STORE_TARGET_ONION, /* store_target */ + H5FD_ONION_FAPL_INFO_REVISION_ID_LATEST, + 0, /* force_write_open */ + 0, /* creation flags, was H5FD_ONION_FAPL_INFO_CREATE_FLAG_ENABLE_PAGE_ALIGNMENT */ + "initial commit" /* comment */ + }; + hid_t file_id = H5I_INVALID_HID; + + /* Setup */ + onion_info.backing_fapl_id = H5Pcreate(H5P_FILE_ACCESS); + + if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) + goto error; + if (H5Pset_fapl_onion(fapl_id, &onion_info) < 0) + goto error; + + if ((paths = onion_filepaths_init(fname, &onion_info)) == NULL) + goto error; + + /*---------------------------------------------------------------------- + * Create the skeleton file (create the file without Onion VFD) + *---------------------------------------------------------------------- + */ + hid_t file, space, dset, dcpl; /* Handles */ + hsize_t dims[2] = {1, ONE_DIM_SIZE}, maxdims[2] = {1, ONE_DIM_SIZE}; + int wdata[1][ONE_DIM_SIZE], /* Write buffer */ + fillval, i, j; + + /* + * Initialize data. + */ + for (i = 0; i < ONE_DIM_SIZE; i++) + wdata[0][i] = i; + + /* + * Create a new file using the default properties. + */ + if ((file = H5Fcreate(paths->canon, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) + goto error; + + /* + * Create dataspace with unlimited dimensions. + */ + if ((space = H5Screate_simple(2, dims, maxdims)) < 0) + goto error; + + /* + * Create the dataset creation property list + */ + if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) + goto error; + + /* + * Set the fill value for the dataset. + */ + fillval = 99; + if (H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fillval) < 0) + goto error; + + /* + * Set the allocation time to "early". This way we can be sure + * that reading from the dataset immediately after creation will + * return the fill value. + */ + if (H5Pset_alloc_time(dcpl, H5D_ALLOC_TIME_EARLY) < 0) + goto error; + + /* + * Create the dataset using the dataset creation property list. + */ + if ((dset = H5Dcreate(file, "DS1", H5T_STD_I32LE, space, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) + goto error; + + /* + * Write the data to the dataset. + */ + if (H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata[0]) < 0) + goto error; + + /* + * Close and release resources. + */ + if (H5Pclose(dcpl) < 0) + goto error; + if (H5Dclose(dset) < 0) + goto error; + if (H5Sclose(space) < 0) + goto error; + if (H5Fclose(file) < 0) + goto error; + + /*---------------------------------------------------------------------- + * First revision: open the file with Onion VFD and change the data + *---------------------------------------------------------------------- + */ + if ((file_id = H5Fopen(paths->canon, H5F_ACC_RDWR, fapl_id)) < 0) + goto error; + + if ((dset = H5Dopen(file_id, "DS1", H5P_DEFAULT)) < 0) + goto error; + + int dset_data[1][ONE_DIM_SIZE]; + for (i = 0; i < ONE_DIM_SIZE; i++) + dset_data[0][i] = i + ONE_DIM_SIZE; + + if (H5Dwrite(dset, H5T_STD_I32LE, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_data) < 0) + goto error; + + if (H5Dclose(dset) < 0) + goto error; + if (H5Fclose(file_id) < 0) + goto error; + + /*---------------------------------------------------------------------- + * Second revision: open the file with Onion VFD and change the data + *---------------------------------------------------------------------- + */ + file_id = H5Fopen(paths->canon, H5F_ACC_RDWR, fapl_id); + goto error; + if (H5I_INVALID_HID == file_id) { + printf("\n\n\n\nERROR OPENING\n\n\n\n"); + goto error; + } + + dset = H5Dopen(file_id, "DS1", H5P_DEFAULT); + goto error; + if (dset < 0) { + printf("\n\n\n\nERROR OPENING DSET\n\n\n\n"); + goto error; + } + + for (i = 0; i < ONE_DIM_SIZE; i++) + dset_data[0][i] = i + 2048; + + if (H5Dwrite(dset, H5T_STD_I32LE, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_data) < 0) + goto error; + + /* CLEANUP */ + if (H5Dclose(dset) < 0) + goto error; + dset = H5I_INVALID_HID; + if (H5Fclose(file_id) < 0) + goto error; + file_id = H5I_INVALID_HID; + + /*---------------------------------------------------------------------- + * Third revision: open the file with Onion VFD and change the data + *---------------------------------------------------------------------- + */ + if ((file_id = H5Fopen(paths->canon, H5F_ACC_RDWR, fapl_id)) < 0) + goto error; + + if ((dset = H5Dopen(file_id, "DS1", H5P_DEFAULT)) < 0) + goto error; + + for (i = 0; i < ONE_DIM_SIZE; i += 20) + dset_data[0][i] = i + 3072; + + if (H5Dwrite(dset, H5T_STD_I32LE, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_data) < 0) + goto error; + + /* CLEANUP */ + if (H5Dclose(dset) < 0) + goto error; + if (H5Fclose(file_id) < 0) + goto error; + if (H5Pclose(fapl_id) < 0) + goto error; + if (H5Pclose(onion_info.backing_fapl_id) < 0) + goto error; + + onion_filepaths_destroy(paths); + + return 0; + +error: + H5E_BEGIN_TRY + { + H5Pclose(onion_info.backing_fapl_id); + H5Pclose(fapl_id); + H5Dclose(dset); + H5Sclose(space); + H5Fclose(file_id); + } + H5E_END_TRY; + + return -1; +} /* test_onion_1d_dset */ + +static int +test_onion_create_delete_objects(const char *fname) +{ + hid_t fapl_id = H5I_INVALID_HID; + struct onion_filepaths *paths = NULL; + H5FD_onion_fapl_info_t onion_info = { + H5FD_ONION_FAPL_INFO_VERSION_CURR, + H5I_INVALID_HID, /* backing_fapl_id */ + ONION_TEST_PAGE_SIZE, /* page_size */ + H5FD_ONION_STORE_TARGET_ONION, /* store_target */ + H5FD_ONION_FAPL_INFO_REVISION_ID_LATEST, + 0, /* force_write_open */ + 0, /* creation flags, was H5FD_ONION_FAPL_INFO_CREATE_FLAG_ENABLE_PAGE_ALIGNMENT */ + "initial commit" /* comment */ + }; + hid_t group_id = H5I_INVALID_HID; + hid_t attr_space_id = H5I_INVALID_HID, attr_id = H5I_INVALID_HID; + hsize_t attr_dim[1] = {4}; + + /* Set up */ + if ((onion_info.backing_fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) + goto error; + if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) + goto error; + if (H5Pset_fapl_onion(fapl_id, &onion_info) < 0) + goto error; + + if ((paths = onion_filepaths_init(fname, &onion_info)) == NULL) + goto error; + + /*---------------------------------------------------------------------- + * Create the skeleton file (create the file without Onion VFD) + *---------------------------------------------------------------------- + */ + + hid_t file, space, dset, dcpl; /* Handles */ + hsize_t dims[2] = {4, 4}, maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED}, chunk[2] = {4, 4}; + int wdata[4][4], /* Write buffer */ + fillval, i, j; + + /* + * Initialize data. + */ + for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) + wdata[i][j] = i + j; + + /* + * Create a new file using the default properties. + */ + if ((file = H5Fcreate(paths->canon, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) + goto error; + + /* + * Create dataspace with unlimited dimensions. + */ + if ((space = H5Screate_simple(2, dims, maxdims)) < 0) + goto error; + + /* + * Create the dataset creation property list, and set the chunk + * size. + */ + if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) + goto error; + if (H5Pset_chunk(dcpl, 2, chunk) < 0) + goto error; + + /* + * Set the fill value for the dataset. + */ + fillval = 99; + if (H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fillval) < 0) + goto error; + + /* + * Set the allocation time to "early". This way we can be sure + * that reading from the dataset immediately after creation will + * return the fill value. + */ + if (H5Pset_alloc_time(dcpl, H5D_ALLOC_TIME_EARLY) < 0) + goto error; + + /* + * Create the dataset using the dataset creation property list. + */ + if ((dset = H5Dcreate(file, "DS1", H5T_STD_I32LE, space, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) + goto error; + + /* + * Write the data to the dataset. + */ + if (H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata) < 0) + goto error; + + if (H5Dclose(dset) < 0) + goto error; + if (H5Fclose(file) < 0) + goto error; + + /*---------------------------------------------------------------------- + * First revision: open the file with Onion VFD and add a dataset (DS2) to the file + *---------------------------------------------------------------------- + */ + if ((file = H5Fopen(paths->canon, H5F_ACC_RDWR, fapl_id)) < 0) + goto error; + + /* + * Create the dataset using the dataset creation property list. + */ + if ((dset = H5Dcreate(file, "DS2", H5T_STD_I32LE, space, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) + goto error; + + /* + * Write the data to the dataset. + */ + if (H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata) < 0) + goto error; + + + if (H5Dclose(dset) < 0) + goto error; + dset = H5I_INVALID_HID; + if (H5Fclose(file) < 0) + goto error; + file = H5I_INVALID_HID; + + /*---------------------------------------------------------------------- + * Second revision: open the file with Onion VFD and remove the dataset (DS2), + * which was added during the first revision. + *---------------------------------------------------------------------- + */ + if ((file = H5Fopen(paths->canon, H5F_ACC_RDWR, fapl_id)) < 0) + goto error; + + if (H5Ldelete(file, "DS2", H5P_DEFAULT) < 0) + goto error; + + if (H5Fclose(file) < 0) + goto error; + file = H5I_INVALID_HID; + + /*---------------------------------------------------------------------- + * Third revision: open the file with Onion VFD and add an attribute to the file + *---------------------------------------------------------------------- + */ + if ((file = H5Fopen(paths->canon, H5F_ACC_RDWR, fapl_id)) < 0) + goto error; + + /* Create dataspace for attribute */ + attr_space_id = H5Screate_simple(1, attr_dim, NULL); + + if ((attr_id = H5Acreate(file, "file_attribute", H5T_STD_I32LE, attr_space_id, H5P_DEFAULT, H5P_DEFAULT)) < 0) + goto error; + + if (H5Sclose(attr_space_id) < 0) + goto error; + if (H5Aclose(attr_id) < 0) + goto error; + if (H5Fclose(file) < 0) + goto error; + file = H5I_INVALID_HID; + + /*---------------------------------------------------------------------- + * Fourth revision: open the file with Onion VFD and delete the attribute + *---------------------------------------------------------------------- + */ + if ((file = H5Fopen(paths->canon, H5F_ACC_RDWR, fapl_id)) < 0) + goto error; + + if (H5Adelete(file, "file_attribute") < 0) + goto error; + + if (H5Fclose(file) < 0) + goto error; + file = H5I_INVALID_HID; + + /*---------------------------------------------------------------------- + * Fifth revision: open the file with Onion VFD and add a group to the file + *---------------------------------------------------------------------- + */ + if ((file = H5Fopen(paths->canon, H5F_ACC_RDWR, fapl_id)) < 0) + goto error; + + if ((group_id = H5Gcreate2(file, "new_group", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + goto error; + + if (H5Gclose(group_id) < 0) + goto error; + if (H5Fclose(file) < 0) + goto error; + file = H5I_INVALID_HID; + + /*---------------------------------------------------------------------- + * Sixth revision: open the file with Onion VFD and delete the newly added group + *---------------------------------------------------------------------- + */ + if ((file = H5Fopen(paths->canon, H5F_ACC_RDWR, fapl_id)) < 0) + goto error; + + if (H5Ldelete(file, "new_group", H5P_DEFAULT) < 0) + goto error; + + if (H5Fclose(file) < 0) + goto error; + file = H5I_INVALID_HID; + + /* + * Close and release resources. + */ + if (H5Pclose(onion_info.backing_fapl_id) < 0) + goto error; + if (H5Pclose(fapl_id) < 0) + goto error; + if (H5Pclose(dcpl) < 0) + goto error; + if (H5Sclose(space) < 0) + goto error; + + onion_filepaths_destroy(paths); + + return 0; +error: + + if (paths != NULL) { + HDremove(paths->canon); + HDremove(paths->onion); + HDremove(paths->recovery); + onion_filepaths_destroy(paths); + } + + if (dset != H5I_INVALID_HID) + (void)H5Dclose(dset); + if (file != H5I_INVALID_HID) + (void)H5Fclose(file); + if (fapl_id != H5I_INVALID_HID) + (void)H5Pclose(fapl_id); + if (onion_info.backing_fapl_id != H5I_INVALID_HID) + H5Pclose(onion_info.backing_fapl_id); + + return -1; +} /* test_onion_create_delete_objects */ + +static int +test_onion_dset_extension(const char *fname) +{ + const char * basename = "integration_dset_ext.h5"; + hid_t fapl_id = H5I_INVALID_HID; + struct onion_filepaths *paths = NULL; + H5FD_onion_fapl_info_t onion_info = { + H5FD_ONION_FAPL_INFO_VERSION_CURR, + H5I_INVALID_HID, /* backing_fapl_id */ + ONION_TEST_PAGE_SIZE, /* page_size */ + H5FD_ONION_STORE_TARGET_ONION, /* store_target */ + H5FD_ONION_FAPL_INFO_REVISION_ID_LATEST, + 0, /* force_write_open */ + 0, /* creation flags, was H5FD_ONION_FAPL_INFO_CREATE_FLAG_ENABLE_PAGE_ALIGNMENT */ + "initial commit" /* comment */ + }; + hid_t file = H5I_INVALID_HID, group_id = H5I_INVALID_HID; + hid_t attr_space_id = H5I_INVALID_HID, attr_id = H5I_INVALID_HID; + hid_t space, dset_space, dset, dcpl; /* Handles */ + hsize_t dims[2] = {4, 4}, maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED}, chunk[2] = {4, 4}; + hsize_t size[2], offset[2]; + int wdata[4][4], /* Write buffer */ + fillval, i, j; + int rdata[4][4]; /* Read buffer */ + + /* Setup */ + if ((onion_info.backing_fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) + goto error; + if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) + goto error; + + if (H5Pset_fapl_onion(fapl_id, &onion_info) < 0) + goto error; + + if ((paths = onion_filepaths_init(fname, &onion_info)) == NULL) + goto error; + + /*---------------------------------------------------------------------- + * Create the skeleton file (create the file without Onion VFD) + *---------------------------------------------------------------------- + */ + /* + * Initialize data. + */ + for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) + wdata[i][j] = i + j; + + /* + * Create a new file using the default properties. + */ + if ((file = H5Fcreate(paths->canon, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) + goto error; + + /* + * Create dataspace with unlimited dimensions. + */ + if ((space = H5Screate_simple(2, dims, maxdims)) < 0) + goto error; + + /* + * Create the dataset creation property list, and set the chunk + * size. + */ + if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) + goto error; + if (H5Pset_chunk(dcpl, 2, chunk) < 0) + goto error; + + /* + * Set the fill value for the dataset. + */ + fillval = 99; + if (H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fillval) < 0) + goto error; + + /* + * Set the allocation time to "early". This way we can be sure + * that reading from the dataset immediately after creation will + * return the fill value. + */ + if (H5Pset_alloc_time(dcpl, H5D_ALLOC_TIME_EARLY) < 0) + goto error; + + /* + * Create the dataset using the dataset creation property list. + */ + if ((dset = H5Dcreate(file, "DS1", H5T_STD_I32LE, space, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) + goto error; + + /* + * Write the data to the dataset. + */ + if (H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata) < 0) + goto error; + + if (H5Dclose(dset) < 0) + goto error; + if (H5Fclose(file) < 0) + goto error; + + /*---------------------------------------------------------------------- + * First revision: open the file with Onion VFD and extend the dataset + *---------------------------------------------------------------------- + */ + if ((file = H5Fopen(paths->canon, H5F_ACC_RDWR, fapl_id)) < 0) + goto error; + + /* Open the dataset */ + if ((dset = H5Dopen(file, "DS1", H5P_DEFAULT)) < 0) + goto error; + + /* Extend the dataset and double the rows */ + size[0] = 2 * dims[0]; + size[1] = dims[1]; + if (H5Dset_extent(dset, size) < 0) + goto error; + + if ((dset_space = H5Dget_space(dset)) < 0) + goto error; + + offset[0] = dims[0]; + offset[1] = 0; + if (H5Sselect_hyperslab(dset_space, H5S_SELECT_SET, offset, NULL, dims, NULL) < 0) + goto error; + + /* Write the data to the dataset. */ + if (H5Dwrite(dset, H5T_NATIVE_INT, space, dset_space, H5P_DEFAULT, wdata) < 0) + goto error; + + if (H5Sclose(dset_space) < 0) + goto error; + + if (H5Dclose(dset) < 0) + goto error; + dset = H5I_INVALID_HID; + if (H5Fclose(file) < 0) + goto error; + file = H5I_INVALID_HID; + + /*---------------------------------------------------------------------- + * Second revision: open the file with Onion VFD and shrink the dataset + *---------------------------------------------------------------------- + */ + if ((file = H5Fopen(paths->canon, H5F_ACC_RDWR, fapl_id)) < 0) + goto error; + + /* Open the dataset */ + if ((dset = H5Dopen(file, "DS1", H5P_DEFAULT)) < 0) + goto error; + + /* Extend the dataset and shrink back the size */ + if (H5Dset_extent(dset, dims) < 0) + goto error; + + if (H5Dclose(dset) < 0) + goto error; + dset = H5I_INVALID_HID; + if (H5Fclose(file) < 0) + goto error; + file = H5I_INVALID_HID; + + /* Close and release resources. */ + if (H5Pclose(onion_info.backing_fapl_id) < 0) + goto error; + if (H5Pclose(fapl_id) < 0) + goto error; + if (H5Pclose(dcpl) < 0) + goto error; + if (H5Sclose(space) < 0) + goto error; + + onion_filepaths_destroy(paths); + + return 0; +error: + + if (paths != NULL) { + HDremove(paths->canon); + HDremove(paths->onion); + HDremove(paths->recovery); + onion_filepaths_destroy(paths); + } + + if (dset != H5I_INVALID_HID) + (void)H5Dclose(dset); + if (file != H5I_INVALID_HID) + (void)H5Fclose(file); + if (fapl_id != H5I_INVALID_HID) + (void)H5Pclose(fapl_id); + if (onion_info.backing_fapl_id != H5I_INVALID_HID) + H5Pclose(onion_info.backing_fapl_id); + + return -1; +} /* test_onion_dset_extension */ + /*------------------------------------------------------------------------- * Function: test_basic * @@ -8058,6 +8767,8 @@ error: H5E_END_TRY; } + + /*------------------------------------------------------------------------- * Function: write_attr * @@ -8143,3 +8854,5 @@ error: return FAIL; } /* end write_dset() */ + + diff --git a/tools/test/h5diff/testh5diff.sh.in b/tools/test/h5diff/testh5diff.sh.in index bd27dd0..be0d3bd 100644 --- a/tools/test/h5diff/testh5diff.sh.in +++ b/tools/test/h5diff/testh5diff.sh.in @@ -124,6 +124,12 @@ $SRC_H5DIFF_TESTFILES/h5diff_strings1.h5 $SRC_H5DIFF_TESTFILES/h5diff_strings2.h5 $SRC_H5DIFF_TESTFILES/h5diff_eps1.h5 $SRC_H5DIFF_TESTFILES/h5diff_eps2.h5 +$SRC_H5DIFF_TESTFILES/h5diff_onion_objs.h5 +$SRC_H5DIFF_TESTFILES/h5diff_onion_objs.h5.onion +$SRC_H5DIFF_TESTFILES/h5diff_onion_dset_ext.h5 +$SRC_H5DIFF_TESTFILES/h5diff_onion_dset_ext.h5.onion +$SRC_H5DIFF_TESTFILES/h5diff_onion_dset_1d.h5 +$SRC_H5DIFF_TESTFILES/h5diff_onion_dset_1d.h5.onion $SRC_TOOLS_TESTFILES/tvlstr.h5 " @@ -356,6 +362,9 @@ $SRC_H5DIFF_TESTFILES/h5diff_800.txt $SRC_H5DIFF_TESTFILES/h5diff_801.txt $SRC_H5DIFF_TESTFILES/h5diff_830.txt $SRC_H5DIFF_TESTFILES/h5diff_90.txt +$SRC_H5DIFF_TESTFILES/h5diff_900.txt +$SRC_H5DIFF_TESTFILES/h5diff_901.txt +$SRC_H5DIFF_TESTFILES/h5diff_902.txt $SRC_H5DIFF_TESTFILES/h5diff_8625.txt $SRC_H5DIFF_TESTFILES/h5diff_8639.txt $SRC_H5DIFF_TESTFILES/h5diff_reg.txt @@ -1214,6 +1223,12 @@ TOOLTEST h5diff_v1.txt -v 1_vds.h5 2_vds.h5 TOOLTEST h5diff_v2.txt -r 1_vds.h5 2_vds.h5 TOOLTEST h5diff_v3.txt -c 1_vds.h5 2_vds.h5 +# ############################################################################## +# Onion VFD tests +# ############################################################################## +TOOLTEST h5diff_900.txt -r -v --vfd-name-1 onion --vfd-value-1 0 --vfd-name-2 onion --vfd-value-2 1 h5diff_onion_objs.h5 h5diff_onion_objs.h5 +TOOLTEST h5diff_901.txt -r -v --vfd-name-1 onion --vfd-value-1 0 --vfd-name-2 onion --vfd-value-2 1 h5diff_onion_dset_ext.h5 h5diff_onion_dset_ext.h5 +TOOLTEST h5diff_902.txt -r -v --vfd-name-1 onion --vfd-value-1 0 --vfd-name-2 onion --vfd-value-2 1 h5diff_onion_dset_1d.h5 h5diff_onion_dset_1d.h5 # ############################################################################## # # END diff --git a/tools/test/h5dump/h5dumpgentest.c b/tools/test/h5dump/h5dumpgentest.c index 7efe53c..9c48573 100644 --- a/tools/test/h5dump/h5dumpgentest.c +++ b/tools/test/h5dump/h5dumpgentest.c @@ -117,6 +117,13 @@ #define FILE87 "tintsnodata.h5" #define FILE88 "tldouble_scalar.h5" #define FILE89 "tfloatsattrs.h5" +#define FILE90 "tst_onion_dset_1d.h5" +#define FILE91 "tst_onion_objs.h5" +#define FILE92 "tst_onion_dset_ext.h5" + +#define ONION_TEST_FIXNAME_SIZE 1024 +#define ONION_TEST_PAGE_SIZE (uint32_t)32 +#define ONE_DIM_SIZE 16 /*------------------------------------------------------------------------- * prototypes @@ -11230,6 +11237,696 @@ error: H5E_END_TRY; } /* gen_err_attr_dspace() */ +/* Structure to collect the onion filepaths in one place. */ +struct onion_filepaths { + char *canon; + char *onion; + char *recovery; +}; + +/* Allocate and populate filepaths with h5_fixname'd strings as appropriate. + * Should be released with onion_filepaths_destroy() when done. + */ +static struct onion_filepaths * +onion_filepaths_init(const char *basename, H5FD_onion_fapl_info_t *fa_info) +{ + struct onion_filepaths *paths = NULL; + + paths = (struct onion_filepaths *)HDmalloc(sizeof(struct onion_filepaths)); + if (NULL == paths) + goto error; + paths->canon = NULL; + paths->onion = NULL; + paths->recovery = NULL; + + paths->canon = HDstrdup(basename); + + paths->onion = (char *)HDmalloc(sizeof(char) * ONION_TEST_FIXNAME_SIZE); + HDsnprintf(paths->onion, ONION_TEST_FIXNAME_SIZE, "%s.onion", paths->canon); + + paths->recovery = (char *)HDmalloc(sizeof(char) * ONION_TEST_FIXNAME_SIZE); + HDsnprintf(paths->recovery, ONION_TEST_FIXNAME_SIZE, "%s.onion.recovery", paths->canon); + + return paths; + +error: + if (paths != NULL) { + if (paths->canon != NULL) + HDfree(paths->canon); + if (paths->onion != NULL) + HDfree(paths->onion); + if (paths->recovery != NULL) + HDfree(paths->recovery); + } + return NULL; +} + +static void +onion_filepaths_destroy(struct onion_filepaths *s) +{ + HDfree(s->canon); + HDfree(s->onion); + HDfree(s->recovery); + HDfree(s); +} + +static int +gent_onion_1d_dset() +{ + hid_t fapl_id = H5I_INVALID_HID; + struct onion_filepaths *paths = NULL; + H5FD_onion_fapl_info_t onion_info = { + H5FD_ONION_FAPL_INFO_VERSION_CURR, + H5I_INVALID_HID, /* backing_fapl_id */ + ONION_TEST_PAGE_SIZE, /* page_size */ + H5FD_ONION_STORE_TARGET_ONION, /* store_target */ + H5FD_ONION_FAPL_INFO_REVISION_ID_LATEST, + 0, /* force_write_open */ + 0, /* creation flags, was H5FD_ONION_FAPL_INFO_CREATE_FLAG_ENABLE_PAGE_ALIGNMENT */ + "initial commit" /* comment */ + }; + hid_t file_id = H5I_INVALID_HID; + + /* Setup */ + onion_info.backing_fapl_id = H5Pcreate(H5P_FILE_ACCESS); + + if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) + goto error; + if (H5Pset_fapl_onion(fapl_id, &onion_info) < 0) + goto error; + + if ((paths = onion_filepaths_init(FILE90, &onion_info)) == NULL) + goto error; + + /*---------------------------------------------------------------------- + * Create the skeleton file (create the file without Onion VFD) + *---------------------------------------------------------------------- + */ + hid_t file, space, dset, dcpl; /* Handles */ + hsize_t dims[2] = {1, ONE_DIM_SIZE}, maxdims[2] = {1, ONE_DIM_SIZE}; + int wdata[1][ONE_DIM_SIZE], /* Write buffer */ + fillval, i, j; + + /* + * Initialize data. + */ + for (i = 0; i < ONE_DIM_SIZE; i++) + wdata[0][i] = i; + + /* + * Create a new file using the default properties. + */ + if ((file = H5Fcreate(paths->canon, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) + goto error; + + /* + * Create dataspace with unlimited dimensions. + */ + if ((space = H5Screate_simple(2, dims, maxdims)) < 0) + goto error; + + /* + * Create the dataset creation property list + */ + if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) + goto error; + + /* + * Set the fill value for the dataset. + */ + fillval = 99; + if (H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fillval) < 0) + goto error; + + /* + * Set the allocation time to "early". This way we can be sure + * that reading from the dataset immediately after creation will + * return the fill value. + */ + if (H5Pset_alloc_time(dcpl, H5D_ALLOC_TIME_EARLY) < 0) + goto error; + + /* + * Create the dataset using the dataset creation property list. + */ + if ((dset = H5Dcreate(file, "DS1", H5T_STD_I32LE, space, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) + goto error; + + /* + * Write the data to the dataset. + */ + if (H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata[0]) < 0) + goto error; + + /* + * Close and release resources. + */ + if (H5Pclose(dcpl) < 0) + goto error; + if (H5Dclose(dset) < 0) + goto error; + if (H5Sclose(space) < 0) + goto error; + if (H5Fclose(file) < 0) + goto error; + + /*---------------------------------------------------------------------- + * First revision: open the file with Onion VFD and change the data + *---------------------------------------------------------------------- + */ + if ((file_id = H5Fopen(paths->canon, H5F_ACC_RDWR, fapl_id)) < 0) + goto error; + + if ((dset = H5Dopen(file_id, "DS1", H5P_DEFAULT)) < 0) + goto error; + + int dset_data[1][ONE_DIM_SIZE]; + for (i = 0; i < ONE_DIM_SIZE; i++) + dset_data[0][i] = i + ONE_DIM_SIZE; + + if (H5Dwrite(dset, H5T_STD_I32LE, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_data) < 0) + goto error; + + if (H5Dclose(dset) < 0) + goto error; + if (H5Fclose(file_id) < 0) + goto error; + + /*---------------------------------------------------------------------- + * Second revision: open the file with Onion VFD and change the data + *---------------------------------------------------------------------- + */ + file_id = H5Fopen(paths->canon, H5F_ACC_RDWR, fapl_id); + goto error; + if (H5I_INVALID_HID == file_id) { + printf("\n\n\n\nERROR OPENING\n\n\n\n"); + goto error; + } + + dset = H5Dopen(file_id, "DS1", H5P_DEFAULT); + goto error; + if (dset < 0) { + printf("\n\n\n\nERROR OPENING DSET\n\n\n\n"); + goto error; + } + + for (i = 0; i < ONE_DIM_SIZE; i++) + dset_data[0][i] = i + 2048; + + if (H5Dwrite(dset, H5T_STD_I32LE, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_data) < 0) + goto error; + + /* CLEANUP */ + if (H5Dclose(dset) < 0) + goto error; + dset = H5I_INVALID_HID; + if (H5Fclose(file_id) < 0) + goto error; + file_id = H5I_INVALID_HID; + + /*---------------------------------------------------------------------- + * Third revision: open the file with Onion VFD and change the data + *---------------------------------------------------------------------- + */ + if ((file_id = H5Fopen(paths->canon, H5F_ACC_RDWR, fapl_id)) < 0) + goto error; + + if ((dset = H5Dopen(file_id, "DS1", H5P_DEFAULT)) < 0) + goto error; + + for (i = 0; i < ONE_DIM_SIZE; i += 20) + dset_data[0][i] = i + 3072; + + if (H5Dwrite(dset, H5T_STD_I32LE, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_data) < 0) + goto error; + + /* CLEANUP */ + if (H5Dclose(dset) < 0) + goto error; + if (H5Fclose(file_id) < 0) + goto error; + if (H5Pclose(fapl_id) < 0) + goto error; + if (H5Pclose(onion_info.backing_fapl_id) < 0) + goto error; + + onion_filepaths_destroy(paths); + + return 0; + +error: + H5E_BEGIN_TRY + { + H5Pclose(onion_info.backing_fapl_id); + H5Pclose(fapl_id); + H5Dclose(dset); + H5Sclose(space); + H5Fclose(file_id); + } + H5E_END_TRY; + + return -1; +} /* gent_onion_1d_dset */ + +static int +gent_onion_create_delete_objects(void) +{ + hid_t fapl_id = H5I_INVALID_HID; + struct onion_filepaths *paths = NULL; + H5FD_onion_fapl_info_t onion_info = { + H5FD_ONION_FAPL_INFO_VERSION_CURR, + H5I_INVALID_HID, /* backing_fapl_id */ + ONION_TEST_PAGE_SIZE, /* page_size */ + H5FD_ONION_STORE_TARGET_ONION, /* store_target */ + H5FD_ONION_FAPL_INFO_REVISION_ID_LATEST, + 0, /* force_write_open */ + 0, /* creation flags, was H5FD_ONION_FAPL_INFO_CREATE_FLAG_ENABLE_PAGE_ALIGNMENT */ + "initial commit" /* comment */ + }; + hid_t group_id = H5I_INVALID_HID; + hid_t attr_space_id = H5I_INVALID_HID, attr_id = H5I_INVALID_HID; + hsize_t attr_dim[1] = {4}; + + /* Set up */ + if ((onion_info.backing_fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) + goto error; + if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) + goto error; + if (H5Pset_fapl_onion(fapl_id, &onion_info) < 0) + goto error; + + if ((paths = onion_filepaths_init(FILE91, &onion_info)) == NULL) + goto error; + + /*---------------------------------------------------------------------- + * Create the skeleton file (create the file without Onion VFD) + *---------------------------------------------------------------------- + */ + + hid_t file, space, dset, dcpl; /* Handles */ + hsize_t dims[2] = {4, 4}, maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED}, chunk[2] = {4, 4}; + int wdata[4][4], /* Write buffer */ + fillval, i, j; + + /* + * Initialize data. + */ + for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) + wdata[i][j] = i + j; + + /* + * Create a new file using the default properties. + */ + if ((file = H5Fcreate(paths->canon, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) + goto error; + + /* + * Create dataspace with unlimited dimensions. + */ + if ((space = H5Screate_simple(2, dims, maxdims)) < 0) + goto error; + + /* + * Create the dataset creation property list, and set the chunk + * size. + */ + if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) + goto error; + if (H5Pset_chunk(dcpl, 2, chunk) < 0) + goto error; + + /* + * Set the fill value for the dataset. + */ + fillval = 99; + if (H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fillval) < 0) + goto error; + + /* + * Set the allocation time to "early". This way we can be sure + * that reading from the dataset immediately after creation will + * return the fill value. + */ + if (H5Pset_alloc_time(dcpl, H5D_ALLOC_TIME_EARLY) < 0) + goto error; + + /* + * Create the dataset using the dataset creation property list. + */ + if ((dset = H5Dcreate(file, "DS1", H5T_STD_I32LE, space, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) + goto error; + + /* + * Write the data to the dataset. + */ + if (H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata) < 0) + goto error; + + if (H5Dclose(dset) < 0) + goto error; + if (H5Fclose(file) < 0) + goto error; + + /*---------------------------------------------------------------------- + * First revision: open the file with Onion VFD and add a dataset (DS2) to the file + *---------------------------------------------------------------------- + */ + if ((file = H5Fopen(paths->canon, H5F_ACC_RDWR, fapl_id)) < 0) + goto error; + + /* + * Create the dataset using the dataset creation property list. + */ + if ((dset = H5Dcreate(file, "DS2", H5T_STD_I32LE, space, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) + goto error; + + /* + * Write the data to the dataset. + */ + if (H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata) < 0) + goto error; + + + if (H5Dclose(dset) < 0) + goto error; + dset = H5I_INVALID_HID; + if (H5Fclose(file) < 0) + goto error; + file = H5I_INVALID_HID; + + /*---------------------------------------------------------------------- + * Second revision: open the file with Onion VFD and remove the dataset (DS2), + * which was added during the first revision. + *---------------------------------------------------------------------- + */ + if ((file = H5Fopen(paths->canon, H5F_ACC_RDWR, fapl_id)) < 0) + goto error; + + if (H5Ldelete(file, "DS2", H5P_DEFAULT) < 0) + goto error; + + if (H5Fclose(file) < 0) + goto error; + file = H5I_INVALID_HID; + + /*---------------------------------------------------------------------- + * Third revision: open the file with Onion VFD and add an attribute to the file + *---------------------------------------------------------------------- + */ + if ((file = H5Fopen(paths->canon, H5F_ACC_RDWR, fapl_id)) < 0) + goto error; + + /* Create dataspace for attribute */ + attr_space_id = H5Screate_simple(1, attr_dim, NULL); + + if ((attr_id = H5Acreate(file, "file_attribute", H5T_STD_I32LE, attr_space_id, H5P_DEFAULT, H5P_DEFAULT)) < 0) + goto error; + + if (H5Sclose(attr_space_id) < 0) + goto error; + if (H5Aclose(attr_id) < 0) + goto error; + if (H5Fclose(file) < 0) + goto error; + file = H5I_INVALID_HID; + + /*---------------------------------------------------------------------- + * Fourth revision: open the file with Onion VFD and delete the attribute + *---------------------------------------------------------------------- + */ + if ((file = H5Fopen(paths->canon, H5F_ACC_RDWR, fapl_id)) < 0) + goto error; + + if (H5Adelete(file, "file_attribute") < 0) + goto error; + + if (H5Fclose(file) < 0) + goto error; + file = H5I_INVALID_HID; + + /*---------------------------------------------------------------------- + * Fifth revision: open the file with Onion VFD and add a group to the file + *---------------------------------------------------------------------- + */ + if ((file = H5Fopen(paths->canon, H5F_ACC_RDWR, fapl_id)) < 0) + goto error; + + if ((group_id = H5Gcreate2(file, "new_group", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + goto error; + + if (H5Gclose(group_id) < 0) + goto error; + if (H5Fclose(file) < 0) + goto error; + file = H5I_INVALID_HID; + + /*---------------------------------------------------------------------- + * Sixth revision: open the file with Onion VFD and delete the newly added group + *---------------------------------------------------------------------- + */ + if ((file = H5Fopen(paths->canon, H5F_ACC_RDWR, fapl_id)) < 0) + goto error; + + if (H5Ldelete(file, "new_group", H5P_DEFAULT) < 0) + goto error; + + if (H5Fclose(file) < 0) + goto error; + file = H5I_INVALID_HID; + + /* + * Close and release resources. + */ + if (H5Pclose(onion_info.backing_fapl_id) < 0) + goto error; + if (H5Pclose(fapl_id) < 0) + goto error; + if (H5Pclose(dcpl) < 0) + goto error; + if (H5Sclose(space) < 0) + goto error; + + onion_filepaths_destroy(paths); + + return 0; +error: + + if (paths != NULL) { + HDremove(paths->canon); + HDremove(paths->onion); + HDremove(paths->recovery); + onion_filepaths_destroy(paths); + } + + if (dset != H5I_INVALID_HID) + (void)H5Dclose(dset); + if (file != H5I_INVALID_HID) + (void)H5Fclose(file); + if (fapl_id != H5I_INVALID_HID) + (void)H5Pclose(fapl_id); + if (onion_info.backing_fapl_id != H5I_INVALID_HID) + H5Pclose(onion_info.backing_fapl_id); + + return -1; +} /* gent_onion_create_delete_objects */ + +static int +gent_onion_dset_extension(void) +{ + const char * basename = "integration_dset_ext.h5"; + hid_t fapl_id = H5I_INVALID_HID; + struct onion_filepaths *paths = NULL; + H5FD_onion_fapl_info_t onion_info = { + H5FD_ONION_FAPL_INFO_VERSION_CURR, + H5I_INVALID_HID, /* backing_fapl_id */ + ONION_TEST_PAGE_SIZE, /* page_size */ + H5FD_ONION_STORE_TARGET_ONION, /* store_target */ + H5FD_ONION_FAPL_INFO_REVISION_ID_LATEST, + 0, /* force_write_open */ + 0, /* creation flags, was H5FD_ONION_FAPL_INFO_CREATE_FLAG_ENABLE_PAGE_ALIGNMENT */ + "initial commit" /* comment */ + }; + hid_t file = H5I_INVALID_HID, group_id = H5I_INVALID_HID; + hid_t attr_space_id = H5I_INVALID_HID, attr_id = H5I_INVALID_HID; + hid_t space, dset_space, dset, dcpl; /* Handles */ + hsize_t dims[2] = {4, 4}, maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED}, chunk[2] = {4, 4}; + hsize_t size[2], offset[2]; + int wdata[4][4], /* Write buffer */ + fillval, i, j; + int rdata[4][4]; /* Read buffer */ + + /* Setup */ + if ((onion_info.backing_fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) + goto error; + if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) + goto error; + + if (H5Pset_fapl_onion(fapl_id, &onion_info) < 0) + goto error; + + if ((paths = onion_filepaths_init(FILE92, &onion_info)) == NULL) + goto error; + + /*---------------------------------------------------------------------- + * Create the skeleton file (create the file without Onion VFD) + *---------------------------------------------------------------------- + */ + /* + * Initialize data. + */ + for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) + wdata[i][j] = i + j; + + /* + * Create a new file using the default properties. + */ + if ((file = H5Fcreate(paths->canon, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) + goto error; + + /* + * Create dataspace with unlimited dimensions. + */ + if ((space = H5Screate_simple(2, dims, maxdims)) < 0) + goto error; + + /* + * Create the dataset creation property list, and set the chunk + * size. + */ + if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) + goto error; + if (H5Pset_chunk(dcpl, 2, chunk) < 0) + goto error; + + /* + * Set the fill value for the dataset. + */ + fillval = 99; + if (H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fillval) < 0) + goto error; + + /* + * Set the allocation time to "early". This way we can be sure + * that reading from the dataset immediately after creation will + * return the fill value. + */ + if (H5Pset_alloc_time(dcpl, H5D_ALLOC_TIME_EARLY) < 0) + goto error; + + /* + * Create the dataset using the dataset creation property list. + */ + if ((dset = H5Dcreate(file, "DS1", H5T_STD_I32LE, space, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) + goto error; + + /* + * Write the data to the dataset. + */ + if (H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata) < 0) + goto error; + + if (H5Dclose(dset) < 0) + goto error; + if (H5Fclose(file) < 0) + goto error; + + /*---------------------------------------------------------------------- + * First revision: open the file with Onion VFD and extend the dataset + *---------------------------------------------------------------------- + */ + if ((file = H5Fopen(paths->canon, H5F_ACC_RDWR, fapl_id)) < 0) + goto error; + + /* Open the dataset */ + if ((dset = H5Dopen(file, "DS1", H5P_DEFAULT)) < 0) + goto error; + + /* Extend the dataset and double the rows */ + size[0] = 2 * dims[0]; + size[1] = dims[1]; + if (H5Dset_extent(dset, size) < 0) + goto error; + + if ((dset_space = H5Dget_space(dset)) < 0) + goto error; + + offset[0] = dims[0]; + offset[1] = 0; + if (H5Sselect_hyperslab(dset_space, H5S_SELECT_SET, offset, NULL, dims, NULL) < 0) + goto error; + + /* Write the data to the dataset. */ + if (H5Dwrite(dset, H5T_NATIVE_INT, space, dset_space, H5P_DEFAULT, wdata) < 0) + goto error; + + if (H5Sclose(dset_space) < 0) + goto error; + + if (H5Dclose(dset) < 0) + goto error; + dset = H5I_INVALID_HID; + if (H5Fclose(file) < 0) + goto error; + file = H5I_INVALID_HID; + + /*---------------------------------------------------------------------- + * Second revision: open the file with Onion VFD and shrink the dataset + *---------------------------------------------------------------------- + */ + if ((file = H5Fopen(paths->canon, H5F_ACC_RDWR, fapl_id)) < 0) + goto error; + + /* Open the dataset */ + if ((dset = H5Dopen(file, "DS1", H5P_DEFAULT)) < 0) + goto error; + + /* Extend the dataset and shrink back the size */ + if (H5Dset_extent(dset, dims) < 0) + goto error; + + if (H5Dclose(dset) < 0) + goto error; + dset = H5I_INVALID_HID; + if (H5Fclose(file) < 0) + goto error; + file = H5I_INVALID_HID; + + /* Close and release resources. */ + if (H5Pclose(onion_info.backing_fapl_id) < 0) + goto error; + if (H5Pclose(fapl_id) < 0) + goto error; + if (H5Pclose(dcpl) < 0) + goto error; + if (H5Sclose(space) < 0) + goto error; + + onion_filepaths_destroy(paths); + + return 0; +error: + + if (paths != NULL) { + HDremove(paths->canon); + HDremove(paths->onion); + HDremove(paths->recovery); + onion_filepaths_destroy(paths); + } + + if (dset != H5I_INVALID_HID) + (void)H5Dclose(dset); + if (file != H5I_INVALID_HID) + (void)H5Fclose(file); + if (fapl_id != H5I_INVALID_HID) + (void)H5Pclose(fapl_id); + if (onion_info.backing_fapl_id != H5I_INVALID_HID) + H5Pclose(onion_info.backing_fapl_id); + + return -1; +} /* gent_onion_dset_extension */ + int main(void) { @@ -11329,5 +12026,10 @@ main(void) gent_err_attr_dspace(); + /* Generate the files for testing Onion VFD */ + gent_onion_1d_dset(); + gent_onion_create_delete_objects(); + gent_onion_dset_extension(); + return 0; } diff --git a/tools/test/h5dump/testh5dump.sh.in b/tools/test/h5dump/testh5dump.sh.in index 9464302..effe393 100644 --- a/tools/test/h5dump/testh5dump.sh.in +++ b/tools/test/h5dump/testh5dump.sh.in @@ -184,6 +184,12 @@ $SRC_H5DUMP_TESTFILES/tvms.h5 $SRC_H5DUMP_TESTFILES/err_attr_dspace.h5 $SRC_H5DUMP_TESTFILES/tCVE_2018_11206_fill_old.h5 $SRC_H5DUMP_TESTFILES/tCVE_2018_11206_fill_new.h5 +$SRC_H5DUMP_TESTFILES/tst_onion_objs.h5 +$SRC_H5DUMP_TESTFILES/tst_onion_objs.h5.onion +$SRC_H5DUMP_TESTFILES/tst_onion_dset_ext.h5 +$SRC_H5DUMP_TESTFILES/tst_onion_dset_ext.h5.onion +$SRC_H5DUMP_TESTFILES/tst_onion_dset_1d.h5 +$SRC_H5DUMP_TESTFILES/tst_onion_dset_1d.h5.onion " LIST_OTHER_TEST_FILES=" @@ -372,6 +378,9 @@ $SRC_H5DUMP_TESTFILES/h5dump-help.txt $SRC_H5DUMP_TESTFILES/out3.h5import $SRC_H5DUMP_TESTFILES/tbinregR.exp $SRC_H5DUMP_TESTFILES/err_attr_dspace.ddl +$SRC_H5DUMP_TESTFILES/tst_onion_objs.ddl +$SRC_H5DUMP_TESTFILES/tst_onion_dset_ext.ddl +$SRC_H5DUMP_TESTFILES/tst_onion_dset_1d.ddl " LIST_ERROR_TEST_FILES=" @@ -1486,6 +1495,11 @@ TOOLTEST err_attr_dspace.ddl err_attr_dspace.h5 TOOLTEST_FAIL tCVE_2018_11206_fill_old.h5 TOOLTEST_FAIL tCVE_2018_11206_fill_new.h5 +# test Onion VFD +TOOLTEST tst_onion_objs.ddl --enable-error-stack -f onion -F 3 tst_onion_objs.h5 +TOOLTEST tst_onion_dset_ext.ddl --enable-error-stack -f onion -F 1 tst_onion_dset_ext.h5 +TOOLTEST tst_onion_dset_1d.ddl --enable-error-stack -f onion -F 1 tst_onion_dset_1d.h5 + # Clean up temporary files/directories CLEAN_TESTFILES_AND_TESTDIR |