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 6200245778; Fri, 9 Aug 2024 12:08:13 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0A91842EE4; Fri, 9 Aug 2024 12:08:09 +0200 (CEST) Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2054.outbound.protection.outlook.com [40.107.247.54]) by mails.dpdk.org (Postfix) with ESMTP id 5A415402C4 for ; Fri, 9 Aug 2024 12:08:06 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fgry8m0RfzNBEYtyluKnsj+3Nm/3orOXDQ4kqhtiSeSG1bUz2R0HwH2342s9c38VFolj+HmdKLRroZrDONCEF6Yie6t0xaGihsjlKYeg4qNGUhh0QkJeW8HDa0S059+76sOvE3S5ptSzqAk0g/kmVGiaY/ZhfkZKF2i6qqGPphR0OpzI1VBPObHjblk3EKlhBknO8cQzCWCmcohOpO3o913/o1RG17VGc25WYlbeAkOecdQscx6BFLRcWBPeHTRVcnWxdVW6zfePvSB7Zu2SXgD98gtzlRrxRcwSI/Ol0oEiIpMfFRdiD2ezJRcME5qvR6IxIn3cEJoYWcbUjVSxkw== 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=rlj6TbwktGuphxsLT7E1iv4WZ/+LLJlVUku+K2BR9LA=; b=kMPosZDLecDhl+2N6fUW+L8YW/PbwQJsbV2qe+QeZARc8S2zFEbvaJYWmwoELN7E9ACg87NX6lMt8Y6DeD2PHs4sMJRmLQ2Lghk5ROS+wlbiARpp45/IrGg3D0cDQXEoSWcrICHKktqSV2GdbZzzMwvy7grjRMIuKZxYp1X0byVWWo4kQkhfVjdvet/Pz95NdT0/tR55MXAG81vXl/VDoeOsNyLs+ivmTLBT8Wzr51Dz0B+3i134vP5v/f2VNcKFLPLbRpAVHuMapNnpu24VzTWXIOasttIYZYhDb7PUxjww0hDK1/n+WMS5aZTXLb1gybjjQhseFqqP1w/RDfwYAA== 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=rlj6TbwktGuphxsLT7E1iv4WZ/+LLJlVUku+K2BR9LA=; b=rnlvAkQfSmjKyGx+mhWEOHyWF0O9kOItUet8LFFsJ/Jpe1m9gT++c8uDvFMKJX4NclHnQe064s2cNgkI0LM+jWlpnI9zhqlre1qaKSDwzefs34VTnjao2Ed8jcNQQrLMfOopop2yBfsOswF5f2c+OuZCwFHxjSnvFRYhpoVuogUK1aLdify9FIJy+QKTufsRD+J5Xx1ftEwb4t9Bg1ITjwnNEoXrrNWJYqHSG+/yD3Ow7WcnhVV2AflIHI5QYw1LvuHHlLwC07S4lvYFgitfv0WA2LJ/1p5VKpFHx60gGrUXfP3QWj9vNJkQyoeGR3t8gMSudTzTkRkjyyYBCDQn7Q== Received: from DB6PR0301CA0076.eurprd03.prod.outlook.com (2603:10a6:6:30::23) by DB9PR07MB7882.eurprd07.prod.outlook.com (2603:10a6:10:2ae::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.15; Fri, 9 Aug 2024 10:08:04 +0000 Received: from DB1PEPF00039232.eurprd03.prod.outlook.com (2603:10a6:6:30:cafe::30) by DB6PR0301CA0076.outlook.office365.com (2603:10a6:6:30::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.14 via Frontend Transport; Fri, 9 Aug 2024 10:08:04 +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 DB1PEPF00039232.mail.protection.outlook.com (10.167.8.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.8 via Frontend Transport; Fri, 9 Aug 2024 10:08:04 +0000 Received: from seliicinfr00050.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; Fri, 9 Aug 2024 12:08:03 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 9E72C1C006D; Fri, 9 Aug 2024 12:08:03 +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 v2 2/5] eal: add unit tests for bit operations Date: Fri, 9 Aug 2024 11:58:26 +0200 Message-ID: <20240809095829.589396-3-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240809095829.589396-1-mattias.ronnblom@ericsson.com> References: <20240809090439.589295-2-mattias.ronnblom@ericsson.com> <20240809095829.589396-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: DB1PEPF00039232:EE_|DB9PR07MB7882:EE_ X-MS-Office365-Filtering-Correlation-Id: 1c3722a7-186d-496d-a628-08dcb85b28f0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|82310400026|376014|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?B?ZjJxcnMvaElZZnllb1d3cnQ4RmJyMlltOEJUb0VEeFlVYmc5WG1hWGhNc01r?= =?utf-8?B?ZGdIQUVJdElVckJYZFVPcUp0ZGpYMSt4MVVGUDZHeWJTdHgxWFU2dDJLZlFx?= =?utf-8?B?UkxYWkhLQ0c2Rjg0MWFYYmRrS0tENWlwTEN6cjlsTU1pRzdtV1ZlOGg5OVpK?= =?utf-8?B?OG56Z3JLdENsSWpHakU3YzhQcVVaaVJHSWVPVnhJMHpaYnlxc3IrUlk2M2NW?= =?utf-8?B?cVRVQlRabEtPWlowRnp5RnZ2bnZZN2pmeE5KTzQ3aE9KMnVqRktQWGxvbEMy?= =?utf-8?B?cldTcHg1UTNOUGdEQ3QzL2sxV3dDQm9vV2dSVWRHd2ZJbktIYzJMNEtwcWZB?= =?utf-8?B?WEQ2cE9nZzBLK0gveHpkNHZOcGIvTTFna09pZUg0RmxQTnEvWTlxZ3RBNXlr?= =?utf-8?B?VzV1cS9UMWlKUkQ1YSsyVnozajJnWFN2Nno3b2ZhVlkyazJWV1pmUUNlTFRT?= =?utf-8?B?aWZLU3ZpWTRtN1IvRTRnckVObjd1aTk4Zi94QVpmYXhxcFY5TVdyY0VZczZt?= =?utf-8?B?Z0F3bXN5SG9hcDNQdWc3SjVXTnVoOTl2ZHJLcW5KbXVHTWx4U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xZVXZnUG5v?= =?utf-8?B?cGlrYnVyaWRmWWdnQmsvYTl2V0krUkJPYTh0d1VmWkZYQk9LVVkrOXZ5Zjh2?= =?utf-8?B?M0dBcWZnWnV6NHdyclNZalFTazQ4ajlHMGViMHR6RndmS0lodDNDN3QydjVs?= =?utf-8?B?eUxQQkF6eWsxdXFkQzMzbllUS0VMQjVxa3RrZ3A1WDVkZFI2cUN6YWREVEdO?= =?utf-8?B?SlZRZ1FFTTYwb3llQzMxQXl0NnFaT0MzY2hORWFGclE5KzJJbU5QVzl5WmZp?= =?utf-8?B?S21rNlFjTTA3U2hNSHNLWWJLd3Vtc21hNmNYRFBuakdkT3FhYTg1NUUwYXRJ?= =?utf-8?B?WVpoa3BIL1BtenJnR09xWlFINzRtLzhUS0VnK0RmRE5XRytscTZlV2xhZzRk?= =?utf-8?B?ai9wcE5uQTFNSHorYjRHQTdVNEQ5V0dRMHdaZDJrbEx0bXc9PQ==?= 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)(376014)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Aug 2024 10:08:04.7381 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1c3722a7-186d-496d-a628-08dcb85b28f0 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: DB1PEPF00039232.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR07MB7882 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 -- 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