From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 78A6DA0547;
	Mon,  5 Dec 2022 21:24:34 +0100 (CET)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 5018D40156;
	Mon,  5 Dec 2022 21:24:33 +0100 (CET)
Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182])
 by mails.dpdk.org (Postfix) with ESMTP id 0426540151
 for <dev@dpdk.org>; Mon,  5 Dec 2022 21:24:31 +0100 (CET)
Received: by linux.microsoft.com (Postfix, from userid 1086)
 id 3A05920B83E2; Mon,  5 Dec 2022 12:24:31 -0800 (PST)
DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3A05920B83E2
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com;
 s=default; t=1670271871;
 bh=TA/2FNK6oujDCeZbw8r5u7qhGOgx1ZITm6iGSapRqp4=;
 h=From:To:Cc:Subject:Date:In-Reply-To:References:From;
 b=MP9J8MzcSihkpMsR5HV/GDu5m/ausa29mmtb0zg/mX+eKMFs0iRrmGtlargHm9MnU
 U8jGsFULDu5Rqm76lB8m9wIN//XduJssGyub24gGPVJRnZRNZDy4x+Ab60mhBS+HvJ
 asiz7E6jagOlatAoPpKpA5niFnOCusrDHcHGSuck=
From: Tyler Retzlaff <roretzla@linux.microsoft.com>
To: dev@dpdk.org, thomas@monjalon.net, david.marchand@redhat.com,
 stephen@networkplumber.org, olivier.matz@6wind.com
Cc: Tyler Retzlaff <roretzla@linux.microsoft.com>
Subject: [PATCH 2/3] test: add rte control thread create API test
Date: Mon,  5 Dec 2022 12:24:27 -0800
Message-Id: <1670271868-11364-3-git-send-email-roretzla@linux.microsoft.com>
X-Mailer: git-send-email 1.8.3.1
In-Reply-To: <1670271868-11364-1-git-send-email-roretzla@linux.microsoft.com>
References: <1670271868-11364-1-git-send-email-roretzla@linux.microsoft.com>
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

Duplicate the rte_ctrl_thread_create test adapted to use
rte_control_thread create to keep both apis under test until
rte_ctrl_thread_create is removed.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 app/test/test_lcores.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/app/test/test_lcores.c b/app/test/test_lcores.c
index a6bb412..517dc3c 100644
--- a/app/test/test_lcores.c
+++ b/app/test/test_lcores.c
@@ -8,6 +8,7 @@
 #include <rte_common.h>
 #include <rte_errno.h>
 #include <rte_lcore.h>
+#include <rte_thread.h>
 
 #include "test.h"
 
@@ -352,6 +353,18 @@ static void *ctrl_thread_loop(void *arg)
 	return NULL;
 }
 
+static uint32_t control_thread_loop(void *arg)
+{
+	struct thread_context *t = arg;
+
+	printf("Control thread running successfully\n");
+
+	/* Set the thread state to DONE */
+	t->state = Thread_DONE;
+
+	return 0;
+}
+
 static int
 test_ctrl_thread(void)
 {
@@ -379,6 +392,34 @@ static void *ctrl_thread_loop(void *arg)
 }
 
 static int
+test_control_thread(void)
+{
+	rte_thread_t jid;
+	struct thread_context ctrl_thread_context;
+	struct thread_context *t;
+
+	/* Create one control thread */
+	t = &ctrl_thread_context;
+	t->state = Thread_INIT;
+	if (rte_control_thread_create((rte_thread_t *)&t->id, "test_control_threads",
+					NULL, control_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.
+	 */
+	jid.opaque_id = t->id;
+	rte_thread_join(jid, NULL);
+
+	/* Check if the control thread set the correct state */
+	if (t->state != Thread_DONE)
+		return -1;
+
+	return 0;
+}
+
+static int
 test_lcores(void)
 {
 	unsigned int eal_threads_count = 0;
@@ -411,6 +452,9 @@ static void *ctrl_thread_loop(void *arg)
 	if (test_ctrl_thread() < 0)
 		return TEST_FAILED;
 
+	if (test_control_thread() < 0)
+		return TEST_FAILED;
+
 	return TEST_SUCCESS;
 }
 
-- 
1.8.3.1