Skip to content

Commit

Permalink
Only run multithreaded H5FL tests when concurrency enabled
Browse files Browse the repository at this point in the history
Also clean up some warnings

Signed-off-by: Quincey Koziol <[email protected]>
  • Loading branch information
qkoziol committed Dec 24, 2024
1 parent 3ac939e commit 4b024d6
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 20 deletions.
7 changes: 6 additions & 1 deletion test/ttsafe.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,13 @@ main(int argc, char *argv[])

#endif /* H5_HAVE_THREADSAFE_API */

#ifdef H5_HAVE_CONCURRENCY
/* Test library packages' threadsafety */
AddTest("h5fl", tts_h5fl, NULL, NULL, NULL, 0, "H5FL package");
AddTest("h5fl", tts_h5fl, NULL, NULL, NULL, 0, "Multithreaded H5FL package");
#else /* H5_HAVE_CONCURRENCY */
/* Test library packages' threadsafety */
AddTest("-h5fl", tts_h5fl, NULL, NULL, NULL, 0, "Multithreaded H5FL package");
#endif /* H5_HAVE_CONCURRENCY */

#else /* H5_HAVE_THREADS */

Expand Down
73 changes: 54 additions & 19 deletions test/ttsafe_h5fl.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ get_active_token(test_token *tokens, unsigned num_possible_tokens)
}

#if 0
static void print_vector(test_vector *vector, test_token *tokens)
static void
print_h5fl_reg_vector(test_vector *vector, test_token *tokens)
{
unsigned num_active_tokens = 0; /* # of active tokens at any position in the test vector execution */

Expand Down Expand Up @@ -324,7 +325,7 @@ static void print_vector(test_vector *vector, test_token *tokens)
#endif

static void
init_vector(unsigned vec_size, test_vector *vector, unsigned num_tokens, test_token *tokens)
init_h5fl_reg_vector(unsigned vec_size, test_vector *vector, unsigned num_tokens, test_token *tokens)
{
unsigned num_active_tokens = 0; /* # of active tokens at any position in the test vector execution */
unsigned curr_alloc_token; /* Current position for allocating tokens */
Expand Down Expand Up @@ -436,7 +437,7 @@ init_vector(unsigned vec_size, test_vector *vector, unsigned num_tokens, test_to
assert(0 == num_active_tokens);
}

static inline void
static inline unsigned
validate_token(const test_token *token)
{
int v;
Expand All @@ -448,31 +449,41 @@ validate_token(const test_token *token)
case ST_ZERO:
v = memcmp(token->val, test_types[token->type_idx].zero, test_types[token->type_idx].elmt_size);
VERIFY(v, 0, "ST_ZERO");
if (0 != v)
return(1);
break;

case ST_FILL1:
v = memcmp(token->val, test_types[token->type_idx].fill1, test_types[token->type_idx].elmt_size);
VERIFY(v, 0, "ST_FILL1");
if (0 != v)
return(1);
break;

case ST_FILL2:
v = memcmp(token->val, test_types[token->type_idx].fill2, test_types[token->type_idx].elmt_size);
VERIFY(v, 0, "ST_FILL2");
if (0 != v)
return(1);
break;

case ST_FILL3:
v = memcmp(token->val, test_types[token->type_idx].fill3, test_types[token->type_idx].elmt_size);
VERIFY(v, 0, "ST_FILL3");
if (0 != v)
return(1);
break;

default:
assert(0 && "Invalid state for token");
abort();
}

return(0);
}

static void
run_vector(test_vector *vector)
static unsigned
run_h5fl_reg_vector(test_vector *vector)
{
/* Execute test vector */
for (unsigned u = 0; u < vector->vec_size; u++) {
Expand All @@ -481,6 +492,8 @@ run_vector(test_vector *vector)
vector->op_vector[u].token->val =
H5FL_reg_malloc(test_types[vector->op_vector[u].param.type_idx].free_list);
CHECK_PTR(vector->op_vector[u].token->val, "H5FL_reg_malloc");
if (NULL == vector->op_vector[u].token->val)
return(1);
vector->op_vector[u].token->type_idx = vector->op_vector[u].param.type_idx;
vector->op_vector[u].token->state = ST_UNINIT;
break;
Expand All @@ -489,21 +502,25 @@ run_vector(test_vector *vector)
vector->op_vector[u].token->val =
H5FL_reg_calloc(test_types[vector->op_vector[u].param.type_idx].free_list);
CHECK_PTR(vector->op_vector[u].token->val, "H5FL_reg_calloc");
if (NULL == vector->op_vector[u].token->val)
return(1);
vector->op_vector[u].token->type_idx = vector->op_vector[u].param.type_idx;
vector->op_vector[u].token->state = ST_ZERO;
break;

case OP_ZERO:
if (ST_UNINIT != vector->op_vector[u].token->state)
validate_token(vector->op_vector[u].token);
if (0 != validate_token(vector->op_vector[u].token))
return(1);
memset(vector->op_vector[u].token->val, 0,
test_types[vector->op_vector[u].token->type_idx].elmt_size);
vector->op_vector[u].token->state = ST_ZERO;
break;

case OP_FILL1:
if (ST_UNINIT != vector->op_vector[u].token->state)
validate_token(vector->op_vector[u].token);
if (0 != validate_token(vector->op_vector[u].token))
return(1);
memcpy(vector->op_vector[u].token->val,
test_types[vector->op_vector[u].token->type_idx].fill1,
test_types[vector->op_vector[u].token->type_idx].elmt_size);
Expand All @@ -512,7 +529,8 @@ run_vector(test_vector *vector)

case OP_FILL2:
if (ST_UNINIT != vector->op_vector[u].token->state)
validate_token(vector->op_vector[u].token);
if (0 != validate_token(vector->op_vector[u].token))
return(1);
memcpy(vector->op_vector[u].token->val,
test_types[vector->op_vector[u].token->type_idx].fill2,
test_types[vector->op_vector[u].token->type_idx].elmt_size);
Expand All @@ -521,7 +539,8 @@ run_vector(test_vector *vector)

case OP_FILL3:
if (ST_UNINIT != vector->op_vector[u].token->state)
validate_token(vector->op_vector[u].token);
if (0 != validate_token(vector->op_vector[u].token))
return(1);
memcpy(vector->op_vector[u].token->val,
test_types[vector->op_vector[u].token->type_idx].fill3,
test_types[vector->op_vector[u].token->type_idx].elmt_size);
Expand All @@ -530,36 +549,45 @@ run_vector(test_vector *vector)

case OP_FREE:
if (ST_UNINIT != vector->op_vector[u].token->state)
validate_token(vector->op_vector[u].token);
if (0 != validate_token(vector->op_vector[u].token))
return(1);
H5FL_reg_free(test_types[vector->op_vector[u].token->type_idx].free_list,
vector->op_vector[u].token->val);
vector->op_vector[u].token->val = NULL;
break;

default:
assert(0 && "Invalid op code");
abort();
}
}

return(0);
}

static H5TS_THREAD_RETURN_TYPE
test_h5fl_reg(void *_vectors)
{
test_vector *vectors = (test_vector *)_vectors;
herr_t result;
H5TS_thread_ret_t ret_value = 0;
unsigned errors = 0;
H5TS_THREAD_RETURN_TYPE ret_value = (H5TS_THREAD_RETURN_TYPE)0;

/* Randomly run a number of vectors */
for (unsigned u = 0; u < NUM_ITERS_PER_THREAD; u++) {
unsigned rng = (unsigned)h5_local_rand() % NUM_VECTORS;

/* Run the test vector */
run_vector(&vectors[rng]);
errors += run_h5fl_reg_vector(&vectors[rng]);
}

if (errors > 0)
ret_value = (H5TS_THREAD_RETURN_TYPE)1;

return ret_value;
}

static test_vector *h5fl_reg_vectors[NUM_THREADS]; /* 'regular' H5FL test vectors */

/*
**********************************************************************
* Test H5FL package
Expand All @@ -568,7 +596,6 @@ test_h5fl_reg(void *_vectors)
void
tts_h5fl(const void H5_ATTR_UNUSED *params)
{
test_vector vectors[NUM_THREADS][NUM_VECTORS]; /* Test vectors */
test_token *tokens[NUM_THREADS]; /* Test tokens */
H5TS_thread_t threads[NUM_THREADS];
herr_t result;
Expand Down Expand Up @@ -602,29 +629,37 @@ tts_h5fl(const void H5_ATTR_UNUSED *params)
CHECK_PTR(tokens[u], "calloc");

/* Initialize the test vectors */
h5fl_reg_vectors[u] = calloc(NUM_VECTORS, sizeof(test_vector));
CHECK_PTR(h5fl_reg_vectors[u], "calloc");

for (unsigned v = 0; v < NUM_VECTORS; v++)
init_vector(NUM_TEST_OPS, &vectors[u][v], MAX_TOKENS, tokens[u]);
init_h5fl_reg_vector(NUM_TEST_OPS, &h5fl_reg_vectors[u][v], MAX_TOKENS, tokens[u]);
}

/* Create threads and have them execute the vector */
for (unsigned u = 0; u < NUM_THREADS; u++) {
result = H5TS_thread_create(&threads[u], test_h5fl_reg, &vectors[u]);
result = H5TS_thread_create(&threads[u], test_h5fl_reg, h5fl_reg_vectors[u]);
CHECK_I(result, "H5TS_thread_create");
}

/* Wait for all threads */
for (unsigned u = 0; u < NUM_THREADS; u++) {
H5TS_THREAD_RETURN_TYPE thread_ret = (H5TS_THREAD_RETURN_TYPE)0;

/* Join thread */
result = H5TS_thread_join(threads[u], NULL);
result = H5TS_thread_join(threads[u], &thread_ret);
CHECK_I(result, "H5TS_thread_join");

/* Verify no errors from thread */
VERIFY(thread_ret, (H5TS_THREAD_RETURN_TYPE)0, "error in thread");
}

/* Free test vectors & tokens */
for (unsigned u = 0; u < NUM_THREADS; u++) {
free(tokens[u]);
/* Initialize the test vectors */
for (unsigned v = 0; v < NUM_VECTORS; v++)
free(vectors[u][v].op_vector);
free(h5fl_reg_vectors[u][v].op_vector);
free(h5fl_reg_vectors[u]);
}

/* Free the zero fill values for each type */
Expand Down

0 comments on commit 4b024d6

Please sign in to comment.