From 8638c9e19c862e00e5281c06b027bab1ad859018 Mon Sep 17 00:00:00 2001 From: Matthew Larson Date: Tue, 26 Nov 2024 11:40:51 -0600 Subject: [PATCH] Integrate with testframe test threading --- test/threads/testmthdf5.c | 30 +++++----- test/threads/unit/mt_misc_test.c | 44 ++------------- test/threads/unit/mt_vl_test.c | 96 +++++--------------------------- 3 files changed, 36 insertions(+), 134 deletions(-) diff --git a/test/threads/testmthdf5.c b/test/threads/testmthdf5.c index ec7a711e4b5..35ded775680 100644 --- a/test/threads/testmthdf5.c +++ b/test/threads/testmthdf5.c @@ -44,6 +44,7 @@ int main(int argc, char *argv[]) int testExpress; int num_errs_occurred = 0; mt_test_params params; + int64_t test_framework_flags = ALLOW_MULTITHREAD; /* Silence compiler warnings */ (void) params; @@ -74,42 +75,43 @@ int main(int argc, char *argv[]) #ifdef H5_HAVE_MULTITHREAD /* H5VL Tests */ AddTest("mt_reg_unreg", mt_test_registration, - NULL, "MT reg/unreg of a single connector", ¶ms, 0); + NULL, "MT reg/unreg of a single connector", ¶ms, test_framework_flags); AddTest("mt_reg_by_name", mt_test_registration_by_name, - NULL, "MT reg/unreg of a single connector by name", ¶ms, 0); + NULL, "MT reg/unreg of a single connector by name", ¶ms, test_framework_flags); AddTest("mt_reg_by_val", mt_test_registration_by_value, - NULL, "MT reg/unreg of a single connector by value", ¶ms, 0); + NULL, "MT reg/unreg of a single connector by value", ¶ms, test_framework_flags); AddTest("mt_dyn_op_reg", mt_test_dyn_op_registration, - NULL, "MT reg/unreg of dynamic optional VOL operations", ¶ms, 0); + NULL, "MT reg/unreg of dynamic optional VOL operations", ¶ms, test_framework_flags); + AddTest("mt_fopen_fail", mt_test_file_open_failure_registration, + NULL, "MT dynamic VOL loading on file open failure", ¶ms, test_framework_flags); + + AddTest("mt_lib_state", mt_test_lib_state_ops, + NULL, "MT usage of library state routines", ¶ms, test_framework_flags); + + AddTest("mt_vol_info", mt_test_vol_info, + NULL, "MT usage of VOL info routines", ¶ms, test_framework_flags); + + /* These tests do their own threading internally - provide no flags */ AddTest("mt_reg_op", mt_test_registration_operation, mt_test_registration_operation_cleanup, "MT reg/unreg of a connector and usage of its routines", ¶ms, 0); - AddTest("mt_fopen_fail", mt_test_file_open_failure_registration, - NULL, "MT dynamic VOL loading on file open failure", ¶ms, 0); - AddTest("mt_prop_copy", mt_test_vol_property_copy, NULL, "MT VOL property copying", ¶ms, 0); - AddTest("mt_lib_state", mt_test_lib_state_ops, - NULL, "MT usage of library state routines", ¶ms, 0); - AddTest("mp_vol_wrp_ctx", mt_test_vol_wrap_ctx, mt_test_vol_wrap_ctx_cleanup, "MT usage of VOL wrap context routines", ¶ms, 0); - AddTest("mt_vol_info", mt_test_vol_info, - NULL, "MT usage of VOL info routines", ¶ms, 0); - AddTest("mt_reg_search", mt_test_register_and_search, NULL, "MT reg/unreg of connectors while searching for connector", ¶ms, 0); /* Misc MT tests */ AddTest("mt_library_init", mt_test_library_init, - NULL, "MT usage of H5open/H5close", ¶ms, 0); + NULL, "MT usage of H5open/H5close", ¶ms, test_framework_flags); #endif /* H5_HAVE_MULTITHREAD */ /* Display testing information */ diff --git a/test/threads/unit/mt_misc_test.c b/test/threads/unit/mt_misc_test.c index 6361cdd6640..443a3a9d537 100644 --- a/test/threads/unit/mt_misc_test.c +++ b/test/threads/unit/mt_misc_test.c @@ -2,51 +2,19 @@ #include "h5test.h" #include -void *mt_test_library_init_helper(void *arg); +#ifdef H5_HAVE_MULTITHREAD /* Test attempted concurrent library initialization/termination */ void mt_test_library_init(void) { - int max_num_threads = GetTestMaxNumThreads(); const mt_test_params *params = (const mt_test_params *)GetTestParameters(); - pthread_t *threads = NULL; - int ret = 0; - - assert(params != NULL); - alarm(params->subtest_timeout); - - if (max_num_threads <= 0) { - TestErrPrintf("Invalid number of threads in MT test: %d\n", max_num_threads); - goto done; - } - - threads = calloc((size_t) max_num_threads, sizeof(pthread_t)); - CHECK(threads, NULL, "calloc"); - - for (int num_threads = 1; num_threads <= max_num_threads; num_threads++) { - for (int j = 0; j < num_threads; j++) { - ret = pthread_create(&threads[j], NULL, mt_test_library_init_helper, (void*)params->num_repetitions); - VERIFY(ret, 0, "pthread_create"); - } - - for (int j = 0; j < num_threads; j++) { - ret = pthread_join(threads[j], NULL); - VERIFY(ret, 0, "pthread_join"); - } - } - - free(threads); - -done: - return; -} - -void *mt_test_library_init_helper(void *arg) { - size_t num_repetitions = (size_t)arg; + size_t num_repetitions = (size_t)params->num_repetitions; for (size_t i = 0; i < num_repetitions; i++) { H5open(); H5close(); } - return NULL; -} \ No newline at end of file + return; +} + +#endif /* H5_HAVE_MULTITHREAD */ \ No newline at end of file diff --git a/test/threads/unit/mt_vl_test.c b/test/threads/unit/mt_vl_test.c index b48495a2f98..2d44689ab0b 100644 --- a/test/threads/unit/mt_vl_test.c +++ b/test/threads/unit/mt_vl_test.c @@ -34,19 +34,12 @@ H5VL_connector_prop_t conn_prop_g; typedef void *(*mt_vl_test_cb)(void *arg); -void mt_test_run_helper_in_parallel(mt_vl_test_cb mt_test_func, void *args); - -void *mt_test_registration_helper(void *arg); -void *mt_test_registration_by_name_helper(void *arg); -void *mt_test_registration_by_value_helper(void *arg); -void *mt_test_dyn_op_registration_helper(void *arg); void *mt_test_registration_operation_helper(void *arg); -void *mt_test_file_open_failure_registration_helper(void *arg); - +void *mt_test_dyn_op_registration_helper(void *arg); void *mt_test_vol_property_copy_helper(void *arg); -void *mt_test_lib_state_ops_helper(void *arg); void *mt_test_vol_wrap_ctx_helper(void *arg); -void *mt_test_vol_info_helper(void *arg); + +void mt_test_run_helper_in_parallel(mt_vl_test_cb mt_test_func, void *args); /* Helper routines used by the tests */ H5VL_subclass_t mt_test_dyn_op_get_vol_subclass(size_t index); @@ -58,20 +51,18 @@ void *mt_test_search_search_by_value_helper(void *arg); void mt_test_run_helper_in_parallel(mt_vl_test_cb mt_test_func, void *args) { pthread_t *threads = NULL; void *thread_return = NULL; - int num_threads = 0; + int max_num_threads = GetTestMaxNumThreads(); int ret = 0; - num_threads = GetTestMaxNumThreads(); - - if (num_threads <= 0) { + if (max_num_threads <= 0) { printf("No threadcount specified with -maxthreads; skipping test\n"); return; } - threads = (pthread_t *)calloc((long unsigned int) num_threads, sizeof(pthread_t)); + threads = (pthread_t *)calloc((long unsigned int) max_num_threads, sizeof(pthread_t)); assert(threads != NULL); - for (int num_threads = 1; num_threads <= num_threads; num_threads++) { + for (int num_threads = 1; num_threads <= max_num_threads; num_threads++) { memset(threads, 0, sizeof(pthread_t) * (long unsigned int) num_threads); for (int i = 0; i < num_threads; i++) { @@ -92,14 +83,6 @@ void mt_test_run_helper_in_parallel(mt_vl_test_cb mt_test_func, void *args) { /* Concurrently register and unregister the same VOL connector from multiple * threads. */ void mt_test_registration(void) { - const mt_test_params *params = (const mt_test_params *) GetTestParameters(); - assert(params != NULL); - alarm(params->subtest_timeout); - mt_test_run_helper_in_parallel(mt_test_registration_helper, NULL); - return; -} - -void *mt_test_registration_helper(void H5_ATTR_UNUSED *arg) { hid_t *vol_ids; herr_t ret = SUCCEED; const mt_test_params *params = NULL; @@ -124,20 +107,12 @@ void *mt_test_registration_helper(void H5_ATTR_UNUSED *arg) { } free(vol_ids); - return NULL; + return; } /* Concurrently register and unregister the same VOL connector by name from multiple * threads. */ void mt_test_registration_by_name(void) { - const mt_test_params *params = (const mt_test_params *) GetTestParameters(); - assert(params != NULL); - alarm(params->subtest_timeout); - mt_test_run_helper_in_parallel(mt_test_registration_by_name_helper, NULL); - return; -} - -void *mt_test_registration_by_name_helper(void H5_ATTR_UNUSED *arg) { hid_t *vol_ids; herr_t ret = SUCCEED; const mt_test_params *params = NULL; @@ -166,20 +141,12 @@ void *mt_test_registration_by_name_helper(void H5_ATTR_UNUSED *arg) { } free(vol_ids); - return NULL; + return; } /* Concurrently register and unregister the same VOL connector by value from multiple * threads. */ void mt_test_registration_by_value(void) { - const mt_test_params *params = (const mt_test_params *) GetTestParameters(); - assert(params != NULL); - alarm(params->subtest_timeout); - mt_test_run_helper_in_parallel(mt_test_registration_by_value_helper, NULL); - return; -} - -void *mt_test_registration_by_value_helper(void H5_ATTR_UNUSED *arg) { hid_t *vol_ids; herr_t ret = SUCCEED; const mt_test_params *params = NULL; @@ -208,19 +175,11 @@ void *mt_test_registration_by_value_helper(void H5_ATTR_UNUSED *arg) { } free(vol_ids); - return NULL; + return; } /* Test concurrent registration and unregistration of dynamic VOL operations */ void mt_test_dyn_op_registration(void) { - const mt_test_params *params = (const mt_test_params *) GetTestParameters(); - assert(params != NULL); - alarm(params->subtest_timeout); - mt_test_run_helper_in_parallel(mt_test_dyn_op_registration_helper, NULL); - return; -} - -void *mt_test_dyn_op_registration_helper(void H5_ATTR_UNUSED *arg) { herr_t registration_result = FAIL; hid_t vol_id = H5I_INVALID_HID; H5VL_subclass_t subcls = H5VL_SUBCLS_NONE; @@ -276,7 +235,7 @@ void *mt_test_dyn_op_registration_helper(void H5_ATTR_UNUSED *arg) { ret = H5VLunregister_connector(vol_id); VERIFY(ret, SUCCEED, "H5VLunregister_connector"); - return NULL; + return; } /* Helper to generate the appropriate VOL subclass for a given iteration */ @@ -384,15 +343,6 @@ void mt_test_registration_operation_cleanup(void) { /* Test that upon file open failure, loading an available VOL connector from * H5PL works in a multi-threaded environment */ void mt_test_file_open_failure_registration(void) { - const mt_test_params *params = (const mt_test_params *) GetTestParameters(); - assert(params != NULL); - alarm(params->subtest_timeout); - - mt_test_run_helper_in_parallel(mt_test_file_open_failure_registration_helper, NULL); - return; -} - -void *mt_test_file_open_failure_registration_helper(void H5_ATTR_UNUSED *arg) { hid_t file_id = H5I_INVALID_HID; hid_t fapl_id = H5I_INVALID_HID; hid_t curr_vol_id = H5I_INVALID_HID; @@ -445,7 +395,7 @@ void *mt_test_file_open_failure_registration_helper(void H5_ATTR_UNUSED *arg) { H5Pclose(fapl_id); if (curr_vol_id != H5I_INVALID_HID) H5VLclose(curr_vol_id); - return NULL; + return; } /* Test that implicit copying of a VOL connector property on a FAPL is handled @@ -667,15 +617,6 @@ void *mt_test_search_search_by_value_helper(void *arg) { /* Test concurrent usage of library state routines */ void mt_test_lib_state_ops(void) { - const mt_test_params *params = (const mt_test_params *) GetTestParameters(); - assert(params != NULL); - alarm(params->subtest_timeout); - - mt_test_run_helper_in_parallel(mt_test_lib_state_ops_helper, NULL); - return; -} - -void *mt_test_lib_state_ops_helper(void H5_ATTR_UNUSED *arg) { void *lib_state = NULL; herr_t ret = SUCCEED; @@ -701,7 +642,7 @@ void *mt_test_lib_state_ops_helper(void H5_ATTR_UNUSED *arg) { ret = H5VLfinish_lib_state(); VERIFY(ret, SUCCEED, "H5VLfinish_lib_state"); - return NULL; + return; } /* Retrieve and free the VOL wrap context in multiple threads executing in parallel. @@ -800,15 +741,6 @@ void mt_test_vol_wrap_ctx_cleanup(void) { * TBD: This largely depends on the connector callbacks of the active connector(s), and * so should probably have a counterpart placed in the API tests for use with various VOL connectors. */ void mt_test_vol_info(void) { - const mt_test_params *params = (const mt_test_params *) GetTestParameters(); - assert(params != NULL); - alarm(params->subtest_timeout); - - mt_test_run_helper_in_parallel(mt_test_vol_info_helper, NULL); - return; -} - -void *mt_test_vol_info_helper(void H5_ATTR_UNUSED *arg) { H5VL_pass_through_info_t vol_info = {H5VL_NATIVE, NULL}; void *vol_info2 = NULL; hid_t vol_id = H5I_INVALID_HID; @@ -860,7 +792,7 @@ void *mt_test_vol_info_helper(void H5_ATTR_UNUSED *arg) { ret = H5VLunregister_connector(vol_id); CHECK(ret, FAIL, "H5VLunregister_connector"); - return NULL; + return; } #endif /* H5_HAVE_MULTITHREAD */ \ No newline at end of file