summaryrefslogtreecommitdiffstats
path: root/testsuites/psxtests
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-05-17 09:47:53 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-05-17 10:58:10 +0200
commit9d8ee11e55a0c9e515409f40900917a58d3bf6cc (patch)
tree42c5466c1b32de149507af31ac14b5ef4c4eacd8 /testsuites/psxtests
parentpsxtests/psxcancel: Add resource check (diff)
downloadrtems-9d8ee11e55a0c9e515409f40900917a58d3bf6cc.tar.bz2
psxtests/psxcancel: Add pthread_detach() tests
Update #2714.
Diffstat (limited to 'testsuites/psxtests')
-rw-r--r--testsuites/psxtests/psxcancel/init.c82
-rw-r--r--testsuites/psxtests/psxcancel/psxcancel.doc5
2 files changed, 87 insertions, 0 deletions
diff --git a/testsuites/psxtests/psxcancel/init.c b/testsuites/psxtests/psxcancel/init.c
index 9b6168e1e0..90f474971d 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 92bb28cb4b..af56bd9ff0 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().