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 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032
0033 #include <pthread.h>
0034 #include <errno.h>
0035 #include "tmacros.h"
0036 #include "pmacros.h"
0037
0038 const char rtems_test_name[] = "PSXKEY 3";
0039
0040
0041 rtems_task Init(rtems_task_argument value );
0042 rtems_task Test_Thread( rtems_task_argument value );
0043
0044 void destructor(void *value);
0045
0046 pthread_key_t Key;
0047 volatile bool destructor_ran;
0048
0049 void destructor(void *value)
0050 {
0051 destructor_ran = true;
0052 }
0053
0054 rtems_task Test_Thread( rtems_task_argument value )
0055 {
0056 int sc;
0057 void *key_value = (void *) value;
0058
0059 puts( "Test_Thread - pthread_setspecific - OK" );
0060 sc = pthread_setspecific( Key, key_value );
0061 rtems_test_assert( !sc );
0062
0063 puts( "Test_Thread - pthread_exit to run key destructors - OK" );
0064 rtems_task_exit();
0065 }
0066
0067 rtems_task Init(rtems_task_argument ignored)
0068 {
0069 rtems_id thread;
0070 rtems_status_code rc;
0071 int sc;
0072 struct timespec delay_request;
0073
0074 TEST_BEGIN();
0075
0076
0077
0078
0079 puts( "Init - pthread_key_create with NULL destructor - OK" );
0080 sc = pthread_key_create( &Key, NULL );
0081 rtems_test_assert( !sc );
0082
0083 puts( "Init - create/start - OK" );
0084 rc = rtems_task_create(
0085 rtems_build_name( 'T', 'E', 'S', 'T' ),
0086 1,
0087 RTEMS_MINIMUM_STACK_SIZE,
0088 RTEMS_DEFAULT_MODES,
0089 RTEMS_DEFAULT_ATTRIBUTES,
0090 &thread
0091 );
0092 rtems_test_assert( rc == RTEMS_SUCCESSFUL );
0093
0094 rc = rtems_task_start( thread, Test_Thread, 0 );
0095 rtems_test_assert( rc == RTEMS_SUCCESSFUL );
0096
0097 puts( "Init - sleep - let thread run - OK" );
0098 delay_request.tv_sec = 0;
0099 delay_request.tv_nsec = 5 * 100000000;
0100 sc = nanosleep( &delay_request, NULL );
0101 rtems_test_assert( !sc );
0102
0103 puts( "Init - pthread_key_delete - OK" );
0104 sc = pthread_key_delete( Key );
0105 rtems_test_assert( sc == 0 );
0106
0107
0108
0109
0110 destructor_ran = false;
0111 puts( "Init - pthread_key_create with non-NULL destructor - OK" );
0112 sc = pthread_key_create( &Key, destructor );
0113 rtems_test_assert( !sc );
0114
0115 puts( "Init - task create/start - OK" );
0116 rc = rtems_task_create(
0117 rtems_build_name( 'T', 'E', 'S', 'T' ),
0118 1,
0119 RTEMS_MINIMUM_STACK_SIZE,
0120 RTEMS_DEFAULT_MODES,
0121 RTEMS_DEFAULT_ATTRIBUTES,
0122 &thread
0123 );
0124 rtems_test_assert( rc == RTEMS_SUCCESSFUL );
0125
0126 rc = rtems_task_start( thread, Test_Thread, 0 );
0127 rtems_test_assert( rc == RTEMS_SUCCESSFUL );
0128
0129 puts( "Init - sleep - let thread run - OK" );
0130 sc = nanosleep( &delay_request, NULL );
0131 rtems_test_assert( !sc );
0132
0133 puts( "Init - verify destructor did NOT ran" );
0134 rtems_test_assert( destructor_ran == false );
0135
0136 puts( "Init - pthread_key_delete - OK" );
0137 sc = pthread_key_delete( Key );
0138 rtems_test_assert( sc == 0 );
0139
0140 TEST_END();
0141 rtems_test_exit(0);
0142 }
0143
0144
0145
0146 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0147 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0148
0149 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0150
0151 #define CONFIGURE_MAXIMUM_TASKS 2
0152 #define CONFIGURE_MAXIMUM_POSIX_KEYS 1
0153
0154 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0155
0156 #define CONFIGURE_INIT
0157 #include <rtems/confdefs.h>
0158
0159