Skip to content

Commit

Permalink
Minor adjustments to usage of alarm(2) timer in tests (HDFGroup#5292)
Browse files Browse the repository at this point in the history
Make alarm(2) timer per-test program rather than per-subtest

Avoid enabling alarm(2) timer when TestExpress is set to 0
  • Loading branch information
jhendersonHDF committed Feb 7, 2025
1 parent bb4cb89 commit d1d09c4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
2 changes: 1 addition & 1 deletion test/h5test.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ extern pthread_key_t test_thread_info_key_g;

/* Macros for the different TestExpress levels for expediting tests */
#define H5_TEST_EXPRESS_EXHAUSTIVE 0 /** Exhaustive run; tests should take as long as necessary */
#define H5_TEST_EXPRESS_FULL 1 /** Full run; tests should take no more than 30 minutes */
#define H5_TEST_EXPRESS_FULL 1 /** Full run; tests should take no more than 20 minutes */
#define H5_TEST_EXPRESS_QUICK 2 /** Quick run; tests should take no more than 10 minutes */
#define H5_TEST_EXPRESS_SMOKE_TEST 3 /** Smoke test; tests should take no more than 1 minute */

Expand Down
63 changes: 36 additions & 27 deletions test/testframe.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ TestInit(const char *ProgName, void (*TestPrivateUsage)(FILE *stream),
/* Initialize value for TestExpress functionality */
h5_get_testexpress();

/* Enable alarm timer for test program once TestExpress setting
* has been determined
*/
if (TestAlarmOn() < 0)
MESSAGE(5, ("Couldn't enable test alarm timer\n"));

/* Record the program name and private routines if provided. */
TestProgName = ProgName;
if (NULL != TestPrivateUsage)
Expand Down Expand Up @@ -506,10 +512,6 @@ PerformTests(void)
test_num_errs = H5_ATOMIC_LOAD(TestArray[Loop].TestNumErrors);
H5_ATOMIC_STORE(TestArray[Loop].TestNumErrors, TestNumErrs_g);

if (TestAlarmOn() < 0)
MESSAGE(5, ("Couldn't enable test alarm timer for test -- %s (%s) \n",
TestArray[Loop].Description, TestArray[Loop].Name));

if (!is_test_mt) {
if (TestArray[Loop].TestSetupFunc)
TestArray[Loop].TestSetupFunc(TestArray[Loop].TestParameters);
Expand All @@ -519,8 +521,6 @@ PerformTests(void)
if (TestArray[Loop].TestCleanupFunc)
TestArray[Loop].TestCleanupFunc(TestArray[Loop].TestParameters);

TestAlarmOff();

test_num_errs = H5_ATOMIC_LOAD(TestArray[Loop].TestNumErrors);
H5_ATOMIC_STORE(TestArray[Loop].TestNumErrors, TestNumErrs_g - test_num_errs);

Expand All @@ -531,7 +531,6 @@ PerformTests(void)

PerformThreadedTest(TestArray[Loop]);

TestAlarmOff();
H5_ATOMIC_STORE(TestArray[Loop].TestNumErrors, TestNumErrs_g - test_num_errs);
MESSAGE(5, ("===============================================\n"));
MESSAGE(5, ("There were %d errors detected.\n\n", (int)H5_ATOMIC_LOAD(TestArray[Loop].TestNumErrors)));
Expand Down Expand Up @@ -894,6 +893,8 @@ TestShutdown(void)

free(TestArray);

TestAlarmOff();

return SUCCEED;
}

Expand Down Expand Up @@ -1140,30 +1141,38 @@ SetTestMaxNumThreads(int max_num_threads)
herr_t
TestAlarmOn(void)
{
/* A TestExpress setting of H5_TEST_EXPRESS_EXHAUSTIVE should allow
* tests to run for as long as necessary, so avoid enabling an
* alarm-style timer here that would, by default, kill the test.
*/
if (GetTestExpress() == H5_TEST_EXPRESS_EXHAUSTIVE)
return SUCCEED;
#ifdef H5_HAVE_ALARM
char *env_val = HDgetenv("HDF5_ALARM_SECONDS"); /* Alarm environment */
unsigned long alarm_sec = H5_ALARM_SEC; /* Number of seconds before alarm goes off */
else {
char *env_val = getenv("HDF5_ALARM_SECONDS"); /* Alarm environment */
unsigned long alarm_sec = H5_ALARM_SEC; /* Number of seconds before alarm goes off */

/* Get the alarm value from the environment variable, if set */
if (env_val != NULL) {
errno = 0;
alarm_sec = strtoul(env_val, NULL, 10);
if (errno != 0) {
if (TestFrameworkProcessID_g == 0)
fprintf(stderr, "%s: error while parsing value (%s) specified for alarm timeout\n", __func__,
env_val);
return FAIL;
}
else if (alarm_sec > (unsigned long)UINT_MAX) {
if (TestFrameworkProcessID_g == 0)
fprintf(stderr, "%s: value (%lu) specified for alarm timeout too large\n", __func__,
alarm_sec);
return FAIL;
/* Get the alarm value from the environment variable, if set */
if (env_val != NULL) {
errno = 0;
alarm_sec = strtoul(env_val, NULL, 10);
if (errno != 0) {
if (TestFrameworkProcessID_g == 0)
fprintf(stderr, "%s: error while parsing value (%s) specified for alarm timeout\n",
__func__, env_val);
return FAIL;
}
else if (alarm_sec > (unsigned long)UINT_MAX) {
if (TestFrameworkProcessID_g == 0)
fprintf(stderr, "%s: value (%lu) specified for alarm timeout too large\n", __func__,
alarm_sec);
return FAIL;
}
}
}

/* Set the number of seconds before alarm goes off */
alarm((unsigned)alarm_sec);
/* Set the number of seconds before alarm goes off */
alarm((unsigned)alarm_sec);
}
#endif

return SUCCEED;
Expand Down

0 comments on commit d1d09c4

Please sign in to comment.