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 DE56C43F04; Thu, 25 Apr 2024 11:10:05 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2998E436CC; Thu, 25 Apr 2024 11:10:02 +0200 (CEST) Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2085.outbound.protection.outlook.com [40.107.13.85]) by mails.dpdk.org (Postfix) with ESMTP id 1F63C436BF for ; Thu, 25 Apr 2024 11:10:00 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LOYSmHajmF45uwZwYYcEp0jKFqCu2PYPU1yydKSXGQz2NlAlaESu8+InoVJvseY/+2hOBengEK/JaRA7PbUrtObOKsoYCt9NI9F9DxGZOT4FyORpFCdco5dG2jsYEfCHUqMPXGSnXqSapGhegnoev1Vr7RoeIsy2bluJcFVSiqdS4NtRdj/oiVAGjr/C3zRXS1Vyn27ttxreQSvHETQI67pisgaw28jX8qDQ0/Ur5POb9ku4JSlptFqkx4EVmd6KXz4M+7oHzIGgcmfR8cF4ng1vGbIUQA9iRkLe7ILzj3AiBvuybB0P4PEkrVPCAAGHNi5lIWUdcnWZrrq1o/HOvQ== 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=BatapY27STw0FuKEsmj8YsDyl0yPZ5d6HKpOdST21Lx9TzE7AdROOZ42S5vem3eD5ihPuDG2ZKofZKlYwOucORGi01OHDQBmsp32UpzTKO3+vtpxXkxupFrEWDwIpYS5y3AeOzLophZHg9xkbjLvKFHqT4Dj3OhsHYQ77XVB/4yuwhtRiBdyupxgkEGF2KQcZN56DFbR3rH+fqulzu+IVn38Evm0CdYtrHJbyTeuYGiPXSHuZs7mV1BQmHi5JE2dlr3UpNVGa3kOIHZGZ/IE7cwGA7qr7C/iIgYhugdZe/UzV9OzKHcnKqzp+NmPm7TQXvttIq4ksm0Xk4HsEpWHOQ== 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=akb05kjnqKlI+48wBC28d7hFChjSSoVte2mLzFIP3OgNEjxX2GhEu/fVauHtaK6j1Her5kX0ZcLsIgLgw8jm+2Ma0sACkbmiCRphQpJyuqBl0fdUVmv4EHb9MgFZ40t1IFui/XDn99pCedrJVBe+DO4j19K/gXxVFiQxI+lSABh4GwGqr/8mIkz6EraprR0bKtX1XRBVjfmYpIo6pcX39Yksm2DHm8aoocrun6B7h25jU9Nt+VWfdnP58Bh80gmGY9+E1uEwnBwg8U/nCr6RmqjRAQwDuPCsKq6qdfKDD1A/Ftg1ATkW48dmI7RI7oT4Sw2Dr4p4k4e/JU7szabziw== Received: from DUZP191CA0048.EURP191.PROD.OUTLOOK.COM (2603:10a6:10:4f8::8) by DBBPR07MB7420.eurprd07.prod.outlook.com (2603:10a6:10:1e4::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.22; Thu, 25 Apr 2024 09:09:58 +0000 Received: from DU2PEPF0001E9C2.eurprd03.prod.outlook.com (2603:10a6:10:4f8:cafe::70) by DUZP191CA0048.outlook.office365.com (2603:10a6:10:4f8::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.25 via Frontend Transport; Thu, 25 Apr 2024 09:09:58 +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 DU2PEPF0001E9C2.mail.protection.outlook.com (10.167.8.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.19 via Frontend Transport; Thu, 25 Apr 2024 09:09:58 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.65) with Microsoft SMTP Server id 15.2.1258.12; Thu, 25 Apr 2024 11:09:57 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 18A3A1C006A; Thu, 25 Apr 2024 11:09:57 +0200 (CEST) From: =?UTF-8?q?Mattias=20R=C3=B6nnblom?= To: CC: , Heng Wang , "Stephen Hemminger" , Tyler Retzlaff , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= Subject: [RFC v2 2/6] eal: add unit tests for bit operations Date: Thu, 25 Apr 2024 10:58:49 +0200 Message-ID: <20240425085853.97888-3-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240425085853.97888-1-mattias.ronnblom@ericsson.com> References: <20240302135328.531940-2-mattias.ronnblom@ericsson.com> <20240425085853.97888-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: DU2PEPF0001E9C2:EE_|DBBPR07MB7420:EE_ X-MS-Office365-Filtering-Correlation-Id: 0f24ff4f-f1da-444b-1a40-08dc65077b1a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|36860700004|82310400014|376005|1800799015; X-Microsoft-Antispam-Message-Info: =?utf-8?B?eGJ6L1FUaXRaZGJUYjlvbkZ1d3M5YzluZHNmVzlBV0xqR2s3NE9jWFZybHVn?= =?utf-8?B?NS9tbGVvaElMRG9pUUxYanlJTkRVMGIrY20yR3orQUtBMHgzK1pmWldqYkNx?= =?utf-8?B?a3doZi9LZ2VqYVdsMXBiRnQ0MnV3SkVnK2crNFQrbVh4eHkwdW9PTWNicndN?= =?utf-8?B?OFpSKytBMUt0WEtmcys1N2ZhclZHTjRiVTg0S2tQdE1xZmhUMVVES1BsaXA1?= =?utf-8?B?Y2tBREJ0elZNTzV0QWZrVWF5ZGNGQVFlS2tEUW5lc2NIQTFaY0hndnJsWnpq?= =?utf-8?B?Z0g3djN2SDVITmRVMGl5aUxWamlkcHhzSy90Mk54L1NBNWdDVUN6dmRySzRn?= =?utf-8?B?OHFya2k5dDhRT0JWSzRvcGdJWktQSUhiR09QUXNBb0lzNklFaTFTRzFYWk9R?= =?utf-8?B?QjZldDJjdkRlRTFnVmR0Tk5UTi8yOEhzeTlQTFF2TkZzbDlQWXN1d0c4ZGxU?= =?utf-8?B?L0psaWYvbi9EMDR2V2I0Ym1OMzVnQTIzeTV4UjlIY1E5a0kvN3pQYW1EOG5Y?= =?utf-8?B?eThveGZZcUdjVmNtTlhINnBRaU9oTWMxV0FBTUVQT2ZZR0N4RjFaT21yekFh?= =?utf-8?B?byt1Z0xtdzJMQU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?utf-8?B?WHhaTmMrMHdZbVR1UW42b1BjVG1HZUV2RWNVb0R1a2lNZTZOVlhBa2hQQUM1?= =?utf-8?B?QXB0RnVhL0xYNGZSQXJrcjdQWjh6RVVNbUpXU0VjYjhNVTdUVjlZcVhFVUxX?= =?utf-8?B?NHprWVVoYWxwNzJ3eDNVZ2JkdExZYk1QUHRlYmFWR3hwSnJiSHJPRHJWU05G?= =?utf-8?B?SFhBNTBnUDJNQ2xSYWZPcnJVbDFheHZIelhrVmhPNHBhNzRlQTh6dE5HWkN4?= =?utf-8?B?TlJoSnhqODlWNjZlUEw5KzFIQWQrSGFXdmw5L1VVSjNOVU5RQ3FHUTZjSjBh?= =?utf-8?B?SnZPTnpralM5NFFxRjZVbjNEa1o5WlRoaUxlWWFYbWtMS1JvSGtGZEdYZlJp?= =?utf-8?Q?7JOR+d98kYAeF?= 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)(36860700004)(82310400014)(376005)(1800799015); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Apr 2024 09:09:58.3471 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0f24ff4f-f1da-444b-1a40-08dc65077b1a 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: DU2PEPF0001E9C2.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR07MB7420 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