Skip to content

Commit

Permalink
Refactor h5test.c, testframe.c and testpar.h testing frameworks
Browse files Browse the repository at this point in the history
Added new testframe.h header to document testing framework functions and
split them away from h5test.h and from test programs that don't
integrate with the testframe.c testing framework

Added new test setup callback to testframe.c testing framework

Added parameters to AddTest() to specify size of test parameters so they
can be copied for later use

Enabled HDF5 error stacks in testframe.c framework by default

Added new maxthreads option to testframe.c framework to allow specifying
the maximum number of threads a multi-threaded test can use

Moved TestExpress functionality out of testframe.c and into more general
h5test.c for wider use by tests through getter and setter

Updated some tests to not mix and match functionality between h5test.c/h
and testframe.c/h

Moved some functionality from testphdf5.h into testpar.h for parallel
tests that aren't part of testphdf5
  • Loading branch information
jhendersonHDF committed Sep 23, 2024
1 parent d1cfe52 commit da2c559
Show file tree
Hide file tree
Showing 72 changed files with 1,685 additions and 825 deletions.
4 changes: 2 additions & 2 deletions c++/test/testhdf5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ main(int argc, char *argv[])
}

/* Display testing information */
TestInfo(argv[0]);
TestInfo(stdout);

/* Parse command line arguments */
TestParseCmdLine(argc, argv);
Expand All @@ -110,7 +110,7 @@ main(int argc, char *argv[])

/* Display test summary, if requested */
if (GetTestSummary())
TestSummary();
TestSummary(stdout);

/* Clean up test files, if allowed */
if (GetTestCleanup() && !getenv(HDF5_NOCLEANUP))
Expand Down
8 changes: 5 additions & 3 deletions hl/test/test_packet_vlen.c
Original file line number Diff line number Diff line change
Expand Up @@ -861,9 +861,11 @@ verify_attribute(hid_t fid, const char *table_name, const char *attr_name)

/* Verify values read in */
for (ii = 0; ii < ATTR_DIM; ii++)
if (attr_data[ii] != read_data[ii])
TestErrPrintf("%d: attribute data different: attr_data[%d]=%d, read_data[%d]=%d\n", __LINE__, ii,
attr_data[ii], ii, read_data[ii]);
if (attr_data[ii] != read_data[ii]) {
fprintf(stderr, "%d: attribute data different: attr_data[%d]=%d, read_data[%d]=%d\n",
__LINE__, ii, attr_data[ii], ii, read_data[ii]);
goto error;
}

/* Close the attribute */
if (H5Aclose(attr_id) < 0)
Expand Down
2 changes: 1 addition & 1 deletion test/btree2.c
Original file line number Diff line number Diff line change
Expand Up @@ -9924,7 +9924,7 @@ main(void)
/* Reset library */
h5_test_init();
fapl = h5_fileaccess();
localTestExpress = TestExpress;
localTestExpress = h5_get_testexpress();

/* For the Direct I/O driver, skip intensive tests due to poor performance */
if (localTestExpress < 2 && !strcmp(driver_name, "direct"))
Expand Down
2 changes: 1 addition & 1 deletion test/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -32368,7 +32368,7 @@ main(void)

H5open();

express_test = GetTestExpress();
express_test = h5_get_testexpress();

printf("=========================================\n");
printf("Internal cache tests\n");
Expand Down
2 changes: 1 addition & 1 deletion test/cache_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -2223,7 +2223,7 @@ main(void)

H5open();

express_test = GetTestExpress();
express_test = h5_get_testexpress();

printf("===================================\n");
printf("Cache API tests\n");
Expand Down
2 changes: 1 addition & 1 deletion test/cache_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -7762,7 +7762,7 @@ main(void)

H5open();

express_test = GetTestExpress();
express_test = h5_get_testexpress();

printf("=========================================\n");
printf("Cache image tests\n");
Expand Down
17 changes: 10 additions & 7 deletions test/dsets.c
Original file line number Diff line number Diff line change
Expand Up @@ -990,14 +990,16 @@ test_compact_io(hid_t fapl)

/* Verify the dataset's layout and fill message versions */
if (fp->shared->low_bound == H5F_LIBVER_EARLIEST) {
VERIFY(dsetp->shared->layout.version, H5O_LAYOUT_VERSION_DEFAULT, "layout_ver_bounds");
VERIFY(dsetp->shared->dcpl_cache.fill.version, H5O_FILL_VERSION_2, "fill_ver_bounds");
if (dsetp->shared->layout.version != H5O_LAYOUT_VERSION_DEFAULT)
TEST_ERROR;
if (dsetp->shared->dcpl_cache.fill.version != H5O_FILL_VERSION_2)
TEST_ERROR;
}
else {
VERIFY(dsetp->shared->layout.version, H5O_layout_ver_bounds[fp->shared->low_bound],
"layout_ver_bounds");
VERIFY(dsetp->shared->dcpl_cache.fill.version, H5O_fill_ver_bounds[fp->shared->low_bound],
"fill_ver_bounds");
if (dsetp->shared->layout.version != H5O_layout_ver_bounds[fp->shared->low_bound])
TEST_ERROR;
if (dsetp->shared->dcpl_cache.fill.version != H5O_fill_ver_bounds[fp->shared->low_bound])
TEST_ERROR;
}

/* Close the dataset and delete from the file */
Expand Down Expand Up @@ -14983,7 +14985,8 @@ test_versionbounds(void)
if (vdset > 0) /* dataset created successfully */
{
/* Virtual dataset is only available starting in V110 */
VERIFY(high >= H5F_LIBVER_V110, true, "virtual dataset");
if (high < H5F_LIBVER_V110)
TEST_ERROR;

if (H5Dclose(vdset) < 0)
TEST_ERROR;
Expand Down
39 changes: 24 additions & 15 deletions test/dtypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -9528,8 +9528,8 @@ test_deprec(hid_t fapl)
dim_mismatch = false;
for (u = 0; u < rank; u++)
if (rdims[u] != dims[u]) {
TestErrPrintf("Array dimension information doesn't match!, rdims1[%u]=%d, tdims1[%u]=%d\n", u,
(int)rdims[u], u, (int)dims[u]);
fprintf(stderr, "Array dimension information doesn't match!, rdims1[%u]=%d, tdims1[%u]=%d\n",
u, (int)rdims[u], u, (int)dims[u]);
dim_mismatch = true;
} /* end if */
if (dim_mismatch)
Expand All @@ -9539,9 +9539,8 @@ test_deprec(hid_t fapl)
dim_mismatch = false;
for (u = 0; u < rank; u++)
if (rperm[u] != -2) {
TestErrPrintf(
"Array dimension permutation information was modified!, rdims1[%u]=%d, tdims1[%u]=%d\n", u,
rperm[u], u, perm[u]);
fprintf(stderr, "Array dimension permutation information was modified!, rdims1[%u]=%d, tdims1[%u]=%d\n",
u, rperm[u], u, perm[u]);
dim_mismatch = true;
} /* end if */
if (dim_mismatch)
Expand Down Expand Up @@ -9946,10 +9945,14 @@ verify_version(hid_t dtype, H5F_libver_t low, unsigned *highest_version)
case H5T_ARRAY: {
H5T_t *base_dtypep = NULL; /* Internal structure of a datatype */

if (low == H5F_LIBVER_EARLIEST)
VERIFY(dtypep->shared->version, H5O_DTYPE_VERSION_2, "H5O_dtype_ver_bounds");
else
VERIFY(dtypep->shared->version, H5O_dtype_ver_bounds[low], "H5O_dtype_ver_bounds");
if (low == H5F_LIBVER_EARLIEST) {
if (dtypep->shared->version != H5O_DTYPE_VERSION_2)
TEST_ERROR;
}
else {
if (dtypep->shared->version != H5O_dtype_ver_bounds[low])
TEST_ERROR;
}

/* Get the base datatype of this array type */
base_dtype = H5Tget_super(dtype);
Expand Down Expand Up @@ -10014,19 +10017,25 @@ verify_version(hid_t dtype, H5F_libver_t low, unsigned *highest_version)
}
/* If this compound datatype contains a datatype of higher version, it
will be promoted to that version, thus, verify with highest version */
if (*highest_version > H5O_dtype_ver_bounds[low])
VERIFY(dtypep->shared->version, *highest_version, "verify_version");
else
VERIFY(dtypep->shared->version, H5O_dtype_ver_bounds[low], "verify_version");
if (*highest_version > H5O_dtype_ver_bounds[low]) {
if (dtypep->shared->version != *highest_version)
TEST_ERROR;
}
else {
if (dtypep->shared->version != H5O_dtype_ver_bounds[low])
TEST_ERROR;
}
break;
}
case H5T_ENUM:
VERIFY(dtypep->shared->version, H5O_dtype_ver_bounds[low], "verify_version");
if (dtypep->shared->version != H5O_dtype_ver_bounds[low])
TEST_ERROR;
break;
case H5T_VLEN:
case H5T_FLOAT:
case H5T_INTEGER:
VERIFY(dtypep->shared->version, H5O_dtype_ver_bounds[H5F_LIBVER_EARLIEST], "verify_version");
if (dtypep->shared->version != H5O_dtype_ver_bounds[H5F_LIBVER_EARLIEST])
TEST_ERROR;
break;
case H5T_NCLASSES:
case H5T_NO_CLASS:
Expand Down
2 changes: 0 additions & 2 deletions test/earray.c
Original file line number Diff line number Diff line change
Expand Up @@ -2302,8 +2302,6 @@ main(void)
/* Reset library */
h5_test_init();
fapl = h5_fileaccess();
if (TestExpress > 0)
printf("***Express test mode %d. Some tests may be skipped\n", TestExpress);

/* Set the filename to use for this test (dependent on fapl) */
h5_fixname(FILENAME[0], fapl, filename_g, sizeof(filename_g));
Expand Down
2 changes: 0 additions & 2 deletions test/farray.c
Original file line number Diff line number Diff line change
Expand Up @@ -1633,8 +1633,6 @@ main(void)
/* Reset library */
h5_test_init();
fapl = h5_fileaccess();
if (TestExpress > 0)
printf("***Express test mode %d. Some tests may be skipped\n", TestExpress);

/* Set the filename to use for this test (dependent on fapl) */
h5_fixname(FILENAME[0], fapl, filename_g, sizeof(filename_g));
Expand Down
16 changes: 9 additions & 7 deletions test/fheap.c
Original file line number Diff line number Diff line change
Expand Up @@ -15960,6 +15960,7 @@ main(void)
const char *driver_name; /* Environment variable */
bool contig_addr_vfd; /* Whether VFD used has a contiguous address space */
bool api_ctx_pushed = false; /* Whether API context pushed */
int test_express;

/* Don't run this test using certain file drivers */
driver_name = h5_get_test_driver_name();
Expand All @@ -15982,9 +15983,10 @@ main(void)
* Activate full testing when this feature is re-enabled
* in the future for parallel build.
*/
if (TestExpress > 0)
printf("***Express test mode %d. Some tests may be skipped\n", TestExpress);
else if (TestExpress == 0) {
test_express = h5_get_testexpress();
if (test_express > 0)
printf("***Express test mode %d. Some tests may be skipped\n", test_express);
else if (test_express == 0) {
#ifdef H5_HAVE_PARALLEL
num_pb_fs = NUM_PB_FS - 2;
#else
Expand Down Expand Up @@ -16200,7 +16202,7 @@ main(void)
/* If this test fails, uncomment the tests above, which build up to this
* level of complexity gradually. -QAK
*/
if (TestExpress > 1)
if (test_express > 1)
printf(
"***Express test mode on. test_man_start_5th_recursive_indirect is skipped\n");
else
Expand Down Expand Up @@ -16248,7 +16250,7 @@ main(void)
nerrors += test_man_remove_first_row(fapl, &small_cparam, &tparam);
nerrors += test_man_remove_first_two_rows(fapl, &small_cparam, &tparam);
nerrors += test_man_remove_first_four_rows(fapl, &small_cparam, &tparam);
if (TestExpress > 1)
if (test_express > 1)
printf("***Express test mode on. Some tests skipped\n");
else {
nerrors += test_man_remove_all_root_direct(fapl, &small_cparam, &tparam);
Expand Down Expand Up @@ -16298,7 +16300,7 @@ main(void)
nerrors +=
test_man_fill_1st_row_3rd_direct_fill_2nd_direct_less_one_wrap_start_block_add_skipped(
fapl, &small_cparam, &tparam);
if (TestExpress > 1)
if (test_express > 1)
printf("***Express test mode on. Some tests skipped\n");
else {
nerrors +=
Expand Down Expand Up @@ -16428,7 +16430,7 @@ main(void)
} /* end block */

/* Random object insertion & deletion */
if (TestExpress > 1)
if (test_express > 1)
printf("***Express test mode on. Some tests skipped\n");
else {
/* Random tests using "small" heap creation parameters */
Expand Down
106 changes: 82 additions & 24 deletions test/h5test.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ const char *LIBVER_NAMES[] = {"earliest", /* H5F_LIBVER_EARLIEST = 0 */
static H5E_auto2_t err_func = NULL;

/* Global variables for testing */
size_t n_tests_run_g = 0;
size_t n_tests_passed_g = 0;
size_t n_tests_failed_g = 0;
size_t n_tests_skipped_g = 0;
uint64_t vol_cap_flags_g = H5VL_CAP_FLAG_NONE;
static int TestExpress_g = -1; /* Whether to expedite testing. -1 means not set yet. */
size_t n_tests_run_g = 0;
size_t n_tests_passed_g = 0;
size_t n_tests_failed_g = 0;
size_t n_tests_skipped_g = 0;
uint64_t vol_cap_flags_g = H5VL_CAP_FLAG_NONE;

static herr_t h5_errors(hid_t estack, void *client_data);
static char *h5_fixname_real(const char *base_name, hid_t fapl, const char *_suffix, char *fullname,
Expand Down Expand Up @@ -274,7 +275,7 @@ h5_test_init(void)
H5Eset_auto2(H5E_DEFAULT, h5_errors, NULL);

/* Retrieve the TestExpress mode */
GetTestExpress();
TestExpress_g = h5_get_testexpress();
} /* end h5_test_init() */

/*-------------------------------------------------------------------------
Expand Down Expand Up @@ -1008,6 +1009,81 @@ h5_get_libver_fapl(hid_t fapl)
return -1;
} /* end h5_get_libver_fapl() */

/*
* Returns the current TestExpress functionality setting.
* Valid values returned are as follows:
*
* 0: Exhaustive run
* Tests should take as long as necessary
* 1: Full run. Default value if H5_TEST_EXPRESS_LEVEL_DEFAULT
* and the HDF5TestExpress environment variable are not defined
* Tests should take no more than 30 minutes
* 2: Quick run
* Tests should take no more than 10 minutes
* 3: Smoke test.
* Default if the HDF5TestExpress environment variable is set to
* a value other than 0-3
* Tests should take less than 1 minute
*
* If the value returned is > 1, then test programs should
* skip some tests so that they complete sooner.
*/
int
h5_get_testexpress(void)
{
char *env_val;
int express_val = TestExpress_g;

/* TestExpress_g is uninitialized if it has a negative value */
if (express_val < 0) {
/* Default to level 1 if not overridden */
express_val = 1;

/* Check if a default test express level is defined (e.g., by build system) */
#ifdef H5_TEST_EXPRESS_LEVEL_DEFAULT
express_val = H5_TEST_EXPRESS_LEVEL_DEFAULT;
if (express_val < 0)
express_val = 1; /* Reset to default */
else if (express_val > 3)
express_val = 3;
#endif
}

/* Check if the HDF5TestExpress environment variable is set to
* override the default level
*/
env_val = getenv("HDF5TestExpress");
if (env_val) {
if (strcmp(env_val, "0") == 0)
express_val = 0;
else if (strcmp(env_val, "1") == 0)
express_val = 1;
else if (strcmp(env_val, "2") == 0)
express_val = 2;
else
express_val = 3;
}

return express_val;
}

/*
* Sets the level of express testing to the given value. Negative
* values are set to the default TestExpress setting (1). Values
* larger than the highest TestExpress setting (3) are set to the
* highest TestExpress setting.
*/
void
h5_set_testexpress(int new_val)
{
if (new_val < 0)
new_val = 1; /* Reset to default */
else if (new_val > 3)
new_val = 3;

TestExpress_g = new_val;
}

/*-------------------------------------------------------------------------
* Function: h5_no_hwconv
*
Expand Down Expand Up @@ -1403,24 +1479,6 @@ h5_get_file_size(const char *filename, hid_t fapl)
} /* end get_file_size() */
H5_GCC_CLANG_DIAG_ON("format-nonliteral")

/*
* This routine is designed to provide equivalent functionality to 'printf'
* and allow easy replacement for environments which don't have stdin/stdout
* available. (i.e. Windows & the Mac)
*/
H5_ATTR_FORMAT(printf, 1, 2)
int
print_func(const char *format, ...)
{
va_list arglist;
int ret_value;

va_start(arglist, format);
ret_value = vprintf(format, arglist);
va_end(arglist);
return ret_value;
}

#ifdef H5_HAVE_FILTER_SZIP

/*-------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit da2c559

Please sign in to comment.