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 524A643F49; Mon, 29 Apr 2024 12:02:17 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 110B9402C7; Mon, 29 Apr 2024 12:02:10 +0200 (CEST) Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on2071.outbound.protection.outlook.com [40.107.15.71]) by mails.dpdk.org (Postfix) with ESMTP id D76EC402C9 for ; Mon, 29 Apr 2024 12:02:07 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lzFLinzKzKGaI38egi4VplPfEsVQpqQn7F2v6uDkH/uhRwKfrRmhMEFkM/zNCQ261yfbi9yK5bw5ZYwsvnwIFCbbhxpaQ760ZejY450VpjS8UQhZa7P9XGpz0IJVYJa5si9ZAqSuxkkifJgvfocv6UlEpVV7btkPvTR6yjGgoGVkrDzFBJ4mm9sE0pw411zhlK49fa4SDpJypegTc7f5h+xW0tQaHLcxT42b6W918LldrZKQfBYB5XnyC2Cak3jL2uUUrfBOr8PbigmYCXWyOkpO2BmIqssYOU5kQtcUbE4RVoaDGKwGc12YSVNyDpVFOGy/wcXuAlBCtyZgbRCToQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=UAXttjTnMNYVno4iLY1+608dHrWTK4YyrJUpoliiT/k=; b=Fxrd5z3fLO1KvtcWjh6DD02vXc8MqhHthlhBeALQ+g1D85FsFDLa3Xx2RvQoubmyCym9OAKaq9tieSUXy3Ma3smEGFgmeCX69kbhiikKs2dtVmMaBwg4umyv0jX8lASI2HAn6baUdfUHh6Ub8CZn2J/J/XL4tV4/XDb88FTtlbqDMvSevZIeXKvzO4V4RvVkHPk6uIdDurmQspZrxk8ztZnMKUMX/XXGiPkCfZq0yAGBtRIZaCQNG9qMHZsqcpvgfu1+uaz3plNYGInE+G31TsugP4LiwB4Dcvcbzmtn7gF0y8sitmT+S1gFam6oygsymWyeqwDAbzUUSM1RRx7OdQ== 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=UAXttjTnMNYVno4iLY1+608dHrWTK4YyrJUpoliiT/k=; b=Kc15a8DwnxeGk17KHZ8kiNt5MrzVmTYOkq/y22WpUnMoH33lSmKdlFrWlSQK+BrtDfUwte8/i+7Vrq383Ge4L9V0SVapaISQrUFKVAtQIPeiMOnqBUXfOqYUhJp0s5MdyH20Cte/TGjkFl7oxI3KfjKy+36VLX6kn5cCfrJTHr3OsUGyU/YJm5ILqlhN4O4uP2CtqTGmt8TG0jScPaiohEIJhrY5nD7JiPNv4GEWHZk1LGPKiHr+jmbajsiTpl7qBLwSDefnrWkUURMpK2dmfDYKydgzRiYWUSj+XqZ0MqQgfhKl7I3FULF6L5wUdxfxeuDf0ARAsVTvPpd7B6mKgg== Received: from AM6P194CA0057.EURP194.PROD.OUTLOOK.COM (2603:10a6:209:84::34) by PAXPR07MB8890.eurprd07.prod.outlook.com (2603:10a6:102:249::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.34; Mon, 29 Apr 2024 10:02:06 +0000 Received: from AMS0EPF00000198.eurprd05.prod.outlook.com (2603:10a6:209:84:cafe::f8) by AM6P194CA0057.outlook.office365.com (2603:10a6:209:84::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.34 via Frontend Transport; Mon, 29 Apr 2024 10:02: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 AMS0EPF00000198.mail.protection.outlook.com (10.167.16.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.18 via Frontend Transport; Mon, 29 Apr 2024 10:02:06 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.63) with Microsoft SMTP Server id 15.2.1544.9; Mon, 29 Apr 2024 12:02:05 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 8A3081C006A; Mon, 29 Apr 2024 12:02:05 +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?= , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= Subject: [RFC v3 2/6] eal: add unit tests for bit operations Date: Mon, 29 Apr 2024 11:51:34 +0200 Message-ID: <20240429095138.106849-3-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240429095138.106849-1-mattias.ronnblom@ericsson.com> References: <20240425085853.97888-2-mattias.ronnblom@ericsson.com> <20240429095138.106849-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: AMS0EPF00000198:EE_|PAXPR07MB8890:EE_ X-MS-Office365-Filtering-Correlation-Id: 342fc930-fffe-4b2d-70db-08dc68336cfc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|376005|36860700004|82310400014|1800799015; X-Microsoft-Antispam-Message-Info: =?utf-8?B?dm1VaXZKbDRXeGdKYlJielNtU0xGMUNnZmJWSysrRU9qU1BMSElMbitkayt0?= =?utf-8?B?SFkyQmNUbWVzM0tIQXg2aXR0Ym55OFFRNDAzbUFNdTBNekFEZ3F0eXRkS25H?= =?utf-8?B?cmdSemRBWUcweSs4cXFBM2RrUHhuSjNYa2xvczNDOWNRdXdrN29ZSGVvVEtZ?= =?utf-8?B?c1V6ZlRXT0JHYTJCMUZHWWRISTBDQVhUWkZNa3B0a09xK0dnY3NEbkFwdUR0?= =?utf-8?B?SlNZSm5CTlByQ1NXK2lHeEEvcnZUMGFhb3k0eEo0Zmp3RHBUbllENG9sRHJL?= =?utf-8?B?VlZVOXFONmJXL3p0ZzlKQVhNeDduWUV6VXZyOFRnT25OdHl5cDFIYUZMVVhC?= =?utf-8?B?UVBpeERQVGhmemsvUlVEdlVhSXZkNWUvWnJLZCtIdmVsUHFoQzUwVmpNWEZY?= =?utf-8?B?Ky9IQUgwSmxZRmNLUjRaRnNpMjcxMlNpZVlYb25HSlhiakNTRFpSMlM0Ritq?= =?utf-8?B?ZUo1K09nYUdWT3plWVYyNGlNMUhBNVgzMWNMOTJSUTY3eGM5S3NaSDVWc0F2?= =?utf-8?B?TGlYcEtJR2dIeTVoK21uVW1nUXlqdzU1T0VjNmJpbFpCelRlMjdpZEZ5ckdj?= =?utf-8?B?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T1pBL1A4Uk9zVzll?= =?utf-8?B?SmNxWk43UkZsSDQ0bUhOSmVhcVBwalJlTnZiQTMzdmR5cU1oTkJWOWU1d1d2?= =?utf-8?B?MW1UcHZtajJGZHA3cG01bFpza0ZWdkQzYzZrVkVPamozRFpMYWhmbThTUUVQ?= =?utf-8?B?aHpwYmx6cW56NkpVSHdlbUhGdlQ2eDRmZC9LRklCVzZYUlluSy8rZk82bVc4?= =?utf-8?B?QWlZMklVcEZBK21waTJoSU5oM1N0clB2cytrRmg5SEduakFXN0d6R0JSWktH?= =?utf-8?B?ZUhKUWZicWRUTHdJU2ZHbWR2YmcvL0xEOXZmaFBtNXpGUWw1a3ZXZFZXMHpy?= =?utf-8?B?bzI2aDB4NmdYRmdRT0RwdmNVa2d0QkMxL0RRemhYSE9OdW93NTN3WnI3dFF4?= =?utf-8?Q?QmbFsW7fvzKDr?= 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:(13230031)(376005)(36860700004)(82310400014)(1800799015); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2024 10:02:06.0246 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 342fc930-fffe-4b2d-70db-08dc68336cfc 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: AMS0EPF00000198.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR07MB8890 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_[set|clear|assign|test]() family of functions. The tests are converted to use the test suite runner framework. Signed-off-by: Mattias Rönnblom --- app/test/test_bitops.c | 76 +++++++++++++++++++++++++++++++++--------- 1 file changed, 61 insertions(+), 15 deletions(-) diff --git a/app/test/test_bitops.c b/app/test/test_bitops.c index 0d4ccfb468..f788b561a0 100644 --- a/app/test/test_bitops.c +++ b/app/test/test_bitops.c @@ -1,13 +1,59 @@ /* 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, \ + 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); \ + } \ + \ + 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_access_32, rte_bit_set, rte_bit_clear, \ + rte_bit_assign, rte_bit_test, 32) + +GEN_TEST_BIT_ACCESS(test_bit_access_64, rte_bit_set, rte_bit_clear, \ + rte_bit_assign, rte_bit_test, 64) + +static uint32_t val32; +static uint64_t val64; #define MAX_BITS_32 32 #define MAX_BITS_64 64 @@ -117,22 +163,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_access_32), + TEST_CASE(test_bit_access_64), + 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