[v5,4/6] test/threads: add tests for thread lifetime API

Message ID 1664989651-29303-5-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series add thread lifetime and attributes API |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Tyler Retzlaff Oct. 5, 2022, 5:07 p.m. UTC
  Test basic functionality and demonstrate use of following thread
lifetime api.

    * rte_thread_create
    * rte_thread_detach
    * rte_thread_join

Signed-off-by: Narcisa Vasile <navasile@microsoft.com>
Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 app/test/test_threads.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 52 insertions(+), 2 deletions(-)
  

Comments

David Marchand Oct. 6, 2022, 8:32 a.m. UTC | #1
On Wed, Oct 5, 2022 at 7:07 PM Tyler Retzlaff
<roretzla@linux.microsoft.com> wrote:
>
> Test basic functionality and demonstrate use of following thread
> lifetime api.
>
>     * rte_thread_create
>     * rte_thread_detach

And, to some extent, rte_thread_equal.

>     * rte_thread_join
>
> Signed-off-by: Narcisa Vasile <navasile@microsoft.com>
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> ---
>  app/test/test_threads.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 52 insertions(+), 2 deletions(-)
>
> diff --git a/app/test/test_threads.c b/app/test/test_threads.c
> index b9d8b4e..1077373 100644
> --- a/app/test/test_threads.c
> +++ b/app/test/test_threads.c
> @@ -14,7 +14,7 @@
>
>  static uint32_t thread_id_ready;
>
> -static void *
> +static uint32_t
>  thread_main(void *arg)

Stopping at this patch, I still see a build failure.
This prototype change makes it uncompatible with remaining calls to
pthread_create.

This is fixed in patch 6 which I intend to squash here (and adding the
check on arg != NULL that is in patch 5).
Deal?
  
Tyler Retzlaff Oct. 6, 2022, 3:19 p.m. UTC | #2
On Thu, Oct 06, 2022 at 10:32:56AM +0200, David Marchand wrote:
> On Wed, Oct 5, 2022 at 7:07 PM Tyler Retzlaff
> <roretzla@linux.microsoft.com> wrote:
> >
> > Test basic functionality and demonstrate use of following thread
> > lifetime api.
> >
> >     * rte_thread_create
> >     * rte_thread_detach
> 
> And, to some extent, rte_thread_equal.
> 
> >     * rte_thread_join
> >
> > Signed-off-by: Narcisa Vasile <navasile@microsoft.com>
> > Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> > ---
> >  app/test/test_threads.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++--
> >  1 file changed, 52 insertions(+), 2 deletions(-)
> >
> > diff --git a/app/test/test_threads.c b/app/test/test_threads.c
> > index b9d8b4e..1077373 100644
> > --- a/app/test/test_threads.c
> > +++ b/app/test/test_threads.c
> > @@ -14,7 +14,7 @@
> >
> >  static uint32_t thread_id_ready;
> >
> > -static void *
> > +static uint32_t
> >  thread_main(void *arg)
> 
> Stopping at this patch, I still see a build failure.
> This prototype change makes it uncompatible with remaining calls to
> pthread_create.

hmm, i must have made a mistake somewhere in the rebase. now i see what
you mean about build failure @ patch 4 i was considering it only with
the entire series applied i had not been testing individual patches in
the series. sorry about that.

> 
> This is fixed in patch 6 which I intend to squash here (and adding the
> check on arg != NULL that is in patch 5).
> Deal?

i have no problem with that.

now that i've read this can you confirm the only outstanding issue
is whether to move code to eal_common_thread? i posted a follow up to
thomas and i'm just waiting on his reply.

if the reply is still a positive to move the code i can fix the above in
a v6.

Thomas waiting on your follow up regarding code move.

thanks
  

Patch

diff --git a/app/test/test_threads.c b/app/test/test_threads.c
index b9d8b4e..1077373 100644
--- a/app/test/test_threads.c
+++ b/app/test/test_threads.c
@@ -14,7 +14,7 @@ 
 
 static uint32_t thread_id_ready;
 
-static void *
+static uint32_t
 thread_main(void *arg)
 {
 	*(rte_thread_t *)arg = rte_thread_self();
@@ -23,7 +23,55 @@ 
 	while (__atomic_load_n(&thread_id_ready, __ATOMIC_ACQUIRE) == 1)
 		;
 
-	return NULL;
+	return 0;
+}
+
+static int
+test_thread_create_join(void)
+{
+	rte_thread_t thread_id;
+	rte_thread_t thread_main_id;
+
+	thread_id_ready = 0;
+	RTE_TEST_ASSERT(rte_thread_create(&thread_id, NULL, thread_main, &thread_main_id) == 0,
+		"Failed to create thread.");
+
+	while (__atomic_load_n(&thread_id_ready, __ATOMIC_ACQUIRE) == 0)
+		;
+
+	RTE_TEST_ASSERT(rte_thread_equal(thread_id, thread_main_id) != 0,
+		"Unexpected thread id.");
+
+	__atomic_store_n(&thread_id_ready, 2, __ATOMIC_RELEASE);
+
+	RTE_TEST_ASSERT(rte_thread_join(thread_id, NULL) == 0,
+		"Failed to join thread.");
+
+	return 0;
+}
+
+static int
+test_thread_create_detach(void)
+{
+	rte_thread_t thread_id;
+	rte_thread_t thread_main_id;
+
+	thread_id_ready = 0;
+	RTE_TEST_ASSERT(rte_thread_create(&thread_id, NULL, thread_main,
+		&thread_main_id) == 0, "Failed to create thread.");
+
+	while (__atomic_load_n(&thread_id_ready, __ATOMIC_ACQUIRE) == 0)
+		;
+
+	RTE_TEST_ASSERT(rte_thread_equal(thread_id, thread_main_id) != 0,
+		"Unexpected thread id.");
+
+	__atomic_store_n(&thread_id_ready, 2, __ATOMIC_RELEASE);
+
+	RTE_TEST_ASSERT(rte_thread_detach(thread_id) == 0,
+		"Failed to detach thread.");
+
+	return 0;
 }
 
 static int
@@ -123,6 +171,8 @@ 
 	.setup = NULL,
 	.teardown = NULL,
 	.unit_test_cases = {
+		TEST_CASE(test_thread_create_join),
+		TEST_CASE(test_thread_create_detach),
 		TEST_CASE(test_thread_affinity),
 		TEST_CASE(test_thread_priority),
 		TEST_CASES_END()