From 55d094a23c0bccd420024795312a7af10f068390 Mon Sep 17 00:00:00 2001 From: Jordan Henderson Date: Tue, 4 Feb 2025 17:11:11 -0600 Subject: [PATCH] Minor adjustments to usage of alarm(2) timer in tests Make alarm(2) timer per-test program rather than per-subtest Avoid enabling alarm(2) timer when TestExpress is set to 0 --- test/h5test.h | 2 +- test/testframe.c | 62 ++++++++++++++++++++++++++++-------------------- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/test/h5test.h b/test/h5test.h index e654f82d01f..899fe3c3e96 100644 --- a/test/h5test.h +++ b/test/h5test.h @@ -204,7 +204,7 @@ H5TEST_DLLVAR MPI_Info h5_io_info_g; /* MPI INFO object for IO */ /* 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 */ diff --git a/test/testframe.c b/test/testframe.c index e4beda0d6c1..edc39b98c05 100644 --- a/test/testframe.c +++ b/test/testframe.c @@ -158,6 +158,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) @@ -461,10 +467,6 @@ PerformTests(void) MESSAGE(2, ("Testing -- %s (%s) \n", TestArray[Loop].Description, TestArray[Loop].Name)); MESSAGE(5, ("===============================================\n")); - if (TestAlarmOn() < 0) - MESSAGE(5, ("Couldn't enable test alarm timer for test -- %s (%s) \n", - TestArray[Loop].Description, TestArray[Loop].Name)); - if (TestArray[Loop].TestSetupFunc) TestArray[Loop].TestSetupFunc(TestArray[Loop].TestParameters); @@ -473,8 +475,6 @@ PerformTests(void) if (TestArray[Loop].TestCleanupFunc) TestArray[Loop].TestCleanupFunc(TestArray[Loop].TestParameters); - TestAlarmOff(); - TestArray[Loop].TestNumErrors = TestNumErrs_g - old_num_errs; MESSAGE(5, ("===============================================\n")); @@ -573,6 +573,8 @@ TestShutdown(void) free(TestArray); + TestAlarmOff(); + return SUCCEED; } @@ -829,30 +831,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 = getenv("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;