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 4D9CA459BD; Tue, 17 Sep 2024 12:57:41 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3893740A6F; Tue, 17 Sep 2024 12:57:36 +0200 (CEST) Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2063.outbound.protection.outlook.com [40.107.104.63]) by mails.dpdk.org (Postfix) with ESMTP id 308FD4025F for ; Tue, 17 Sep 2024 12:57:33 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=paVyrVJ4vpzUHR79NrOE6qlYi0dqM6mdjjVmAJ8EpsuGp4vRwvUCtdHdCAOK9mGIu6jk2qPe7My2nWwfPprRmDTNdGIV1BJ/whN9DThHRIMy1YwsFdIBy8tHswQ6TXGjjlbMS6spw+CQ0ugGtcjslmOrzbzwjG/crQHw3U6q3nOwYAQYE1cvrqUvVo2TaG1z3WRtfUb3Igv2m9Hek9XLBn7Jvr6Z0ci18jB+Z77/gFCy2/Szey6o3zT8f2igpobyMhOzwn6RbzFxww5QHxXarhonjpacEC/v9VwkMS84G49V2XN11FugsoaRLfvtggwOGs4XnFhkyGTiBC1t7yHH/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=ezEYBPowzt/LXFrC0D94yBrzgof08m2a+lJxHGflYxmOXXRgsPScQ9qeS51OyafKLfxPorL0iLn8Bk8iatxEcGKz/ACsf7uh4Lwh5S4mXudUCmbnJzJIGLv2/nWLhEcz3xhqEE9KcqJog2tTRTwSKCgm6eVUjSQeuw3pKkjBgvTAltfHWKDAnNkYoG69yCGnkO/TzaXvy/Y2NiEwD7veUgJXBFAPAl5o9/az6e8h58U5YtsQb2v4tyd+cjuRFjg8d8gEbRfTWYCtUPVfwg1YgosAg7OC9X/SziiU+LX33rsXPa70Tt4YAVmzfFNw5RK8YuqrED5jDAP1IU9AmPGTIA== 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=OyBIUMUeT6Sv++JgcJGWzoslN9Xe2YYcwQdayfUGRYEGcbfYOajB3hiX3G5V7Tt8GWiOohnEeZk8xToUFZecnRuWxfEzz7pkq93BKbrHIz3mWGz8g/LGh+UI+PXKjMN54ea2Q2INCr7gZ4Ooq9O/kMGpZzHaRsU70qC6RB76GcZGdnFVbmZecN4KauDLBIVmEiMphcswnzlF+WAEtTaSO1yTAchYS3/G/rz8MDiFFd2KnqL8GiJUCIlRUQViqyP+nEtWFPD8fJRUiwHf7cyE9RmO5dFpWkOq3YuqP6pV0fRlFcxE14tD6Kb9FFl/ANpjQPd/ZxLl8e41vKxvJzWBjg== Received: from AM7PR03CA0029.eurprd03.prod.outlook.com (2603:10a6:20b:130::39) by AS1PR07MB8542.eurprd07.prod.outlook.com (2603:10a6:20b:481::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.24; Tue, 17 Sep 2024 10:57:30 +0000 Received: from AM4PEPF00027A69.eurprd04.prod.outlook.com (2603:10a6:20b:130:cafe::5e) by AM7PR03CA0029.outlook.office365.com (2603:10a6:20b:130::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.30 via Frontend Transport; Tue, 17 Sep 2024 10:57: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 AM4PEPF00027A69.mail.protection.outlook.com (10.167.16.87) 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, 17 Sep 2024 10:57:30 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.69) with Microsoft SMTP Server id 15.2.1544.11; Tue, 17 Sep 2024 12:57:29 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id F047B38007A; Tue, 17 Sep 2024 12:57:28 +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 v8 3/6] eal: add unit tests for bit operations Date: Tue, 17 Sep 2024 12:48:08 +0200 Message-ID: <20240917104811.723863-4-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240917104811.723863-1-mattias.ronnblom@ericsson.com> References: <20240917093646.723777-2-mattias.ronnblom@ericsson.com> <20240917104811.723863-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: AM4PEPF00027A69:EE_|AS1PR07MB8542:EE_ X-MS-Office365-Filtering-Correlation-Id: 874bb36c-043a-4d09-e6d3-08dcd707867e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|1800799024|36860700013|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?TU5jTUx4SDU3QXlsd0VPK2M4RnFlNXFEd2tMb3Fzcm5tUUhDYmhHb0UvakU5?= =?utf-8?B?WXRYRmJNNW00Z2NoZ2RiL2dIVzZWN0F3YmtHZnVjRTJtN050NVVzNjd5RGVn?= =?utf-8?B?NnRtZm5rTUpnUHUxbUhpaTlOQUJjWXpOZTdFQ2UxTXdwZkl6Vm1ONm1Mamh1?= =?utf-8?B?UW90bHlqeVR2WmZvVzd3QlZoOXJpODZPcnh0R0twZzdOR25namlsb0czQzNz?= =?utf-8?B?ZW02WS9nN0N6Ymd4WktmeW1OZCtaUWRpSkg3RENxZ3BuQ3F4U251alJJY2JL?= =?utf-8?B?VkJUOVBMdy9CN3UxU0M3Y0MzT3FFNmw5cWFKS0Qzb0NGQ2tCYUovemowVXJt?= =?utf-8?B?SVh2eFEvaiszU2ZUZ2t3SEhaM096MDJuRzlGcmZvS0gzYnRCZG8yRGVQOUNO?= =?utf-8?B?YW5taERUUDg0am1BU2U5cE5YLzYxSWJvU09TNC9RSnRDTjVEMXArT2l5SnVQ?= =?utf-8?B?NFNxOEgrMkkxdlVsR25ta3VxL2cwb2lvU0FLKzd1NThRVWlTVG9zU0ZIc0h4?= =?utf-8?B?Q0dndHhsRSt4SnlpSE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TVpNMFRUa1pZcGxzckdMV3d4RWQzOVdTMUpJMUFtbzJnVlZNbmRH?= =?utf-8?B?a0JiSlY2UDN2WnRyQkp4RG9Wa2VKK2FKMHB5MmRMempqRlBuZURSbG9jUW9l?= =?utf-8?B?Nm9iTFRyV1RPcDRvb0tNM0Z4R0t3MFBweGtXNFQ3THoxVFh3WmVyLzF2Sjcy?= =?utf-8?B?ZHEya212cW1HS24xRVVHd1FHUW9KWkp2WEU5eVovWUZ1OVJGNEd1QU5rRnJx?= =?utf-8?B?MkNoZVhER2FtdXIxa2hubDhETzlyTlR1bjdxT0lnZlphZ0FsbDhET2ZXNjhw?= =?utf-8?B?WEJMMEJyelVjTHl4KzFubjFXT3VBcER3V1JXODdEakQzZVplTHhRUlhqWitB?= =?utf-8?Q?nT1GB/W36ZnWi5VxOsC6rbc3zfe0B7yeEGDjE=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)(36860700013)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2024 10:57:30.0349 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 874bb36c-043a-4d09-e6d3-08dcd707867e 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: AM4PEPF00027A69.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS1PR07MB8542 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