diff --git a/test/API/H5_api_file_test.c b/test/API/H5_api_file_test.c index f06358348c8..80c835d0be9 100644 --- a/test/API/H5_api_file_test.c +++ b/test/API/H5_api_file_test.c @@ -1620,11 +1620,6 @@ test_get_file_obj_count(void) return; } - if (GetTestMaxNumThreads() == 0) { - printf(" Active thread count is invalid\n"); - TEST_ERROR; - } - TESTING_2("test setup"); if (prefix_filename(test_path_prefix, GET_OBJ_COUNT_TEST_FILENAME1, &prefixed_filename1) < 0) { diff --git a/test/API/H5_api_test.c b/test/API/H5_api_test.c index e07f8e42588..8dddfd96889 100644 --- a/test/API/H5_api_test.c +++ b/test/API/H5_api_test.c @@ -211,16 +211,12 @@ main(int argc, char **argv) #ifndef H5_HAVE_MULTITHREAD if (TEST_EXECUTION_THREADED) { - fprintf(stderr, "HDF5 must be built with multi-thread support to run multi-threaded API tests\n"); + fprintf(stderr, "HDF5 must be built with multi-thread support to run threaded API tests\n"); err_occurred = TRUE; goto done; } #endif - if (GetTestMaxNumThreads() <= 0) { - SetTestMaxNumThreads(API_TESTS_DEFAULT_NUM_THREADS); - } - if (!TEST_EXECUTION_THREADED) { /* Populate global test filename */ if ((chars_written = HDsnprintf(H5_api_test_filename_g, H5_TEST_FILENAME_MAX_LENGTH, "%s%s",test_path_prefix, @@ -412,7 +408,6 @@ main(int argc, char **argv) static int H5_api_test_create_containers(const char *filename, uint64_t vol_cap_flags) { - int max_threads = GetTestMaxNumThreads(); char *tl_filename = NULL; if (!(vol_cap_flags & H5VL_CAP_FLAG_FILE_BASIC)) { @@ -420,9 +415,9 @@ H5_api_test_create_containers(const char *filename, uint64_t vol_cap_flags) goto error; } - if (max_threads > 1) { + if (TEST_EXECUTION_THREADED) { #ifdef H5_HAVE_MULTITHREAD - for (int i = 0; i < max_threads; i++) { + for (int i = 0; i < GetTestMaxNumThreads(); i++) { if ((tl_filename = generate_threadlocal_filename(test_path_prefix, i, filename)) == NULL) { printf(" failed to generate thread-local API test filename\n"); goto error; @@ -532,7 +527,6 @@ H5_api_test_create_single_container(const char *filename, uint64_t vol_cap_flags static int H5_api_test_destroy_container_files(void) { - int max_threads = GetTestMaxNumThreads(); char *filename = NULL; if (!(vol_cap_flags_g & H5VL_CAP_FLAG_FILE_BASIC)) { @@ -540,13 +534,13 @@ H5_api_test_destroy_container_files(void) { goto error; } - if (max_threads > 1) { + if (TEST_EXECUTION_THREADED) { #ifndef H5_HAVE_MULTITHREAD printf(" thread-specific cleanup requested, but multithread support not enabled\n"); goto error; #endif - for (int i = 0; i < max_threads; i++) { + for (int i = 0; i < GetTestMaxNumThreads(); i++) { if ((filename = generate_threadlocal_filename(test_path_prefix, i, TEST_FILE_NAME)) == NULL) { printf(" failed to generate thread-local API test filename\n"); goto error; diff --git a/test/API/H5_api_test_util.c b/test/API/H5_api_test_util.c index 370eb7829d4..f56655679e6 100644 --- a/test/API/H5_api_test_util.c +++ b/test/API/H5_api_test_util.c @@ -649,7 +649,7 @@ generate_random_dataspace(int rank, const hsize_t *max_dims, hsize_t *dims_out, * is responsible for freeing the returned filename * pointer with free(). * - * If the API tests are being run multi-threaded, + * If the API tests are being run in separate thread(s) * then the framework-assigned thread index will be inserted as well. */ herr_t diff --git a/test/API/H5_api_test_util.h b/test/API/H5_api_test_util.h index be0040052cc..b4ffaaa3990 100644 --- a/test/API/H5_api_test_util.h +++ b/test/API/H5_api_test_util.h @@ -13,8 +13,6 @@ #ifndef H5_API_TEST_UTIL_H_ #define H5_API_TEST_UTIL_H_ -#define API_TESTS_DEFAULT_NUM_THREADS 1 - #include "hdf5.h" hid_t generate_random_datatype(H5T_class_t parent_class, hbool_t is_compact); diff --git a/test/h5test.h b/test/h5test.h index 3dc2220a460..b0f72d247f5 100644 --- a/test/h5test.h +++ b/test/h5test.h @@ -110,7 +110,7 @@ typedef struct thread_info_t { char* test_thread_filename; /* The name of the test container file */ } thread_info_t; -/* Whether or not the tests are configured to execute using multi-threaded infrastructure. +/* Whether or not the tests are configured to execute using threaded infrastructure. * Note that if GetTestMaxNumThreads() == 1, then the tests are still only run in a single thread, * but that thread is a new thread spawned by the main thread. */ #define TEST_EXECUTION_THREADED (GetTestMaxNumThreads() >= 1) @@ -129,7 +129,7 @@ extern pthread_key_t test_thread_info_key_g; #endif /* H5_HAVE_MULTITHREAD */ /* Flag values for TestFrameworkFlags */ -#define ALLOW_MULTITHREAD 0x00000001 /* Run the test in a multi-threaded environment */ +#define ALLOW_MULTITHREAD 0x00000001 /* Allow test to be run in spawned thread(s) based on runtime configuration */ /* * Print the current location on the standard output stream. diff --git a/test/testframe.c b/test/testframe.c index 784a015fa84..f0b6f9959e5 100644 --- a/test/testframe.c +++ b/test/testframe.c @@ -349,30 +349,29 @@ void PerformTests(void) { unsigned Loop; - bool is_test_mt = false; + bool is_test_threaded = false; bool mt_initialized = false; int old_num_errs = 0; - int max_num_threads = GetTestMaxNumThreads(); /* Silence compiler warnings */ (void) mt_initialized; for (Loop = 0; Loop < Index; Loop++) { - is_test_mt = (Test[Loop].TestFrameworkFlags & ALLOW_MULTITHREAD) && (max_num_threads > 1); + is_test_threaded = (Test[Loop].TestFrameworkFlags & ALLOW_MULTITHREAD) && (TEST_EXECUTION_THREADED); old_num_errs = H5_ATOMIC_LOAD(Test[Loop].NumErrors); if (Test[Loop].SkipFlag) { MESSAGE(2, ("Skipping -- %s (%s) \n", Test[Loop].Description, Test[Loop].Name)); } else { - MESSAGE(2, ("Testing %s -- %s (%s) \n", (is_test_mt ? "(Multi-threaded)" : ""), + MESSAGE(2, ("Testing %s -- %s (%s) \n", (is_test_threaded ? "(Threaded)" : ""), Test[Loop].Description, Test[Loop].Name)); MESSAGE(5, ("===============================================\n")); H5_ATOMIC_STORE(Test[Loop].NumErrors, num_errs_g); Test_parameters = Test[Loop].TestParameters; TestAlarmOn(); - if (!is_test_mt) { + if (!is_test_threaded) { Test[Loop].Call(); TestAlarmOff(); H5_ATOMIC_STORE(Test[Loop].NumErrors, num_errs_g - old_num_errs); @@ -393,17 +392,12 @@ PerformTests(void) memset(final_results, (int) TEST_UNINIT, H5_MAX_NUM_SUBTESTS * sizeof(test_outcome_t)); - if (max_num_threads <= 0) { - fprintf(stderr, "Invalid number of threads specified\n"); - exit(EXIT_FAILURE); - } - - if ((threads = (pthread_t *)calloc((size_t) max_num_threads, sizeof(pthread_t))) == NULL) { + if ((threads = (pthread_t *)calloc((size_t) GetTestMaxNumThreads(), sizeof(pthread_t))) == NULL) { fprintf(stderr, "Error allocating memory for threads\n"); exit(EXIT_FAILURE); } - if ((thread_args = (TestThreadArgs *)calloc((size_t) max_num_threads, sizeof(TestThreadArgs))) == NULL) { + if ((thread_args = (TestThreadArgs *)calloc((size_t) GetTestMaxNumThreads(), sizeof(TestThreadArgs))) == NULL) { fprintf(stderr, "Error allocating memory for thread arguments\n"); exit(EXIT_FAILURE); } @@ -417,7 +411,7 @@ PerformTests(void) mt_initialized = true; } - for (int i = 0; i < max_num_threads; i++) { + for (int i = 0; i < GetTestMaxNumThreads(); i++) { thread_args[i].ThreadIndex = i; thread_args[i].Call = Test[Loop].Call; thread_args[i].num_tests = 0; @@ -444,7 +438,7 @@ PerformTests(void) } } - for (int i = 0; i < max_num_threads; i++) { + for (int i = 0; i < GetTestMaxNumThreads(); i++) { ret = pthread_join(threads[i], NULL); if (ret != 0) { @@ -459,7 +453,7 @@ PerformTests(void) } /* Verify that each thread reported the same number of subtests */ - for (int i = 0; i < max_num_threads; i++) { + for (int i = 0; i < GetTestMaxNumThreads(); i++) { if (thread_args[i].num_tests != thread_args[0].num_tests) { fprintf(stderr, "Thread %d reported %ld subtests, but thread 0 reported %ld\n", i, thread_args[i].num_tests, thread_args[0].num_tests); exit(EXIT_FAILURE); @@ -470,7 +464,7 @@ PerformTests(void) H5_ATOMIC_ADD(n_tests_run_g, thread_args[0].num_tests); for (size_t j = 0; j < thread_args[0].num_tests; j++) { - for (int i = 0; i < max_num_threads; i++) + for (int i = 0; i < GetTestMaxNumThreads(); i++) final_results[j] = ((final_results[j] > thread_args[i].test_outcomes[j]) ? final_results[j] : thread_args[i].test_outcomes[j]); /* Display subtest description, if result is from subtest */ @@ -505,7 +499,7 @@ PerformTests(void) } } - for (int i = 0; i < max_num_threads; i++) { + for (int i = 0; i < GetTestMaxNumThreads(); i++) { free(thread_args[i].test_outcomes); free(thread_args[i].test_descriptions); thread_args[i].test_outcomes = NULL; @@ -538,7 +532,7 @@ PerformTests(void) #ifdef H5_HAVE_MULTITHREAD /* - * Set up and execute a test flagged for multi-threaded + * Set up and execute a test flagged for threaded * execution within a single thread. */ void *ThreadTestWrapper(void *test) @@ -933,15 +927,6 @@ SetTest(const char *testname, int action) #ifdef H5_HAVE_MULTITHREAD /* Set up global variables used for API tests */ int H5_mt_test_global_setup(void) { - int max_threads = 0; - - /* Set up thread count, used for some file tests */ - max_threads = GetTestMaxNumThreads(); - - if (max_threads <= 0) { - printf(" invalid max thread count\n"); - goto error; - } /* Set up pthread key */ if (pthread_key_create(&test_thread_info_key_g, H5_test_thread_info_key_destructor) != 0) {