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 6284CA00C3; Wed, 7 Dec 2022 20:00:33 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 75AFA42D2C; Wed, 7 Dec 2022 20:00:22 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id E0B9E41611 for ; Wed, 7 Dec 2022 20:00:19 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id 41E3F20B83E7; Wed, 7 Dec 2022 11:00:19 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 41E3F20B83E7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1670439619; bh=abDnkdqhU+B0VkAyIXFOG20TAXQsjHYao1QsSnBwsbk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kICSShHSULzPYvfeVCiunmYpt0+G5JwW/ofZv/WFtObooeA51/B8bcW/anrva2+tO I/VpRedvNvjhjQZBlmf7JrLSJUbDJMG1tINnbWrjCzgSmkqHzsIYtHPYJtH3XrE42K 6aVKm7xd8SxIOEhIwXi+p9maWLySaZcacI64vEEE= From: Tyler Retzlaff To: dev@dpdk.org Cc: thomas@monjalon.net, david.marchand@redhat.com, olivier.matz@6wind.com, stephen@networkplumber.org, Tyler Retzlaff Subject: [PATCH 3/5] test: add a unit test for set and get lcore name APIs Date: Wed, 7 Dec 2022 11:00:15 -0800 Message-Id: <1670439617-9054-4-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1670439617-9054-1-git-send-email-roretzla@linux.microsoft.com> References: <1670439617-9054-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 Signed-off-by: Tyler Retzlaff --- app/test/test_lcores.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/app/test/test_lcores.c b/app/test/test_lcores.c index a6bb412..153b6f4 100644 --- a/app/test/test_lcores.c +++ b/app/test/test_lcores.c @@ -379,6 +379,55 @@ static void *ctrl_thread_loop(void *arg) } static int +test_lcores_set_get_name(void) +{ + char out[RTE_LCORE_NAME_MAX_LEN]; + char outcmp[RTE_LCORE_NAME_MAX_LEN]; + const unsigned int lcore_id = rte_get_main_lcore(); + const size_t outlen = sizeof(out); + const char empty[] = ""; + const char valid[] = "0123456789abcde"; + const char invalid[] = "0123456789abcdef"; + + memset(outcmp, 0xff, outlen); + + memset(out, 0xff, outlen); + RTE_TEST_ASSERT(rte_lcore_set_name(lcore_id, empty) == 0, + "Failed to set empty lcore name."); + RTE_TEST_ASSERT(rte_lcore_get_name(lcore_id, out, outlen) == 0, + "Failed to get empty lcore name."); + RTE_TEST_ASSERT(strcmp(empty, out) == 0, + "Failed to set and get empty lcore name."); + + memset(out, 0xff, outlen); + RTE_TEST_ASSERT(rte_lcore_set_name(lcore_id, valid) == 0, + "Failed to set valid lcore name."); + RTE_TEST_ASSERT(rte_lcore_get_name(lcore_id, out, outlen) == 0, + "Failed to get valid lcore name."); + RTE_TEST_ASSERT(strcmp(valid, out) == 0, + "Failed to set and get valid lcore name."); + + memset(out, 0xff, outlen); + RTE_TEST_ASSERT(rte_lcore_set_name(lcore_id, invalid) == -ERANGE, + "Failed to fail set with invalid lcore name."); + RTE_TEST_ASSERT(memcmp(outcmp, out, outlen) == 0, + "Failed to preserve caller buffer after set failure."); + + RTE_TEST_ASSERT(rte_lcore_get_name(lcore_id, out, outlen) == 0, + "Failed to get valid lcore name after set failure."); + RTE_TEST_ASSERT(strcmp(valid, out) == 0, + "Failed to preserve valid lcore name after set failure."); + + memset(out, 0xff, outlen); + RTE_TEST_ASSERT(rte_lcore_get_name(lcore_id, out, outlen - 1) == -EINVAL, + "Failed to fail get with output buffer too small."); + RTE_TEST_ASSERT(memcmp(outcmp, out, outlen) == 0, + "Failed to preserve caller buffer after get failure."); + + return TEST_SUCCESS; +} + +static int test_lcores(void) { unsigned int eal_threads_count = 0; @@ -411,6 +460,9 @@ static void *ctrl_thread_loop(void *arg) if (test_ctrl_thread() < 0) return TEST_FAILED; + if (test_lcores_set_get_name() < 0) + return TEST_FAILED; + return TEST_SUCCESS; } -- 1.8.3.1