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 BC42145777; Fri, 9 Aug 2024 11:14:25 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A90BC42E7D; Fri, 9 Aug 2024 11:14:20 +0200 (CEST) Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2068.outbound.protection.outlook.com [40.107.104.68]) by mails.dpdk.org (Postfix) with ESMTP id AD966402A5 for ; Fri, 9 Aug 2024 11:14:18 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=EBjbsHEcWDMCy72gYMZHwGXiRe9nqPDu7fV777//8Fx7EtgdgHs4nK96XEo+jjfgbNSJouhQeAGeCQhZcb+LnEKT0A2wYcSI1NvTmqnC8UYsuvuQ3gKzXBrp9M8Z1Elrs3t8YheHC+HXDXbxyBGpex+hxwMXfP6exdMhirX9adJX18mAJyyDFvzlzIfqPmSlHxseRK9vNmctYKiU5SDeabwOZiXS0j3e/ty+i+lrEqleF3E8ZvsjGZ0JEUu4HOvnkw443MLCpsQ9HgPePBr0+iQzpcIa1L58FUWG69c+0B5bsL18CWg33kw8fBzztuRXU7T1BGfOfoROqxDCcGycYA== 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=d8z68B8fzU8h0PRajH8DnhYus8GmVFVNaHI8wvhWqbw=; b=WaPxl2lxu8mTvfhk9OMcRcunQWufShqnUR70WzkiOzC3fCjFyYHKpJcP3FbJEdAvQoSNtWzW9CP7nHSCSozzv3TkY+J7QwJcPdGMlDIWRoEEn70UPu0LoNt27VRMAdDNZnYdPxJlDpt5cKt3VD3Q8ua4Qu6Jx5JfzrFt9VlJf7kaHJeQz/cWRx/ersINL2eUOMxkilZxzywRa1n0wEag+v/FpSihpdlInIt1n4ebTdCVtzInE2dtkAP5I2sS7M+xaIcmOA9+c0+Og6VBKk4cO05QOl9J+45iEqWbpudj66dCOQ5afMST2Fg1TaOokT8km7h40xLHbcDo01HhxhTWYg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 192.176.1.74) smtp.rcpttodomain=arm.com 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=d8z68B8fzU8h0PRajH8DnhYus8GmVFVNaHI8wvhWqbw=; b=t8Ilu3VX5Sf9yPQoQeMh86M1bFbuyj52pqJtVSiClxwcNHE0cSNkNSDdt9QW4PkZHLY8AUGuoTDDud+jwUSg8YeHhinmBNg8OUcAgsf/P1ngKLiikJscUIhmg7AaKVX9NZzZbagjw0qyBCFi92R7/WjSNH4N8C2QQb1FRwWtjstMUl59Xta/fNW0ap0yIYLYOPLn6bpjLhxJjYSuQvaCzWD7XZMK2/N56eheAP7UzaEF8luOD/yTyoiD/FIIOjQAXAXPXDRxZBAz3q6e/7l/KJsTrryZSx2EE8szQuY0/MZT9a5UQO/FGhTkaNweDnZ1rZtAszBCb+YsY+pQ4Un4kA== Received: from PR2P264CA0018.FRAP264.PROD.OUTLOOK.COM (2603:10a6:101::30) by PAVPR07MB9216.eurprd07.prod.outlook.com (2603:10a6:102:316::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.13; Fri, 9 Aug 2024 09:14:16 +0000 Received: from AM4PEPF00025F98.EURPRD83.prod.outlook.com (2603:10a6:101:0:cafe::bc) by PR2P264CA0018.outlook.office365.com (2603:10a6:101::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.15 via Frontend Transport; Fri, 9 Aug 2024 09:14:16 +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 AM4PEPF00025F98.mail.protection.outlook.com (10.167.16.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.2 via Frontend Transport; Fri, 9 Aug 2024 09:14:16 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.63) with Microsoft SMTP Server id 15.2.1544.11; Fri, 9 Aug 2024 11:14:15 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 946D01C006D; Fri, 9 Aug 2024 11:14:15 +0200 (CEST) From: =?UTF-8?q?Mattias=20R=C3=B6nnblom?= To: CC: , Heng Wang , "Stephen Hemminger" , Joyce Kong , Tyler Retzlaff , =?UTF-8?q?Morten=20Br=C3=B8rup?= , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= Subject: [PATCH 2/5] eal: add unit tests for bit operations Date: Fri, 9 Aug 2024 11:04:36 +0200 Message-ID: <20240809090439.589295-3-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240809090439.589295-1-mattias.ronnblom@ericsson.com> References: <20240505083737.118649-2-mattias.ronnblom@ericsson.com> <20240809090439.589295-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: AM4PEPF00025F98:EE_|PAVPR07MB9216:EE_ X-MS-Office365-Filtering-Correlation-Id: 90829c63-7430-44d1-e3c2-08dcb853a4cb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|82310400026|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?B?Sjl2bFJGelB3V3BPaWhpMG1ndERJZG11Wi93NG5tTXpOLzdsZkJSOTE4dmx3?= =?utf-8?B?U1kxNjJ6bTJtMVQwc3M3WEg2K3V3WE42R2V6MERtVktpWmtPYWdsYWlsbVRI?= =?utf-8?B?MTVPblphOW94MFlsR3kxanFiV1hxM1ZVa2xyalUyTTdTM1VuNWtWa2pzMkRk?= =?utf-8?B?M3Z2UmtZKzBCK2UyS09Cb1lrcnRtRGF6eGVpS1dSYlpBd3VIbEVPVWw2UHkx?= =?utf-8?B?L3VDRW5qaHU1WmdTM2tqbVpSU2JlQWc1L2pBSkdySXo3K0dVSCtqdThVcEVm?= =?utf-8?B?RVpyMXlwcGtjdnNXNmRBazlnUXJUN1d6bVZEMXpjSjZldmZxTWphWjY2aGZm?= =?utf-8?B?QUFweDN6c0NRdSsxUVFoek9aRnNPdTVQdE11TzN0ZVA3UnVjNHZRN3A1OHZ3?= =?utf-8?B?VkFuR1RwcjNDWTNpVFFQcmFFeXlXbng3bTFwYVhmYUdON3g4ZmQ2eThXa0ln?= =?utf-8?B?djBJYW1TVTk0UG84T3NWcE42cWlXZkhocmpvQ2pST05MVnBFRFdkRThaYURN?= =?utf-8?B?ZVo5bktWZXZQTkZKcEZCM1FFNVRMcHZGSlpsRkc2ZjlUWWZpZmhIR3lGaDk2?= =?utf-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dCQjA4?= =?utf-8?B?VFJVY1MyV1RsUEdGRDI4WDE3MjE5bXl2ZittZHFEdHBwTm1EM2hFSWIyVjJR?= =?utf-8?B?aUZoZE5RSXBGVC82NG9GZHpVY2tqQ1N0VmZLN1poUlZyL2ErcUx4bW9YMDJj?= =?utf-8?B?SElwbktPTjV2dlkwNXQ4dTRaQjd5VldOc1Q4UnYzN3FJcW9BTGFmeEFWRXJG?= =?utf-8?B?UjlscGZDQTRZdnRWN2N6d09Cc2JINEZYNUR6Rjdtem9mRmt2T1l2akdORlhn?= =?utf-8?B?NVdzdTgvTnFwbVVKcVRDTUZ3Q2ExeDY2NG9UTW9WZ3FtN2E2b2dTbDZTd1pI?= =?utf-8?B?TjFPaG9ybXY1Z3hPNDMxQlAzVXkzTEFOVUV1U1ZYOEpnc0x5OWtyZVVjREZn?= =?utf-8?B?cVQ4djJmQndZRWFzUGQ0R3hzTjU3bmh3dmtnRHN4VG4xQXc9PQ==?= 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)(376014)(82310400026)(36860700013)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Aug 2024 09:14:16.5920 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 90829c63-7430-44d1-e3c2-08dcb853a4cb 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: AM4PEPF00025F98.EURPRD83.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAVPR07MB9216 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. RFC v6: * Test rte_bit_*test() usage through const pointers. RFC v4: * Remove redundant line continuations. Signed-off-by: Mattias Rönnblom Acked-by: Morten Brørup Acked-by: Tyler Retzlaff --- 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