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 6";
0040
0041 static int Data_array[4] = {1, 2, 3, 4};
0042
0043 static pthread_key_t key1, key2, key3;
0044
0045 static rtems_id Thread_Master;
0046
0047 static int Key3_Destructor_Counter;
0048
0049 static void Wake_Up_Master(void)
0050 {
0051 rtems_status_code rc;
0052
0053 rc = rtems_event_transient_send( Thread_Master );
0054 rtems_test_assert( rc == RTEMS_SUCCESSFUL );
0055 }
0056
0057 static void Wait_For_Worker(void)
0058 {
0059 rtems_status_code rc;
0060
0061 rc = rtems_event_transient_receive(
0062 RTEMS_WAIT,
0063 RTEMS_NO_TIMEOUT
0064 );
0065 rtems_test_assert( rc == RTEMS_SUCCESSFUL );
0066 }
0067
0068 static rtems_task Test_Thread1( rtems_task_argument argument )
0069 {
0070 int sc;
0071 int *value;
0072 struct timespec delay_request;
0073
0074 puts( "Test_Thread 1 - key1 pthread_setspecific - OK" );
0075 sc = pthread_setspecific( key1, &Data_array[0] );
0076 rtems_test_assert( !sc );
0077
0078 puts( "Test_Thread 1 - key2 pthread_setspecific - OK" );
0079 sc = pthread_setspecific( key2, &Data_array[1] );
0080 rtems_test_assert( !sc );
0081
0082 puts( "Test_Thread 1 - sleep - let thread2 run - OK" );
0083 delay_request.tv_sec = 0;
0084 delay_request.tv_nsec = 4 * 100000000;
0085 sc = nanosleep( &delay_request, NULL );
0086 rtems_test_assert( !sc );
0087
0088 puts( "Test_Thread 1 - key1 pthread_getspecific - OK" );
0089 value = pthread_getspecific( key1 );
0090 rtems_test_assert( *value == Data_array[0] );
0091
0092 puts( "Test_Thread 1 - key2 pthread_getspecific - OK" );
0093 value = pthread_getspecific( key2 );
0094 rtems_test_assert( *value == Data_array[1] );
0095
0096 rtems_task_exit();
0097 }
0098
0099 static rtems_task Test_Thread2( rtems_task_argument argument )
0100 {
0101 int sc;
0102 int *value;
0103
0104 puts( "Test_Thread 2 - key1 pthread_setspecific - OK" );
0105 sc = pthread_setspecific( key1, &Data_array[2] );
0106 rtems_test_assert( !sc );
0107
0108 puts( "Test_Thread 2 - key2 pthread_setspecific - OK" );
0109 sc = pthread_setspecific( key2, &Data_array[3] );
0110 rtems_test_assert( !sc );
0111
0112 puts( "Test_Thread 2 - key1 pthread_getspecific - OK" );
0113 value = pthread_getspecific( key1 );
0114 rtems_test_assert( *value == Data_array[2] );
0115
0116 puts( "Test_Thread 2 - key2 pthread_getspecific - OK" );
0117 value = pthread_getspecific( key2 );
0118 rtems_test_assert( *value == Data_array[3] );
0119
0120 rtems_task_exit();
0121 }
0122
0123 static void Key3_Destructor( void *value )
0124 {
0125 rtems_test_assert( value == &Thread_Master );
0126 ++Key3_Destructor_Counter;
0127 }
0128
0129 static rtems_task Test_Thread3( rtems_task_argument argument )
0130 {
0131 int sc;
0132 void *value;
0133
0134 puts( "Test_Thread 3 - key3 pthread_getspecific - OK" );
0135 value = pthread_getspecific( key3 );
0136 rtems_test_assert( value == NULL );
0137
0138 puts( "Test_Thread 3 - key3 pthread_setspecific - OK" );
0139 sc = pthread_setspecific( key3, &Thread_Master );
0140 rtems_test_assert( sc == 0 );
0141
0142 if ( argument == 0 ) {
0143 puts( "Test_Thread 3 - restart self - OK" );
0144 rtems_task_restart( RTEMS_SELF, 1 );
0145 } else if ( argument == 1 ) {
0146 Wake_Up_Master();
0147 rtems_task_exit();
0148 }
0149
0150 rtems_test_assert( false );
0151 }
0152
0153 static rtems_task Init( rtems_task_argument ignored )
0154 {
0155 rtems_id thread1;
0156 rtems_id thread2;
0157 rtems_id thread3;
0158 rtems_status_code rc;
0159 int sc;
0160 struct timespec delay_request;
0161
0162 TEST_BEGIN();
0163
0164 Thread_Master = rtems_task_self();
0165
0166 puts( "Init - pthread key1 create - OK" );
0167 sc = pthread_key_create( &key1, NULL );
0168 rtems_test_assert( !sc );
0169
0170 puts( "Init - pthread key2 create - OK" );
0171 sc = pthread_key_create( &key2, NULL );
0172 rtems_test_assert( !sc );
0173
0174 puts( "Init - thread1 create - OK" );
0175 rc = rtems_task_create(
0176 rtems_build_name( 'T', 'E', 'S', 'T' ),
0177 1,
0178 RTEMS_MINIMUM_STACK_SIZE,
0179 RTEMS_DEFAULT_MODES,
0180 RTEMS_DEFAULT_ATTRIBUTES,
0181 &thread1
0182 );
0183 rtems_test_assert( rc == RTEMS_SUCCESSFUL );
0184
0185 rc = rtems_task_start( thread1, Test_Thread1, 0 );
0186 rtems_test_assert( rc == RTEMS_SUCCESSFUL );
0187
0188 puts( "Init - thread2 create - OK" );
0189 rc = rtems_task_create(
0190 rtems_build_name( 'T', 'E', 'S', 'T' ),
0191 1,
0192 RTEMS_MINIMUM_STACK_SIZE,
0193 RTEMS_DEFAULT_MODES,
0194 RTEMS_DEFAULT_ATTRIBUTES,
0195 &thread2
0196 );
0197 rtems_test_assert( rc == RTEMS_SUCCESSFUL );
0198
0199 rc = rtems_task_start( thread2, Test_Thread2, 0 );
0200 rtems_test_assert( rc == RTEMS_SUCCESSFUL );
0201
0202 puts( "Init - sleep - let thread run - OK" );
0203 delay_request.tv_sec = 0;
0204 delay_request.tv_nsec = 8 * 100000000;
0205 sc = nanosleep( &delay_request, NULL );
0206 rtems_test_assert( !sc );
0207
0208 puts( "Init - pthread key1 delete - OK" );
0209 sc = pthread_key_delete( key1 );
0210 rtems_test_assert( sc == 0 );
0211
0212 puts( "Init - pthread key2 delete - OK" );
0213 sc = pthread_key_delete( key2 );
0214 rtems_test_assert( sc == 0 );
0215
0216 puts( "Init - pthread key3 create - OK" );
0217 sc = pthread_key_create( &key3, Key3_Destructor );
0218 rtems_test_assert( sc == 0 );
0219
0220 puts( "Init - thread3 create - OK" );
0221 rc = rtems_task_create(
0222 rtems_build_name( 'R', 'E', 'S', 'T' ),
0223 1,
0224 RTEMS_MINIMUM_STACK_SIZE,
0225 RTEMS_DEFAULT_MODES,
0226 RTEMS_DEFAULT_ATTRIBUTES,
0227 &thread3
0228 );
0229 rtems_test_assert( rc == RTEMS_SUCCESSFUL );
0230
0231 puts( "Init - thread3 start - OK" );
0232 rc = rtems_task_start( thread3, Test_Thread3, 0 );
0233 rtems_test_assert( rc == RTEMS_SUCCESSFUL );
0234
0235 Wait_For_Worker();
0236
0237 rtems_test_assert( Key3_Destructor_Counter == 2 );
0238
0239 puts( "Init - pthread key3 delete - OK" );
0240 sc = pthread_key_delete( key3 );
0241 rtems_test_assert( sc == 0 );
0242
0243 TEST_END();
0244 rtems_test_exit(0);
0245 }
0246
0247
0248
0249 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0250 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0251
0252 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0253
0254 #define CONFIGURE_MAXIMUM_TASKS 3
0255 #define CONFIGURE_MAXIMUM_POSIX_KEYS 2
0256
0257 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0258
0259 #define CONFIGURE_INIT
0260 #include <rtems/confdefs.h>
0261
0262