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 9D41C43F54; Tue, 30 Apr 2024 14:18:40 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CD974402BF; Tue, 30 Apr 2024 14:18:35 +0200 (CEST) Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2080.outbound.protection.outlook.com [40.107.8.80]) by mails.dpdk.org (Postfix) with ESMTP id 1457D400EF for ; Tue, 30 Apr 2024 14:18:34 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hL/8cZ/o7dtJsiwFi7aAo4IhGWf7Umo2RcuMhU0iQO3jhGB5i1GovLQRtKFeNLlc47p5p/gr8tvJIcIO3V6noDTR9k87b6v5kZJ3H+0e6DfnL41Q8Tqj/A/A3IDBoHa42a+Vl3cu5LMvmtO7K9Fojy2VGxfRabr/IrCabp1f1bAkhIVZuqJRkMV773A0UP+OH0lAmIJKfC6CeyK/uSBbBkLTacVBUSt6ENUpZetqZweUpBS2IFlxzrun+BZ2WgGP/fMozExEiUW+a3cMKXDF/sg0gbtWTARJ959o91FX8PCDogG3UHo78gg0EwOY8yKkJkZ5BnCtAEFv4a7Dtqk4Gw== 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=AKLCj0QO2OfLYDg+BOGI4tq2nFpH6aDvVED+L9/ETChoVv6QES+Bae/KRzR8EyJz/8EDmJ7+mtizwnDt7HovAB/YQUT3xBqYKTfha6j9CTzc7WasqT8s3SbXYfubAAae2SLgzHfiGhgh4QmLzolRIhrT9rt7E7SB/plB7M+0ALR82vI+iUXKGXLnZkZB93w/S8+VeHjUYgtpXrjdmqvY9Ot6CKnOjM87lBXjnon3Jpmvh6aujkz67Uu52ZJz9tkHgzNwrqg/MhYE+MiG9C6O//IhvBnJTVD2C8CBpAPV+5ia85AxXAVBDyrZYWrJ9a/AQE1cpVRUQW++hd3yjfZ71Q== 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=Eue3ToxeOcMcNJMz6wqA/b9fJ+GqoLTYSwHTE5xpUDsKxZhvl8hJLTddJcCW3/68FQgPQlfTe6TRvPQBlbaWZLS89umUg/HyBcCXeeQ9lKMhaZyOs5dEt9FF8BNmuUuG6/MUQQV+V8wqZJpfwfC0/F/JsWCBltDt/X7y0z26nB9S81vL1JuORS21bIqPq4FlG/mLEiuuPQVrk8WggWeL3HG1DxrsPFSPs8EJDcEINnn7wPJDwi6lFsyEeOeeBiMm1HvFZqdHDFXEjdnwRaeev++flPL3tN4DpUyVzuLpUm+x3v4wVZzuADMv/aqIr9PcZMaxN665do5hUI4YVaU+dQ== Received: from DB7PR05CA0040.eurprd05.prod.outlook.com (2603:10a6:10:2e::17) by PA4PR07MB7263.eurprd07.prod.outlook.com (2603:10a6:102:d0::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.36; Tue, 30 Apr 2024 12:18:32 +0000 Received: from DU2PEPF00028D08.eurprd03.prod.outlook.com (2603:10a6:10:2e:cafe::6a) by DB7PR05CA0040.outlook.office365.com (2603:10a6:10:2e::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.34 via Frontend Transport; Tue, 30 Apr 2024 12:18:32 +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 DU2PEPF00028D08.mail.protection.outlook.com (10.167.242.168) 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 12:18:32 +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.9; Tue, 30 Apr 2024 14:18:31 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id B6756380061; Tue, 30 Apr 2024 14:18:31 +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 v5 2/6] eal: add unit tests for bit operations Date: Tue, 30 Apr 2024 14:08:06 +0200 Message-ID: <20240430120810.108928-3-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240430120810.108928-1-mattias.ronnblom@ericsson.com> References: <20240430095523.108688-2-mattias.ronnblom@ericsson.com> <20240430120810.108928-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: DU2PEPF00028D08:EE_|PA4PR07MB7263:EE_ X-MS-Office365-Filtering-Correlation-Id: 87ff3429-9400-482f-942b-08dc690fa6d7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|1800799015|82310400014|376005|36860700004; X-Microsoft-Antispam-Message-Info: =?utf-8?B?TjJLSmI2UDBxdm9VV3dsUVhRSTRIV1YzQ3VGSzhTWDU4alFTaTM2MEdhTXgw?= =?utf-8?B?d3pwWXJ4bkJVMDBFR2I5bjV6MDFETlVZR000dWlmZW9zeVY0QlZvZnhHV1hj?= =?utf-8?B?c2tnbTh2OUE3QVdnVkMweHc5RVNLcngwdS9BZTFJc1MrODI4ejJsc0loU0hN?= =?utf-8?B?ekxJQ0xUSms3ZkxFMzVRT0w3aU03QUxRWU1MbStFTTNXa1l4OUQyMjQvcVJQ?= =?utf-8?B?RUkySzB2cGU0TlVPc1hnWU9Jbk9IenRueXdDY3huUjF4Zm5JZlcvYlZ3ZkUw?= =?utf-8?B?WnBNcHhZbjVneVdJOXZWQ2h0b0JUY2JaeG16VVdJMDI2aEdkY2pVM0ZsL1Y0?= =?utf-8?B?RXljaW1aaGFBNmJ4NWllbUI3VS9nRDV4MlFrY2Q0bXB6TzZxMVVVOWczWjdE?= =?utf-8?B?Nks4ek1EUzBpVk1BMGRDRlczemd5UUdpM3VweDhpZ0k4Umk5RzFpRHlNSFZS?= =?utf-8?B?OU5UeGNEYWJPeXIzSi92SjFsd1IvRzREWGtld2s1Zk0wUnA5ODlvMlZlcHB2?= =?utf-8?B?d0FGc0ZJdk12NWZhMDA2N2liMVE0WlpJOXcvL0xnMGhYcjBqV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5R29zQ3hvSWlLTUdxbUlRY01Bck5DVFhR?= =?utf-8?B?dTkrV25ZS2s3UnRIZ3lQQjA2ZDBKOFVzbjRkTUN4ZmdrU0VBdEJQOWUrOU1L?= =?utf-8?B?NVIxLzlZeUcwYS9VTlpid3ZKdDROWHpxUEpYU0dkdEU0TElZcHBoeHdUc0xC?= =?utf-8?B?MTFscnhxaGIvekgzUFdHUzVUVkp1SS9mNjFLUEV0K0s3TVpmUXEzUC9sSFRt?= =?utf-8?B?R1VFRXhzWFN1Y2xtSGxYcFJ4OVZWcGtzZjVTb1dOSGRJbUdETDY4MXpRRkpN?= =?utf-8?B?WGV1eUIrK1B3QzNsNTlWU0plMzBHbWVyVHJPVmxHK2lJOCtxRTBFZHZPWTJK?= =?utf-8?B?bW0vWlZzSURpanl4eVF1MkxuYmFCTUEvaXk4SnBDNTZqZXZTREZ0VUZoa3kw?= =?utf-8?Q?AYg6B5bKkTzCb?= 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)(1800799015)(82310400014)(376005)(36860700004); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2024 12:18:32.3558 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 87ff3429-9400-482f-942b-08dc690fa6d7 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: DU2PEPF00028D08.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR07MB7263 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