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 9A0A143FAE; Sun, 5 May 2024 10:48:42 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 030E940685; Sun, 5 May 2024 10:48:09 +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 EB7A2402E7 for ; Sun, 5 May 2024 10:48:01 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V6eP1NvJlxAW9/h5to43iwkvXc5FwCJIdmqL6dxYi08vtF+0rLQIP92LxXgaycBeu9I2SiHRIReDf2h1zPGIEdq6GYonMt4dLA9SKDNasAP7Oh3Fv94U0Ced3KC5eJroQwqQAPrt0Txu/Yxq+sbViTpd0lf2pDauhJEzHZz98q4J5TcW3g+yzek+5gtOvvTCn9TIIElXSQ6FLxFzqKfcOGoU/ExJedCt219yNz3LNPygpGkDwdJ32eyq5HiaSraEU0NiMiRIH5R9ENTByCDDCxUWnF3FNOkYAs7xdiYg8J+e/5x8eKICMU8JBsaKhqagcLlEWWGoe1W8KWXd7kqfSQ== 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=9OUelsYpMkkuM3XvGHV53aJb4v8YWs53DjmkXfumHoc=; b=A+gbuZs4Sw/U4l9ILTJ1HYElyriZ07mqsVo2PN+FwIBbcIhY+db2HSvJyfNsnOBaVGWBRXMauKZEatrvVGmKYKFnvh3qZjJLIdapr8R/AG2BnTJxEbzugqucJFoo38HAN/5i6yEpccJCEjoELPuUoRX4JC0p55u2qp30aH3uWLlRU7DdSWYi228nIIiSLjEDir2wfu8WhQeIyj/vCwckoSYXUChQKUVMl5hSJV3EDmujQGmE1w2zSCvKZSsbKBhBKzTwEK+jL5afYkBnjjTFWPZsuyAFXuhjp/fQzpNLBo5qgQTtTv1jvYo79KmfHHu5a/RiMzW3hdbNQ3pZ3uDsrg== 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=9OUelsYpMkkuM3XvGHV53aJb4v8YWs53DjmkXfumHoc=; b=s0lgSk171Nc4RWDWE8H0gi4nMrep/7cfBozUSOO4UznmNFTH0wN2z8ZOjdj2/b6V/7NeuHbzKDblrQ+DhinSPChTrjDHyv1V5oS/WlPQtt57XXlIQKAw5DOhWgX+tgJuv7aBmjM1t96nNXJIY2HjKsuL8O1B5RbjF3mpjvR42xz/F1fPDPX/eIrW4hO0gPQeyXc9f5D9c4u/XfT0XBXV/mnHVpLH8l1RXI6r037c3wgY79DWEhXFEIviTadYHPkGR7u095DxrWAtdO/ko5spS2SpynEIHsAIm2NzY+xezZASyvJydslkx0gxLfy5wNT4z7VqoN5NBWyCcAaAUb9bNw== Received: from DB3PR08CA0028.eurprd08.prod.outlook.com (2603:10a6:8::41) by AM7PR07MB7009.eurprd07.prod.outlook.com (2603:10a6:20b:1b0::10) 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:48:00 +0000 Received: from DU2PEPF0001E9C4.eurprd03.prod.outlook.com (2603:10a6:8:0:cafe::2b) by DB3PR08CA0028.outlook.office365.com (2603:10a6:8::41) 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:48:00 +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 DU2PEPF0001E9C4.mail.protection.outlook.com (10.167.8.73) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.18 via Frontend Transport; Sun, 5 May 2024 08:47:59 +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:59 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id 220FD38007A; Sun, 5 May 2024 10:47:59 +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 6/6] eal: add unit tests for atomic bit access functions Date: Sun, 5 May 2024 10:37:37 +0200 Message-ID: <20240505083737.118649-7-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: DU2PEPF0001E9C4:EE_|AM7PR07MB7009:EE_ X-MS-Office365-Filtering-Correlation-Id: 3d80fdf8-c30c-45c0-d2db-08dc6ce01143 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?dmtsemNYckk0VUZWR3VHTXlFSTJPRFNkZHFtblNkVUNaRVBVR2hIWkV6emhV?= =?utf-8?B?MG5zbkwyQmFoc2sxZkp0UENiT0M2TUdnTU05RnNiMWNwYlZLdTlzbUhuQ2hM?= =?utf-8?B?RThEd1o1RUdNQWMxOW5TSmNISVV3cm81N3ZIbzFEcUl6eDZxeFRlbDgwMlZ1?= =?utf-8?B?VFpCRWJvZktBUysvME1pS1RmN1QraVpMalltODF5b0o3d3pvWUdhRWY0clJt?= =?utf-8?B?YlUyZGNKaXFGTnZ3VTBWVk1iTTBtVGdOK0REZW1DU2FIbG9ZLzBHYm1aSDcx?= =?utf-8?B?WTcrQkxxQkhIRGRWaE1IVVJublU3VU90QmpSYW5HVUY2RW12RUZFQ2lray9X?= =?utf-8?B?QzZadUdJcTJZWlZDVERRU0JGRXpuajI1S1poZUQzZFhxWTVsMktHZUJKWEFO?= =?utf-8?B?QTVSNkxLaW5lZ24rOU1FTVlvTmVIUDRyemJILzBrMTZqd005Uk1SamRnb3or?= =?utf-8?B?NlBZMWlibjFxZTM2cy9BazJZNDZSNy9iVHo0Q3R3cDdoUjlhZE5FN2JpL0Ja?= =?utf-8?B?WjQzN2JCcE81TEk1RFpNQlVKUHVERjl6Zko2Szgxb1NBbkVYRUs1N2dLLzJR?= =?utf-8?B?T2tUMHdYMkI1OFlMSEVVeTg4Qms0VW9vZWg2YU04WFVzbnVDTFlIY0xQNHQw?= =?utf-8?B?YkhsTU1DbGxUeGFlcEJXUjZZdldyOTZ2d0NzeDk4YVpnbmQwd1VVMVJiQmFS?= =?utf-8?B?czQvcFB4aTVRbFNzVWhWS1hyNU5tRC9oeWV1MWpUNEluSmtrQ1FZSGJpOTBU?= =?utf-8?B?OHRCSm1nTjhKbzVRakJzbGRNdXp2NjNPRi9RUHE5dlNSaC95Qjg0NnVtOGdW?= =?utf-8?B?eFhqZFNHWHRIdk1IMnVmSGFnVTRyR25TMXV4Q2dhRXFINXlwaWpzYkxYWFps?= =?utf-8?B?ZVhKckxTTGFOYWxSaXZXNDFBR3ZpV01nUzRPTEdYYlR3Q0FQMlZuZkN6NHJ5?= =?utf-8?B?bXhZbzI4YTZ6aE1LL1dMN0xkYVlqT3hRV3dkTG9hWTVGa2dXZ0xXTjVLSnVT?= =?utf-8?B?aDBCS3czWDZWMENqUEpUcGFPOHQrVXFnUWhnbWU1Tmd2Rk53eFR2amNtNEw2?= =?utf-8?B?ekhrMWY5SUhnK2kyTlVFUkM1UlBaNFJRMUNuMnlHZG4yZ0xJbC85dTBRb2JK?= =?utf-8?B?Sit0eExnallRa2FWaWVJalVwcjAxSjYzL21yY04yM3FyMmdPZU1va0VLblU5?= =?utf-8?B?RExlUWtKNC81QjNTOVMyQUV6MGNKa0xiR2F4bFhxV3JBd3VsRDE2U1Q5Wncy?= =?utf-8?B?anMvRjYwL2tUSDZ1T1VrSVR0czMrTXM1ZVQxOFQxb0VTdTcweHFydEhIb21L?= =?utf-8?B?SDQrcnN2Vk1MY0Qzd0dJNytrZkhKUW9oQk1va1NYb0dVaHJsZ1o3VGVZR2Nx?= =?utf-8?B?c2l6VGpFZDIzZzlyb1Z5T29aQndLdlRpQkVDaldDamRiU0s1Zm9naHRmQ1U1?= =?utf-8?B?MGJ0cHlDQjNsTFZXTUpBRXllU1VmN0xLdm9jdXFBUnovL3lVd2FKY3g5VEkr?= =?utf-8?B?M2VCcEgzWUZONnlxT24xckdORTdyMUF4Slk1UUJIYWNLNXhYUzFqWmJJQjh3?= =?utf-8?B?UlBWeHZmQ3Z0RmN2NXZQbldUK1JYT0ZPY3RhVlBmWW5kM0VqOVF4NllyYjdO?= =?utf-8?B?bGpsVUZGaEhnaGxjZXpBQmJRcVh3MjBBZFk5SVcvRmxIOW9kR0o4NVNJckRs?= =?utf-8?B?aHZEVDUvaE9VU0FDMVNrdUZOdDIzZk9QL1kvYkU3NDExQ0loN3dRalRiYWln?= =?utf-8?B?Z2dNdHo3N2NEQ0RxODJNRWszRnhMMi95Y1NxRU9zQk4rc0dvZXRCVzl3OUli?= =?utf-8?B?d0F0dGx0M3MyYUxub1RvOVdXd2NyNTFUNXYzWkNVOGRjTE41ZStaemx2UXBv?= =?utf-8?Q?GPKk2jg6K1ind?= 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:59.6961 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3d80fdf8-c30c-45c0-d2db-08dc6ce01143 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: DU2PEPF0001E9C4.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR07MB7009 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_atomic_*() family of functions. RFC v4: * Add atomicity test for atomic bit flip. RFC v3: * Rename variable 'main' to make ICC happy. Signed-off-by: Mattias Rönnblom Acked-by: Morten Brørup Acked-by: Tyler Retzlaff --- app/test/test_bitops.c | 315 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 314 insertions(+), 1 deletion(-) diff --git a/app/test/test_bitops.c b/app/test/test_bitops.c index 9bffc4da14..c86d7e1f77 100644 --- a/app/test/test_bitops.c +++ b/app/test/test_bitops.c @@ -3,10 +3,13 @@ * Copyright(c) 2024 Ericsson AB */ +#include #include -#include #include +#include +#include +#include #include #include "test.h" @@ -69,6 +72,304 @@ GEN_TEST_BIT_ACCESS(test_bit_once_access64, rte_bit_once_set, rte_bit_once_clear, rte_bit_once_assign, rte_bit_once_flip, rte_bit_once_test, 64) +#define bit_atomic_set(addr, nr) \ + rte_bit_atomic_set(addr, nr, rte_memory_order_relaxed) + +#define bit_atomic_clear(addr, nr) \ + rte_bit_atomic_clear(addr, nr, rte_memory_order_relaxed) + +#define bit_atomic_assign(addr, nr, value) \ + rte_bit_atomic_assign(addr, nr, value, rte_memory_order_relaxed) + +#define bit_atomic_flip(addr, nr) \ + rte_bit_atomic_flip(addr, nr, rte_memory_order_relaxed) + +#define bit_atomic_test(addr, nr) \ + rte_bit_atomic_test(addr, nr, rte_memory_order_relaxed) + +GEN_TEST_BIT_ACCESS(test_bit_atomic_access32, bit_atomic_set, + bit_atomic_clear, bit_atomic_assign, + bit_atomic_flip, bit_atomic_test, 32) + +GEN_TEST_BIT_ACCESS(test_bit_atomic_access64, bit_atomic_set, + bit_atomic_clear, bit_atomic_assign, + bit_atomic_flip, bit_atomic_test, 64) + +#define PARALLEL_TEST_RUNTIME 0.25 + +#define GEN_TEST_BIT_PARALLEL_ASSIGN(size) \ + \ + struct parallel_access_lcore ## size \ + { \ + unsigned int bit; \ + uint ## size ##_t *word; \ + bool failed; \ + }; \ + \ + static int \ + run_parallel_assign ## size(void *arg) \ + { \ + struct parallel_access_lcore ## size *lcore = arg; \ + uint64_t deadline = rte_get_timer_cycles() + \ + PARALLEL_TEST_RUNTIME * rte_get_timer_hz(); \ + bool value = false; \ + \ + do { \ + bool new_value = rte_rand() & 1; \ + bool use_test_and_modify = rte_rand() & 1; \ + bool use_assign = rte_rand() & 1; \ + \ + if (rte_bit_atomic_test(lcore->word, lcore->bit, \ + rte_memory_order_relaxed) != value) { \ + lcore->failed = true; \ + break; \ + } \ + \ + if (use_test_and_modify) { \ + bool old_value; \ + if (use_assign) \ + old_value = rte_bit_atomic_test_and_assign( \ + lcore->word, lcore->bit, new_value, \ + rte_memory_order_relaxed); \ + else { \ + old_value = new_value ? \ + rte_bit_atomic_test_and_set( \ + lcore->word, lcore->bit, \ + rte_memory_order_relaxed) : \ + rte_bit_atomic_test_and_clear( \ + lcore->word, lcore->bit, \ + rte_memory_order_relaxed); \ + } \ + if (old_value != value) { \ + lcore->failed = true; \ + break; \ + } \ + } else { \ + if (use_assign) \ + rte_bit_atomic_assign(lcore->word, lcore->bit, \ + new_value, \ + rte_memory_order_relaxed); \ + else { \ + if (new_value) \ + rte_bit_atomic_set( \ + lcore->word, lcore->bit, \ + rte_memory_order_relaxed); \ + else \ + rte_bit_atomic_clear( \ + lcore->word, lcore->bit, \ + rte_memory_order_relaxed); \ + } \ + } \ + \ + value = new_value; \ + } while (rte_get_timer_cycles() < deadline); \ + \ + return 0; \ + } \ + \ + static int \ + test_bit_atomic_parallel_assign ## size(void) \ + { \ + unsigned int worker_lcore_id; \ + uint ## size ## _t word = 0; \ + struct parallel_access_lcore ## size lmain = { \ + .word = &word \ + }; \ + struct parallel_access_lcore ## size lworker = { \ + .word = &word \ + }; \ + \ + if (rte_lcore_count() < 2) { \ + printf("Need multiple cores to run parallel test.\n"); \ + return TEST_SKIPPED; \ + } \ + \ + worker_lcore_id = rte_get_next_lcore(-1, 1, 0); \ + \ + lmain.bit = rte_rand_max(size); \ + do { \ + lworker.bit = rte_rand_max(size); \ + } while (lworker.bit == lmain.bit); \ + \ + int rc = rte_eal_remote_launch(run_parallel_assign ## size, \ + &lworker, worker_lcore_id); \ + TEST_ASSERT(rc == 0, "Worker thread launch failed"); \ + \ + run_parallel_assign ## size(&lmain); \ + \ + rte_eal_mp_wait_lcore(); \ + \ + TEST_ASSERT(!lmain.failed, "Main lcore atomic access failed"); \ + TEST_ASSERT(!lworker.failed, "Worker lcore atomic access " \ + "failed"); \ + \ + return TEST_SUCCESS; \ + } + +GEN_TEST_BIT_PARALLEL_ASSIGN(32) +GEN_TEST_BIT_PARALLEL_ASSIGN(64) + +#define GEN_TEST_BIT_PARALLEL_TEST_AND_MODIFY(size) \ + \ + struct parallel_test_and_set_lcore ## size \ + { \ + uint ## size ##_t *word; \ + unsigned int bit; \ + uint64_t flips; \ + }; \ + \ + static int \ + run_parallel_test_and_modify ## size(void *arg) \ + { \ + struct parallel_test_and_set_lcore ## size *lcore = arg; \ + uint64_t deadline = rte_get_timer_cycles() + \ + PARALLEL_TEST_RUNTIME * rte_get_timer_hz(); \ + do { \ + bool old_value; \ + bool new_value = rte_rand() & 1; \ + bool use_assign = rte_rand() & 1; \ + \ + if (use_assign) \ + old_value = rte_bit_atomic_test_and_assign( \ + lcore->word, lcore->bit, new_value, \ + rte_memory_order_relaxed); \ + else \ + old_value = new_value ? \ + rte_bit_atomic_test_and_set( \ + lcore->word, lcore->bit, \ + rte_memory_order_relaxed) : \ + rte_bit_atomic_test_and_clear( \ + lcore->word, lcore->bit, \ + rte_memory_order_relaxed); \ + if (old_value != new_value) \ + lcore->flips++; \ + } while (rte_get_timer_cycles() < deadline); \ + \ + return 0; \ + } \ + \ + static int \ + test_bit_atomic_parallel_test_and_modify ## size(void) \ + { \ + unsigned int worker_lcore_id; \ + uint ## size ## _t word = 0; \ + unsigned int bit = rte_rand_max(size); \ + struct parallel_test_and_set_lcore ## size lmain = { \ + .word = &word, \ + .bit = bit \ + }; \ + struct parallel_test_and_set_lcore ## size lworker = { \ + .word = &word, \ + .bit = bit \ + }; \ + \ + if (rte_lcore_count() < 2) { \ + printf("Need multiple cores to run parallel test.\n"); \ + return TEST_SKIPPED; \ + } \ + \ + worker_lcore_id = rte_get_next_lcore(-1, 1, 0); \ + \ + int rc = rte_eal_remote_launch(run_parallel_test_and_modify ## size, \ + &lworker, worker_lcore_id); \ + TEST_ASSERT(rc == 0, "Worker thread launch failed"); \ + \ + run_parallel_test_and_modify ## size(&lmain); \ + \ + rte_eal_mp_wait_lcore(); \ + \ + uint64_t total_flips = lmain.flips + lworker.flips; \ + bool expected_value = total_flips % 2; \ + \ + TEST_ASSERT(expected_value == rte_bit_test(&word, bit), \ + "After %"PRId64" flips, the bit value " \ + "should be %d", total_flips, expected_value); \ + \ + uint64_t expected_word = 0; \ + rte_bit_assign(&expected_word, bit, expected_value); \ + \ + TEST_ASSERT(expected_word == word, "Untouched bits have " \ + "changed value"); \ + \ + return TEST_SUCCESS; \ + } + +GEN_TEST_BIT_PARALLEL_TEST_AND_MODIFY(32) +GEN_TEST_BIT_PARALLEL_TEST_AND_MODIFY(64) + +#define GEN_TEST_BIT_PARALLEL_FLIP(size) \ + \ + struct parallel_flip_lcore ## size \ + { \ + uint ## size ##_t *word; \ + unsigned int bit; \ + uint64_t flips; \ + }; \ + \ + static int \ + run_parallel_flip ## size(void *arg) \ + { \ + struct parallel_flip_lcore ## size *lcore = arg; \ + uint64_t deadline = rte_get_timer_cycles() + \ + PARALLEL_TEST_RUNTIME * rte_get_timer_hz(); \ + do { \ + rte_bit_atomic_flip(lcore->word, lcore->bit, \ + rte_memory_order_relaxed); \ + lcore->flips++; \ + } while (rte_get_timer_cycles() < deadline); \ + \ + return 0; \ + } \ + \ + static int \ + test_bit_atomic_parallel_flip ## size(void) \ + { \ + unsigned int worker_lcore_id; \ + uint ## size ## _t word = 0; \ + unsigned int bit = rte_rand_max(size); \ + struct parallel_flip_lcore ## size lmain = { \ + .word = &word, \ + .bit = bit \ + }; \ + struct parallel_flip_lcore ## size lworker = { \ + .word = &word, \ + .bit = bit \ + }; \ + \ + if (rte_lcore_count() < 2) { \ + printf("Need multiple cores to run parallel test.\n"); \ + return TEST_SKIPPED; \ + } \ + \ + worker_lcore_id = rte_get_next_lcore(-1, 1, 0); \ + \ + int rc = rte_eal_remote_launch(run_parallel_flip ## size, \ + &lworker, worker_lcore_id); \ + TEST_ASSERT(rc == 0, "Worker thread launch failed"); \ + \ + run_parallel_flip ## size(&lmain); \ + \ + rte_eal_mp_wait_lcore(); \ + \ + uint64_t total_flips = lmain.flips + lworker.flips; \ + bool expected_value = total_flips % 2; \ + \ + TEST_ASSERT(expected_value == rte_bit_test(&word, bit), \ + "After %"PRId64" flips, the bit value " \ + "should be %d", total_flips, expected_value); \ + \ + uint64_t expected_word = 0; \ + rte_bit_assign(&expected_word, bit, expected_value); \ + \ + TEST_ASSERT(expected_word == word, "Untouched bits have " \ + "changed value"); \ + \ + return TEST_SUCCESS; \ + } + +GEN_TEST_BIT_PARALLEL_FLIP(32) +GEN_TEST_BIT_PARALLEL_FLIP(64) + static uint32_t val32; static uint64_t val64; @@ -187,6 +488,18 @@ static struct unit_test_suite test_suite = { TEST_CASE(test_bit_access64), TEST_CASE(test_bit_once_access32), TEST_CASE(test_bit_once_access64), + TEST_CASE(test_bit_access32), + TEST_CASE(test_bit_access64), + TEST_CASE(test_bit_once_access32), + TEST_CASE(test_bit_once_access64), + TEST_CASE(test_bit_atomic_access32), + TEST_CASE(test_bit_atomic_access64), + TEST_CASE(test_bit_atomic_parallel_assign32), + TEST_CASE(test_bit_atomic_parallel_assign64), + TEST_CASE(test_bit_atomic_parallel_test_and_modify32), + TEST_CASE(test_bit_atomic_parallel_test_and_modify64), + TEST_CASE(test_bit_atomic_parallel_flip32), + TEST_CASE(test_bit_atomic_parallel_flip64), TEST_CASE(test_bit_relaxed_set), TEST_CASE(test_bit_relaxed_clear), TEST_CASE(test_bit_relaxed_test_set_clear), -- 2.34.1