From patchwork Wed Nov 10 03:01:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Narcisa Ana Maria Vasile X-Patchwork-Id: 104081 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2DB6AA034F; Wed, 10 Nov 2021 04:02:45 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DE4FF41152; Wed, 10 Nov 2021 04:01:57 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id AA4D94014D for ; Wed, 10 Nov 2021 04:01:47 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1059) id 564AF20C3553; Tue, 9 Nov 2021 19:01:46 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 564AF20C3553 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1636513306; bh=7i4NhbM6kQaXOHqvRtOUlDficy8oCtW6uzrSgIHHThc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OEGJVL4QEjpTN6Yfm3jOQEp8qelyXJxwxG9KbhZlI41AUikXQQZEB987gGPa70HKC sW8MDZNKcRRWzohAhQ6UY0tBgvGDup332p8rQCQ0pF8sWbB3WTo2+t3/mHLCq45iBy X88aKSgogf8RS/1DJxAu06ANEFn/Jnsz9i/o/Bso= 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:36 -0800 Message-Id: <1636513302-7359-8-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 07/13] app/test: add unit tests for rte_thread_self 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. Test the rte_thread_self() functionality used to retrieve the thread id. Signed-off-by: Narcisa Vasile --- app/test/meson.build | 2 ++ app/test/test_threads.c | 63 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 app/test/test_threads.c diff --git a/app/test/meson.build b/app/test/meson.build index 96670c3504..9fd34459e9 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -146,6 +146,7 @@ test_sources = files( 'test_tailq.c', 'test_thash.c', 'test_thash_perf.c', + 'test_threads.c', 'test_timer.c', 'test_timer_perf.c', 'test_timer_racecond.c', @@ -287,6 +288,7 @@ fast_tests = [ ['reorder_autotest', true], ['service_autotest', true], ['thash_autotest', true], + ['threads_autotest', true], ['trace_autotest', true], ] diff --git a/app/test/test_threads.c b/app/test/test_threads.c new file mode 100644 index 0000000000..e7ee50741c --- /dev/null +++ b/app/test/test_threads.c @@ -0,0 +1,63 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2021 Microsoft. + */ + +#include +#include + +#include "test.h" + +#define THREADS_COUNT 20 + +RTE_LOG_REGISTER(threads_logtype_test, test.threads, INFO); + +static void * +thread_loop_self(void *arg) +{ + rte_thread_t *id = arg; + + *id = rte_thread_self(); + + return NULL; +} + +static int +test_thread_self(void) +{ + rte_thread_t threads_ids[THREADS_COUNT]; + rte_thread_t self_ids[THREADS_COUNT] = {}; + int ret; + int i; + + for (i = 0; i < THREADS_COUNT; ++i) { + ret = rte_thread_create(&threads_ids[i], NULL, thread_loop_self, + &self_ids[i]); + RTE_TEST_ASSERT(ret == 0, "Failed to create threads!"); + } + + for (i = 0; i < THREADS_COUNT; ++i) { + RTE_TEST_ASSERT(rte_thread_join(threads_ids[i], NULL) == 0, "Failed to join thread!"); + RTE_TEST_ASSERT_EQUAL(threads_ids[i].opaque_id, + self_ids[i].opaque_id, "Unexpected thread id!"); + } + + return 0; +} + +static struct unit_test_suite threads_test_suite = { + .suite_name = "threads autotest", + .setup = NULL, + .teardown = NULL, + .unit_test_cases = { + TEST_CASE(test_thread_self), + TEST_CASES_END() + } +}; + +static int +test_threads(void) +{ + return unit_test_suite_runner(&threads_test_suite); +} + +REGISTER_TEST_COMMAND(threads_autotest, test_threads);