Changeset 9d8ee11 in rtems


Ignore:
Timestamp:
May 17, 2016, 7:47:53 AM (3 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
3c20d28
Parents:
f014f84
git-author:
Sebastian Huber <sebastian.huber@…> (05/17/16 07:47:53)
git-committer:
Sebastian Huber <sebastian.huber@…> (05/17/16 08:58:10)
Message:

psxtests/psxcancel: Add pthread_detach() tests

Update #2714.

Location:
testsuites/psxtests/psxcancel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • testsuites/psxtests/psxcancel/init.c

    rf014f84 r9d8ee11  
    1616#include <errno.h>
    1717#include <sched.h>
     18#include <semaphore.h>
    1819
    1920#if defined(__rtems__)
     
    3334
    3435static volatile bool countTask_handler;
     36
     37static sem_t masterSem;
     38
     39static sem_t workerSem;
    3540
    3641static void countTask_cancel_handler(void *ignored)
     
    8388}
    8489
     90static void *taskAsyncAndDetached(void *ignored)
     91{
     92  int sc;
     93
     94  sc = pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, NULL );
     95  fatal_posix_service_status( sc, 0, "cancel type taskAsyncAndDetached" );
     96
     97  sc = sem_post( &workerSem );
     98  rtems_test_assert( sc == 0 );
     99
     100  sc = sem_wait( &masterSem );
     101  rtems_test_assert( sc == 0 );
     102
     103  rtems_test_assert( 0 );
     104}
     105
     106static void *taskSelfDetach(void *ignored)
     107{
     108  int sc;
     109
     110  sc = sem_post( &workerSem );
     111  rtems_test_assert( sc == 0 );
     112
     113  sleep( 1 );
     114
     115  sc = pthread_detach( pthread_self() );
     116  fatal_posix_service_status( sc, 0, "detach taskSelfDetach" );
     117
     118  pthread_exit( (void *) 123 );
     119}
     120
    85121static void resourceSnapshotInit( void )
    86122{
     
    107143  int       sc;
    108144  int       old;
     145  void     *exit_value;
    109146
    110147  TEST_BEGIN();
     148
     149  sc = sem_init( &masterSem, 0, 0 );
     150  rtems_test_assert( sc == 0 );
     151
     152  sc = sem_init( &workerSem, 0, 0 );
     153  rtems_test_assert( sc == 0 );
    111154
    112155  resourceSnapshotInit();
     
    132175  sc = pthread_cancel(0x100);
    133176  fatal_posix_service_status( sc, ESRCH, "cancel bad Id" );
     177
     178  resourceSnapshotCheck();
     179
     180  /* Test resource reclamation due to pthread_detach() */
     181
     182  sc = pthread_create( &task, NULL, taskAsyncAndDetached, NULL );
     183  fatal_posix_service_status( sc, 0, "create taskAsyncAndDetached" );
     184
     185  sc = sem_wait( &workerSem );
     186  rtems_test_assert( sc == 0 );
     187
     188  sc = pthread_cancel( task );
     189  fatal_posix_service_status( sc, 0, "cancel taskAsyncAndDetached" );
     190
     191  sc = pthread_detach( task );
     192  fatal_posix_service_status( sc, 0, "detach taskAsyncAndDetached" );
     193
     194  sched_yield();
     195
     196  sc = pthread_join( task, &exit_value );
     197  fatal_posix_service_status( sc, ESRCH, "join taskAsyncAndDetached" );
     198
     199  resourceSnapshotCheck();
     200
     201  /* Test pthread_detach() after pthread_join() */
     202
     203  sc = pthread_create( &task, NULL, taskSelfDetach, NULL );
     204  fatal_posix_service_status( sc, 0, "create taskSelfDetach" );
     205
     206  sc = sem_wait( &workerSem );
     207  rtems_test_assert( sc == 0 );
     208
     209  sc = pthread_join( task, &exit_value );
     210  fatal_posix_service_status( sc, 0, "join taskSelfDetach" );
     211  rtems_test_assert( exit_value == (void *) 123 );
     212
     213  resourceSnapshotCheck();
    134214
    135215  /* Start countTask deferred */
     
    184264
    185265#define CONFIGURE_MAXIMUM_POSIX_THREADS 2
     266#define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES 2
     267
    186268#define CONFIGURE_POSIX_INIT_THREAD_TABLE
    187269
Note: See TracChangeset for help on using the changeset viewer.