File indexing completed on 2025-05-11 08:24:39
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 #ifdef HAVE_CONFIG_H
0031 #include "config.h"
0032 #endif
0033
0034 #include <pthread.h>
0035 #include <errno.h>
0036 #include "tmacros.h"
0037 #include "pmacros.h"
0038
0039 const char rtems_test_name[] = "PSXKEY 9";
0040
0041
0042 rtems_task Init(rtems_task_argument argument);
0043 rtems_task Test_Thread(rtems_task_argument argument);
0044 void destructor(void *value);
0045
0046 int Data_array[1] = {1};
0047
0048 pthread_key_t key;
0049 volatile bool destructor_ran;
0050
0051 void destructor(void *value)
0052 {
0053 destructor_ran = true;
0054 }
0055
0056 rtems_task Test_Thread( rtems_task_argument arg )
0057 {
0058 void *argument = (void *)arg;
0059 int sc;
0060
0061 puts( "Test_Thread - key pthread_setspecific - OK" );
0062 sc = pthread_setspecific( key, argument );
0063 rtems_test_assert( !sc );
0064
0065 puts( "Test_Thread - pthread_exit to run key destructors - OK" );
0066 rtems_task_exit();
0067 }
0068
0069 rtems_task Init( rtems_task_argument ignored )
0070 {
0071 rtems_id thread;
0072 rtems_status_code rc;
0073 int sc;
0074 struct timespec delay_request;
0075
0076 TEST_BEGIN();
0077
0078 puts( "Init - pthread key create with destructor - OK" );
0079 sc = pthread_key_create( &key, destructor );
0080 rtems_test_assert( !sc );
0081
0082 puts( "Init - thread create - OK" );
0083 rc = rtems_task_create(
0084 rtems_build_name( 'T', 'E', 'S', 'T' ),
0085 1,
0086 RTEMS_MINIMUM_STACK_SIZE,
0087 RTEMS_DEFAULT_MODES,
0088 RTEMS_DEFAULT_ATTRIBUTES,
0089 &thread
0090 );
0091 rtems_test_assert( rc == RTEMS_SUCCESSFUL );
0092
0093 rc = rtems_task_start( thread, Test_Thread, (rtems_task_argument)Data_array );
0094 rtems_test_assert( rc == RTEMS_SUCCESSFUL );
0095
0096 puts( "Init - sleep - let thread run - OK" );
0097 delay_request.tv_sec = 0;
0098 delay_request.tv_nsec = 8 * 100000000;
0099 sc = nanosleep( &delay_request, NULL );
0100 rtems_test_assert( !sc );
0101
0102 puts( "Init - verify destructor run - OK" );
0103 rtems_test_assert( destructor_ran == true );
0104
0105 puts( "Init - pthread key delete - OK" );
0106 sc = pthread_key_delete( key );
0107 rtems_test_assert( sc == 0 );
0108
0109 TEST_END();
0110 rtems_test_exit(0);
0111 }
0112
0113
0114
0115 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0116 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0117
0118 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0119
0120 #define CONFIGURE_MAXIMUM_TASKS 2
0121 #define CONFIGURE_MAXIMUM_POSIX_KEYS 1
0122
0123 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0124
0125 #define CONFIGURE_INIT
0126 #include <rtems/confdefs.h>
0127
0128