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 9255045945; Mon, 9 Sep 2024 17:07:10 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7FAF940291; Mon, 9 Sep 2024 17:07:10 +0200 (CEST) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2060.outbound.protection.outlook.com [40.107.20.60]) by mails.dpdk.org (Postfix) with ESMTP id 2393A4028A for ; Mon, 9 Sep 2024 17:07:09 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XsNxzAd5kCAXjwbAL5AAOXOPtKqngcS53akTC2IrZ0iCYsPLASA5ayVsrZxzYaw/fO8TLARJ2ynysul5W1NSJEOZ56KOqrUm+NKfUMsk49zwahPLL9WFyehSiYLyUQXlRw8rSLM9V/bEHpesRXcA62R0ZYwV0JMnGutdhJfvGore3nrmJXk16ZGL4z/1Dv3ALES6ZrQJqJSbkwCLGHVm6D0y5zt5bFs54RhKhOfLzQoR0ebLkc8MiKsZ98FjMTrt/TfBsDMHer96oMJHVYyPrr/97pJifXS4mDbx0tTgcNgZ9V5/eyoHF5aZJvYY2AgTvyD3QUuSbX6wzTfDAGd5ow== 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=LflrHBQs7d8Z7xymHwXHK/ea1MgJhuvn1TZKo/K0wmLlb2ROZ92FbLsVLWjiWsWzOT2Pnd/wp9AXayJbIXNbrAdifysq3EOR8qiAdwY7bW4g4bvTHiV2/uWL1BPJnrTik3kbkAOGPjMPe8joUOw+sZp2CNC3trmu6u8Df6zcak2XpuoFf3u3vM4UZ6+GMlLU239+ROSv2nG1U0/bJsdhtab3oR9xWNuDVrHbBWB+AqURniyxU07ed/pmNdP4IcadZYmzxrhXhoIefRfCn653+dDY9gL/EAjX/ekkIZYRNgdpiYbeQMqgWsGtiLJn66ycXC2kDfkPkmij8dNI7XgJrg== 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=lCulBbq6cXdk5gnMLi4TseFf/iwvDa99l4UcPwwAzgC5+v1/b+LRcUPbhqpos0iZIL3ZVe+JZ/DeIheXKbRaUEgIxlcHOgvxbVoJK8DLx9p4N057yVOueLrTVcinWPrPPE9/L1JBai2OmEImSdyFaijYdfzjkCxq7lALb81LD7FPAK8GDHFBfwY/OqteN3DbUg7XjBao6xezwQ4FsIpa8M7zYtRDD3FpGhmZZQhMyHrYf4YYDUjJ9QXQVZ823a4w2OGhUvZ/OHZYcVz/IfSgoSx5T4VhDZ9wiE7CWF3yIxlaS6bp9N893uOTr04Wbjn/mrRDLQXlEAEOlvRIIdnkJw== Received: from AM4PR0302CA0027.eurprd03.prod.outlook.com (2603:10a6:205:2::40) by AM9PR07MB7988.eurprd07.prod.outlook.com (2603:10a6:20b:308::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.23; Mon, 9 Sep 2024 15:07:05 +0000 Received: from AM3PEPF00009B9E.eurprd04.prod.outlook.com (2603:10a6:205:2:cafe::e0) by AM4PR0302CA0027.outlook.office365.com (2603:10a6:205:2::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.23 via Frontend Transport; Mon, 9 Sep 2024 15:07:05 +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 AM3PEPF00009B9E.mail.protection.outlook.com (10.167.16.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Mon, 9 Sep 2024 15:07:05 +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; Mon, 9 Sep 2024 17:07:05 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id 1665238007A; Mon, 9 Sep 2024 17:07:05 +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 , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= Subject: [PATCH v4 3/6] eal: add unit tests for bit operations Date: Mon, 9 Sep 2024 16:57:40 +0200 Message-ID: <20240909145743.697342-4-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240909145743.697342-1-mattias.ronnblom@ericsson.com> References: <20240812124930.604796-2-mattias.ronnblom@ericsson.com> <20240909145743.697342-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: AM3PEPF00009B9E:EE_|AM9PR07MB7988:EE_ X-MS-Office365-Filtering-Correlation-Id: 87deb600-1a22-44bd-06b1-08dcd0e1114c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?B?Qlp5bFBEZ0VYZ0lpeTNFY1NRR2ZtWVdxWWk2emxxSFJsU0JBdFFuRmt0blRX?= =?utf-8?B?RHVXSGJsZWJ0YXhBdzhHeGlBR1RJZlRKLzBXREFTdFNDYUZXanYyWjdKb3VW?= =?utf-8?B?ZEJSbnBiNkU3OHNncjBmS25ObGZOdjdYZjJDMkwrMjJBcExWbnh1YzJhYWYx?= =?utf-8?B?cnFJekhYbU5IMlByZ1N5OVdPNE9zejJ2YVkydE1jUWJrS1BFdkgvZEhtQndn?= =?utf-8?B?YTlTMHZNR0ZyNDVMMjcva0daNFNHRmd5MitLNFNHSjBwbFdwTyt6Tm04eTVP?= =?utf-8?B?NWxXR0dlTmoyUzZ1NEV3U2dOQnJrbWE2TDBGMU1NbjkvbTlMdmxJNHBiSEJj?= =?utf-8?B?RU5ETkR5QTBxWk1RZ0ZpZU4vUTBTWW11blFsSmxlbk0rc1FMMUhDZmdoVWFs?= =?utf-8?B?SlBqaGNWbXhnSEpKeVpyYU5scmM1K0VMaDFOV2tKMXJBTlovTWt4cCsxZmFl?= =?utf-8?B?a096OVJjRm9yVW1XMVZIMTc1NXdiTXFJMUp0MWFuTkZwL3lIdlVTVmg2TGtH?= =?utf-8?B?SjBXeGRnMWc3dlpNaFdvUnhUNW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BBK1d1SkdUYTFqS0U5MXZodENrMVI4ZzBudExURWpQYzAvenZQSDErUFZF?= =?utf-8?B?cEYyWUtEbHdWOWNRb2svOWpQREJWTEkwRjZTRS8rM0F5L2JyVEN2S01tblBT?= =?utf-8?B?aFNiRTBvVjJCQmtOK2twYkZJTHI3QzlpYVJFZWt6cnpldktDQW1oQ05oU3oz?= =?utf-8?B?TTZGYXY4TWRKYjkvNVV2Qklmblc4MHZYZldjRy9JZ21xVytrN1FMQW15YXZi?= =?utf-8?B?N1BsRzdEcG5BZEhSSjV4Q0JzS3lwVysvYnhDVi9IU05OVllaQ3hvaTFTV3Zp?= =?utf-8?B?eU4xZUtDbGNMYjJIUUR0dFpuS3ZWemVMb0FWYXdGWkRZbWNaOCtoNkJTNkZR?= =?utf-8?B?RHF0ZHUwK3dZYVBjWnhSTDFid3VxRjcrOU8waHZGREorMHA5Y1Z6cE1NUXJ2?= =?utf-8?B?NFlwSlJTT0lPcFRoSDF4Wk91a2x0dytLTW5EdVhXYS9Vd1RpYUR4bjZxb0tq?= =?utf-8?Q?zizZA2Id0syv/jjJn/SO8c7KnW/yGBRG?= 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)(1800799024)(36860700013)(376014)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2024 15:07:05.5556 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 87deb600-1a22-44bd-06b1-08dcd0e1114c 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: AM3PEPF00009B9E.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR07MB7988 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