File indexing completed on 2025-05-11 08:24:50
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 #if !defined(OPERATION_COUNT)
0030 #define OPERATION_COUNT 100
0031 #endif
0032
0033 #ifdef HAVE_CONFIG_H
0034 #include "config.h"
0035 #endif
0036
0037 #include <rtems/btimer.h>
0038
0039 #define CONFIGURE_INIT
0040 #include "system.h"
0041
0042 #if defined(TM02)
0043 const char rtems_test_name[] = "TIME TEST 2";
0044 #define SEMAPHORE_ATTRIBUTES (RTEMS_COUNTING_SEMAPHORE | RTEMS_FIFO)
0045 #define ATTR_DESC "counting/FIFO"
0046
0047 #elif defined(TM31)
0048 const char rtems_test_name[] = "TIME TEST 31";
0049 #define SEMAPHORE_ATTRIBUTES (RTEMS_COUNTING_SEMAPHORE | RTEMS_PRIORITY)
0050 #define ATTR_DESC "counting/priority"
0051
0052 #elif defined(TM33)
0053 const char rtems_test_name[] = "TIME TEST 33";
0054 #define SEMAPHORE_ATTRIBUTES RTEMS_BINARY_SEMAPHORE
0055 #define ATTR_DESC "binary/FIFO"
0056
0057 #elif defined(TM35)
0058 const char rtems_test_name[] = "TIME TEST 35";
0059 #define SEMAPHORE_ATTRIBUTES (RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY)
0060 #define ATTR_DESC "binary/priority"
0061
0062 #else
0063 #error "Unknown test configuration"
0064 #endif
0065
0066 rtems_id High_id;
0067 rtems_id Low_id;
0068 rtems_id Semaphore_id;
0069
0070 rtems_task High_task(
0071 rtems_task_argument argument
0072 );
0073
0074 rtems_task Middle_tasks(
0075 rtems_task_argument argument
0076 );
0077
0078 rtems_task Low_task(
0079 rtems_task_argument argument
0080 );
0081
0082 int operation_count = OPERATION_COUNT;
0083
0084 void test_init(void);
0085
0086 rtems_task Init(
0087 rtems_task_argument argument
0088 )
0089 {
0090 rtems_status_code status;
0091
0092 Print_Warning();
0093
0094 TEST_BEGIN();
0095
0096 test_init();
0097
0098 status = rtems_task_suspend( RTEMS_SELF );
0099 directive_failed( status, "rtems_task_suspend" );
0100 }
0101
0102 void test_init(void)
0103 {
0104 rtems_status_code status;
0105 int index;
0106 rtems_task_priority priority;
0107
0108 priority = 2;
0109
0110 status = rtems_task_create(
0111 rtems_build_name( 'H', 'I', 'G', 'H' ),
0112 priority,
0113 RTEMS_MINIMUM_STACK_SIZE,
0114 RTEMS_DEFAULT_MODES,
0115 RTEMS_DEFAULT_ATTRIBUTES,
0116 &High_id
0117 );
0118 directive_failed( status, "rtems_task_create of high task" );
0119
0120 priority++;
0121
0122 status = rtems_task_start( High_id, High_task, 0 );
0123 directive_failed( status, "rtems_task_start of high task" );
0124
0125 if ( OPERATION_COUNT > RTEMS_MAXIMUM_PRIORITY - 2u )
0126 operation_count = (int) (RTEMS_MAXIMUM_PRIORITY - 2u);
0127 for ( index=2 ; index < operation_count ; index++ ) {
0128 status = rtems_task_create(
0129 rtems_build_name( 'M', 'I', 'D', ' ' ),
0130 priority,
0131 RTEMS_MINIMUM_STACK_SIZE,
0132 RTEMS_DEFAULT_MODES,
0133 RTEMS_DEFAULT_ATTRIBUTES,
0134 &Low_id
0135 );
0136 directive_failed( status, "rtems_task_create middle" );
0137
0138 priority++;
0139
0140 status = rtems_task_start( Low_id, Middle_tasks, 0 );
0141 directive_failed( status, "rtems_task_start middle" );
0142 }
0143
0144 status = rtems_task_create(
0145 rtems_build_name( 'L', 'O', 'W', ' ' ),
0146 priority,
0147 RTEMS_MINIMUM_STACK_SIZE,
0148 RTEMS_DEFAULT_MODES,
0149 RTEMS_DEFAULT_ATTRIBUTES,
0150 &Low_id
0151 );
0152 directive_failed( status, "rtems_task_create low" );
0153
0154 status = rtems_task_start( Low_id, Low_task, 0 );
0155 directive_failed( status, "rtems_task_start low" );
0156
0157 status = rtems_semaphore_create(
0158 rtems_build_name( 'S', 'M', '1', ' '),
0159 0,
0160 SEMAPHORE_ATTRIBUTES,
0161 RTEMS_NO_PRIORITY,
0162 &Semaphore_id
0163 );
0164 directive_failed( status, "rtems_semaphore_create of SM1" );
0165 }
0166
0167 rtems_task High_task(
0168 rtems_task_argument argument
0169 )
0170 {
0171
0172 benchmark_timer_initialize();
0173
0174 (void) rtems_semaphore_obtain(
0175 Semaphore_id,
0176 RTEMS_DEFAULT_OPTIONS,
0177 RTEMS_NO_TIMEOUT
0178 );
0179 }
0180
0181 rtems_task Middle_tasks(
0182 rtems_task_argument argument
0183 )
0184 {
0185 (void) rtems_semaphore_obtain(
0186 Semaphore_id,
0187 RTEMS_DEFAULT_OPTIONS,
0188 RTEMS_NO_TIMEOUT
0189 );
0190 }
0191
0192 rtems_task Low_task(
0193 rtems_task_argument argument
0194 )
0195 {
0196 end_time = benchmark_timer_read();
0197
0198 put_time(
0199 "rtems_semaphore_obtain: " ATTR_DESC " not available caller blocks",
0200 end_time,
0201 operation_count - 1,
0202 0,
0203 0
0204 );
0205
0206 TEST_END();
0207 rtems_test_exit( 0 );
0208 }