From patchwork Thu May 2 05:57:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Mattias_R=C3=B6nnblom?= X-Patchwork-Id: 139796 X-Patchwork-Delegate: thomas@monjalon.net 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 EC49743F65; Thu, 2 May 2024 08:07:46 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8BF61402D9; Thu, 2 May 2024 08:07:34 +0200 (CEST) Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2064.outbound.protection.outlook.com [40.107.104.64]) by mails.dpdk.org (Postfix) with ESMTP id A69F04026F for ; Thu, 2 May 2024 08:07:31 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Zu2u4qXEZheB+tS0yN+wGYwnYBGP4W2w6YPAxqRTl47clLUkAxzOWAnBPxOmmfbS8mje0QvoOadL7Ar5JsSHQWDGvWpAfcIe2Z/1f+nLaiB0k3WCcULwpEZjz8FR8IPjWE4ZgwqoCdfDN1/cP9aMcklkG1uL7SF7Rv0/o2P2EPEgXXUUwELhgyKwR9AdzirPSAqNnSxFN9b7ycHn6lE0uDvBFLEWlViLVyod+0wnbZH4yDvYkjXmulbohB0vr7VgZ/NWU+IVxe1epPPaKynpF8uuIfuzQR1sO8CDnasEQnFxffLERClg1CFi5DRLKKDm7votyBzjZ0Jb0aCdrxAKIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=d8z68B8fzU8h0PRajH8DnhYus8GmVFVNaHI8wvhWqbw=; b=YvAZ+hEgbuF1d3NHXDL6NGynUV1I599AP7xBu93M3WqaAT9NvRYvsCp6f+dRB/xFDURFctHtA8oGeblMeWp5chjZJVBjUayEpUtiC2V4i6QqzzqRN119/kMN3Y8ytRVc3kUmW/DwUZPy+mQSmLsax69wWHq6Uk1TIlKGBKBmnrCUHeTZ0rNLrFV/Mvq14r4S8iuqVuh64cgBlQJ9/GX0hWJa0ujt5SZ1+se/2xfjiOQ0ZrIY/q3QK5BSR5vZgHzRsZflowqW9sO8EUij/E8xK5/ckGb+1xXCCFmMcJTcq41rEtMRdPqFB30SvBUYyXK9xqkoqJk5rNUNhyKJH0TI7A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 192.176.1.74) smtp.rcpttodomain=dpdk.org smtp.mailfrom=ericsson.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ericsson.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=d8z68B8fzU8h0PRajH8DnhYus8GmVFVNaHI8wvhWqbw=; b=RHyaA7Otl18h2ScW4s7iwOxlH7Q/oN1hgqzkeD5hbE3VY9UFTT6fMWyD3hqnaeO5A2XTnmbLseNePJJx7tAC/UGR+Ti8VJiw5pxQN5ShgQWwCSrFmQuM7V2d1Q4VWhGOfRu/pwzIMRyvf3FjdLgTpa3/GGwwHbr669ftoEUk3FIc+yCAT+FYw3QXuMNOH9wmKwhDL1i56Sos/LEKm9ya4UDP528JhEUB6AykTyxRQDnmPXfEZzgg1X8wx9yAq6i7BlCEIU82UGILJ1lQLzw4SN/KacIHtpT5LL7J1Gtd3Vv3dgc9hwyA+AEdJiCZmnXwWIvnkBcwSFLyuIPdXCO8Lw== Received: from DUZPR01CA0202.eurprd01.prod.exchangelabs.com (2603:10a6:10:4b6::13) by PR3PR07MB6954.eurprd07.prod.outlook.com (2603:10a6:102:76::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.28; Thu, 2 May 2024 06:07:30 +0000 Received: from DB1PEPF00039230.eurprd03.prod.outlook.com (2603:10a6:10:4b6:cafe::b6) by DUZPR01CA0202.outlook.office365.com (2603:10a6:10:4b6::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.27 via Frontend Transport; Thu, 2 May 2024 06:07:30 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 192.176.1.74) smtp.mailfrom=ericsson.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ericsson.com; Received-SPF: Pass (protection.outlook.com: domain of ericsson.com designates 192.176.1.74 as permitted sender) receiver=protection.outlook.com; client-ip=192.176.1.74; helo=oa.msg.ericsson.com; pr=C Received: from oa.msg.ericsson.com (192.176.1.74) by DB1PEPF00039230.mail.protection.outlook.com (10.167.8.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.18 via Frontend Transport; Thu, 2 May 2024 06:07:30 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.61) with Microsoft SMTP Server id 15.2.1544.9; Thu, 2 May 2024 08:07:29 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id 5DFD3380061; Thu, 2 May 2024 08:07:29 +0200 (CEST) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: , Heng Wang , "Stephen Hemminger" , Tyler Retzlaff , =?utf-8?q?Morten_Br=C3=B8rup?= , =?utf-8?q?Mattia?= =?utf-8?q?s_R=C3=B6nnblom?= Subject: [RFC v6 2/6] eal: add unit tests for bit operations Date: Thu, 2 May 2024 07:57:02 +0200 Message-ID: <20240502055706.112443-3-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240502055706.112443-1-mattias.ronnblom@ericsson.com> References: <20240430120810.108928-2-mattias.ronnblom@ericsson.com> <20240502055706.112443-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB1PEPF00039230:EE_|PR3PR07MB6954:EE_ X-MS-Office365-Filtering-Correlation-Id: 8509c36f-ce17-4ea2-b481-08dc6a6e2663 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|36860700004|376005|1800799015; X-Microsoft-Antispam-Message-Info: =?utf-8?q?dD2wO5ZckcxWAMWiSgyPynNr+zTYQOs?= =?utf-8?q?ypA8uBZ2K0oVSCHaT4kqYaeMdMyBVJYn29KrTJluOYEm+RiLcitcAP+oxD5qju2dB?= =?utf-8?q?Ggjpx+Oanz3Thdcepda1TM7jhP3s1NuGNiRNppIDIYe9C+sark+cz9/A9Tgc8ZMBi?= =?utf-8?q?94dLaBDrCF2acpFldZo+p+KxKqxgn3KGKf/EwfEKU6uqysPjv8RoEbOWwecl/8TP7?= =?utf-8?q?Uo289yf2SMN2b2vRclTdJJ+p0wWUkL766Fo2YI0ZsKoklW8FCSTsWxopvzonZIYOU?= =?utf-8?q?yHhrlLf50u1LMbyvhM29HmlkZ38paHc7f9hy/O5p48WjGHypDiJGriaqE0EmhUovR?= =?utf-8?q?4FbZGpIt+hVbvmvVQeY87PR1ygQuN72/Uep2Qo1wkDaLsapl2AbU4DR8C3BYrG1dY?= =?utf-8?q?gj2tdMEwGc94lTf6jBarj6s8vT2kBajK05PtUAN3420E+1hlhJ2uhqTBrdvdLt9zL?= =?utf-8?q?3lB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P:192.176.1.74; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:oa.msg.ericsson.com; PTR:office365.se.ericsson.net; CAT:NONE; SFS:(13230031)(36860700004)(376005)(1800799015); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2024 06:07:30.2001 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8509c36f-ce17-4ea2-b481-08dc6a6e2663 X-MS-Exchange-CrossTenant-Id: 92e84ceb-fbfd-47ab-be52-080c6b87953f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=92e84ceb-fbfd-47ab-be52-080c6b87953f; Ip=[192.176.1.74]; Helo=[oa.msg.ericsson.com] X-MS-Exchange-CrossTenant-AuthSource: DB1PEPF00039230.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR07MB6954 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 Extend bitops tests to cover the rte_bit_[test|set|clear|assign|flip]() functions. The tests are converted to use the test suite runner framework. RFC v6: * Test rte_bit_*test() usage through const pointers. RFC v4: * Remove redundant line continuations. Signed-off-by: Mattias Rönnblom Acked-by: Morten Brørup Acked-by: Tyler Retzlaff --- app/test/test_bitops.c | 85 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 70 insertions(+), 15 deletions(-) diff --git a/app/test/test_bitops.c b/app/test/test_bitops.c index 0d4ccfb468..322f58c066 100644 --- a/app/test/test_bitops.c +++ b/app/test/test_bitops.c @@ -1,13 +1,68 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2019 Arm Limited + * Copyright(c) 2024 Ericsson AB */ +#include + #include #include +#include #include "test.h" -uint32_t val32; -uint64_t val64; +#define GEN_TEST_BIT_ACCESS(test_name, set_fun, clear_fun, assign_fun, \ + flip_fun, test_fun, size) \ + static int \ + test_name(void) \ + { \ + uint ## size ## _t reference = (uint ## size ## _t)rte_rand(); \ + unsigned int bit_nr; \ + uint ## size ## _t word = (uint ## size ## _t)rte_rand(); \ + \ + for (bit_nr = 0; bit_nr < size; bit_nr++) { \ + bool reference_bit = (reference >> bit_nr) & 1; \ + bool assign = rte_rand() & 1; \ + if (assign) \ + assign_fun(&word, bit_nr, reference_bit); \ + else { \ + if (reference_bit) \ + set_fun(&word, bit_nr); \ + else \ + clear_fun(&word, bit_nr); \ + \ + } \ + TEST_ASSERT(test_fun(&word, bit_nr) == reference_bit, \ + "Bit %d had unexpected value", bit_nr); \ + flip_fun(&word, bit_nr); \ + TEST_ASSERT(test_fun(&word, bit_nr) != reference_bit, \ + "Bit %d had unflipped value", bit_nr); \ + flip_fun(&word, bit_nr); \ + \ + const uint ## size ## _t *const_ptr = &word; \ + TEST_ASSERT(test_fun(const_ptr, bit_nr) == \ + reference_bit, \ + "Bit %d had unexpected value", bit_nr); \ + } \ + \ + for (bit_nr = 0; bit_nr < size; bit_nr++) { \ + bool reference_bit = (reference >> bit_nr) & 1; \ + TEST_ASSERT(test_fun(&word, bit_nr) == reference_bit, \ + "Bit %d had unexpected value", bit_nr); \ + } \ + \ + TEST_ASSERT(reference == word, "Word had unexpected value"); \ + \ + return TEST_SUCCESS; \ + } + +GEN_TEST_BIT_ACCESS(test_bit_access32, rte_bit_set, rte_bit_clear, + rte_bit_assign, rte_bit_flip, rte_bit_test, 32) + +GEN_TEST_BIT_ACCESS(test_bit_access64, rte_bit_set, rte_bit_clear, + rte_bit_assign, rte_bit_flip, rte_bit_test, 64) + +static uint32_t val32; +static uint64_t val64; #define MAX_BITS_32 32 #define MAX_BITS_64 64 @@ -117,22 +172,22 @@ test_bit_relaxed_test_set_clear(void) return TEST_SUCCESS; } +static struct unit_test_suite test_suite = { + .suite_name = "Bitops test suite", + .unit_test_cases = { + TEST_CASE(test_bit_access32), + TEST_CASE(test_bit_access64), + TEST_CASE(test_bit_relaxed_set), + TEST_CASE(test_bit_relaxed_clear), + TEST_CASE(test_bit_relaxed_test_set_clear), + TEST_CASES_END() + } +}; + static int test_bitops(void) { - val32 = 0; - val64 = 0; - - if (test_bit_relaxed_set() < 0) - return TEST_FAILED; - - if (test_bit_relaxed_clear() < 0) - return TEST_FAILED; - - if (test_bit_relaxed_test_set_clear() < 0) - return TEST_FAILED; - - return TEST_SUCCESS; + return unit_test_suite_runner(&test_suite); } REGISTER_FAST_TEST(bitops_autotest, true, true, test_bitops);