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 6FA2545954; Tue, 10 Sep 2024 10:41:55 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 442C1427E0; Tue, 10 Sep 2024 10:41:29 +0200 (CEST) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2059.outbound.protection.outlook.com [40.107.20.59]) by mails.dpdk.org (Postfix) with ESMTP id 93DFD427D4 for ; Tue, 10 Sep 2024 10:41:27 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kLLjy7QgyL4mS8ZSXD8RLSEqyEixebT8OyQnP1a8eCuwrnWBgtViaUMHAWh8Z/JqMKZx/fn/l4wuIPNqcUrk6BgcrZGVNifJPgpwAjNydnlYGELywpiqJugFtKxe6SaFapPnaFJfqqIuRhdw2NP55GRkJYlTymxyTSk/TAi8oNNKmAbi3A5x4zhcBJGUV5mjlw8dSG9z6R9+5ODT/71PnJb0iozcRmjP0nQ8N57VBBCuizwpbzKRZAVyWliAl13Diz4ulBFETKC333LtaLjOeLwU7sHVl7t9FHFg/eMayGP5rr1gEHUyGfty9qJUuVGbK6RueXVKfF4Z+gdCnlL8+g== 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=yIq6HRC0RmXGOb1pBUluNHBl7u2wtclW5PTy8gx7taULfSmrq7TPUsj1VgqPfOneolQjYzNVSK+l1gTi46NYNnMMtxjdFj3GTTACOPHUukoqYPthxAOUFWHpU9sSFhmAcvptMvwEsS/Iw0vwVzPz4EOI5gzRQaMgcxemmRStbe4xyZI03LPeQ9a5gFOmWpOAyvPTXniMl4/JKWqSFlWsv8gyZLMLxYnM/PEFPDOi+JGLSKvq7IpwNz4douCJwEzDOKUMYJ0P1EXpqgahXl/KODXGbo77uFnu88HbwwUXn+pL+Uw7msNX+EmfFsImxpTmTPUwyK4h46YiZMsGvJWjVQ== 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=rDptnN9eo8vV8QjvCeGDIJzKN2HOqJcTfqfoKo7OsJsbxRSbe75FPADEVrdIbe5eBaI33m6fqdm48xoVgxftl73HiOiqkd0KI4AWwHqmrd4UU2iKWi7lYwemvU8GbNW3XG4iDpUcMOO1vKyqsfIYgsy6QJR6UklZRCxDh8gXxigq5/s+p+3D+LX6x2a0z0N1lzPtO0c32kvD3nS/1cVD9ZK3Qh9WpDPZpi9lbN/A+CARLyYx2lBM223x8rKyXudTQBnOsCsNSAJNrGKRbMbfDL2yqvc/KxbylQARAlYpFhlIwNFhuiCcGudIu6JsVFQHTpodR65RDCyTrF/3bOMAjg== Received: from AS8PR07CA0004.eurprd07.prod.outlook.com (2603:10a6:20b:451::19) by DB9PR07MB9991.eurprd07.prod.outlook.com (2603:10a6:10:4ca::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24; Tue, 10 Sep 2024 08:41:25 +0000 Received: from AMS0EPF000001B3.eurprd05.prod.outlook.com (2603:10a6:20b:451:cafe::bc) by AS8PR07CA0004.outlook.office365.com (2603:10a6:20b:451::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24 via Frontend Transport; Tue, 10 Sep 2024 08:41:25 +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 AMS0EPF000001B3.mail.protection.outlook.com (10.167.16.167) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Tue, 10 Sep 2024 08:41:25 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.67) with Microsoft SMTP Server id 15.2.1544.11; Tue, 10 Sep 2024 10:41:08 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id A4D4038007A; Tue, 10 Sep 2024 10:41:08 +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 v6 3/6] eal: add unit tests for bit operations Date: Tue, 10 Sep 2024 10:31:36 +0200 Message-ID: <20240910083139.699291-4-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240910083139.699291-1-mattias.ronnblom@ericsson.com> References: <20240910062051.699096-2-mattias.ronnblom@ericsson.com> <20240910083139.699291-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: AMS0EPF000001B3:EE_|DB9PR07MB9991:EE_ X-MS-Office365-Filtering-Correlation-Id: fc70adda-afba-4e84-5f27-08dcd1745b54 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|376014|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?B?eUNUYWMvK053RzFJanRzR3l5VWxxS3ZpWWZtaGRIRytMRlA4R3BJTjNWZzVa?= =?utf-8?B?RnhBSm1McDkzYy9ucy9wWTZYVnJZZ0RjQ1U0YkFsQ0FGT2J6S09QbDFsdEpN?= =?utf-8?B?RVpYSjlaS1NQNTFvYzhFNmh4SURyVUp5ZTZ2QTNkdEVsR3NuMHBHQndmcEZs?= =?utf-8?B?THJWMHYrOWhET2JZSmxSYXRkWWpSelZiV0gxT1FwZjB3ZEZLREV1dEZMbU5R?= =?utf-8?B?WjRXc3U1OEh5UkNrMWJCeTZJV3ZMYnlmVmQwWEJZYzFnbXlhQ2taVlNxelVD?= =?utf-8?B?cGtmdnZvZzVXWHQzL2Y3Q0d6Skc2cDZ0ZlI5Y0FqMHMzcXFweEN3NGxWckVx?= =?utf-8?B?b2UvWVBMV2daQS9Bd1BMOERuR0hBUWc3TXN3WWdXNDVpYjVWUXR2NmNQbk9p?= =?utf-8?B?eXR2WWJtUUVCK3UwR01HMVlObEFoTENOdEpDS3VFS3JnYzlZa0k0WkFDc3Zi?= =?utf-8?B?M3hSaXF1UEJhQ0FBTkhRcGxBRWNTODVEdzdkbzJweWV4MWtzRTROZUd4aW5h?= =?utf-8?B?YUdWZWxGbEVKU2t6Ti9I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utf-8?B?SllvMzdSSmJzR1YyOW5uaXkvZk9ZNHVZSVdvZ0VtNUV6QzRtU016QWM1NGhy?= =?utf-8?B?M2R2RHZkK3EvMjk1RWxsdDgzamFMcnlTcEgrNmtNZWh1SDZjVFVkdU4zT2Jp?= =?utf-8?B?TXJPV05oVlBHZC85QjBpZFBvN2hhNVo0Ri8zTG9mV2NDWEtvRWxrdmRLSDhi?= =?utf-8?B?SlVBRGIwelFLZDVrbjFVTGN1QXJqMkloR0ZwMTh6bzB4bXFmQ3liNFB2N0dL?= =?utf-8?B?elZLRkxrMDNJcEhicjJnMXdIZlpaOUdSKzcva2FaZlpjMnM3UUhjMDV4M3Q2?= =?utf-8?B?ZTBqQ05rTk1aeCtMb3NWQ1c2ZHE4V0RDNkFtWFNtNnByYXBOUXN5UlE2L2dp?= =?utf-8?B?aElKVzREUHlJZnBhR3R5NzhvZjc3RmY3WU9VcUV5T0VKbEJhWWhHL0ZDR1VQ?= =?utf-8?B?cnViMG02QlBjQ1g1bEp3ZVB5Tm9JMHJYdGp6YUV3dmhmYS9FN1J4VlFpK0Vq?= =?utf-8?Q?BxOlCSdOD1fGZeFM6gE7ZDtyIvNkwUo5?= 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)(36860700013)(376014)(1800799024)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 08:41:25.4372 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fc70adda-afba-4e84-5f27-08dcd1745b54 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: AMS0EPF000001B3.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR07MB9991 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