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 69DE543F3A; Tue, 30 Apr 2024 12:06:11 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6FEDA402CF; Tue, 30 Apr 2024 12:05:58 +0200 (CEST) Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2084.outbound.protection.outlook.com [40.107.13.84]) by mails.dpdk.org (Postfix) with ESMTP id E02A040262 for ; Tue, 30 Apr 2024 12:05:54 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NefJeH5p2TSlpE35s2E/a/Awi/n1jes2aob99cUKn0k3Zf34o840tOPgpz2PX+Kn97hKypmjDt+neh3DAh1nD7K/Ywofu0MtRC24q0veRmVtxZsdnoBa+/0Ne20IDOdaEFOFWBskMFgzSAl37JcU+uTbSnWX/gDuUZSMyKDslvGthaOQX9O+TmsFDvTbe2gDV5kcfgMDbTUAP3K5GS1bGrigiD8ISaRkx89Kh6SohAIP56yWZolLNzw47DOtrrsF2KT0Xjs9HhfqFxd6sV60bJbBf+RLmE7HnHI+4S5NoujBTr2xMSL763xhKq3saK/dsdWasXOAOU6ZNItRTYLGpg== 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=70JPJO0XF4kc1nFz9IBwmvdNoabAvqTSzlYxlf9/jws=; b=FCE1heg2vXZKTOt41f0DIbSO53pfSwNMlca85i8zMurcdymzg3aB/cznCQW2vfMjQNzfkm39+3Oc8QF44u1f1CrGEDhtgQLwkK47e73eBBTeOaIXiwzE3d6kiNayeL9NFssHJvEKNyUzfReUWWSQowC47DgDFLmHArpZqa4rVTAz+fCp5anW0XB918EiCj3nCqokCKKhTCS/LdOoOzf9bpijz9lHvpTYZ5kinW6hKvm3H1mVzssYyv6S6MNSsj+oHJFO8Eq2TOdbkAuxn7gyEx0dXowbu01/NXCeemInvqqI5WZbANpgLxE35MeD4hqCNuXGPas7Zsga7cdtCy9elA== 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=70JPJO0XF4kc1nFz9IBwmvdNoabAvqTSzlYxlf9/jws=; b=w1F8d4l0QFhhDncrm2KvWlBq07sRYjU1Bk1Kl9YelAsQwSWMhdBpNM7oyHN3Kk2/fIbUxT/JCVTsCK3CTvwE2f0+F54XQjhP8r8lm807HuXkiPQz+takgqLfZ6DlAdKJnM3AZ2IXbHkKcUncAZ15mC84LRGu9vbBzTUyNb1X+MnWMq92DfmDXVKgHERlB0OmtwYib2pl3gGPEg3nM3C2RtpDe4dNa8OSS0R8pRKAns5H4acHUCWSHyzIPtxtA65ygxYXQAn0L+W40onPtbBCQZmIZPI/g34FSvZoE53oPAPw5Ktgm5KQtMwGLfAG+DwzYonWVGZRi0esNKun1yomGg== Received: from DUZP191CA0043.EURP191.PROD.OUTLOOK.COM (2603:10a6:10:4f8::26) by DU2PR07MB8347.eurprd07.prod.outlook.com (2603:10a6:10:2e6::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.34; Tue, 30 Apr 2024 10:05:53 +0000 Received: from DB1PEPF000509F6.eurprd02.prod.outlook.com (2603:10a6:10:4f8:cafe::8) by DUZP191CA0043.outlook.office365.com (2603:10a6:10:4f8::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.36 via Frontend Transport; Tue, 30 Apr 2024 10:05:53 +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 DB1PEPF000509F6.mail.protection.outlook.com (10.167.242.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.18 via Frontend Transport; Tue, 30 Apr 2024 10:05:53 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.66) with Microsoft SMTP Server id 15.2.1544.9; Tue, 30 Apr 2024 12:05:52 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 94E351C006A; Tue, 30 Apr 2024 12:05:52 +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 v4 2/6] eal: add unit tests for bit operations Date: Tue, 30 Apr 2024 11:55:19 +0200 Message-ID: <20240430095523.108688-3-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240430095523.108688-1-mattias.ronnblom@ericsson.com> References: <20240429095138.106849-2-mattias.ronnblom@ericsson.com> <20240430095523.108688-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: DB1PEPF000509F6:EE_|DU2PR07MB8347:EE_ X-MS-Office365-Filtering-Correlation-Id: 2c23b9a0-0898-4c91-0f94-08dc68fd1ecd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|376005|82310400014|1800799015|36860700004; X-Microsoft-Antispam-Message-Info: =?utf-8?B?angvRU4rRG0zZ2R6aWhVU3h1OW9laXRrZFk0eEs5Q1JyeW16cDFPNmIvRFdv?= =?utf-8?B?NFhWQVEwNHNBa0RmZGNyYkU5a2ZZS3dwMWpGSzVQK0ZxNTNneTF3dGg2Z1JG?= =?utf-8?B?SThiNSs2Q29KdmxQRzVBa0J3MXdnUXZ2a2FaMmRIWnN6bVYvbXlGZG1tZUxu?= =?utf-8?B?VVExSitMWHN0TEt5eExkeWdjTjBQbTk2Z25CQndqeEh5RE5tT3VmU2h3MG9T?= =?utf-8?B?bkNCQlFLTFhGWVBtYWJHK0dtRnIxdGliYk4xb2FDUmNCb1ZZS0RMekZybmsz?= =?utf-8?B?QnZ0NDB3ZkFKcWJ2WHM3SlZPN3dCeGhHazRzYlJkRVo1MTZ4cHVDNHFoaUVO?= =?utf-8?B?TndNSXM3ejBqM2ptTUdqdi9vTmZaSC92c3RONmpVQnp5ejRPeGx3cW5uMml3?= =?utf-8?B?QjV1c1JmOCtLbXRqOEtnN0Q4d0FJWHpNYXlkOEtLUVlKeksyT0VVck9tNVZM?= =?utf-8?B?bmhOakZpYjJSN0FieXZFQy9HN1JxdnJSNnVORERManZ2ckVPZFJiZXN2Skho?= =?utf-8?B?cjd1ZUs5a1JKMHlSYm4xR3FxenpOZmY5cnJFcFUydzlvamRMN3dFR1BkTi9q?= =?utf-8?B?cW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?= =?utf-8?B?dlZMYWVCZDZxb29rcWlEUVM4QlJIbXBGeGxId3NtWDRSWm5hcWpDY1BCcWZh?= =?utf-8?B?MGtBR1QxK1lCenlwcm4rc0hRQmtRQURsUTZEUDVWQ2Q2QkszSWdUdmxHMnp6?= =?utf-8?B?QnNzMDFXSDJqU0MvQldtcDVhS0I1Y3gyWmhsUFVFS2VYRGFVQ1oxSUpWYk9o?= =?utf-8?B?TTNOd3FEemtXUFdiejlQaUxOQXhudW52K0lWdUROakRiaXpXQW16UjVmKyt3?= =?utf-8?B?UDh3YjdXV2x2eGRlWWVJZ2VuVTlzb2tPNWMwUDBkNm5CSXZ2MXdTNy9KTGlN?= =?utf-8?B?R2dna2lJUGk3VTQ4QnlZZzVPNU8wZ1c0SjVqNGc3WnB5V0hLNlFFYnA1M1V3?= =?utf-8?Q?0EW/zv7QcOFNf?= 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)(82310400014)(1800799015)(36860700004); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2024 10:05:53.1756 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2c23b9a0-0898-4c91-0f94-08dc68fd1ecd 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: DB1PEPF000509F6.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR07MB8347 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. RFC v4: * Remove redundant line continuations. Signed-off-by: Mattias Rönnblom Acked-by: Morten Brørup Acked-by: Tyler Retzlaff --- app/test/test_bitops.c | 80 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 65 insertions(+), 15 deletions(-) diff --git a/app/test/test_bitops.c b/app/test/test_bitops.c index 0d4ccfb468..111f9b328e 100644 --- a/app/test/test_bitops.c +++ b/app/test/test_bitops.c @@ -1,13 +1,63 @@ /* 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); \ + } \ + \ + 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 +167,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