From f68e116ce9286d7f1977fb364b4da7dbaeca9ef6 Mon Sep 17 00:00:00 2001 From: Binh-Minh Date: Mon, 8 Jul 2024 06:04:00 -0400 Subject: [PATCH] Additional cleanup --- c++/test/h5cpputil.cpp | 10 +-- c++/test/h5cpputil.h | 162 ++++++++++++++--------------------------- c++/test/tattr.cpp | 6 +- 3 files changed, 62 insertions(+), 116 deletions(-) diff --git a/c++/test/h5cpputil.cpp b/c++/test/h5cpputil.cpp index a3ee2fcc1c8..63d880d8f54 100644 --- a/c++/test/h5cpputil.cpp +++ b/c++/test/h5cpputil.cpp @@ -234,8 +234,6 @@ void verify_val(const char *x, const char *value, const char *where, int line, const char *file_name, const char *var) { - /* cerr << endl << "this verify_val const char *x and const char *value" << endl; - */ if (strcmp(x, value) != 0) { cerr << endl; cerr << "*** UNEXPECTED VALUE at line " << line << " from " << file_name << "::" << where @@ -258,8 +256,6 @@ void verify_val(const H5std_string &x, const H5std_string &value, const char *where, int line, const char *file_name, const char *var) { - /* cerr << endl << "this verify_val const H5std_string& x and const H5std_string& value" << endl; - */ verify_val(x.c_str(), value.c_str(), where, line, file_name, var); } @@ -491,7 +487,7 @@ TestCleanup(void) * Retrieve Summary request value. * 0 means no summary, 1 means yes. */ -H5_ATTR_PURE int +int GetTestSummary(void) { return (Summary); @@ -501,7 +497,7 @@ GetTestSummary(void) * Retrieve Cleanup request value. * 0 means no Cleanup, 1 means yes. */ -H5_ATTR_PURE int +int GetTestCleanup(void) { return (CleanUp); @@ -524,7 +520,7 @@ SetTestNoCleanup(void) /* * Retrieve the number of testing errors for the testing framework */ -H5_ATTR_PURE int +int GetTestNumErrs(void) { return (num_errs); diff --git a/c++/test/h5cpputil.h b/c++/test/h5cpputil.h index fb6d4a0f2b1..625dba0f8e4 100644 --- a/c++/test/h5cpputil.h +++ b/c++/test/h5cpputil.h @@ -27,26 +27,43 @@ using namespace H5; using std::cerr; using std::endl; -extern size_t n_tests_passed_g; -extern size_t n_tests_failed_g; -extern size_t n_tests_skipped_g; +class InvalidActionException : public Exception { + public: + InvalidActionException(const H5std_string &func_name, const H5std_string &message = DEFAULT_MSG); + InvalidActionException(); + ~InvalidActionException() override = default; +}; + +class TestFailedException : public Exception { + public: + TestFailedException(const H5std_string &func_name, const H5std_string &message = DEFAULT_MSG); + TestFailedException(); + ~TestFailedException() override = default; +}; + +/* + * Some are duplicated from h5test.* + */ + +extern size_t n_tests_passed_g; +extern size_t n_tests_failed_g; +extern size_t n_tests_skipped_g; /* Number of seconds to wait before killing a test (requires alarm(2)) */ #define H5_ALARM_SEC 1200 /* default is 20 minutes */ -/* Routines for operating on the list of tests (for the "all in one" tests) */ -char *h5cpp_fixname(const char *base_name, hid_t fapl, char *fullname, size_t size); -void TestUsage(void); -void AddTest(const char *TheName, void (*TheCall)(void), void (*Cleanup)(void), const char *TheDescr); -void TestInfo(const char *ProgName); -void TestParseCmdLine(int argc, char *argv[]); -void PerformTests(void); -void TestSummary(void); -void TestCleanup(void); -void TestShutdown(void); -/* void TestInit(const char *ProgName, void (*private_usage)(void), - int (*private_parser)(int ac, char *av[])); -*/ +/* + * Various functions for operating on the list of tests + */ +char *h5cpp_fixname(const char *base_name, hid_t fapl, char *fullname, size_t size); +void TestUsage(void); +void AddTest(const char *TheName, void (*TheCall)(void), void (*Cleanup)(void), + const char *TheDescr); +void TestInfo(const char *ProgName); +void TestParseCmdLine(int argc, char *argv[]); +void PerformTests(void); +void TestSummary(void); +void TestCleanup(void); int GetTestSummary(void); int GetTestCleanup(void); int SetTestNoCleanup(void); @@ -54,11 +71,12 @@ int GetTestExpress(void); int SetTestExpress(int newval); int GetTestNumErrs(void); void IncTestNumErrs(void); -const void *GetTestParameters(void); -const char *h5cpp_get_test_driver_name(void); void TestAlarmOn(void); void TestAlarmOff(void); +/* Checks the HDF5_DRIVER and HDF5_TEST_DRIVER environment variables */ +const char *h5cpp_get_test_driver_name(void); + /* Return srcdir path */ const char *h5cpp_get_srcdir(void); @@ -66,26 +84,12 @@ const char *h5cpp_get_srcdir(void); const char *h5cpp_get_srcdir_filename(const char *filename); /* - * The name of the test is printed by saying TESTING("something") which will - * result in the string `Testing something' being flushed to standard output. * If a test passes, fails, or is skipped then the PASSED(), H5_FAILED(), or * SKIPPED() macro should be called. After H5_FAILED() or SKIPPED() the caller * should print additional information to stdout indented by at least four * spaces. If the h5_errors() is used for automatic error handling then * the H5_FAILED() macro is invoked automatically when an API function fails. */ -#define TESTING(WHAT) \ - do { \ - printf("Testing %-62s", WHAT); \ - fflush(stdout); \ - n_tests_run_g++; \ - } while (0) -#define TESTING_2(WHAT) \ - do { \ - printf(" Testing %-60s", WHAT); \ - fflush(stdout); \ - n_tests_run_g++; \ - } while (0) #define PASSED() \ do { \ puts(" PASSED"); \ @@ -98,54 +102,22 @@ const char *h5cpp_get_srcdir_filename(const char *filename); fflush(stdout); \ n_tests_failed_g++; \ } while (0) -#define H5_WARNING() \ - do { \ - puts("*WARNING*"); \ - fflush(stdout); \ - } while (0) #define SKIPPED() \ do { \ puts(" -SKIP-"); \ fflush(stdout); \ n_tests_skipped_g++; \ } while (0) -#define PUTS_ERROR(s) \ - do { \ - puts(s); \ - AT(); \ - goto error; \ - } while (0) -#define TEST_ERROR \ - do { \ - H5_FAILED(); \ - AT(); \ - goto error; \ - } while (0) -#define STACK_ERROR \ - do { \ - H5Eprint2(H5E_DEFAULT, stdout); \ - goto error; \ - } while (0) -#define FAIL_STACK_ERROR \ - do { \ - H5_FAILED(); \ - AT(); \ - H5Eprint2(H5E_DEFAULT, stdout); \ - goto error; \ - } while (0) -#define FAIL_PUTS_ERROR(s) \ - do { \ - H5_FAILED(); \ - AT(); \ - puts(s); \ - goto error; \ - } while (0) #define SUBTEST(TEST) \ do { \ printf(" Subtest: %-52s", TEST); \ fflush(stdout); \ } while (0) +/* + * Overloaded/Template functions to verify values and display proper info + */ + int check_values(hsize_t i, hsize_t j, int apoint, int acheck); void check_values(const char *value, const char *msg, int line, const char *file_name); void display_error(const char *msg, const char *where, int line, const char *file_name); @@ -154,39 +126,15 @@ void issue_fail_msg(const char *where, int line, const char *file_name, const ch void issue_fail_msg(const char *where, int line, const char *file_name, const char *func_name, const char *message); -class InvalidActionException : public Exception { - public: - InvalidActionException(const H5std_string &func_name, const H5std_string &message = DEFAULT_MSG); - InvalidActionException(); - ~InvalidActionException() override = default; -}; - -class TestFailedException : public Exception { - public: - TestFailedException(const H5std_string &func_name, const H5std_string &message = DEFAULT_MSG); - TestFailedException(); - ~TestFailedException() override = default; -}; - -// Overloaded/Template functions to verify values and display proper info - -// MESSAGE +// MESSAGE from h5test.* void MESSAGE(int num); void MESSAGE(const char *msg); void MESSAGE(const char *msg, const char *desc, const char *name); -// Verifies -void verify_val(const char *x, const char *value, const char *where, int line, const char *file_name, - const char *var); -void verify_val(const H5std_string &x, const H5std_string &value, const char *where, int line, - const char *file_name, const char *var); - template void verify_val(Type1 x, Type2 value, const char *where, int line, const char *file_name, const char *var) { - /* cerr << endl << "verify_val template" << endl; - */ if (x != value) { cerr << endl; cerr << "*** UNEXPECTED VALUE at line " << line << " from" << file_name << "::" << where @@ -196,6 +144,19 @@ verify_val(Type1 x, Type2 value, const char *where, int line, const char *file_n } } +template +void +verify_val(Type1 x, Type2 value, float epsilon, const char *msg, int line, const char *file_name) +{ + if (x == value) { + cerr << endl; + cerr << "*** UNEXPECTED FLOAT VALUE: " << file_name << ":line " << line << ": " << msg + << " different: " << x << ", should be " << value << " (epsilon=" << epsilon << ")" << endl; + IncTestNumErrs(); + throw TestFailedException(file_name, msg); + } +} + template void verify_val_noteq(Type1 x, Type2 value, const char *where, int line, const char *file_name, const char *var) @@ -209,6 +170,7 @@ verify_val_noteq(Type1 x, Type2 value, const char *where, int line, const char * } } +// It was already determined that the values differ (by fabs), display the message template void display_difference(Type1 x, Type2 value, const char *where, int line, const char *file_name, const char *var) @@ -220,6 +182,7 @@ display_difference(Type1 x, Type2 value, const char *where, int line, const char throw TestFailedException(where, ""); } +// Checks for failure template void CHECK(Type1 x, Type2 value, const char *msg, int line, const char *file_name) @@ -232,19 +195,6 @@ CHECK(Type1 x, Type2 value, const char *msg, int line, const char *file_name) } } -template -void -verify_val(Type1 x, Type2 value, float epsilon, const char *msg, int line, const char *file_name) -{ - if (x == value) { - cerr << endl; - cerr << "*** UNEXPECTED FLOAT VALUE: " << file_name << ":line " << line << ": " << msg - << " different: " << x << ", should be " << value << " (epsilon=" << epsilon << ")" << endl; - IncTestNumErrs(); - throw TestFailedException(file_name, msg); - } -} - /* Prototypes for the test routines */ #ifdef __cplusplus extern "C" { diff --git a/c++/test/tattr.cpp b/c++/test/tattr.cpp index a7f2e943e4f..f2c3b5bf2e8 100644 --- a/c++/test/tattr.cpp +++ b/c++/test/tattr.cpp @@ -800,7 +800,7 @@ test_attr_compound_read(FileAccPropList &fapl) var); sprintf(var, "read_data4[%d][%d].%c", i, j, 'd'); - if (abs(read_data4[i][j].d - attr_data4[i][j].d) > DBL_EPSILON) { + if (fabs(read_data4[i][j].d - attr_data4[i][j].d) > DBL_EPSILON) { display_difference(read_data4[i][j].d, attr_data4[i][j].d, "DSetAccPropList::getChunkCache", __LINE__, __FILE__, "w0_1"); } @@ -929,7 +929,7 @@ test_attr_scalar_read(FileAccPropList &fapl) // Read attribute information float read_data2 = 0.0; // Buffer for reading 1st attribute ds_attr.read(PredType::NATIVE_FLOAT, &read_data2); - if (abs(read_data2 - attr_data5) > FLT_EPSILON) + if (fabs(read_data2 - attr_data5) > FLT_EPSILON) display_difference(read_data2, attr_data5, "Attribute::read", __LINE__, __FILE__, "read_data2"); // Get the dataspace of the attribute @@ -1221,7 +1221,7 @@ test_attr_mult_read(FileAccPropList &fapl) for (i = 0; i < ATTR3_DIM1; i++) for (j = 0; j < ATTR3_DIM2; j++) for (k = 0; k < ATTR3_DIM3; k++) { - if (abs(attr_data3[i][j][k] - read_data3[i][j][k]) > DBL_EPSILON) { + if (fabs(attr_data3[i][j][k] - read_data3[i][j][k]) > DBL_EPSILON) { char var[VAR_LEN]; sprintf(var, "read_data3[%d][%d][%d]", i, j, k); display_difference(read_data3[i][j][k], attr_data3[i][j][k], "Attribute::read",