File indexing completed on 2025-05-11 08:24:48
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 #define CONFIGURE_INIT
0034 #include "system.h"
0035
0036 const char rtems_test_name[] = "SP SEMAPHORE ERROR 02";
0037
0038 rtems_task Init(
0039 rtems_task_argument argument
0040 )
0041 {
0042 rtems_status_code status;
0043
0044 TEST_BEGIN();
0045
0046 Semaphore_name[ 1 ] = rtems_build_name( 'S', 'M', '1', ' ' );
0047 Semaphore_name[ 2 ] = rtems_build_name( 'S', 'M', '2', ' ' );
0048 Task_name[ 2 ] = rtems_build_name( 'T', 'A', '2', ' ' );
0049
0050 status = rtems_task_create(
0051 Task_name[ 2 ],
0052 1,
0053 RTEMS_MINIMUM_STACK_SIZE,
0054 RTEMS_DEFAULT_MODES,
0055 RTEMS_DEFAULT_ATTRIBUTES,
0056 &Task_id[ 2 ]
0057 );
0058 directive_failed( status, "rtems_task_create of TA2" );
0059 puts( "TA1 - rtems_task_create - TA2 created - RTEMS_SUCCESSFUL" );
0060
0061 puts( "TA1 - rtems_task_start - start TA2 - RTEMS_SUCCESSFUL" );
0062 status = rtems_task_start( Task_id[ 2 ], Task_2, 0 );
0063 directive_failed( status, "rtems_task_start of TA2" );
0064
0065
0066 status = rtems_semaphore_create(
0067 Semaphore_name[ 1 ],
0068 1,
0069 RTEMS_DEFAULT_ATTRIBUTES,
0070 RTEMS_NO_PRIORITY,
0071 &Semaphore_id[ 1 ]
0072 );
0073 directive_failed( status, "rtems_semaphore_create" );
0074 puts( "TA1 - rtems_semaphore_create - 1 - RTEMS_SUCCESSFUL" );
0075
0076 status = rtems_semaphore_create(
0077 Semaphore_name[ 2 ],
0078 1,
0079 RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | RTEMS_INHERIT_PRIORITY,
0080 RTEMS_NO_PRIORITY,
0081 &Semaphore_id[ 2 ]
0082 );
0083 directive_failed( status, "rtems_semaphore_create" );
0084 puts( "TA1 - rtems_semaphore_create - 2 - RTEMS_SUCCESSFUL" );
0085
0086 status = rtems_semaphore_obtain(
0087 100,
0088 RTEMS_DEFAULT_OPTIONS,
0089 RTEMS_NO_TIMEOUT
0090 );
0091 fatal_directive_status(
0092 status,
0093 RTEMS_INVALID_ID,
0094 "rtems_semaphore_obtain with illegal id"
0095 );
0096 puts( "TA1 - rtems_semaphore_obtain - RTEMS_INVALID_ID" );
0097
0098 status = rtems_semaphore_obtain(
0099 Semaphore_id[ 1 ],
0100 RTEMS_DEFAULT_OPTIONS,
0101 RTEMS_NO_TIMEOUT
0102 );
0103 directive_failed( status, "rtems_semaphore_obtain successful" );
0104 puts( "TA1 - rtems_semaphore_obtain - got sem 1 - RTEMS_SUCCESSFUL" );
0105
0106 status = rtems_semaphore_obtain(
0107 Semaphore_id[ 1 ],
0108 RTEMS_NO_WAIT,
0109 RTEMS_NO_TIMEOUT
0110 );
0111 fatal_directive_status(
0112 status,
0113 RTEMS_UNSATISFIED,
0114 "rtems_semaphore_obtain not available"
0115 );
0116 puts( "TA1 - rtems_semaphore_obtain - RTEMS_UNSATISFIED" );
0117
0118 puts( "TA1 - rtems_semaphore_obtain - timeout in 3 seconds" );
0119 status = rtems_semaphore_obtain(
0120 Semaphore_id[ 1 ],
0121 RTEMS_DEFAULT_OPTIONS,
0122 3 * rtems_clock_get_ticks_per_second()
0123 );
0124 fatal_directive_status(
0125 status,
0126 RTEMS_TIMEOUT,
0127 "rtems_semaphore_obtain timeout"
0128 );
0129 puts( "TA1 - rtems_semaphore_obtain - woke up with RTEMS_TIMEOUT" );
0130
0131 status = rtems_semaphore_release( Semaphore_id[ 2 ] );
0132 fatal_directive_status(
0133 status,
0134 RTEMS_NOT_OWNER_OF_RESOURCE,
0135 "rtems_semaphore_release and not owner"
0136 );
0137 puts( "TA1 - rtems_semaphore_release - RTEMS_NOT_OWNER_OF_RESOURCE" );
0138
0139 status = rtems_semaphore_release( 100 );
0140 fatal_directive_status(
0141 status,
0142 RTEMS_INVALID_ID,
0143 "rtems_semaphore_release with illegal id"
0144 );
0145 puts( "TA1 - rtems_semaphore_release - RTEMS_INVALID_ID" );
0146
0147 puts( "TA1 - rtems_task_wake_after - yield processor - RTEMS_SUCCESSFUL" );
0148 status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
0149 directive_failed( status, "rtems_task_wake_after (yield)" );
0150
0151 puts( "TA1 - rtems_semaphore_delete - delete sem 1 - RTEMS_SUCCESSFUL" );
0152 status = rtems_semaphore_delete( Semaphore_id[ 1 ] );
0153 directive_failed( status, "rtems_semaphore_delete of SM1" );
0154
0155 puts( "TA1 - rtems_semaphore_obtain - binary semaphore" );
0156 status = rtems_semaphore_obtain(
0157 Semaphore_id[ 2 ],
0158 RTEMS_DEFAULT_OPTIONS,
0159 RTEMS_NO_TIMEOUT
0160 );
0161 directive_failed( status, "rtems_semaphore_obtain");
0162
0163 puts( "TA1 - rtems_semaphore_delete - delete sem 2 - RTEMS_RESOURCE_IN_USE" );
0164
0165 status = rtems_semaphore_delete( Semaphore_id[ 2 ] );
0166 fatal_directive_status(
0167 status,
0168 RTEMS_RESOURCE_IN_USE,
0169 "rtems_semaphore_delete of SM2"
0170 );
0171
0172 puts( "TA1 - rtems_task_wake_after - yield processor - RTEMS_SUCCESSFUL" );
0173 status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
0174 directive_failed( status, "rtems_task_wake_after (yield)" );
0175
0176 TEST_END();
0177 }