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 4";
0040
0041
0042 rtems_task Init(rtems_task_argument argument);
0043 rtems_task Test_Thread1(rtems_task_argument argument);
0044 rtems_task Test_Thread2(rtems_task_argument argument);
0045
0046 int Data_array[2] = {1, 2};
0047 rtems_id thread1, thread2;
0048
0049 pthread_key_t Key;
0050
0051 rtems_task Test_Thread1( rtems_task_argument argument )
0052 {
0053 int sc;
0054 int *value;
0055 struct timespec delay_request;
0056
0057 puts( "Test_Thread 1 - pthread_setspecific - OK" );
0058 sc = pthread_setspecific( Key, &Data_array[0] );
0059 rtems_test_assert( !sc );
0060
0061 puts( "Test_Thread 1 - sleep - let thread 2 run - OK" );
0062 delay_request.tv_sec = 0;
0063 delay_request.tv_nsec = 4 * 100000000;
0064 sc = nanosleep( &delay_request, NULL );
0065 rtems_test_assert( !sc );
0066
0067 puts( "Test_Thread 1 - pthread_getspecific - OK" );
0068 value = pthread_getspecific( Key );
0069 rtems_test_assert( *value == Data_array[0] );
0070
0071 rtems_task_exit();
0072 }
0073
0074 rtems_task Test_Thread2( rtems_task_argument argument )
0075 {
0076 int sc;
0077 int *value;
0078
0079 puts( "Test_Thread 2 - pthread_setspecific - OK" );
0080 sc = pthread_setspecific( Key, &Data_array[1] );
0081 rtems_test_assert( !sc );
0082
0083 puts( "Test_Thread 2 - pthread_getspecific - OK" );
0084 value = pthread_getspecific( Key );
0085 rtems_test_assert( *value == Data_array[1] );
0086
0087 rtems_task_exit();
0088 }
0089
0090 rtems_task Init( rtems_task_argument ignored )
0091 {
0092 int sc;
0093 rtems_status_code rc;
0094 struct timespec delay_request;
0095
0096 TEST_BEGIN();
0097
0098 puts( "Init - pthread_key_create - OK" );
0099 sc = pthread_key_create( &Key, NULL );
0100 rtems_test_assert( !sc );
0101
0102 puts( "Init - create - OK" );
0103 rc = rtems_task_create(
0104 rtems_build_name( 'T', 'E', 'S', 'T' ),
0105 1,
0106 RTEMS_MINIMUM_STACK_SIZE,
0107 RTEMS_DEFAULT_MODES,
0108 RTEMS_DEFAULT_ATTRIBUTES,
0109 &thread1
0110 );
0111 rtems_test_assert( rc == RTEMS_SUCCESSFUL );
0112
0113 rc = rtems_task_start( thread1, Test_Thread1, 0 );
0114 rtems_test_assert( rc == RTEMS_SUCCESSFUL );
0115
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 &thread2
0123 );
0124 rtems_test_assert( rc == RTEMS_SUCCESSFUL );
0125
0126 rc = rtems_task_start( thread2, Test_Thread2, 0 );
0127 rtems_test_assert( rc == RTEMS_SUCCESSFUL );
0128
0129 puts( "Init - sleep - let thread run - OK" );
0130 delay_request.tv_sec = 0;
0131 delay_request.tv_nsec = 8 * 100000000;
0132 sc = nanosleep( &delay_request, NULL );
0133 rtems_test_assert( !sc );
0134
0135 puts( "Init - pthread_key_delete - OK" );
0136 sc = pthread_key_delete( Key );
0137 rtems_test_assert( sc == 0 );
0138
0139 TEST_END();
0140 rtems_test_exit(0);
0141 }
0142
0143
0144
0145 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0146 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0147
0148 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0149
0150 #define CONFIGURE_MAXIMUM_TASKS 3
0151 #define CONFIGURE_MAXIMUM_POSIX_KEYS 1
0152
0153 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0154
0155 #define CONFIGURE_INIT
0156 #include <rtems/confdefs.h>
0157
0158