[2/2] test: enable lcores test on Windows

Message ID 1670287169-15325-3-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series enable lcores test on Windows |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS

Commit Message

Tyler Retzlaff Dec. 6, 2022, 12:39 a.m. UTC
  Stop using pthread and convert the test to use EAL thread APIs. Because
the EAL thread APIs provide more than just a stub for thread join on
Windows the tests now pass and need not be skipped.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 app/test/test_lcores.c | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)
  

Comments

Stephen Hemminger Dec. 14, 2022, 4:53 p.m. UTC | #1
On Mon,  5 Dec 2022 16:39:29 -0800
Tyler Retzlaff <roretzla@linux.microsoft.com> wrote:

> Stop using pthread and convert the test to use EAL thread APIs. Because
> the EAL thread APIs provide more than just a stub for thread join on
> Windows the tests now pass and need not be skipped.
> 
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>

This makes sense to cover the API's even if not on Windows.

Acked-by: Stephen Hemminger <stephen@networkplumber.org>
  

Patch

diff --git a/app/test/test_lcores.c b/app/test/test_lcores.c
index a6bb412..5b43aa5 100644
--- a/app/test/test_lcores.c
+++ b/app/test/test_lcores.c
@@ -8,17 +8,18 @@ 
 #include <rte_common.h>
 #include <rte_errno.h>
 #include <rte_lcore.h>
+#include <rte_thread.h>
 
 #include "test.h"
 
 struct thread_context {
 	enum { Thread_INIT, Thread_ERROR, Thread_DONE } state;
 	bool lcore_id_any;
-	pthread_t id;
+	rte_thread_t id;
 	unsigned int *registered_count;
 };
 
-static void *thread_loop(void *arg)
+static uint32_t thread_loop(void *arg)
 {
 	struct thread_context *t = arg;
 	unsigned int lcore_id;
@@ -55,7 +56,7 @@  static void *thread_loop(void *arg)
 	if (t->state != Thread_ERROR)
 		t->state = Thread_DONE;
 
-	return NULL;
+	return 0;
 }
 
 static int
@@ -77,7 +78,7 @@  static void *thread_loop(void *arg)
 		t->state = Thread_INIT;
 		t->registered_count = &registered_count;
 		t->lcore_id_any = false;
-		if (pthread_create(&t->id, NULL, thread_loop, t) != 0)
+		if (rte_thread_create(&t->id, NULL, thread_loop, t) != 0)
 			break;
 		non_eal_threads_count++;
 	}
@@ -96,7 +97,7 @@  static void *thread_loop(void *arg)
 	t->state = Thread_INIT;
 	t->registered_count = &registered_count;
 	t->lcore_id_any = true;
-	if (pthread_create(&t->id, NULL, thread_loop, t) == 0) {
+	if (rte_thread_create(&t->id, NULL, thread_loop, t) == 0) {
 		non_eal_threads_count++;
 		printf("non-EAL threads count: %u\n", non_eal_threads_count);
 		while (__atomic_load_n(&registered_count, __ATOMIC_ACQUIRE) !=
@@ -110,7 +111,7 @@  static void *thread_loop(void *arg)
 	ret = 0;
 	for (i = 0; i < non_eal_threads_count; i++) {
 		t = &thread_contexts[i];
-		pthread_join(t->id, NULL);
+		rte_thread_join(t->id, NULL);
 		if (t->state != Thread_DONE)
 			ret = -1;
 	}
@@ -262,7 +263,7 @@  struct limit_lcore_context {
 	t->state = Thread_INIT;
 	t->registered_count = &registered_count;
 	t->lcore_id_any = false;
-	if (pthread_create(&t->id, NULL, thread_loop, t) != 0)
+	if (rte_thread_create(&t->id, NULL, thread_loop, t) != 0)
 		goto cleanup_threads;
 	non_eal_threads_count++;
 	while (__atomic_load_n(&registered_count, __ATOMIC_ACQUIRE) !=
@@ -285,7 +286,7 @@  struct limit_lcore_context {
 	t->state = Thread_INIT;
 	t->registered_count = &registered_count;
 	t->lcore_id_any = true;
-	if (pthread_create(&t->id, NULL, thread_loop, t) != 0)
+	if (rte_thread_create(&t->id, NULL, thread_loop, t) != 0)
 		goto cleanup_threads;
 	non_eal_threads_count++;
 	while (__atomic_load_n(&registered_count, __ATOMIC_ACQUIRE) !=
@@ -309,7 +310,7 @@  struct limit_lcore_context {
 	ret = 0;
 	for (i = 0; i < non_eal_threads_count; i++) {
 		t = &thread_contexts[i];
-		pthread_join(t->id, NULL);
+		rte_thread_join(t->id, NULL);
 		if (t->state != Thread_DONE)
 			ret = -1;
 	}
@@ -330,7 +331,7 @@  struct limit_lcore_context {
 	__atomic_store_n(&registered_count, 0, __ATOMIC_RELEASE);
 	for (i = 0; i < non_eal_threads_count; i++) {
 		t = &thread_contexts[i];
-		pthread_join(t->id, NULL);
+		rte_thread_join(t->id, NULL);
 	}
 error:
 	if (handle[1] != NULL)
@@ -361,7 +362,7 @@  static void *ctrl_thread_loop(void *arg)
 	/* Create one control thread */
 	t = &ctrl_thread_context;
 	t->state = Thread_INIT;
-	if (rte_ctrl_thread_create(&t->id, "test_ctrl_threads",
+	if (rte_ctrl_thread_create((pthread_t *)&t->id, "test_ctrl_threads",
 					NULL, ctrl_thread_loop, t) != 0)
 		return -1;
 
@@ -369,7 +370,7 @@  static void *ctrl_thread_loop(void *arg)
 	 * This also acts as the barrier such that the memory operations
 	 * in control thread are visible to this thread.
 	 */
-	pthread_join(t->id, NULL);
+	rte_thread_join(t->id, NULL);
 
 	/* Check if the control thread set the correct state */
 	if (t->state != Thread_DONE)
@@ -384,9 +385,6 @@  static void *ctrl_thread_loop(void *arg)
 	unsigned int eal_threads_count = 0;
 	unsigned int i;
 
-	if (RTE_EXEC_ENV_IS_WINDOWS)
-		return TEST_SKIPPED;
-
 	for (i = 0; i < RTE_MAX_LCORE; i++) {
 		if (!rte_lcore_has_role(i, ROLE_OFF))
 			eal_threads_count++;