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 711AAA034F; Wed, 10 Nov 2021 04:02:27 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CCAF041141; Wed, 10 Nov 2021 04:01:54 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id BB2B6410E0 for ; Wed, 10 Nov 2021 04:01:47 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1059) id 8469220C355F; Tue, 9 Nov 2021 19:01:46 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 8469220C355F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1636513306; bh=WN3DCfVJu0blknD3hDZXIgi5EA0LnrtxwwTYl2Xdpa4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IllwzPSylrZc8A90mbLaraUFScnSC5RGqJ4r3NdqG+4WWiB8tUEFq7u4/D+9BAiaM AdiefOy3KFhn5KIuYyJAxO+Uu0uTZVZSvmmUqAQon9Qlp5pFti69TO8x6hy11Yehx6 D9Akaevb6x8RxRwuXSGidwFFAnKIPo4dxxaFd1o8= From: Narcisa Ana Maria Vasile To: dev@dpdk.org, thomas@monjalon.net, dmitry.kozliuk@gmail.com, khot@microsoft.com, navasile@microsoft.com, dmitrym@microsoft.com, roretzla@microsoft.com, talshn@nvidia.com, ocardona@microsoft.com Cc: bruce.richardson@intel.com, david.marchand@redhat.com, pallavi.kadam@intel.com Date: Tue, 9 Nov 2021 19:01:40 -0800 Message-Id: <1636513302-7359-12-git-send-email-navasile@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1636513302-7359-1-git-send-email-navasile@linux.microsoft.com> References: <1633765318-28356-1-git-send-email-navasile@linux.microsoft.com> <1636513302-7359-1-git-send-email-navasile@linux.microsoft.com> Subject: [dpdk-dev] [PATCH v17 11/13] app/test: add unit tests for barrier 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 Sender: "dev" From: Narcisa Vasile As a new API for threading is introduced, a set of unit tests have been added to test the new interface. Verify that the barrier correctly synchronizes all threads. Verify that the threads are unblocked after the required number of threads have called barrier_wait(). Signed-off-by: Narcisa Vasile --- app/test/test_threads.c | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/app/test/test_threads.c b/app/test/test_threads.c index 9fcae34179..00f604ab7e 100644 --- a/app/test/test_threads.c +++ b/app/test/test_threads.c @@ -195,6 +195,54 @@ test_thread_detach(void) return ret; } +struct thread_context { + rte_thread_barrier *barrier; + int barrier_result; +}; + +static void * +thread_loop_barrier(void *arg) +{ + struct thread_context *ctx = arg; + + ctx->barrier_result = rte_thread_barrier_wait(ctx->barrier); + if (ctx->barrier_result > 0) + rte_log(RTE_LOG_DEBUG, threads_logtype_test, "Failed to wait at barrier!"); + + return NULL; +} + +static int +test_thread_barrier(void) +{ + rte_thread_t thread_id; + struct thread_context ctx; + rte_thread_barrier barrier; + int ret = 0; + int result = 0; + + ret = rte_thread_barrier_init(&barrier, 2); + RTE_TEST_ASSERT(ret == 0, "Failed to initialize barrier!"); + + ctx.barrier = &barrier; + ret = rte_thread_create(&thread_id, NULL, thread_loop_barrier, &ctx); + RTE_TEST_ASSERT(ret == 0, "Failed to create thread!"); + + result = rte_thread_barrier_wait(&barrier); + RTE_TEST_ASSERT(result <= 0, "Failed to wait at the barrier!"); + + ret = rte_thread_join(thread_id, NULL); + RTE_TEST_ASSERT(ret == 0, "Failed to join threads!"); + + ret = rte_thread_barrier_destroy(&barrier); + RTE_TEST_ASSERT(ret == 0, "Failed to destroy barrier!"); + + RTE_TEST_ASSERT(ctx.barrier_result <= 0, "Child thread failed to wait at the barrier!"); + RTE_TEST_ASSERT_NOT_EQUAL(ctx.barrier_result, result, "Threads were not blocked at the barrier!"); + + return 0; +} + static struct unit_test_suite threads_test_suite = { .suite_name = "threads autotest", .setup = NULL, @@ -204,6 +252,7 @@ static struct unit_test_suite threads_test_suite = { TEST_CASE(test_thread_attributes_affinity), TEST_CASE(test_thread_attributes_priority), TEST_CASE(test_thread_detach), + TEST_CASE(test_thread_barrier), TEST_CASES_END() } }; -- 2.31.0.vfs.0.1