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 2A52E459D8; Thu, 19 Sep 2024 21:41:02 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 39C0F433E8; Thu, 19 Sep 2024 21:40:50 +0200 (CEST) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2083.outbound.protection.outlook.com [40.107.21.83]) by mails.dpdk.org (Postfix) with ESMTP id 9412D433D6 for ; Thu, 19 Sep 2024 21:40:46 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GXFkHoLPkdeWlwNHsiQ4oDC2eeD0wFsibP+PQSvAPLioJTBGTBpASkF9xfUOJvPDKHFz6VkBTKRlJWXscGW+Vk5tX4aUCGQWhGG2XNuMlYiapZbxykbLjdYmB3+xGsZpBJZaW0A4CLYS7UyCCePNqYhI5a01kan6b2/LymFHCrPf3O5rH8auIWDrZ+OWjPT9n7jqWMbjNnHB77lCLDd50EVS36u6WnO4a0TS8fi3XxX+wBASJ6EXg+MfYL4WxKNoKKgeS/UtNJgIU1RAeEEuUcvkWr/X3APTw3MqHWo3Wysv4ZAlzM6pEf7qL/UelWDjbfggwDtw2oiCYh/HtNYfwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=FORcAcTImC3VO+jULR5YD9MPGU81/5BIeguEUjIfy6I=; b=QaSYVsJByU0BMbH1cMu3E/RTAasVMFaBexCoiYC+cYtcc9GM+UqX/ygrS3ndhzM4Yg0FTsppC6r1tMx4pNuykucneb36GRlChQCnER7e5caFo0C2Ccttj+93/Qv2Tj2uXMD3N+2Mu6TyyiZQZ7+/QTBWxdBx+O7AI82cPlN/Q/BmHSmOob2Gyg+bMD2XDbqqArIHxKsbhNX+nD9Y8zLyu3aMWBT7216GL++aRqZPFTmO6S+t/Sx9TEkPT5+YDnikIGXPonpW7OctwfN5orl0AvkmNOfEnGoymXlcCAQGD3bx6R9KfJwQC5iUgB1c3KYchKSJv7a9d361bIs1+QJ0Ow== 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=FORcAcTImC3VO+jULR5YD9MPGU81/5BIeguEUjIfy6I=; b=nu6b4/UEV63VU/LR5cxdPCE0IqbL2TqrSf2ol+i9eGADGtJEKiNjtekBdF2pS7eZPC8XkrJeHnvVrEjvxxAnhuk88nQKrTK0VZzWYhCVRZHfJQEUPA4NDQ/0noRw5ekpY2Fq+vaJCxKKN4v9mBsTlhte4mNjT73HM1mcoZ/M3+x3ta7++IZgGVRmHHv7xhhe8+ef8rBRyJN1+GvEyMKgrwOzfd5/VFARJKNREmWJE5FREci8FH3PK4QIUM+fev0obezQP1L8/S13aSPzcLGEbQG4a0F+lVOcfgms4T8gaCFFDd2NywvUqZhZBKHW2OzF1Ew74P3DSRhszXoDeMs34Q== Received: from AM6PR0502CA0043.eurprd05.prod.outlook.com (2603:10a6:20b:56::20) by PAXPR07MB7933.eurprd07.prod.outlook.com (2603:10a6:102:13a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.22; Thu, 19 Sep 2024 19:40:42 +0000 Received: from AMS0EPF0000019D.eurprd05.prod.outlook.com (2603:10a6:20b:56:cafe::82) by AM6PR0502CA0043.outlook.office365.com (2603:10a6:20b:56::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.30 via Frontend Transport; Thu, 19 Sep 2024 19:40:42 +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 AMS0EPF0000019D.mail.protection.outlook.com (10.167.16.249) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Thu, 19 Sep 2024 19:40:42 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.63) with Microsoft SMTP Server id 15.2.1544.11; Thu, 19 Sep 2024 21:40:41 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id B5C5D1C0070; Thu, 19 Sep 2024 21:40:41 +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?= , Jack Bond-Preston , David Marchand , Chengwen Feng , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= Subject: [PATCH v10 6/7] eal: add unit tests for atomic bit access functions Date: Thu, 19 Sep 2024 21:31:23 +0200 Message-ID: <20240919193124.737943-7-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240919193124.737943-1-mattias.ronnblom@ericsson.com> References: <20240918090445.725283-2-mattias.ronnblom@ericsson.com> <20240919193124.737943-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: AMS0EPF0000019D:EE_|PAXPR07MB7933:EE_ X-MS-Office365-Filtering-Correlation-Id: 9c777163-5b65-4071-3806-08dcd8e2f286 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|82310400026|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: =?utf-8?B?V1M3Q3E5THlWdS83RTkyd0VIemdYMyt4T2tJYVlnWlIvdElhS3FTbk5MMkhq?= =?utf-8?B?T2IwU1VTbUlZbiszSzI4aXJXRFVZT0J6MDhPY2JIellRSGphSkVzVEltV3Vn?= =?utf-8?B?UUJOQm9tWUcwUDV4dFNtZDRxYlhCWnBUUzZjRGhIRzJodmJoY0FhbDdUL2Rq?= =?utf-8?B?N2s2OEw3MjExOTZDR1o3UnJnUFFLOWZ0VWR2cjRrWHZjY0duUCs1SDVmcVpJ?= =?utf-8?B?emVuendpVUw0MjBpdWtSODZwNHFoS2pDd2JGMWw0eS9MaWcrd3VoN2NBbGhx?= =?utf-8?B?c0xvaDVSSmY1YzdCYkJ2N0p2UTdHMWxpVVdxV3Jwa21Ca2sxUFJhdlVpdGd3?= =?utf-8?B?QXhRVzF6QXVOSFdwejMwWUFqT3YveWh3Q1lHenFHUWtRTEx5MWU4b1Zua2xv?= =?utf-8?B?UEdXRlc0aEVZVmFIbGorQmprQnpPRGo0UmtjYjRBSzJtS2xNeSttcEM1MkV5?= =?utf-8?B?RWZBRno2OXd1TklzRzdHQ3lsSUdIRFVNNDZCVVpIOG55UXBtME1nRFg0WjJD?= =?utf-8?B?T3NBM01NTHYxSWZQOEhDUUs2Mit0TnorNzFuYSswOXU5R2l3M2xYRDUzcVBJ?= =?utf-8?B?dXgxb05SK1F3TUdLTzZiWGVqbWo3U0pZMkNjamV0WW4rNlZSM1VzSXo4RjdS?= =?utf-8?B?NGlsRzFOLzNFRTlDcytVb2hGRFNiMGVtKzZyNldIS1JIMkZDNHkxWEFFZi84?= =?utf-8?B?K3NDWm9OalJsQ1pjVERzekE4K2luaXA4VDFTZWl4YzY0WHA2aGdEUnNrN2hP?= =?utf-8?B?M3lyWjZMM0wrVGhWeGZMby9JSGZ3cGc1Sk9NOUIvTVlpM1U2eTVmQkRUQjds?= =?utf-8?B?R2pDNHVtclp0QTlRQ21oRlVjSjZLcVJhc0J4TUlTWHZOeWZOMzhhVWRSYlFC?= =?utf-8?B?OXpiYlZZcnRJS0oySC9DUDNPWjBJTHdzWU1Zbi9ObmRqN3E0V2VrK0htaUpp?= =?utf-8?B?eTM0a3FDNHo2TTNFaENZbFZiQ3RFRzBMaWFJdTRTUmk1TUY1K25IbXBBbksx?= =?utf-8?B?a0dPeUhhN1MrYVVsS2Z0dmk1alRtZWkxRDlDbVBIeGt0cEllNWx5dUY4dmNX?= =?utf-8?B?T3FyTFdjYlRXTmE2aWFRd1R1dXdTMkhrdmFZTkE2UUNxNkhueVZJOHRPclhG?= =?utf-8?B?enI2RndCMjM3QWo5bGpXNzhIS1M1SnoyTjJJaG5kQWhnRzBNZ25DLzBrcWsy?= =?utf-8?B?YXJFUnVDMnZIekVPYnEyd0U2UHJ0eXlwUC9kYVFOSUhsdk5qUmZuN2ducDhF?= =?utf-8?B?VzNyK1pXYmptUVcrZ1Nsb2pJMmJCcHFCYkFpQ2hqY2g2QXhXeGw1a2krbi9y?= =?utf-8?B?S1VGeHhUU1hRMUV3NTNSa0NXNWMrbzZNamQvOEdsZVdPY3FzOWFSQXF0U2Q2?= =?utf-8?B?TlhhbGFZakNwbEJPZSt1QkFxVnpGcTUyYzB0OUs3QXFGN2lGMzJpVnUyeUdH?= =?utf-8?B?dTVnV0VOL0wyNlZGM0p4UmJVM2tJOG1veElJOEFUcGQzZFVpT3RKdGdDRHkv?= =?utf-8?B?VFRhQmlvcHA1bk1HTFNDbjdBdWJOTENHbkRWcU1SeVAxYUpDQ2xOUytGbnFU?= =?utf-8?B?U3kzMUN0VlBRVk40Wmo2c0o3dG5EVUliRm5kT0FkODc2SE5CWXo2VENKNTRk?= =?utf-8?B?Lzc4NGtOQk5qdThqcWx2bzZCRDVmUXRZaWs5c0tvNTdNWk92dm1jdjI3N3Jn?= =?utf-8?B?U2s1a1FlT1pSWHk5RDdndHJYbEtGOGJnbnY1a0ZDQktWUlhwbFpXRkpuWTBR?= =?utf-8?B?NFFNWWF3ZDJ3WjE5bU04cDE3ZHVGQXFnMk5YU3R6ejRRTTJYLy9icXRoMlBp?= =?utf-8?B?Y3ZubGZaYjYzaE1EUyszVXI0ZVdTYU1STFZvalJjTTh4M3ZzVDdlL1RwNjY2?= =?utf-8?Q?RhfPyYyBgQIuC?= 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:(13230040)(376014)(82310400026)(1800799024)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2024 19:40:42.1764 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9c777163-5b65-4071-3806-08dcd8e2f286 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: AMS0EPF0000019D.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR07MB7933 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. Signed-off-by: Mattias Rönnblom Acked-by: Morten Brørup Acked-by: Tyler Retzlaff Acked-by: Jack Bond-Preston -- RFC v4: * Add atomicity test for atomic bit flip. RFC v3: * Rename variable 'main' to make ICC happy. --- app/test/test_bitops.c | 313 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 312 insertions(+), 1 deletion(-) diff --git a/app/test/test_bitops.c b/app/test/test_bitops.c index 322f58c066..b80216a0a1 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" @@ -61,6 +64,304 @@ GEN_TEST_BIT_ACCESS(test_bit_access32, rte_bit_set, rte_bit_clear, GEN_TEST_BIT_ACCESS(test_bit_access64, rte_bit_set, rte_bit_clear, rte_bit_assign, rte_bit_flip, rte_bit_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; @@ -177,6 +478,16 @@ static struct unit_test_suite test_suite = { .unit_test_cases = { TEST_CASE(test_bit_access32), TEST_CASE(test_bit_access64), + TEST_CASE(test_bit_access32), + TEST_CASE(test_bit_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