File indexing completed on 2025-05-11 08:24:47
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 #ifdef HAVE_CONFIG_H
0032 #include "config.h"
0033 #endif
0034
0035 #include <rtems/test.h>
0036 #include <rtems/test-info.h>
0037
0038 #include <rtems/score/threadimpl.h>
0039
0040 const char rtems_test_name[] = "SPINTRCRITICAL 16";
0041
0042 typedef struct {
0043 Thread_Control *thread;
0044 rtems_id semaphore;
0045 } test_context;
0046
0047 static T_interrupt_test_state interrupt( void *arg )
0048 {
0049 test_context *ctx;
0050 T_interrupt_test_state state;
0051 Thread_Wait_flags flags;
0052 rtems_status_code sc;
0053
0054 state = T_interrupt_test_get_state();
0055
0056 if (state != T_INTERRUPT_TEST_ACTION) {
0057 return T_INTERRUPT_TEST_CONTINUE;
0058 }
0059
0060 ctx = arg;
0061 flags = _Thread_Wait_flags_get( ctx->thread );
0062
0063 if (
0064 flags == ( THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_INTEND_TO_BLOCK )
0065 ) {
0066 state = T_INTERRUPT_TEST_DONE;
0067 } else if (
0068 flags == ( THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_BLOCKED )
0069 ) {
0070 state = T_INTERRUPT_TEST_LATE;
0071 } else {
0072 state = T_INTERRUPT_TEST_EARLY;
0073 }
0074
0075 sc = rtems_semaphore_release( ctx->semaphore );
0076 T_quiet_rsc_success( sc );
0077
0078 return state;
0079 }
0080
0081 static void prepare( void *arg )
0082 {
0083 test_context *ctx;
0084 rtems_status_code sc;
0085
0086 ctx = arg;
0087
0088 do {
0089 sc = rtems_semaphore_obtain( ctx->semaphore, RTEMS_NO_WAIT, 0 );
0090 } while ( sc == RTEMS_SUCCESSFUL );
0091 }
0092
0093 static void action( void *arg )
0094 {
0095 test_context *ctx;
0096 rtems_status_code sc;
0097
0098 ctx = arg;
0099 sc = rtems_semaphore_obtain( ctx->semaphore, RTEMS_DEFAULT_OPTIONS, 2 );
0100 T_quiet_rsc_success( sc );
0101 }
0102
0103 static void blocked( void *arg )
0104 {
0105 test_context *ctx;
0106 rtems_status_code sc;
0107
0108 T_interrupt_test_change_state(
0109 T_INTERRUPT_TEST_ACTION,
0110 T_INTERRUPT_TEST_LATE
0111 );
0112
0113 ctx = arg;
0114 sc = rtems_semaphore_release( ctx->semaphore );
0115 T_quiet_rsc_success( sc );
0116 }
0117
0118 static const T_interrupt_test_config config = {
0119 .prepare = prepare,
0120 .action = action,
0121 .interrupt = interrupt,
0122 .blocked = blocked,
0123 .max_iteration_count = 10000
0124 };
0125
0126
0127
0128
0129
0130 T_TEST_CASE( SemaphoreSatisfyBeforeTimeout )
0131 {
0132 test_context ctx;
0133 rtems_status_code sc;
0134 T_interrupt_test_state state;
0135
0136 ctx.thread = _Thread_Get_executing();
0137
0138 sc = rtems_semaphore_create(
0139 rtems_build_name( 'S', 'M', '1', ' ' ),
0140 0,
0141 RTEMS_DEFAULT_ATTRIBUTES,
0142 RTEMS_NO_PRIORITY,
0143 &ctx.semaphore
0144 );
0145 T_assert_rsc_success( sc );
0146
0147 state = T_interrupt_test( &config, &ctx );
0148 T_eq_int( state, T_INTERRUPT_TEST_DONE );
0149
0150 sc = rtems_semaphore_delete( ctx.semaphore );
0151 T_rsc_success( sc );
0152 }
0153
0154 static rtems_task Init( rtems_task_argument argument )
0155 {
0156 rtems_test_run( argument, TEST_STATE );
0157 }
0158
0159
0160
0161 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0162 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0163
0164 #define CONFIGURE_MAXIMUM_TASKS 1
0165 #define CONFIGURE_MAXIMUM_SEMAPHORES 1
0166 #define CONFIGURE_MICROSECONDS_PER_TICK 1000
0167 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0168
0169 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0170
0171 #define CONFIGURE_INIT
0172 #include <rtems/confdefs.h>
0173
0174