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 DF94F459DD; Fri, 20 Sep 2024 08:34:22 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C4511433EC; Fri, 20 Sep 2024 08:34:03 +0200 (CEST) Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2065.outbound.protection.outlook.com [40.107.247.65]) by mails.dpdk.org (Postfix) with ESMTP id 10DC240A87 for ; Fri, 20 Sep 2024 08:33:59 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jaJ+MQuAanev0l6mGaPq7deHJm2gpty75mr2zKKWDMkZQ0Sxx9MlcuWV0Fev5EGzh90Agmk+T4Go9Th+l9rnfeU6Sox48VqeHAfp6NIxT94sPH1DffQh5eQqquCJXTWzAtc6rKN0xlwlyfaMraOLoe/RFHF4x3njy7/gLNdS2kngT81wOpB6T7+EuNAKPFCBNLBGzJ9UrvjMeN7NLmVd22xRFYwbvlu9fuHkQe5mwGv3spZfT2cD9oQehXRltCOkK7irMC0nqEcv9u2qEHyBal7rJTtnuGKwOHXZojsPa1tdMNkacXWUGzsQtXh+s2NAAzWruCuRjmk63MzruEFpHQ== 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=Z4PHkyPx6lcuTetXLkfXrapNunrCk88vre6qC5utM/mLpP7G44J3YuSCMNBwPVNWMAG5o7gQInUAclMFdEOTk2vfN82UnxU3j6IAkSqjmYcMAueQXabJFRTQvmM3VKO/3NQo28ZgUbNTyV+Qxwo1IQoM6PDPlgjPfwTWb2UNZV1tn/kL4TDSWZy4S/SQNfub0aWGQoijajXzDsIIjWCVjLqU96DEzYKa2CAUoaCfonWW4+peWUQVzfnhTS80Mv8m6NhN58g3pixHbDWSt/LJ8r8pDV4j1+N8mMcjb3zwix/EOsW4BPQXggsPKkK2vC5s4h1dm5IMEc4rm5ZzPZah3A== 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=eEge9hC6e55u81W5VH56bwutt2rWhvBlepkdbnQO3YMY7La9OLQwdSZ8Sc2QF5osvspkcoz9RJBSPK4xtaCnuR1FNlMfuQ+xA8AF4QFZc/CdqDBkaDMATwTDXGNZzJHNYFAgmvnqC5HHGS3L+EV00hytti1WOhXT6hsqjWAdtBubWWKOUFiUu54w58bfSySikxaiZcSvjUS+tF6Omh26+5ofLlYg/08I8uVAxkF0TzCrIgmhaA3aw8b1v6Ez+yVM444RZlQXHmEZMBs8gi7jTKJAEfb1bxWIEoEeNiIlKRALxvq9dD3qpyaVoyvKWfN6r6fw3gDEksafy1UUQLU46A== Received: from DB8PR03CA0009.eurprd03.prod.outlook.com (2603:10a6:10:be::22) by DBAPR07MB6614.eurprd07.prod.outlook.com (2603:10a6:10:18f::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.16; Fri, 20 Sep 2024 06:33:55 +0000 Received: from DU6PEPF0000A7E4.eurprd02.prod.outlook.com (2603:10a6:10:be:cafe::c6) by DB8PR03CA0009.outlook.office365.com (2603:10a6:10:be::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.30 via Frontend Transport; Fri, 20 Sep 2024 06:33:55 +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 DU6PEPF0000A7E4.mail.protection.outlook.com (10.167.8.43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Fri, 20 Sep 2024 06:33:55 +0000 Received: from seliicinfr00050.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; Fri, 20 Sep 2024 08:33:53 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id D3DD81C006D; Fri, 20 Sep 2024 08:33:53 +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 v11 4/7] eal: add unit tests for bit operations Date: Fri, 20 Sep 2024 08:24:34 +0200 Message-ID: <20240920062437.738706-5-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240920062437.738706-1-mattias.ronnblom@ericsson.com> References: <20240919193124.737943-2-mattias.ronnblom@ericsson.com> <20240920062437.738706-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: DU6PEPF0000A7E4:EE_|DBAPR07MB6614:EE_ X-MS-Office365-Filtering-Correlation-Id: d574d8b1-8019-4c9a-c1d7-08dcd93e3373 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|82310400026|1800799024|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?QnRaM01YdnZpSjluc3IxbVh2aGVmRHUxTUZDVVdYenJlODQrb2xBQnZ4ZzhG?= =?utf-8?B?bXYxaEVHWGllblNNSi9ETGgvSFdLb0tqTmJKTWhsWFI2cE5DVzB6T0JyS2pj?= =?utf-8?B?U3FhWTViU0ZFM2JZS2hiTFpYY2U1NmVmazd1VTZpUXgwcHduR1dmTVBxUkpT?= =?utf-8?B?SUkzSTFUYURKYTR3UjdkbFFoQWVFandvYnhFVjE3eE4xa2RkYzFhNitRQlVo?= =?utf-8?B?dDV2cy81Q1JyMGkwNHFOVXlNRndPTms4dURJQld0OG1hR05HSHI0SXZLS3Ns?= =?utf-8?B?czJFbk8rUmF6blowZVdNanF2T3ZOUDk3aUJkSkF1QWtVVDNzZUFtUDVIVDh6?= =?utf-8?B?MlJWajhBY0tycmdpTld5V2dtOFdqc3ZXc2ovYzl1c1NBTWNWQ1d0cEpXT1c5?= =?utf-8?B?WWZTMlNtcFRpSGxlZUNrOFh3UXppUHRqaVpiNW8xSTBCOGZsK09iVnp5a3NQ?= =?utf-8?B?U2N5UkdDTmxlOEI3bjEzc2ZPbGRLcDNzQlVzYk9QTlFNWEswRjg4Y1JBNWFi?= =?utf-8?B?MUM5YzFRUXdsS2NFZ0lNbDZTM2FFejk4a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diMVF5M01McWxtOUY4OFMyNGpwNFM1LzlUS0J0ZUppWmFiUG5ML0hNSEF5?= =?utf-8?B?T0pmZEZPQkxMZVFjc3lEWFlTMjF3UkN6N3U2QWM4WERXMDFlVE55dGsvQ3VQ?= =?utf-8?B?NVBubVRZY2JkTUc1SG9vZ3YxUHRGMC9UTVZIWjh3R093bVcwMWVILzQ2Sys2?= =?utf-8?B?c0hkNk1TdmFUMGU1a3dIUERzdm5FYitFYVJHZHQyNjhQVWttRzdFVnNRTjhv?= =?utf-8?B?YVc1K3VhRG9YTjRocGFtVlVCTnNZaGUyUFRLTksrV25zQ0IraFRFalBWUGR2?= =?utf-8?B?RFBnd2xOTzFOT2NLeTZFQ2VnR0t6dXV6ZjNEYXlFMTlUalh6ZU9VbU12L0RS?= =?utf-8?Q?1ZAUwAWT5ub0OB1OyGBVJqXmoCNtoHIqMryjE=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)(36860700013)(82310400026)(1800799024)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2024 06:33:55.3410 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d574d8b1-8019-4c9a-c1d7-08dcd93e3373 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: DU6PEPF0000A7E4.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR07MB6614 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