[dpdk-dev] [PATCH v3 2/2] test/eal: add a test for rte_ctrl_thread_create

Honnappa Nagarahalli honnappa.nagarahalli at arm.com
Mon Aug 30 18:34:13 CEST 2021


Add a testcase to test launching of control threads.

Signed-off-by: Honnappa Nagarahalli <honnappa.nagarahalli at arm.com>
---
 app/test/test_lcores.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/app/test/test_lcores.c b/app/test/test_lcores.c
index 19a7ab9fce..738148f339 100644
--- a/app/test/test_lcores.c
+++ b/app/test/test_lcores.c
@@ -340,6 +340,44 @@ test_non_eal_lcores_callback(unsigned int eal_threads_count)
 	return -1;
 }
 
+static void *ctrl_thread_loop(void *arg)
+{
+	struct thread_context *t = arg;
+
+	printf("Control thread running successfully\n");
+
+	/* Set the thread state to DONE */
+	t->state = DONE;
+
+	return NULL;
+}
+
+static int
+test_crtl_thread(void)
+{
+	struct thread_context ctrl_thread_context;
+	struct thread_context *t;
+
+	/* Create one control thread */
+	t = &ctrl_thread_context;
+	t->state = INIT;
+	if (rte_ctrl_thread_create(&t->id, "test_ctrl_threads",
+					NULL, ctrl_thread_loop, t) != 0)
+		return -1;
+
+	/* Wait till the control thread exits.
+	 * This also acts as the barrier such that the memory operations
+	 * in control thread are visible to this thread.
+	 */
+	pthread_join(t->id, NULL);
+
+	/* Check if the control thread set the correct state */
+	if (t->state != DONE)
+		return -1;
+
+	return 0;
+}
+
 static int
 test_lcores(void)
 {
@@ -367,6 +405,9 @@ test_lcores(void)
 	if (test_non_eal_lcores_callback(eal_threads_count) < 0)
 		return TEST_FAILED;
 
+	if (test_crtl_thread() < 0)
+		return TEST_FAILED;
+
 	return TEST_SUCCESS;
 }
 
-- 
2.25.1



More information about the dev mailing list