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 869DD459C6; Wed, 18 Sep 2024 11:14:27 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EADE542F1F; Wed, 18 Sep 2024 11:14:12 +0200 (CEST) Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2087.outbound.protection.outlook.com [40.107.105.87]) by mails.dpdk.org (Postfix) with ESMTP id 5F1C142DE4 for ; Wed, 18 Sep 2024 11:14:08 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WlDM6/BOIFTVviu/qoPjVem47pEbwyHkYwi2TCzqEtEVrT+59l02pTMgAFIu9PZa1P5ui4isZNu3zuFOCsnQGkh9veGPM3iiTGK536aq0mrguY2CPR9Y5YzYvvHZRdL+mb0UbFo+bfa7UmsiOlBQSf0vecRNkKXiF/4tYmsbjD8MoqCHyIXnN8LNTSa0SLd3lNOVdq+b8e8ZNvEaWArTmlOhUMtKeZRfIJW2E9DjeHMzysPUWu3SmbuFnwfjrfvLrIK5CdzkOo3he540f4fiHphT+QC0aUJrXVAeNxovPXKIiFp8iOfylKW93lK+GKj1ErYLHVAFarhAbrjD74e1wQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=eDPlkPzDFJtO4sz7hZmX4OJ9OYhBCG/rC8QsdOd5aoo=; b=M5oZDTVTroYYR8V7/5Wqm14VmrCmeX+OawILCNJnE9S92Jr1UGuDI0vo0dDpL3LJqDgKCkxHKBz6ROFHxoTvCJP3tVQadvDWft41DVWhFafh+RNiIUry3ZQxAD/npXpHntgAx/Ed/6HaS2lYMJ2BmFdiZ0TJhZa7axhwz/MU7+lxpVC2yaP8S9fuhDAF75PNOcV7eBHb9KXD7jlKVKkEddQ+6XrlOmLlx36Y0VIYmInHbrK0TK5SdhkvOOdvSx0FqdE2HbZJ9EnA2/MLOiBc7uU8zdpSogSehDWJs2FuEID7KEgObpzyF/4McRM+rKIPJhxvtFmJ3eGuCX4q7ChD5w== 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=eDPlkPzDFJtO4sz7hZmX4OJ9OYhBCG/rC8QsdOd5aoo=; b=LkJOqiplnLzyJGd2QzlGcveyPMkl68zckGT5+cbsWKgTRzwT+eKM5HvVkOSOS0xTHvzSMg719tHCzxO8wE80q+viSYWeiqfci/F8WNtvgRHfxL8jJiQP+s81fBe9dot4bxWKuX4E9yidNHTlZe80mudLW/nZ8z965yrTVTr3o4GBn0KD20g/JDfvzkjn1aGXBMTdv7h/P1t47j2UjfMCxkvUBqhOchB3r/clRWN4iRd0h9U3b+oQoxzJ1135WzA3ee1uZdfJ5ftAeZPLtr3e3m1TsKmhs4e4Az8KMzt9L3sdrUAvF97tlLXnZxEAaUf0xwR78GkBxueQ05k7ISvglQ== Received: from DU7P195CA0001.EURP195.PROD.OUTLOOK.COM (2603:10a6:10:54d::15) by DBAPR07MB6566.eurprd07.prod.outlook.com (2603:10a6:10:180::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.24; Wed, 18 Sep 2024 09:14:03 +0000 Received: from DU2PEPF00028D0B.eurprd03.prod.outlook.com (2603:10a6:10:54d:cafe::4a) by DU7P195CA0001.outlook.office365.com (2603:10a6:10:54d::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.25 via Frontend Transport; Wed, 18 Sep 2024 09:14:03 +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 DU2PEPF00028D0B.mail.protection.outlook.com (10.167.242.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Wed, 18 Sep 2024 09:14:03 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.66) with Microsoft SMTP Server id 15.2.1544.11; Wed, 18 Sep 2024 11:14:03 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id 27DEA38007A; Wed, 18 Sep 2024 11:14:03 +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?= , Jack Bond-Preston , David Marchand , Chengwen Feng , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= Subject: [PATCH v9 3/6] eal: add unit tests for bit operations Date: Wed, 18 Sep 2024 11:04:42 +0200 Message-ID: <20240918090445.725283-4-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240918090445.725283-1-mattias.ronnblom@ericsson.com> References: <20240917104811.723863-2-mattias.ronnblom@ericsson.com> <20240918090445.725283-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: DU2PEPF00028D0B:EE_|DBAPR07MB6566:EE_ X-MS-Office365-Filtering-Correlation-Id: ae6ef2c2-aaca-4694-d309-08dcd7c23dae X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|1800799024|376014|36860700013; X-Microsoft-Antispam-Message-Info: =?utf-8?B?WHh5OW5VZFhYMytQQ0VMWXFJRVVXcDNBWG5teTVOWm1TcURFZkJGMjBrajQ1?= =?utf-8?B?QTZscUI4NVN5ZnFvSi9RSytnTExLVE9oTGJhMXYyTzRFZHQvOUhkM3d5bytE?= =?utf-8?B?WnhkMjJWZG9jZ0VGa3dZN0x3SHdEZ1pFRmFwSk9yQ1A0dFVSc1F5akNUZnBj?= =?utf-8?B?QUswN1JRLzdtS3BycHZtdENrK1pIbHBYRStGNGZWVzhrWXVjbDg4S0lyK1N6?= =?utf-8?B?djQzMEUzYmF2ZXk4RWdDanZpLzcrL28raFZCNTVMUW9aUVBYTjRnTnA5VVE1?= =?utf-8?B?Z3I4bjR5TGo1TlVaUG5wdDJvcnVldU5aWE1udEVGREd0N1FvM0RDTXNRR3RK?= =?utf-8?B?c2RGekpaSnVyVGh2LzdDZ3JXMXIvc2owNk9vcEF4aGN4NklMRkxRRk8yNGcy?= =?utf-8?B?RXNwSnRoRUVMUy9nRWNONHgyUkVYc2h5YUtjdnA2bTZ2NDdadDd3K1IxdUF2?= =?utf-8?B?TWdyUEFSOXp6MEtUeEF3TGhuUS92UlcvRllBdWFIRUZuTjlVOFBEZGQ4OEIr?= =?utf-8?B?K3BRQ0pDK0RIbTR2Q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-8?B?S0ovZzFQeS9GbENvOVpyb2Jvb05NWk9uUnhqYXB5WVFkMHk3azlPS3FpNjJx?= =?utf-8?B?Zmh3RE4xRGpiWlJnZlNFTG5RMUkrTlRMeWRZVUpOK080NW96RTJHekNsYUov?= =?utf-8?B?Vms3RkNwRmdxWk92TUZVdE5jTWlGVzM5L0EweHczRXlvdXY2bFF4NklzNThl?= =?utf-8?B?TzB4L3VDUyttRGRWNWptVXloeDJWeW0rdmpNUldTc0w2bTNPVk5zMFpSSmhZ?= =?utf-8?B?dU9lb2dwRlQ3V3JucHdMQnZrWDJJSUpjNXp4LzFZaEVXREpDZXFBaW03MFhM?= =?utf-8?B?SnBpcFFyR0t0c0pLRWVZQS90b2YvUm96U2JnUkJZU2FyVFdIc0orSU5kblMy?= =?utf-8?Q?bLCq5pkvLi6JdI/cUgmWcUGzQtP4JFxPucIQY=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:(13230040)(82310400026)(1800799024)(376014)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2024 09:14:03.7325 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ae6ef2c2-aaca-4694-d309-08dcd7c23dae 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: DU2PEPF00028D0B.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR07MB6566 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. Signed-off-by: Mattias Rönnblom Acked-by: Morten Brørup Acked-by: Tyler Retzlaff Acked-by: Jack Bond-Preston -- RFC v6: * Test rte_bit_*test() usage through const pointers. RFC v4: * Remove redundant line continuations. --- 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