Skip to content

Commit

Permalink
Remove default API test num threads
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjala committed Dec 23, 2024
1 parent df6b0a9 commit 3a291a4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 48 deletions.
5 changes: 0 additions & 5 deletions test/API/H5_api_file_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 5 additions & 11 deletions test/API/H5_api_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -412,17 +408,16 @@ 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)) {
printf(" VOL connector doesn't support file creation\n");
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;
Expand Down Expand Up @@ -532,21 +527,20 @@ 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)) {
printf(" container should not have been created\n");
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;
Expand Down
2 changes: 1 addition & 1 deletion test/API/H5_api_test_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions test/API/H5_api_test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/h5test.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down
39 changes: 12 additions & 27 deletions test/testframe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3a291a4

Please sign in to comment.