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 9F07545952; Tue, 10 Sep 2024 08:30:26 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8C28842789; Tue, 10 Sep 2024 08:30:20 +0200 (CEST) Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2065.outbound.protection.outlook.com [40.107.104.65]) by mails.dpdk.org (Postfix) with ESMTP id EB6B74021F for ; Tue, 10 Sep 2024 08:30:17 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FYU1lSR7ysow+Qr29YV4tVGMNdESGaAZbkkoJemU1BTLk56VXC3MZzf2P1NHkoIed/YehOirUL0gtQVbppra+/VA8qEd4WSUDYJGc3z+51E7Xmdq9MveuPaWBWWwjiZeiLHSfQe1wiAtL01PDnt1Cw6tnMGqh6Gx861wVNdXIWPfPbpVIKPu3d2WGYAzJMhePPrfTHzOUyDGyUwAZiQINouwG0ezqIxi0GdGmvRANkieasg96d6em3kh/U4GO5xorUSeUd/qCLbEbLeTQdgtb1VO2xExEUAjnxyjcn8W6q8H/PSoMGPsoxJ8ewHnGp6m10o+sphESGFRf0x+aErsew== 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=I8hJuRbEfBK+RRSwrXLYnvYUWxx79aQXZTfSo08ItWD+lOTVpm0ZQKaFrf0B8dd3ImpI1mWHUFz/AgNisxUbEEqeobqHDwxA+yt881C1scgBwKyIrLODr4wugL6RUxowenFb5RzfGWruG7OCo3J5UHg6GOUN12Iz3O61SKCtFRSYvB7Yg730UYsqzvzp6MG46OQ0pfX4GDPvj/3eQvA3lPuXXzZGQFLQO3rw1WV4c8Lm8AUrRz0+eohR9CbtnSQOrf8GtVgo4+c7PPsuajKr3HpCLgkTZKwspmxpZEZE3YaneVn8h6w8tHvRiwA8u6BZOfK2aj5gUOGzhFn2dFzZAQ== 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=mZd3GNcrkhP8n/pgQP0xHE5/vDNXN4QHi1bYA0vkBuGfY4WRhLpS5gnc6mxz2uEidRUTqt5rP72Q9E4aDN/bzbSQc5u2H3hImdNQBazjZxSOno5Sw0A1Ck9fOcfwRWCo+QiklEIzueNFnxbAw07HEVA6/L30uabHWPrdtBUXNzgcJ1zwHqK7vBN063nHxem5wlrf2ADmvkjTCShi3lIQLGvpqFS6+eyrTxMkSQC0EqLQ5CX98IPWkCdZ4sVRkvB3fIdqYykjJQuzEnELhvh2CUYiKhM+n5LQBHvY8SCwlkaCdTVO/gOIdwNsL90GZXDhLTrdMaug2TiNY0f0boBM2w== Received: from AS4P191CA0005.EURP191.PROD.OUTLOOK.COM (2603:10a6:20b:5d5::15) by DB9PR07MB7866.eurprd07.prod.outlook.com (2603:10a6:10:2a9::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24; Tue, 10 Sep 2024 06:30:13 +0000 Received: from AM4PEPF00027A64.eurprd04.prod.outlook.com (2603:10a6:20b:5d5:cafe::44) by AS4P191CA0005.outlook.office365.com (2603:10a6:20b:5d5::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.25 via Frontend Transport; Tue, 10 Sep 2024 06:30:13 +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 AM4PEPF00027A64.mail.protection.outlook.com (10.167.16.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, 10 Sep 2024 06:30:13 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.64) with Microsoft SMTP Server id 15.2.1544.11; Tue, 10 Sep 2024 08:30:12 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id B90611C006D; Tue, 10 Sep 2024 08:30:12 +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 v5 3/6] eal: add unit tests for bit operations Date: Tue, 10 Sep 2024 08:20:48 +0200 Message-ID: <20240910062051.699096-4-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240910062051.699096-1-mattias.ronnblom@ericsson.com> References: <20240909145743.697342-2-mattias.ronnblom@ericsson.com> <20240910062051.699096-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: AM4PEPF00027A64:EE_|DB9PR07MB7866:EE_ X-MS-Office365-Filtering-Correlation-Id: 0f499a2d-579c-411b-b4a1-08dcd16206ee X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|376014|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?B?dkd0MFBscHN2MWlGYlVEMWp4V29mdUR2eWdjZDVka2MwTVhuNGREbHNSV0Jy?= =?utf-8?B?dGlnYUNsY0YyWWZwdUdFWkNsY3A3VDBXUHFJV1puZjZkWlZkMXJUY2FiaVdJ?= =?utf-8?B?S3lmakZpUXFjaXRqUFMxaVV3RlcvY3ZpcFFsdFlJQWE2cnJCNFRJRFNwVFM0?= =?utf-8?B?SXV6a3NtczJnVU1CRmJ0SUNyd2xKUENaK0RmTkN2VktyYzl2MVh1c0liaTc3?= =?utf-8?B?bFpIdWtyU29pODRaZU1BVEdLYlpCZmJoK1E4cGhCbWNoS1MrWG56UHFKU2lv?= =?utf-8?B?QzM2azBWK0NZQ0t1bWoySXJKQ21PNGF1Ym9OZGw2blhFVkhiZmdiS2RPN0dB?= =?utf-8?B?L00rS3hJN09SbUNJeTFKL1QyRXo4RlVFR1pQQWF5S1ZCKzlSd0ZyNmU3YnY1?= =?utf-8?B?ak5NQ3hxTVRSQ1F6UVRUcGlqamFoRTBqRXZhaGR5RmxjWnNwQ2kyeS85ODhy?= =?utf-8?B?RnhXMmIzOU96VXR0UTUvQXlhbnNyay9scFJEQUZTMmJIWUxRb09nVUloR05Z?= =?utf-8?B?Q2JlaVRMOFRYR1FnRVRS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1YjVzQUF6OXVqWHJOeVpDNExBb0xBYWE3WFVoQjBVSkJxcVB2WEI1ejN3?= =?utf-8?B?WW1jYjllbTJLMTZjMGtQWmxxenN4QVF1bDk2RUhHTUFDWUxWTVpyTGVVdUJh?= =?utf-8?B?aVZoWnVNM3dtR2J4aUhBRnF2Y2Q5SnlxbzNZS0tPaE80akNHODBXb3QzTVAr?= =?utf-8?B?d0FoRTZ4Vlg5ellVMGxwZjFLUzVINlBJa08yWmtOZTF1Zk4rZGJDUWpFYnNr?= =?utf-8?B?ZFkwWXNQa0h5ejBSKzY2VFE2MmFNNWVrNTRTdmtqWStMN3hMVFBHdnRqdVk0?= =?utf-8?B?M1RzbzhuRUN2YWV6cmNOL0lNdy8zWVR1dkpobm1Vdmo3cWJWUWpVbC9HMVBq?= =?utf-8?B?RjNrQ0VJSlZ1cmJaSVJ2UHc4NHREOHUxK0pBMVVZS1VqN1B1MEtrb3lGTkNa?= =?utf-8?B?VEI4Z1lwcVVJTWt5VzhiMlo3ZkhSYVVFa0tlbjN2MnFzU2tEUFg4SmdFQlI4?= =?utf-8?Q?B/deyHUQMF8zI6XFKPzTpyun26Tmc1Ai?= 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)(376014)(1800799024)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 06:30:13.2606 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0f499a2d-579c-411b-b4a1-08dcd16206ee 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: AM4PEPF00027A64.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR07MB7866 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