test: fix race in per lcore test

Message ID 20250317143015.2559854-1-david.marchand@redhat.com (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers
Series test: fix race in per lcore test |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-marvell-Functional success Functional Testing PASS
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS

Commit Message

David Marchand March 17, 2025, 2:30 p.m. UTC
In some CI, this unit test can fail, as the main thread may get
rescheduled while lcores execute the callback waiting 100ms.

Bugzilla ID: 1668
Fixes: af75078fece3 ("first public release")
Cc: stable@dpdk.org

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 app/test/test_per_lcore.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
  

Patch

diff --git a/app/test/test_per_lcore.c b/app/test/test_per_lcore.c
index 63c5c80c24..9c72f0fa21 100644
--- a/app/test/test_per_lcore.c
+++ b/app/test/test_per_lcore.c
@@ -59,17 +59,29 @@  display_vars(__rte_unused void *arg)
 }
 
 static int
-test_per_lcore_delay(__rte_unused void *arg)
+test_per_lcore_delay(void *arg)
 {
+	RTE_ATOMIC(bool) *wait;
+
 	rte_delay_ms(100);
 	printf("wait 100ms on lcore %u\n", rte_lcore_id());
 
+	if (arg == NULL)
+		return 0;
+
+	wait = arg;
+	while (rte_atomic_load_explicit(wait, rte_memory_order_relaxed)) {
+		rte_delay_ms(100);
+		printf("wait 100ms on lcore %u\n", rte_lcore_id());
+	}
+
 	return 0;
 }
 
 static int
 test_per_lcore(void)
 {
+	RTE_ATOMIC(bool) wait = true;
 	unsigned lcore_id;
 	int ret;
 
@@ -86,7 +98,7 @@  test_per_lcore(void)
 	}
 
 	/* test if it could do remote launch twice at the same time or not */
-	ret = rte_eal_mp_remote_launch(test_per_lcore_delay, NULL, SKIP_MAIN);
+	ret = rte_eal_mp_remote_launch(test_per_lcore_delay, &wait, SKIP_MAIN);
 	if (ret < 0) {
 		printf("It fails to do remote launch but it should able to do\n");
 		return -1;
@@ -97,6 +109,7 @@  test_per_lcore(void)
 		printf("It does remote launch successfully but it should not at this time\n");
 		return -1;
 	}
+	rte_atomic_store_explicit(&wait, false, rte_memory_order_relaxed);
 	RTE_LCORE_FOREACH_WORKER(lcore_id) {
 		if (rte_eal_wait_lcore(lcore_id) < 0)
 			return -1;