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 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=20R=C3=B6nnblom?= To: CC: , Heng Wang , "Stephen Hemminger" , Tyler Retzlaff , =?UTF-8?q?Morten=20Br=C3=B8rup?= , =?UTF-8?q?Mattias=20R=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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit 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?B?ZEQyd081WmNrY3hXQU1XaVNneVB5bk5yK3pUWVFPc3lwQTh1QloySzBvVlND?= =?utf-8?B?SGFUNGtxWWFlTWRNeUJWSlluMjlLclRKbHVPWUVtK1JpTGNpdGNBUCtveEQ1?= =?utf-8?B?cWp1MmRCR2dqcHgrT2FuejNUaGRjZXBkYTFUTTdqaFAzczFOdUdOaVJOcHBJ?= =?utf-8?B?RElZZTlDK3NhcmsrY3o5L0E5VGdjOFpNQmk5NGRMYUJEckNGMmFjcEZsZFpv?= =?utf-8?B?K3ArS3hLcXhnbjNLR0tmL0V3ZkVLVTZ1cXlzUGp2OFJvRWJPV3dlY2wvOFRQ?= =?utf-8?B?N1VvMjg5eWYyU01OMmIydlJjbFRkSkorcDB3V1VrTDc2NkZvMllJMFpzS29r?= =?utf-8?B?bFc4RkNTVHNXeG9wdnpvblpJWU9VeUhocmxMZjUwdTFMTWJ5dmhNMjlIbWxr?= =?utf-8?B?WjM4cGFIYzdmOWh5L081cDQ4V2pHSHlwRGlKR3JpYXFFMEVtaFVvdlI0RmJa?= =?utf-8?B?R3BJdCtoVmJ2bXZWUWVZODdQUjF5Z1F1TjcyL1VlcDJRbzF3a0RhTHNhcGwy?= =?utf-8?B?QWJVNERSOEMzQllyRzFkWWdqMnRkTUV3R2M5NGxUZjZqQmFyajZzOHZUMmt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ZRHB0WHNMRThFbkt1?= =?utf-8?B?M0Z2b0Fab1I1QjdUTEwxQ1ZFaWZCNzJTa3ZpK21qbXJTSTIxeXZDZUdyYi9F?= =?utf-8?B?allrU3dXaGdpK0xwUERGaGtGUmQyOEEwTTBFS1hkM2VMMlBLRHN6dG0vK3dL?= =?utf-8?B?TkpydFY0MjJXZUxtR2dHZElSeXo4VVVEdDhGeWJFZk5wOEE1TlhJQlJCS0x2?= =?utf-8?B?WXZ6ZUFCSnd2Nkp6bGp4bDZYY0tTSGJYOGk3eE4rQ2N3NHVwREdSbTlTdkE2?= =?utf-8?B?TnpaRHVjQnRNNjh4elk4ZE12SE5CQlJGQ3JwemdsOTBNakh4VmJSV05JSVcr?= =?utf-8?Q?GQ13o/FvzMG4jXN7XHJVoQLpInMRaTWcCB2Cs=3D?= X-Forefront-Antispam-Report: CIP: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); -- 2.34.1