From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 98210A0544; Wed, 15 Jun 2022 01:47:22 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 36E3640222; Wed, 15 Jun 2022 01:47:22 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id AC40840222 for ; Wed, 15 Jun 2022 01:47:20 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1086) id E772C20C3225; Tue, 14 Jun 2022 16:47:19 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com E772C20C3225 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1655250439; bh=fFtUc9ko61TzoazD0rcBjkXX1svyex1TTZ6aVa/QRW4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RGdUHTrHQanlqGrGnc6LlS3cbIpji6quH6M4zYTcZmNEXbCmFIBpsQI+6aS/znsMO h4w+GNooLuiqtS0lLCqSWZ/+Tf7QkuyoYr3sOzeo+Ad+zvFOvCmhBZXB4F1txwVSLT 6asTPymZFi0UqqYRUvNETaOrffZm4u4xrGEcn+XA= From: Tyler Retzlaff To: dev@dpdk.org Cc: thomas@monjalon.net, dmitry.kozliuk@gmail.com, anatoly.burakov@intel.com, Tyler Retzlaff , Narcisa Vasile Subject: [PATCH v2 4/6] test/threads: add tests for thread lifetime API Date: Tue, 14 Jun 2022 16:47:16 -0700 Message-Id: <1655250438-18044-5-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1655250438-18044-1-git-send-email-roretzla@linux.microsoft.com> References: <1654783134-13303-1-git-send-email-roretzla@linux.microsoft.com> <1655250438-18044-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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org test basic functionality and demonstrate use of following thread lifetime api. * rte_thread_create * rte_thread_detach * rte_thread_join Signed-off-by: Narcisa Vasile Signed-off-by: Tyler Retzlaff --- app/test/test_threads.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/app/test/test_threads.c b/app/test/test_threads.c index b9d8b4e..9a30af5 100644 --- a/app/test/test_threads.c +++ b/app/test/test_threads.c @@ -27,6 +27,54 @@ } static int +test_thread_create_join(void) +{ + rte_thread_t thread_id; + rte_thread_t thread_main_id; + + thread_id_ready = 0; + RTE_TEST_ASSERT(rte_thread_create(&thread_id, NULL, thread_main, &thread_main_id) == 0, + "Failed to create thread."); + + while (__atomic_load_n(&thread_id_ready, __ATOMIC_ACQUIRE) == 0) + ; + + RTE_TEST_ASSERT(rte_thread_equal(thread_id, thread_main_id) != 0, + "Unexpected thread id."); + + __atomic_store_n(&thread_id_ready, 2, __ATOMIC_RELEASE); + + RTE_TEST_ASSERT(rte_thread_join(thread_id, NULL) == 0, + "Failed to join thread."); + + return 0; +} + +static int +test_thread_create_detach(void) +{ + rte_thread_t thread_id; + rte_thread_t thread_main_id; + + thread_id_ready = 0; + RTE_TEST_ASSERT(rte_thread_create(&thread_id, NULL, thread_main, + &thread_main_id) == 0, "Failed to create thread."); + + while (__atomic_load_n(&thread_id_ready, __ATOMIC_ACQUIRE) == 0) + ; + + RTE_TEST_ASSERT(rte_thread_equal(thread_id, thread_main_id) != 0, + "Unexpected thread id."); + + __atomic_store_n(&thread_id_ready, 2, __ATOMIC_RELEASE); + + RTE_TEST_ASSERT(rte_thread_detach(thread_id) == 0, + "Failed to detach thread."); + + return 0; +} + +static int test_thread_priority(void) { pthread_t id; @@ -123,6 +171,8 @@ .setup = NULL, .teardown = NULL, .unit_test_cases = { + TEST_CASE(test_thread_create_join), + TEST_CASE(test_thread_create_detach), TEST_CASE(test_thread_affinity), TEST_CASE(test_thread_priority), TEST_CASES_END() -- 1.8.3.1