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 78634A00C2; Mon, 23 May 2022 15:07:27 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 44E6342685; Mon, 23 May 2022 15:07:19 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id B1BFE40156 for ; Mon, 23 May 2022 15:07:16 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1086) id AE30720B87F3; Mon, 23 May 2022 06:07:15 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com AE30720B87F3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1653311235; bh=XFawlqs0bP4s6Fgz4FWh6CiErLcUMjquf2KmwtF1DoE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GFzbOEUkqDprvXUHiSVr7MYLt+gZYQx2HtkdMJkMlbLtZQhMNTBdyvrAsvs75CUCp 6fav4upliXVJYzhztVevOz6O1CK3kV9QvSTJHpCeNL71eRzuF7YwGjtKw3emIhsxoH YWJUbT1LUIk2BY1KszYSXyYEbyRNJ9mKRzcInOgU= From: Tyler Retzlaff To: dev@dpdk.org Cc: thomas@monjalon.net, dmitry.kozliuk@gmail.com, anatoly.burakov@intel.com, Tyler Retzlaff Subject: [PATCH v2 2/2] test/threads: add unit test for get set priority Date: Mon, 23 May 2022 06:07:14 -0700 Message-Id: <1653311234-329-3-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1653311234-329-1-git-send-email-roretzla@linux.microsoft.com> References: <1653302773-11043-1-git-send-email-roretzla@linux.microsoft.com> <1653311234-329-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 Add unit tests to exercise and demonstrate rte_thread_{get,set}_priority(). Signed-off-by: Tyler Retzlaff --- app/test/test_threads.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/app/test/test_threads.c b/app/test/test_threads.c index e1a2ea5..dbc20e6 100644 --- a/app/test/test_threads.c +++ b/app/test/test_threads.c @@ -24,6 +24,56 @@ } static int +test_thread_priority(void) +{ + pthread_t id; + rte_thread_t thread_id; + enum rte_thread_priority priority; + + thread_id_ready = 0; + RTE_TEST_ASSERT(pthread_create(&id, NULL, thread_main, &thread_id) == 0, + "Failed to create thread"); + + while (__atomic_load_n(&thread_id_ready, __ATOMIC_ACQUIRE) == 0) + ; + + priority = RTE_THREAD_PRIORITY_NORMAL; + RTE_TEST_ASSERT(rte_thread_set_priority(thread_id, priority) == 0, + "Failed to set thread priority"); + RTE_TEST_ASSERT(rte_thread_get_priority(thread_id, &priority) == 0, + "Failed to get thread priority"); + RTE_TEST_ASSERT(priority == RTE_THREAD_PRIORITY_NORMAL, + "Priority set mismatches priority get"); + + priority = RTE_THREAD_PRIORITY_REALTIME_CRITICAL; +#ifndef RTE_EXEC_ENV_WINDOWS + RTE_TEST_ASSERT(rte_thread_set_priority(thread_id, priority) == -ENOTSUP, + "Priority set to critical should fail"); + RTE_TEST_ASSERT(rte_thread_get_priority(thread_id, &priority) == 0, + "Failed to get thread priority"); + RTE_TEST_ASSERT(priority == RTE_THREAD_PRIORITY_NORMAL, + "Failed set to critical should have retained normal"); +#else + RTE_TEST_ASSERT(rte_thread_set_priority(thread_id, priority) == 0, + "Priority set to critical should succeed"); + RTE_TEST_ASSERT(rte_thread_get_priority(thread_id, &priority) == 0, + "Failed to get thread priority"); + RTE_TEST_ASSERT(priority == RTE_THREAD_PRIORITY_REALTIME_CRITICAL, + "Priority set mismatches priority get"); +#endif + + priority = RTE_THREAD_PRIORITY_NORMAL; + RTE_TEST_ASSERT(rte_thread_set_priority(thread_id, priority) == 0, + "Failed to set thread priority"); + RTE_TEST_ASSERT(rte_thread_get_priority(thread_id, &priority) == 0, + "Failed to get thread priority"); + RTE_TEST_ASSERT(priority == RTE_THREAD_PRIORITY_NORMAL, + "Priority set mismatches priority get"); + + return 0; +} + +static int test_thread_affinity(void) { pthread_t id; @@ -31,6 +81,7 @@ rte_cpuset_t cpuset0; rte_cpuset_t cpuset1; + thread_id_ready = 0; RTE_TEST_ASSERT(pthread_create(&id, NULL, thread_main, &thread_id) == 0, "Failed to create thread"); @@ -68,6 +119,7 @@ .teardown = NULL, .unit_test_cases = { TEST_CASE(test_thread_affinity), + TEST_CASE(test_thread_priority), TEST_CASES_END() } }; -- 1.8.3.1