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 5F027459BC; Tue, 17 Sep 2024 11:46:28 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C8F8E40A72; Tue, 17 Sep 2024 11:46:13 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2058.outbound.protection.outlook.com [40.107.22.58]) by mails.dpdk.org (Postfix) with ESMTP id 2FDDC4025F for ; Tue, 17 Sep 2024 11:46:10 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TxvE96tApMXRLKAx5x52gu8JtCEzRZuKuITrl1ULCjwcdAp+bPKISvn79Incsu8AbY4yTU6EainkxlMkTxHv+zh+SdP+MpUPIQM+MU3kVrIZ/PCthEVlk84UsSTKIyFnRjyMi/0uduZKEa91Qj6e5RdNxhqx57XrUGmKkzJFHhU6kMkhCcxiDFju/tbeYqoseVaX1lV8/9vEit+bAWKMMYXJaDyzYfTxmz3VwjqYjEYAyN3i6QbAndV69eNNHEnKi2TCq0ng0O7Q7p2xP5Wno8UmeykS4dUnNXdEYYh3pY8hED0pw0S1CyRq56CwaYJkhQOD3/dy9ODUKGUCPz+GOQ== 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=wd03nAg2Yhnk4z8g5J/28ZbECeOKtQrNFf8QiiSRh5PIVtB53E/bXjOyvqklO99lu+0z+R+RuvKtzz4GTofjtQyz1C+s0w4Bna5L71g4lKl9Hkc+3Kdw22oxeyNQWpKFNHICEVxmVpRRqvmYGj6/lFYAcHvmFhTCplUYhTjtcBorH1bF/Wf8OYdFb/Ox+C/a44W4nautFQXdK9uJORDMVMc2AvtprqShXoJkoKDVcaLSCa5F4g7Jfe5jyWfPM5aT5eJ7DE0mRymRN9MsA9/CPslsEYH8tOmxOiMKNUte1m15NR2jdjMrJzuatiRagGuck0WSiM7tVI43luoDmqDYmw== 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=KcQl4Qu6NH/gSRy4rkT01dRiIYZIwhLarAXstg/hXxIUfFofXAiMkN0qS4zLLwT+eGTFA8xaIPXYdzk1xuMkBBEabXjcNw91cqsfuE/wvnjrLEB+zg9L5EEGewUbklI/cnTn1tR/wufugEAVD6AwlNu4nA+9bgKudyWw40F5Bs6UCpVuRVZit+3wK8iqI4sIMh2DGaRj2Amega48rcagW4L3QD9hbypvzOiE5cX5+eTo5bpvMGNnUmCLYR7g7zBs8yItqlZVce/fSq/CEJY43Cel9jblZVtjRsRhDIAcc1zmbRHDlF4FVr3bHPOezgpf1XYok2xruanmK0n2KybNQA== Received: from DUZPR01CA0305.eurprd01.prod.exchangelabs.com (2603:10a6:10:4b7::26) by AM7PR07MB6852.eurprd07.prod.outlook.com (2603:10a6:20b:1b3::8) 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 09:46:06 +0000 Received: from DB1PEPF000509F1.eurprd03.prod.outlook.com (2603:10a6:10:4b7:cafe::7b) by DUZPR01CA0305.outlook.office365.com (2603:10a6:10:4b7::26) 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 09:46:06 +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 DB1PEPF000509F1.mail.protection.outlook.com (10.167.242.75) 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 09:46:05 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.60) with Microsoft SMTP Server id 15.2.1544.11; Tue, 17 Sep 2024 11:46:04 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 7ABA31C006D; Tue, 17 Sep 2024 11:46:04 +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 v7 3/6] eal: add unit tests for bit operations Date: Tue, 17 Sep 2024 11:36:43 +0200 Message-ID: <20240917093646.723777-4-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240917093646.723777-1-mattias.ronnblom@ericsson.com> References: <20240809201440.590464-1-mattias.ronnblom@ericsson.com> <20240917093646.723777-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: DB1PEPF000509F1:EE_|AM7PR07MB6852:EE_ X-MS-Office365-Filtering-Correlation-Id: 08e88db5-61bc-42d0-e132-08dcd6fd8cdd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|376014|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?B?R0ZDM0hJM1FyN09wRjhHaU90emwxQ1F5R2pONXQydVpmaFYvcXorVXlSOTRn?= =?utf-8?B?MllVeURka3lmSHBPakRRZjFWR3M3TVNPNHJrVTIxK3R2Lzd2T1RmVUFKbU01?= =?utf-8?B?VWk4dW4wNWRIUVBXTDJmMENHcVRxc1dUR2xIMURuNnpHOUdiRkRxUVNYYnUr?= =?utf-8?B?SCs3YXhDekpldFdVTG5QNjcyUWV4cjZhZVBiclRheTBZWXJXOXVTVFFzcmNs?= =?utf-8?B?M0tvRDhFY3A2emlKRnJ3V1BQQ3dyTXJrM2dPeHBSaXFodDlYOGxscld4SStL?= =?utf-8?B?Y0hmdjc2SmlCVWFpcHBzOUU3Zm5Zd2JiN2hkMEtUV2xiWlMyYVVjeTRONUlt?= =?utf-8?B?KzhaKy81bUNWZ1ZCelRUWGN1Ym1IMlZVdXdMcFluelZZREFmbVM1Q2dpaDc2?= =?utf-8?B?dlpaR0ZsNWdpSU1yb1VmZm51L1JDQVJnbDd1K2Fwdk1WTmt0WmF0TUZVMFZu?= =?utf-8?B?NVkxaStVbElMQllpVTBMMjNnZTBqMDBGeEtYck9MWFhNM1E4T2ljVE1DOUEz?= =?utf-8?B?M0F2Si90Z2I0VzVFNjlMY2JCND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TE5KOU1sdVZERDBHZVZ4eXB4Y2Y1YUpFTGIzc1NLN1h1b2MyKzZY?= =?utf-8?B?b1hxUFdaQXJLckxLcUxGQ2ZkKzVxcFJ2YUNMZUswZHpjcWYwSGo5Rmt0SXBZ?= =?utf-8?B?M2ZTZmZseUpTRGJVdlI3VldMendMb0JLWEt1Q2piUmRTRkducExBQVVOemVn?= =?utf-8?B?SUJGaHl6SDZZQ3FaNUVhZ3dvRmRqVXdwUTFqcWZUd3dZbEprWkRaOHdoM3Jk?= =?utf-8?B?d055ajZuV01GQmxjSjdqaGN0RjVpVUNFZXdqRUhZYlIzQTdIdTRyQzlSZXQw?= =?utf-8?B?U0twcHNoZ2tDbis0THFicGh3MzhJOG5RM0NwNGxmM0Mvamg2Z3FDRjREMlFC?= =?utf-8?Q?lgtEQP7GzMIQ88cb6w20gcaWb39+e/E0ju9yM=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)(376014)(36860700013)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2024 09:46:05.7407 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 08e88db5-61bc-42d0-e132-08dcd6fd8cdd 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: DB1PEPF000509F1.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR07MB6852 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