diff mbox

[API-NEXT,PATCHv3,9/9] validation: thrmask: test worker and control APIs

Message ID 1437485540-4862-10-git-send-email-stuart.haslam@linaro.org
State Superseded
Headers show

Commit Message

Stuart Haslam July 21, 2015, 1:32 p.m. UTC
Add tests for odp_thrmask_worker() and odp_thrmask_control()

Signed-off-by: Stuart Haslam <stuart.haslam@linaro.org>
---
 test/validation/thread/thread.c | 70 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)

Comments

Christophe Milard July 22, 2015, 11:13 a.m. UTC | #1
On 2015-07-21 14:32, Stuart Haslam wrote:
> Add tests for odp_thrmask_worker() and odp_thrmask_control()
> 
> Signed-off-by: Stuart Haslam <stuart.haslam@linaro.org>

Reviewed-by: Christophe Milard <christophe.milard@linaro.org>

> ---
>  test/validation/thread/thread.c | 70 +++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 70 insertions(+)
> 
> diff --git a/test/validation/thread/thread.c b/test/validation/thread/thread.c
> index d8ea8b0..6fbdaef 100644
> --- a/test/validation/thread/thread.c
> +++ b/test/validation/thread/thread.c
> @@ -7,11 +7,16 @@
>  #include <odp.h>
>  #include <odp_cunit_common.h>
>  #include <mask_common.h>
> +#include <test_debug.h>
>  #include "thread.h"
>  
>  /* Helper macro for CU_TestInfo initialization */
>  #define _CU_TEST_INFO(test_func) {#test_func, test_func}
>  
> +/* Test thread entry and exit synchronization barriers */
> +odp_barrier_t bar_entry;
> +odp_barrier_t bar_exit;
> +
>  static void thread_test_odp_cpu_id(void)
>  {
>  	(void)odp_cpu_id();
> @@ -30,6 +35,69 @@ static void thread_test_odp_thread_count(void)
>  	CU_PASS();
>  }
>  
> +static void *thread_func(void *arg TEST_UNUSED)
> +{
> +	/* indicate that thread has started */
> +	odp_barrier_wait(&bar_entry);
> +
> +	CU_ASSERT(odp_thread_type() == ODP_THREAD_WORKER);
> +
> +	/* wait for indication that we can exit */
> +	odp_barrier_wait(&bar_exit);
> +
> +	return NULL;
> +}
> +
> +static void thread_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 thread_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 thread_suite[] = {
>  	_CU_TEST_INFO(thread_test_odp_cpu_id),
>  	_CU_TEST_INFO(thread_test_odp_thread_id),
> @@ -48,6 +116,8 @@ static CU_TestInfo thread_suite[] = {
>  	_CU_TEST_INFO(thread_test_odp_thrmask_first),
>  	_CU_TEST_INFO(thread_test_odp_thrmask_last),
>  	_CU_TEST_INFO(thread_test_odp_thrmask_next),
> +	_CU_TEST_INFO(thread_test_odp_thrmask_worker),
> +	_CU_TEST_INFO(thread_test_odp_thrmask_control),
>  	CU_TEST_INFO_NULL,
>  };
>  
> -- 
> 2.1.1
> 
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> https://lists.linaro.org/mailman/listinfo/lng-odp
diff mbox

Patch

diff --git a/test/validation/thread/thread.c b/test/validation/thread/thread.c
index d8ea8b0..6fbdaef 100644
--- a/test/validation/thread/thread.c
+++ b/test/validation/thread/thread.c
@@ -7,11 +7,16 @@ 
 #include <odp.h>
 #include <odp_cunit_common.h>
 #include <mask_common.h>
+#include <test_debug.h>
 #include "thread.h"
 
 /* Helper macro for CU_TestInfo initialization */
 #define _CU_TEST_INFO(test_func) {#test_func, test_func}
 
+/* Test thread entry and exit synchronization barriers */
+odp_barrier_t bar_entry;
+odp_barrier_t bar_exit;
+
 static void thread_test_odp_cpu_id(void)
 {
 	(void)odp_cpu_id();
@@ -30,6 +35,69 @@  static void thread_test_odp_thread_count(void)
 	CU_PASS();
 }
 
+static void *thread_func(void *arg TEST_UNUSED)
+{
+	/* indicate that thread has started */
+	odp_barrier_wait(&bar_entry);
+
+	CU_ASSERT(odp_thread_type() == ODP_THREAD_WORKER);
+
+	/* wait for indication that we can exit */
+	odp_barrier_wait(&bar_exit);
+
+	return NULL;
+}
+
+static void thread_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 thread_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 thread_suite[] = {
 	_CU_TEST_INFO(thread_test_odp_cpu_id),
 	_CU_TEST_INFO(thread_test_odp_thread_id),
@@ -48,6 +116,8 @@  static CU_TestInfo thread_suite[] = {
 	_CU_TEST_INFO(thread_test_odp_thrmask_first),
 	_CU_TEST_INFO(thread_test_odp_thrmask_last),
 	_CU_TEST_INFO(thread_test_odp_thrmask_next),
+	_CU_TEST_INFO(thread_test_odp_thrmask_worker),
+	_CU_TEST_INFO(thread_test_odp_thrmask_control),
 	CU_TEST_INFO_NULL,
 };