Skip to content

Commit

Permalink
Integrate with testframe test threading
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjala committed Nov 26, 2024
1 parent a76f959 commit 8638c9e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 134 deletions.
30 changes: 16 additions & 14 deletions test/threads/testmthdf5.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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", &params, 0);
NULL, "MT reg/unreg of a single connector", &params, test_framework_flags);

AddTest("mt_reg_by_name", mt_test_registration_by_name,
NULL, "MT reg/unreg of a single connector by name", &params, 0);
NULL, "MT reg/unreg of a single connector by name", &params, test_framework_flags);

AddTest("mt_reg_by_val", mt_test_registration_by_value,
NULL, "MT reg/unreg of a single connector by value", &params, 0);
NULL, "MT reg/unreg of a single connector by value", &params, test_framework_flags);

AddTest("mt_dyn_op_reg", mt_test_dyn_op_registration,
NULL, "MT reg/unreg of dynamic optional VOL operations", &params, 0);
NULL, "MT reg/unreg of dynamic optional VOL operations", &params, test_framework_flags);

AddTest("mt_fopen_fail", mt_test_file_open_failure_registration,
NULL, "MT dynamic VOL loading on file open failure", &params, test_framework_flags);

AddTest("mt_lib_state", mt_test_lib_state_ops,
NULL, "MT usage of library state routines", &params, test_framework_flags);

AddTest("mt_vol_info", mt_test_vol_info,
NULL, "MT usage of VOL info routines", &params, 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", &params, 0);

AddTest("mt_fopen_fail", mt_test_file_open_failure_registration,
NULL, "MT dynamic VOL loading on file open failure", &params, 0);

AddTest("mt_prop_copy", mt_test_vol_property_copy,
NULL, "MT VOL property copying", &params, 0);

AddTest("mt_lib_state", mt_test_lib_state_ops,
NULL, "MT usage of library state routines", &params, 0);

AddTest("mp_vol_wrp_ctx", mt_test_vol_wrap_ctx,
mt_test_vol_wrap_ctx_cleanup, "MT usage of VOL wrap context routines", &params, 0);

AddTest("mt_vol_info", mt_test_vol_info,
NULL, "MT usage of VOL info routines", &params, 0);

AddTest("mt_reg_search", mt_test_register_and_search,
NULL, "MT reg/unreg of connectors while searching for connector", &params, 0);

/* Misc MT tests */
AddTest("mt_library_init", mt_test_library_init,
NULL, "MT usage of H5open/H5close", &params, 0);
NULL, "MT usage of H5open/H5close", &params, test_framework_flags);

#endif /* H5_HAVE_MULTITHREAD */
/* Display testing information */
Expand Down
44 changes: 6 additions & 38 deletions test/threads/unit/mt_misc_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,19 @@
#include "h5test.h"
#include <pthread.h>

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;
}
return;
}

#endif /* H5_HAVE_MULTITHREAD */
96 changes: 14 additions & 82 deletions test/threads/unit/mt_vl_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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++) {
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand All @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */

0 comments on commit 8638c9e

Please sign in to comment.