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 D51B143FAE; Sun, 5 May 2024 10:48:15 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9183D402EF; Sun, 5 May 2024 10:48:03 +0200 (CEST) Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2043.outbound.protection.outlook.com [40.107.6.43]) by mails.dpdk.org (Postfix) with ESMTP id 88AAD4025D for ; Sun, 5 May 2024 10:47:59 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CLwfoVz2j00zzT0fwWjk4EB27Xju7NbgYRBKQraoii1POE2jPGD+AohT5IZRlPsSKj5NTPcxK81vDCxLZkkSp6sasJ6lT93jBP+B38RGrDupOiqT0cW2CnZZ07+hTwXfOyC8ekatQsYkhBaEHaOPR1UtHeGeNFkM89loM0g9Gisi+FRbUxVWbEuB3xBoYYGoTpNmKW7LT+OcIWghUz7ciJS1/yIz2qVw6CE7PJi9UcBVFUENyZ4kbwIxzmSaHudjMGbUSbnF/NARkMPE3TyCZ+UqqGcXdEfkk5DgybkiAi9oYR1OxCS7RTq3bNQrDi300NUsArGroP0K0sNAKACo9A== 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=d8z68B8fzU8h0PRajH8DnhYus8GmVFVNaHI8wvhWqbw=; b=iscgQAO6bLJyxRjf1AG7CVdFENOtSByCeWMvuFDyxsOLmFBSgF5endm1r57q1cZAZvGC16BUPTA1NAfeIBrPcJHOm0dzjnAB3QzOuq6O54k5/E2oHeuFsIxBgmCpCg+OKyv93DFED/m1iZIhhUy1oWl03p90pryS1tjRflqhvSdvEgNiET2p7Uc4uoi7eRz4kYCzlhcs8LKx7WRB3qhyj0Wnhz0XvlNg0poxphaidwGY/tmxutmio7Tfzp3J6n+f8RDMrRLT2jrLoHk6Qidoxk4IpStf6RTgotJ4pyL9ihlQTQ2v39Ge9VwE3/mLBJu1yuIqV68UvYKKmpdpyKl03A== 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=d8z68B8fzU8h0PRajH8DnhYus8GmVFVNaHI8wvhWqbw=; b=YtY0hpTF3XyUXvweruLbBht1drIbDfJQE1tIpZppIhHFS3XVsgETc05Syr06CcS+WiswoLtXJ116wr34lIZxQErnjJJDb1Kt5IdvI6nfqANEr24spUCAYIlob89iBgUJAfqNsNLcjI+ywi+T8S/0RkOgttOWLF8iqS2F2sYBEiG3J3lPkS8oZG8A41Wt8UYL6U1mlL82eBmDipsjLglE20kWB1LUXMum0zKZkutI3bKvuV0pSjddoKN/mMO/nmHAtQ24VDzoywkKxm104NYFtNK4eHXgsy0L2+uVcNksx3d36wcZDZuQOpI4g1hmOaVxwmcx9+kRHe5mqw6jwaiszQ== Received: from DB7PR05CA0058.eurprd05.prod.outlook.com (2603:10a6:10:2e::35) by DUZPR07MB9815.eurprd07.prod.outlook.com (2603:10a6:10:4d8::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.39; Sun, 5 May 2024 08:47:57 +0000 Received: from DU2PEPF0001E9C1.eurprd03.prod.outlook.com (2603:10a6:10:2e:cafe::ba) by DB7PR05CA0058.outlook.office365.com (2603:10a6:10:2e::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.40 via Frontend Transport; Sun, 5 May 2024 08:47:57 +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 DU2PEPF0001E9C1.mail.protection.outlook.com (10.167.8.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.19 via Frontend Transport; Sun, 5 May 2024 08:47:57 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.64) with Microsoft SMTP Server id 15.2.1544.9; Sun, 5 May 2024 10:47:57 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id F092C38007A; Sun, 5 May 2024 10:47:56 +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 v7 2/6] eal: add unit tests for bit operations Date: Sun, 5 May 2024 10:37:33 +0200 Message-ID: <20240505083737.118649-3-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240505083737.118649-1-mattias.ronnblom@ericsson.com> References: <20240502055706.112443-2-mattias.ronnblom@ericsson.com> <20240505083737.118649-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: DU2PEPF0001E9C1:EE_|DUZPR07MB9815:EE_ X-MS-Office365-Filtering-Correlation-Id: cb861e23-09c7-4ecf-fb7a-08dc6ce00fed X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|82310400017|36860700004|1800799015|376005; X-Microsoft-Antispam-Message-Info: =?utf-8?B?MmYrUW1HOE1vUnVibUxKSEVEd1loVHBsRThpSCtBYnJWNUlTRkN0OWNuQndD?= =?utf-8?B?TWMxT0JTSVVuZjBJUEVJVkFoZnV3V3Fmam84ZlUzSHo4N3BZQlNkazhhcTJN?= =?utf-8?B?RncwdjNNY0JpMmpLdU05OTd5anVyQ0F2ZnkyMnhSZmpxN3ZXYTliVjExZk9a?= =?utf-8?B?V01oR3R4Tmk4V1pucUdyLytuZkYzc21sa0pza0thTGp4UmFKc05zVG9SNWVz?= =?utf-8?B?MWtjL0JLS3FJV2lnTlpsdmxyRVRGZGhHNy9zYVVDMndLN3JBNk0wSDRFRUFH?= =?utf-8?B?ejJHYU5ZUU40MWlpM2t3ZGlHSDlkTHVqakdKWktNQlhSaG8rUTBFWFNGYTNz?= =?utf-8?B?ak00ZEhCb082YmpJZzBUbVpVWXYwOXlDWm1ZaEJPTGdjbERHd0t1RGJuOXRC?= =?utf-8?B?OXhzcXJjNkxxMDBCY3NOejFSakM4RHdyUnZFSm9pbkp6dFNYcSszSE56Rk5Z?= =?utf-8?B?TlJTNktpTS9QeWpNckRjTEdCQkxoRHBUcThsUUo3MDE0RkYyQVpnWFRGRU1w?= =?utf-8?B?TkI2ak9TQVhjaG11a1dJVjJsZnFHT0pPSmFrZEhvV0NLSkJHZ0cvY1d2R0Ew?= =?utf-8?B?cFpSbUlrTVZSOTR4UnpRWnB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?QVEwdDZxa0MxRHpPaS9JSzRQVExLZ2ZvU0YvbGFOQ1A4eEtGdmVqS0c2c0lR?= =?utf-8?B?Rnd2YXFzenJ6QjRIa2FhWWRUWndYelcvakg4MWk2TjVmQUhWYUVTaUI3ZTNn?= =?utf-8?B?ZzFZVlZzaGJDQ0gybWhvL3U4NjVXSjlPVFFFNWhVdXlJbVpxcnowNVJVMzZq?= =?utf-8?B?bjFsRUFoRHV6NlJMaERlR0E5OGs5L1did3pVOTk2Zno3SmRTRU5BVnhCOVBi?= =?utf-8?B?NklpRGZINnNMVWxGTmQzKzNXM1U4VmxQMC9LbjRhd2VGRXJ0M2tYMUhYby9U?= =?utf-8?Q?Sn0GIeCXO9CWMd+4W34P+l6XUwL5OPxmzqYrM=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:(13230031)(82310400017)(36860700004)(1800799015)(376005); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2024 08:47:57.4715 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cb861e23-09c7-4ecf-fb7a-08dc6ce00fed 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: DU2PEPF0001E9C1.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DUZPR07MB9815 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. RFC v6: * Test rte_bit_*test() usage through const pointers. 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 | 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.34.1