Skip to content

Commit

Permalink
validation: thread: add tests for new control/worker thread count fun…
Browse files Browse the repository at this point in the history
…ctions

Add validation tests for the new control/worker thread count functions.

Signed-off-by: Matias Elo <matias.elo@nokia.com>
Reviewed-by: Tuomas Taipale <tuomas.taipale@nokia.com>
  • Loading branch information
MatiasElo authored and psavol committed Dec 19, 2023
1 parent a240b22 commit 05b146f
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions test/validation/api/thread/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,31 @@ static void thread_test_odp_thread_count(void)
{
int count = odp_thread_count();

/* One thread running */
/* One control thread running */
CU_ASSERT(count == 1);
CU_ASSERT(odp_thread_control_count() == 1);
CU_ASSERT(odp_thread_control_count() <= odp_thread_control_count_max());
CU_ASSERT(odp_thread_worker_count() == 0);

CU_ASSERT(count >= 1);
CU_ASSERT(count <= odp_thread_count_max());
CU_ASSERT(count <= ODP_THREAD_COUNT_MAX);
CU_ASSERT(odp_thread_count_max() <= ODP_THREAD_COUNT_MAX);
}

static void thread_test_odp_thread_count_max(void)
{
int max_threads = odp_thread_count_max();
int max_control = odp_thread_control_count_max();
int max_worker = odp_thread_worker_count_max();

CU_ASSERT(max_threads > 0);
CU_ASSERT(max_threads <= ODP_THREAD_COUNT_MAX);

CU_ASSERT(max_control >= 0);
CU_ASSERT(max_control <= max_threads);

CU_ASSERT(max_worker >= 0);
CU_ASSERT(max_worker <= max_threads);
}

static int thread_func(void *arg)
Expand Down Expand Up @@ -175,7 +193,9 @@ static void thread_test_odp_thrmask_worker(void)
ret = odp_thrmask_worker(&mask);
CU_ASSERT(ret == odp_thrmask_count(&mask));
CU_ASSERT(ret == num);
CU_ASSERT(ret == odp_thread_worker_count());
CU_ASSERT(ret <= odp_thread_count_max());
CU_ASSERT(ret <= odp_thread_worker_count_max());

/* allow thread(s) to exit */
odp_barrier_wait(&global_mem->bar_exit);
Expand All @@ -194,16 +214,18 @@ static void thread_test_odp_thrmask_control(void)

CU_ASSERT(odp_thread_type() == ODP_THREAD_CONTROL);

/* should start out with 1 worker thread */
/* Should start out with 1 control thread */
ret = odp_thrmask_control(&mask);
CU_ASSERT(ret == odp_thrmask_count(&mask));
CU_ASSERT(ret == odp_thread_control_count());
CU_ASSERT(ret == 1);
}

odp_testinfo_t thread_suite[] = {
ODP_TEST_INFO(thread_test_odp_cpu_id),
ODP_TEST_INFO(thread_test_odp_thread_id),
ODP_TEST_INFO(thread_test_odp_thread_count),
ODP_TEST_INFO(thread_test_odp_thread_count_max),
ODP_TEST_INFO(thread_test_odp_thrmask_to_from_str),
ODP_TEST_INFO(thread_test_odp_thrmask_equal),
ODP_TEST_INFO(thread_test_odp_thrmask_zero),
Expand Down

0 comments on commit 05b146f

Please sign in to comment.