2019-04-05 00:03:05 +08:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* Copyright by The HDF Group. *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
|
|
|
* the COPYING file, which can be found at the root of the source code *
|
2021-02-17 22:52:04 +08:00
|
|
|
* distribution tree, or in https://www.hdfgroup.org/licenses. *
|
2019-04-05 00:03:05 +08:00
|
|
|
* If you do not have access to either file, you may request a copy from *
|
|
|
|
* help@hdfgroup.org. *
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
/*
|
2019-08-16 05:46:00 +08:00
|
|
|
* Purpose: Tests datasets stored in external raw files.
|
2019-04-05 00:03:05 +08:00
|
|
|
*/
|
2019-04-10 05:20:19 +08:00
|
|
|
#include "external_common.h"
|
2019-04-05 00:03:05 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
static const char *EXT_ENV_FNAME[] = {"extern_env_dir/env_file_1", NULL};
|
2019-08-16 05:46:00 +08:00
|
|
|
|
2019-04-05 00:03:05 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: test_path_env
|
|
|
|
*
|
|
|
|
* Purpose: Test whether the value of HDF5_EXTFILE_PREFIX will overwrite
|
|
|
|
* the efile_prefix dataset access property.
|
|
|
|
* This will create an HDF5 file in a subdirectory which will
|
|
|
|
* refer to ../extern_*a.raw
|
|
|
|
* The files are then accessed by setting the HDF5_EXTFILE_PREFIX
|
|
|
|
* environment variable to "${ORIGIN}".
|
|
|
|
* The efile_prefix dataset access property is set to "someprefix",
|
|
|
|
* which will cause an error if the value is not overwritten by
|
|
|
|
* the environment variable.
|
|
|
|
*
|
|
|
|
* Return: Success: 0
|
|
|
|
* Failure: 1
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
test_path_env(hid_t fapl)
|
|
|
|
{
|
2023-09-09 07:06:23 +08:00
|
|
|
hid_t file = H5I_INVALID_HID; /* file to write to */
|
|
|
|
hid_t dcpl = H5I_INVALID_HID; /* dataset creation properties */
|
|
|
|
hid_t space = H5I_INVALID_HID; /* data space */
|
|
|
|
hid_t dapl = H5I_INVALID_HID; /* dataset access property list */
|
|
|
|
hid_t dset = H5I_INVALID_HID; /* dataset */
|
|
|
|
size_t i; /* miscellaneous counters */
|
|
|
|
char filename[1024]; /* file name */
|
|
|
|
int part[PART_SIZE]; /* raw data buffer (partial) */
|
|
|
|
int whole[TOTAL_SIZE]; /* raw data buffer (total) */
|
|
|
|
hsize_t cur_size; /* current data space size */
|
|
|
|
char buffer[1024]; /* buffer to read efile_prefix */
|
2019-04-05 00:03:05 +08:00
|
|
|
|
|
|
|
TESTING("prefix in HDF5_EXTFILE_PREFIX");
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (HDmkdir("extern_env_dir", (mode_t)0755) < 0 && errno != EEXIST)
|
2019-04-05 00:03:05 +08:00
|
|
|
TEST_ERROR;
|
|
|
|
|
2019-04-24 05:40:02 +08:00
|
|
|
h5_fixname(EXT_ENV_FNAME[0], fapl, filename, sizeof(filename));
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
FAIL_STACK_ERROR;
|
2019-04-05 00:03:05 +08:00
|
|
|
|
|
|
|
/* Reset the raw data files */
|
2023-09-06 04:11:52 +08:00
|
|
|
if (reset_raw_data_files(true) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2019-04-05 00:03:05 +08:00
|
|
|
|
|
|
|
/* Create the dataset */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
FAIL_STACK_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < N_EXT_FILES; i++) {
|
2023-09-16 06:13:18 +08:00
|
|
|
snprintf(filename, sizeof(filename), "..%sextern_env_%dr.raw", H5_DIR_SEPS, (int)i + 1);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Pset_external(dcpl, filename, (off_t)(i * GARBAGE_PER_FILE), (hsize_t)sizeof(part)) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
FAIL_STACK_ERROR;
|
2019-04-05 00:03:05 +08:00
|
|
|
} /* end for */
|
|
|
|
|
|
|
|
cur_size = TOTAL_SIZE;
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((space = H5Screate_simple(1, &cur_size, NULL)) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
FAIL_STACK_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((dapl = H5Pcreate(H5P_DATASET_ACCESS)) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
FAIL_STACK_ERROR;
|
2019-04-05 00:03:05 +08:00
|
|
|
|
|
|
|
/* Set prefix to a nonexistent directory, will be overwritten by environment variable */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Pset_efile_prefix(dapl, "someprefix") < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
FAIL_STACK_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Pget_efile_prefix(dapl, buffer, sizeof(buffer)) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
FAIL_STACK_ERROR;
|
2023-09-16 06:13:18 +08:00
|
|
|
if (strcmp(buffer, "someprefix") != 0)
|
2019-04-05 00:03:05 +08:00
|
|
|
FAIL_PUTS_ERROR("efile prefix not set correctly");
|
|
|
|
|
|
|
|
/* Create dataset */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((dset = H5Dcreate2(file, "dset1", H5T_NATIVE_INT, space, H5P_DEFAULT, dcpl, dapl)) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
FAIL_STACK_ERROR;
|
2019-04-05 00:03:05 +08:00
|
|
|
|
|
|
|
/* Read the entire dataset and compare with the original */
|
2023-06-30 03:33:46 +08:00
|
|
|
memset(whole, 0, sizeof(whole));
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Dread(dset, H5T_NATIVE_INT, space, space, H5P_DEFAULT, whole) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
FAIL_STACK_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < TOTAL_SIZE; i++)
|
|
|
|
if (whole[i] != (signed)i)
|
2019-04-05 00:03:05 +08:00
|
|
|
FAIL_PUTS_ERROR("Incorrect value(s) read.");
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Dclose(dset) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
FAIL_STACK_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Pclose(dapl) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
FAIL_STACK_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Pclose(dcpl) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
FAIL_STACK_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Sclose(space) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
FAIL_STACK_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Fclose(file) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
FAIL_STACK_ERROR;
|
2019-04-05 00:03:05 +08:00
|
|
|
|
|
|
|
PASSED();
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
2020-09-30 22:27:10 +08:00
|
|
|
H5E_BEGIN_TRY
|
|
|
|
{
|
2019-04-05 00:03:05 +08:00
|
|
|
H5Pclose(dapl);
|
|
|
|
H5Dclose(dset);
|
|
|
|
H5Pclose(dcpl);
|
|
|
|
H5Sclose(space);
|
|
|
|
H5Fclose(file);
|
2020-09-30 22:27:10 +08:00
|
|
|
}
|
2023-06-16 12:49:02 +08:00
|
|
|
H5E_END_TRY
|
2019-04-05 00:03:05 +08:00
|
|
|
return 1;
|
|
|
|
} /* end test_path_env() */
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: main
|
|
|
|
*
|
|
|
|
* Purpose: Runs external dataset tests.
|
|
|
|
*
|
|
|
|
* Return: EXIT_SUCCESS/EXIT_FAILURE
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
2023-09-09 07:06:23 +08:00
|
|
|
hid_t fapl_id_old = H5I_INVALID_HID; /* file access properties (old format) */
|
|
|
|
hid_t fapl_id_new = H5I_INVALID_HID; /* file access properties (new format) */
|
|
|
|
hid_t fid = H5I_INVALID_HID; /* file for test_1* functions */
|
|
|
|
hid_t gid = H5I_INVALID_HID; /* group to emit diagnostics */
|
|
|
|
unsigned latest_format; /* default or latest file format */
|
|
|
|
int nerrors = 0; /* number of errors */
|
2019-04-05 00:03:05 +08:00
|
|
|
|
|
|
|
h5_reset();
|
|
|
|
|
|
|
|
/* Get a fapl for the old (default) file format */
|
|
|
|
fapl_id_old = h5_fileaccess();
|
|
|
|
|
|
|
|
/* Copy and set up a fapl for the latest file format */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((fapl_id_new = H5Pcopy(fapl_id_old)) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
FAIL_STACK_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Pset_libver_bounds(fapl_id_new, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
FAIL_STACK_ERROR;
|
2019-04-05 00:03:05 +08:00
|
|
|
|
|
|
|
/* Test with old & new format groups */
|
2023-09-06 04:11:52 +08:00
|
|
|
for (latest_format = false; latest_format <= true; latest_format++) {
|
2023-09-09 07:06:23 +08:00
|
|
|
hid_t current_fapl_id = H5I_INVALID_HID;
|
2019-04-05 00:03:05 +08:00
|
|
|
|
|
|
|
/* Set the fapl for different file formats */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (latest_format) {
|
2023-09-16 06:13:18 +08:00
|
|
|
puts("\nTesting with the latest file format:");
|
2019-04-05 00:03:05 +08:00
|
|
|
current_fapl_id = fapl_id_new;
|
|
|
|
} /* end if */
|
|
|
|
else {
|
2023-09-16 06:13:18 +08:00
|
|
|
puts("Testing with the default file format:");
|
2019-04-05 00:03:05 +08:00
|
|
|
current_fapl_id = fapl_id_old;
|
|
|
|
} /* end else */
|
|
|
|
|
|
|
|
nerrors += test_path_env(current_fapl_id);
|
|
|
|
} /* end for */
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (nerrors > 0)
|
|
|
|
goto error;
|
2019-04-05 00:03:05 +08:00
|
|
|
|
|
|
|
/* Close the new ff fapl. h5_cleanup will take care of the old ff fapl */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Pclose(fapl_id_new) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
FAIL_STACK_ERROR;
|
2019-04-05 00:03:05 +08:00
|
|
|
|
2023-09-16 06:13:18 +08:00
|
|
|
puts("All external storage tests passed.");
|
2019-04-05 00:03:05 +08:00
|
|
|
|
|
|
|
/* Clean up files used by file set tests */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (h5_cleanup(EXT_ENV_FNAME, fapl_id_old)) {
|
2019-04-22 23:23:38 +08:00
|
|
|
HDremove("extern_env_1r.raw");
|
|
|
|
HDremove("extern_env_2r.raw");
|
|
|
|
HDremove("extern_env_3r.raw");
|
|
|
|
HDremove("extern_env_4r.raw");
|
|
|
|
|
|
|
|
HDremove("extern_env_1w.raw");
|
|
|
|
HDremove("extern_env_2w.raw");
|
|
|
|
HDremove("extern_env_3w.raw");
|
|
|
|
HDremove("extern_env_4w.raw");
|
2019-04-05 00:03:05 +08:00
|
|
|
|
2019-04-24 05:40:02 +08:00
|
|
|
HDrmdir("extern_env_dir");
|
2019-04-05 00:03:05 +08:00
|
|
|
} /* end if */
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
|
|
|
error:
|
2020-09-30 22:27:10 +08:00
|
|
|
H5E_BEGIN_TRY
|
|
|
|
{
|
2019-04-05 00:03:05 +08:00
|
|
|
H5Fclose(fid);
|
|
|
|
H5Pclose(fapl_id_old);
|
|
|
|
H5Pclose(fapl_id_new);
|
|
|
|
H5Gclose(gid);
|
2020-09-30 22:27:10 +08:00
|
|
|
}
|
2023-06-16 12:49:02 +08:00
|
|
|
H5E_END_TRY
|
2019-04-05 00:03:05 +08:00
|
|
|
nerrors = MAX(1, nerrors);
|
2023-06-28 23:31:32 +08:00
|
|
|
printf("%d TEST%s FAILED.\n", nerrors, 1 == nerrors ? "" : "s");
|
2019-04-05 00:03:05 +08:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
} /* end main() */
|