Add tests for odp_thrmask_worker() and odp_thrmask_control() Signed-off-by: Stuart Haslam <stuart.has...@linaro.org> --- test/validation/thrmask/thrmask.c | 72 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 5 deletions(-)
diff --git a/test/validation/thrmask/thrmask.c b/test/validation/thrmask/thrmask.c index 15d39c3..d07744e 100644 --- a/test/validation/thrmask/thrmask.c +++ b/test/validation/thrmask/thrmask.c @@ -7,9 +7,74 @@ #include <odp.h> #include "odp_cunit_common.h" +#include "test_debug.h" #include "thrmask.h" #include "mask_common.h" +odp_barrier_t bar_entry; +odp_barrier_t bar_exit; + +static void *thread_func(void *arg TEST_UNUSED) +{ + /* indicate that thread has started */ + odp_barrier_wait(&bar_entry); + + /* wait for indication that we can exit */ + odp_barrier_wait(&bar_exit); + + return NULL; +} + +static void thrmask_test_odp_thrmask_worker(void) +{ + odp_thrmask_t mask; + int ret; + pthrd_arg args = { .testcase = 0, .numthrds = 1 }; + + CU_ASSERT_FATAL(odp_thread_type() == ODP_THREAD_CONTROL); + + odp_barrier_init(&bar_entry, args.numthrds + 1); + odp_barrier_init(&bar_exit, args.numthrds + 1); + + /* should start out with 0 worker threads */ + ret = odp_thrmask_worker(&mask); + CU_ASSERT(ret == odp_thrmask_count(&mask)); + CU_ASSERT(ret == 0); + + /* start the test thread(s) */ + ret = odp_cunit_thread_create(thread_func, &args); + CU_ASSERT(ret == args.numthrds); + + if (ret != args.numthrds) + return; + + /* wait for thread(s) to start */ + odp_barrier_wait(&bar_entry); + + ret = odp_thrmask_worker(&mask); + CU_ASSERT(ret == odp_thrmask_count(&mask)); + CU_ASSERT(ret == args.numthrds); + CU_ASSERT(ret <= ODP_CONFIG_MAX_THREADS); + + /* allow thread(s) to exit */ + odp_barrier_wait(&bar_exit); + + odp_cunit_thread_exit(&args); +} + +static void thrmask_test_odp_thrmask_control(void) +{ + odp_thrmask_t mask; + int ret; + + CU_ASSERT(odp_thread_type() == ODP_THREAD_CONTROL); + + /* should start out with 1 worker thread */ + ret = odp_thrmask_control(&mask); + CU_ASSERT(ret == odp_thrmask_count(&mask)); + CU_ASSERT(ret == 1); +} + static CU_TestInfo thrmask_suite[] = { {"odp_thrmask_to/from_str()", thrmask_test_odp_thrmask_to_from_str}, {"odp_thrmask_equal()", thrmask_test_odp_thrmask_equal}, @@ -25,6 +90,8 @@ static CU_TestInfo thrmask_suite[] = { {"odp_thrmask_first()", thrmask_test_odp_thrmask_first}, {"odp_thrmask_last()", thrmask_test_odp_thrmask_last}, {"odp_thrmask_next()", thrmask_test_odp_thrmask_next}, + {"odp_thrmask_worker()", thrmask_test_odp_thrmask_worker}, + {"odp_thrmask_control()", thrmask_test_odp_thrmask_control}, CU_TEST_INFO_NULL, }; @@ -33,11 +100,6 @@ static CU_SuiteInfo thrmask_suites[] = { CU_SUITE_INFO_NULL, }; -unsigned max_supported_num_in_mask(void) -{ - return ODP_CONFIG_MAX_THREADS; -} - int thrmask_main(void) { return odp_cunit_run(thrmask_suites); -- 2.1.1 _______________________________________________ lng-odp mailing list lng-odp@lists.linaro.org https://lists.linaro.org/mailman/listinfo/lng-odp