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 55D1C459D7; Fri, 20 Sep 2024 12:57:46 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 54BC343437; Fri, 20 Sep 2024 12:57:22 +0200 (CEST) Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02on2064.outbound.protection.outlook.com [40.107.249.64]) by mails.dpdk.org (Postfix) with ESMTP id 98A9B43417 for ; Fri, 20 Sep 2024 12:57:16 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=e1jQq0cTtq6Y4JF6DMga898lp8y4dNpM8wGfURvTOunD0YFO89RGxN98CFSG4S4yNt/SHCT0ozLPOpeX2WeGe0usaDrMAFP+dnY0/AzivgHcEBYu4EB5+kOk31aSfY3qRDjjY4+1bIjVtvV6y/dkqOlrgIFTsDZxKHLMmRfLi7iR4p4qmnqhpxgKJ+xPIT8BS8QsgEvP4t56660FSJ8P4s4Ha8icpjCy487HRTdR2u7eWAFo9DSCiNymxCRiooRgXO9CPPcZLV829z0eUxcsFQgTfmVra0D1UbmbTVtOpYqBxEcczT+RxdIqqq9syPWlB+iKuEFerqa4CCr7NBOWiA== 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=mrRoHiMDazia8Z90n4c/qDAJOX2xsrUn5w/V60OXedM=; b=ADfzlZep/TuRY/7JBUgTLMowocTuQw7f4+doDcf4mhySJtQ3qBUlt2hXMhrvbvMKriVHpNYvaG2xUAc7FoxKzwtPsrSCcPaTrdks98Zj01syF4BB90H8GH3p7/aXI1PFX7YP7YK/6AVtfBksFuPbMrNqRKDaIPjSjlS33BDYjIRR7vz+ic78SKcq/xUrTpLz4dQayKn6KcPALs6EkEtSigKxeZ2ckH3NOPRVJZGOtk+ywR/l0166V96VvzOSBsik/NF54CrIcxF1wupY0/cjUdrkf6vKequjk6zVhhBK3f0W2maKCh+JPPgj86xpZBaADJj0XR0aQkZ9zq8XgRdU4w== 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=mrRoHiMDazia8Z90n4c/qDAJOX2xsrUn5w/V60OXedM=; b=yIPllOYkoODKzg2kbz8SJxKVhFUxrtAxdjXbZWjit3VfhCFK56L3OIvVIIWkrF1zFqb4NGozYSEOryeWlD2DIpODqVVAW9WFpZtQXUZF7iviXA5UvZwzERsYhpXGItICUNDSCZH794nIK4IZqNs66BqWXvq7GjMbTNcWl6ceDuC4HMuFrr+Ez50GIV9+1w31RNYi4KB1OM42cydFLjKb8nI2v50f2OchuQ77IQUGFtcHCD4wNY7sybVNZxdc/tAoNO7vf51iTy4DrF6scNcK9fDvxauVty04SRxA1zBxNi7Z4EersjDrm2rpEnaGZJNC9VzX6C52pbXuj0lu/wx7sw== Received: from DUZPR01CA0328.eurprd01.prod.exchangelabs.com (2603:10a6:10:4ba::13) by PAWPR07MB9806.eurprd07.prod.outlook.com (2603:10a6:102:380::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.22; Fri, 20 Sep 2024 10:57:12 +0000 Received: from DB1PEPF00039231.eurprd03.prod.outlook.com (2603:10a6:10:4ba:cafe::3b) by DUZPR01CA0328.outlook.office365.com (2603:10a6:10:4ba::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.29 via Frontend Transport; Fri, 20 Sep 2024 10:57:12 +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 DB1PEPF00039231.mail.protection.outlook.com (10.167.8.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Fri, 20 Sep 2024 10:57:12 +0000 Received: from seliicinfr00049.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; Fri, 20 Sep 2024 12:57:11 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id 1C1C338007A; Fri, 20 Sep 2024 12:57:11 +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 v12 4/7] eal: add unit tests for bit operations Date: Fri, 20 Sep 2024 12:47:51 +0200 Message-ID: <20240920104754.739033-5-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240920104754.739033-1-mattias.ronnblom@ericsson.com> References: <20240920062437.738706-2-mattias.ronnblom@ericsson.com> <20240920104754.739033-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: DB1PEPF00039231:EE_|PAWPR07MB9806:EE_ X-MS-Office365-Filtering-Correlation-Id: d12e0016-7bd2-42a8-232a-08dcd962fb17 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?B?ZkRWNWNETExnSmJLZnA4K3NlMjN1Y0VmUmFSbTB0VERhZnE4TmJMbVBOR0w3?= =?utf-8?B?eHFmN3ZURExYLzQ0YXZLLy9MMm4zMUJ4SlMwL01MQ0tnUnNmcURDNEJycGIv?= =?utf-8?B?OUhtcGNXZy91enE3aDlra3VPWGRUZjMya0tSMVAxTEJiRUIxZGpwditDV1pt?= =?utf-8?B?YWVXbXptaGphR1p6bTViSG1OR3lvRkw1aEZhTTJURXN0SDVxZThPdDlLZWZM?= =?utf-8?B?ek5qQkhidzBDL0ZIL1lHZzBFNThEZWNYdUt2TENpd1ZOUmp5ZjFSYUZ2U2JF?= =?utf-8?B?VVFJV0thdEREdENVbWFjdFo3U1IwMURFSGpqTCtYakVHZWpBL0VBbGdCSld5?= =?utf-8?B?eG0vUG1iTmw2Vzg1RUNScm03SG9MZFFBTUVXV3F3b0ZXV1MrRTZCOURzT3M4?= =?utf-8?B?VmFFOWFEUzFyQWdrYk80UGxscTAzK3VBK294V1ViTGpOMVp4aHByTVNUMHNr?= =?utf-8?B?bGExaDVBaUdXRTd2cCt4YXM0Z3hhYXRDYlh5a0wzRmFXcUZsT1F2SXNQZmxx?= =?utf-8?B?Wk9qeEx4c3NiZnNzeGRjYWx3bDdvNDViUlNtVFN1ZGh2NFQvVFN3NHlYdFJQ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R0MENWMHBN?= =?utf-8?B?NHh1MDRQeGRVcUhyRkFobXkxMHRKTjN3bVRlR1RpbFFLajhlWUNBOTY4ekdT?= =?utf-8?B?ZHB1ZnZaTnozaFlhNDE5bVhCWk5mc0h1SFB2WHVuY0NjOWkyR1ExSktOM2ZT?= =?utf-8?B?ZHVjM2pGYXAyeXNEbVBwZHhxcWc0OUNhOHFGMTEydmNlTGVGd1BXd011SW1Y?= =?utf-8?B?WGF4MnhKU2FUdkI4WlpYYStHbnFORllJU05Cc01RKy9wWkM1MUxvQ3N2eUFm?= =?utf-8?B?dERuQlM3aVFnWUl3TWEwOXlHakloOUdsQ2NlMWdGa0VpYlR3NnpleWtHVGZM?= =?utf-8?Q?8t1S9Ma+ZXZYd2YR4HswKh1w3/QlMR8G6kN44=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)(376014)(36860700013)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2024 10:57:12.0356 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d12e0016-7bd2-42a8-232a-08dcd962fb17 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: DB1PEPF00039231.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR07MB9806 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.43.0