Skip to content

Commit

Permalink
Additional cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bmribler committed Jul 8, 2024
1 parent 8f5e804 commit f68e116
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 116 deletions.
10 changes: 3 additions & 7 deletions c++/test/h5cpputil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
162 changes: 56 additions & 106 deletions c++/test/h5cpputil.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,65 +27,69 @@ 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);
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);

/* Append the test file name to the srcdir path and return the whole string */
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"); \
Expand All @@ -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);
Expand All @@ -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 <class Type1, class Type2>
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
Expand All @@ -196,6 +144,19 @@ verify_val(Type1 x, Type2 value, const char *where, int line, const char *file_n
}
}

template <class Type1, class Type2>
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 <class Type1, class Type2>
void
verify_val_noteq(Type1 x, Type2 value, const char *where, int line, const char *file_name, const char *var)
Expand All @@ -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 <class Type1, class Type2>
void
display_difference(Type1 x, Type2 value, const char *where, int line, const char *file_name, const char *var)
Expand All @@ -220,6 +182,7 @@ display_difference(Type1 x, Type2 value, const char *where, int line, const char
throw TestFailedException(where, "");
}

// Checks for failure
template <class Type1, class Type2>
void
CHECK(Type1 x, Type2 value, const char *msg, int line, const char *file_name)
Expand All @@ -232,19 +195,6 @@ CHECK(Type1 x, Type2 value, const char *msg, int line, const char *file_name)
}
}

template <class Type1, class Type2>
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" {
Expand Down
6 changes: 3 additions & 3 deletions c++/test/tattr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit f68e116

Please sign in to comment.