File indexing completed on 2025-05-11 08:24:40
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
0031
0032 #ifdef HAVE_CONFIG_H
0033 #include "config.h"
0034 #endif
0035
0036 #define CONFIGURE_INIT
0037 #include "system.h"
0038
0039 const char rtems_test_name[] = "PSXONCE 1";
0040
0041 static pthread_once_t once_a = PTHREAD_ONCE_INIT;
0042
0043 static pthread_once_t once_b = PTHREAD_ONCE_INIT;
0044
0045 static rtems_id master;
0046
0047 static int test_init_routine_call_counter = 0;
0048
0049 static void Test_init_routine( void )
0050 {
0051 puts( "Test_init_routine: invoked" );
0052 ++test_init_routine_call_counter;
0053 }
0054
0055 static void routine_b( void )
0056 {
0057 rtems_status_code sc;
0058
0059 rtems_test_assert( test_init_routine_call_counter == 2 );
0060 ++test_init_routine_call_counter;
0061
0062 sc = rtems_event_send( master, RTEMS_EVENT_0 );
0063 rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0064 }
0065
0066 static void use_b( rtems_task_argument arg )
0067 {
0068 int status;
0069
0070 (void) arg;
0071
0072 status = pthread_once( &once_b, routine_b );
0073 rtems_test_assert( status == 0 );
0074
0075 rtems_task_exit();
0076 }
0077
0078 static void routine_a( void )
0079 {
0080 rtems_status_code sc;
0081 rtems_id id;
0082 rtems_event_set events;
0083
0084 rtems_test_assert( test_init_routine_call_counter == 1 );
0085 ++test_init_routine_call_counter;
0086
0087 master = rtems_task_self();
0088
0089 sc = rtems_task_create(
0090 rtems_build_name( 'T', 'A', 'S', 'K' ),
0091 RTEMS_MINIMUM_PRIORITY,
0092 RTEMS_MINIMUM_STACK_SIZE,
0093 RTEMS_DEFAULT_MODES,
0094 RTEMS_DEFAULT_ATTRIBUTES,
0095 &id
0096 );
0097 rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0098
0099 sc = rtems_task_start( id, use_b, 0 );
0100 rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0101
0102 events = 0;
0103 sc = rtems_event_receive(
0104 RTEMS_EVENT_0,
0105 RTEMS_EVENT_ANY | RTEMS_WAIT,
0106 RTEMS_NO_TIMEOUT,
0107 &events
0108 );
0109 rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0110 rtems_test_assert( events == RTEMS_EVENT_0 );
0111
0112 rtems_test_assert( test_init_routine_call_counter == 3 );
0113 }
0114
0115 rtems_task Init(rtems_task_argument argument)
0116 {
0117 int status;
0118 pthread_once_t once = PTHREAD_ONCE_INIT;
0119
0120 TEST_BEGIN();
0121
0122 puts( "Init: pthread_once - EINVAL (NULL once_control)" );
0123 status = pthread_once( NULL, Test_init_routine );
0124 rtems_test_assert( status == EINVAL );
0125
0126 puts( "Init: pthread_once - EINVAL (NULL init_routine)" );
0127 status = pthread_once( &once, NULL );
0128 rtems_test_assert( status == EINVAL );
0129
0130 puts( "Init: pthread_once - SUCCESSFUL (init_routine executes)" );
0131 status = pthread_once( &once, Test_init_routine );
0132 rtems_test_assert( !status );
0133 printf( "Init: call counter: %d\n", test_init_routine_call_counter );
0134 rtems_test_assert( test_init_routine_call_counter == 1 );
0135
0136 puts( "Init: pthread_once - SUCCESSFUL (init_routine does not execute)" );
0137 status = pthread_once( &once, Test_init_routine );
0138 rtems_test_assert( !status );
0139 printf( "Init: call counter: %d\n", test_init_routine_call_counter );
0140 rtems_test_assert( test_init_routine_call_counter == 1 );
0141
0142 status = pthread_once( &once_a, routine_a );
0143 rtems_test_assert( status == 0 );
0144 rtems_test_assert( test_init_routine_call_counter == 3 );
0145
0146 TEST_END();
0147 rtems_test_exit( 0 );
0148 }