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 2CEC9459D8; Thu, 19 Sep 2024 21:40:46 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id ECBE343314; Thu, 19 Sep 2024 21:40:45 +0200 (CEST) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2078.outbound.protection.outlook.com [40.107.20.78]) by mails.dpdk.org (Postfix) with ESMTP id 0757940B8C for ; Thu, 19 Sep 2024 21:40:44 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ezvZsqFIvp7Gn2ppMtX0aI1WV/NvmLaGIn/fcTqnWzumJJ/gbySZiJTAd7ffureZRaJPpPVODzHu9TWJEc7FYSGxnXK3y1LY7uzZtmRBaMWgD2ZeS2OuLYtMGsz6m+jFvw1YL4COQn0yIrWFfnA+fbqxfqXix66jYyHWg1NKxejGuU2tmCWHIATiBE+HXfx6fFCwxIb4YoZg2xtDhTjDs/05h0frpD5lw81UUvbk2vs3xswMbEfoIU00rWH9hNEZe/74JflM3YgHKdi6aZEj7gB4q0lmwXbH6As9wKQVIVJiXBF8Bs9HzT2qQxB7XC8XQvIqS/4mqLG+CeUYtnwzcg== 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=Y0pACmMCpSGMaC1+OA/vrBXnML+ZJsjZAto1SFKJRd4U7l5lJtADGg+pEXiidPxBGW/H6E6VFjlmLll1VzP90TAdYy7MhI5jXnNYBS2g8gsnGHrq+FFmxW7CaCpLXV6FOj9wVrpiMjK24j+lwPypkFwUlHu7Sg5bGiyF7YslL4SIPQQHwe2sfWQt3t8k11SFFJFWu15rhWjp8tdHLKfodDQKftX/A16YNP6u7IhaCJAR75GxQJdZ1KsNFcZ9EQjChQtxxx4UHLeR9Vu2FRHUCNP5GNiuclnyE+gLZ+DewY9h8MMmcPeyEp4zWU6KbzHbCEF1dpbgVfq4hkfNEJ4qSA== 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=wPjeBxb+ew4Xd2fCubeWomDt2iH+QIgIHE7dfxL/JZZywOiY1Fp2G7bCXaErV21N3BiRrwNW17iHH0+P9/wlhSRoqEmxTA2bEopVSMWjEB602s3KODjtLbPwhD1b2229UawlsgIahhZ/QGuM5K4ZkObdhKUdYS20wnCPOAZh6YGZVCEYaeREpRpU69RQHxsaZdx0YudbDaBtalzj3Knywo87nemYnvlppcQ8UbiL5UMvC/7tnoPOrGjmRTnr/6ldmPr5mfek02WIDfFdC9Rd2vJfTywxjBCiJFe+CeYWaXZ4997d9JhbmM19RvRiSu9xow+fVdS7DbmdS1fSKet59g== Received: from DU2P250CA0030.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:231::35) by DB9PR07MB9713.eurprd07.prod.outlook.com (2603:10a6:10:4ef::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.18; Thu, 19 Sep 2024 19:40:43 +0000 Received: from DB1PEPF00039233.eurprd03.prod.outlook.com (2603:10a6:10:231:cafe::12) by DU2P250CA0030.outlook.office365.com (2603:10a6:10:231::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.30 via Frontend Transport; Thu, 19 Sep 2024 19:40:43 +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 DB1PEPF00039233.mail.protection.outlook.com (10.167.8.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Thu, 19 Sep 2024 19:40:43 +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; Thu, 19 Sep 2024 21:40:41 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 9AD741C006D; Thu, 19 Sep 2024 21:40:41 +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 v10 4/7] eal: add unit tests for bit operations Date: Thu, 19 Sep 2024 21:31:21 +0200 Message-ID: <20240919193124.737943-5-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240919193124.737943-1-mattias.ronnblom@ericsson.com> References: <20240918090445.725283-2-mattias.ronnblom@ericsson.com> <20240919193124.737943-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: DB1PEPF00039233:EE_|DB9PR07MB9713:EE_ X-MS-Office365-Filtering-Correlation-Id: a344fef6-a6c2-404f-091a-08dcd8e2f32c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|82310400026|376014|36860700013; X-Microsoft-Antispam-Message-Info: =?utf-8?B?TDRuM2gyRDcxMmhRUVRvZmVzYVBYVzdXU2NoRVNDRHNabUZlTk0xcnpLREhl?= =?utf-8?B?cExKMFp1SUN2NzdRQUJnSUdqSUtOVUZFSTJpN0dOTXJCRmoxRlpUYnV2MVBO?= =?utf-8?B?dFZOblM0NC9JUms2cDBnZ1VoMU5IUi9sYnJsekJTaWtPbnBjZzhxQUMvdUds?= =?utf-8?B?NldsYTlSRkJCc1FtN2JiWklQRW0zQkU0cXVKL1RWY0VObVUyeC85RS9qRGF3?= =?utf-8?B?Z2xrR3QxSk00c0FtUGYzRmhHb0hIRUdubUExa1hxa0REZDFwRFNqUUJqa293?= =?utf-8?B?enZjVlNEK043L3Jmc2JqcTQzbEx0aXZhU3BncHlGSjhVcCtLRnVKaDRLK1Nl?= =?utf-8?B?dzloanBPN0JxRTFibkJ1Vm5HZHdPWkNyRUxjNGNNVnlzemVxSy9XNUx1MkE1?= =?utf-8?B?MkxQVENJK1pIUkNqclE2QVhVMlZlWDgyYzNnVE5aR2dsL2orR1NrLzg0QjY3?= =?utf-8?B?bm1vUE9ESjRIQTdqUHNNMnlMUkdRNVhWKy9ONVdUMFpNQ0t5M0FhdEc4QVIx?= =?utf-8?B?MHJ6amF1eDkvT2dwckpLTnVqTmFqcUZNUC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ZTd2tWR2lHeWhjNHpvUlpFV01UN0Y3aWs3WjlrYmFKQ3F4R3NK?= =?utf-8?B?RnZSak1SVllRbWFrQWZjRW41Qld2bWV6ZlVkNmlKS0ZxMDRzWDhxd1JIdkNI?= =?utf-8?B?TGVmdnpGVFp4azZYK2ZLemFvRWZvWVNKOUV2OWR2cW1BaTkvbGdBUDNNVFpz?= =?utf-8?B?cEppT21iU29jSmNkS0gweVBYYWdwcCswdzkyY2IrY1lRSkF2aXp5cjdVOTdY?= =?utf-8?B?clpieWhsODc4V1RVUHRNOHM2emxqQ29pRFc2V3dETVVpbCtYMWtUU1VkUkF0?= =?utf-8?B?TFlYblh6TENLRGUyWDQ5UWdFSXZ6REhINHI3L2M2S0d4dXlRWkdCUnFEa3Fp?= =?utf-8?Q?iRauKwtgHwKQHnnWH2NvYaOupoRSBEHf2u5eg=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)(1800799024)(82310400026)(376014)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2024 19:40:43.2944 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a344fef6-a6c2-404f-091a-08dcd8e2f32c 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: DB1PEPF00039233.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR07MB9713 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