[rtems commit] psxtests/psxcancel: Add pthread_detach() tests
Sebastian Huber
sebh at rtems.org
Tue May 17 09:00:30 UTC 2016
Module: rtems
Branch: master
Commit: 9d8ee11e55a0c9e515409f40900917a58d3bf6cc
Changeset: http://git.rtems.org/rtems/commit/?id=9d8ee11e55a0c9e515409f40900917a58d3bf6cc
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Tue May 17 09:47:53 2016 +0200
psxtests/psxcancel: Add pthread_detach() tests
Update #2714.
---
testsuites/psxtests/psxcancel/init.c | 82 +++++++++++++++++++++++++++++
testsuites/psxtests/psxcancel/psxcancel.doc | 5 ++
2 files changed, 87 insertions(+)
diff --git a/testsuites/psxtests/psxcancel/init.c b/testsuites/psxtests/psxcancel/init.c
index 9b6168e..90f4749 100644
--- a/testsuites/psxtests/psxcancel/init.c
+++ b/testsuites/psxtests/psxcancel/init.c
@@ -15,6 +15,7 @@
#include <unistd.h>
#include <errno.h>
#include <sched.h>
+#include <semaphore.h>
#if defined(__rtems__)
#include <rtems.h>
@@ -33,6 +34,10 @@ static rtems_resource_snapshot initialSnapshot;
static volatile bool countTask_handler;
+static sem_t masterSem;
+
+static sem_t workerSem;
+
static void countTask_cancel_handler(void *ignored)
{
countTask_handler = true;
@@ -82,6 +87,37 @@ static void *countTaskAsync(void *ignored)
}
}
+static void *taskAsyncAndDetached(void *ignored)
+{
+ int sc;
+
+ sc = pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, NULL );
+ fatal_posix_service_status( sc, 0, "cancel type taskAsyncAndDetached" );
+
+ sc = sem_post( &workerSem );
+ rtems_test_assert( sc == 0 );
+
+ sc = sem_wait( &masterSem );
+ rtems_test_assert( sc == 0 );
+
+ rtems_test_assert( 0 );
+}
+
+static void *taskSelfDetach(void *ignored)
+{
+ int sc;
+
+ sc = sem_post( &workerSem );
+ rtems_test_assert( sc == 0 );
+
+ sleep( 1 );
+
+ sc = pthread_detach( pthread_self() );
+ fatal_posix_service_status( sc, 0, "detach taskSelfDetach" );
+
+ pthread_exit( (void *) 123 );
+}
+
static void resourceSnapshotInit( void )
{
#if defined(__rtems__)
@@ -106,9 +142,16 @@ static void resourceSnapshotCheck( void )
int taskparameter = 0;
int sc;
int old;
+ void *exit_value;
TEST_BEGIN();
+ sc = sem_init( &masterSem, 0, 0 );
+ rtems_test_assert( sc == 0 );
+
+ sc = sem_init( &workerSem, 0, 0 );
+ rtems_test_assert( sc == 0 );
+
resourceSnapshotInit();
/* generate some error conditions */
@@ -132,6 +175,43 @@ static void resourceSnapshotCheck( void )
sc = pthread_cancel(0x100);
fatal_posix_service_status( sc, ESRCH, "cancel bad Id" );
+ resourceSnapshotCheck();
+
+ /* Test resource reclamation due to pthread_detach() */
+
+ sc = pthread_create( &task, NULL, taskAsyncAndDetached, NULL );
+ fatal_posix_service_status( sc, 0, "create taskAsyncAndDetached" );
+
+ sc = sem_wait( &workerSem );
+ rtems_test_assert( sc == 0 );
+
+ sc = pthread_cancel( task );
+ fatal_posix_service_status( sc, 0, "cancel taskAsyncAndDetached" );
+
+ sc = pthread_detach( task );
+ fatal_posix_service_status( sc, 0, "detach taskAsyncAndDetached" );
+
+ sched_yield();
+
+ sc = pthread_join( task, &exit_value );
+ fatal_posix_service_status( sc, ESRCH, "join taskAsyncAndDetached" );
+
+ resourceSnapshotCheck();
+
+ /* Test pthread_detach() after pthread_join() */
+
+ sc = pthread_create( &task, NULL, taskSelfDetach, NULL );
+ fatal_posix_service_status( sc, 0, "create taskSelfDetach" );
+
+ sc = sem_wait( &workerSem );
+ rtems_test_assert( sc == 0 );
+
+ sc = pthread_join( task, &exit_value );
+ fatal_posix_service_status( sc, 0, "join taskSelfDetach" );
+ rtems_test_assert( exit_value == (void *) 123 );
+
+ resourceSnapshotCheck();
+
/* Start countTask deferred */
{
sc = pthread_create(&task, NULL, countTaskDeferred, &taskparameter);
@@ -183,6 +263,8 @@ static void resourceSnapshotCheck( void )
#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
#define CONFIGURE_MAXIMUM_POSIX_THREADS 2
+#define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES 2
+
#define CONFIGURE_POSIX_INIT_THREAD_TABLE
#define CONFIGURE_INIT
diff --git a/testsuites/psxtests/psxcancel/psxcancel.doc b/testsuites/psxtests/psxcancel/psxcancel.doc
index 92bb28c..af56bd9 100644
--- a/testsuites/psxtests/psxcancel/psxcancel.doc
+++ b/testsuites/psxtests/psxcancel/psxcancel.doc
@@ -19,6 +19,7 @@ directives:
pthread_cleanup_pop
pthread_create
pthread_cancel
+ pthread_detach
pthread_join
concepts:
@@ -41,3 +42,7 @@ concepts:
+ Verify normal paths through pthread_mutexattr_gettype
+ Verify normal paths through pthread_mutexattr_settype
+
++ Ensure that a pthread_detach() leads to a resource reclamation.
+
++ Ensure that a pthread_join() works if issued before a pthread_detach().
More information about the vc
mailing list