File indexing completed on 2025-05-11 08:24:41
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 #include <errno.h>
0034 #include <timesys.h>
0035 #include <rtems/btimer.h>
0036 #include <pthread.h>
0037 #include "test_support.h"
0038
0039 const char rtems_test_name[] = "PSXTMRWLOCK 01";
0040
0041
0042 void *POSIX_Init(void *argument);
0043
0044 pthread_rwlock_t rwlock;
0045
0046 static void benchmark_pthread_rwlock_init(void)
0047 {
0048 benchmark_timer_t end_time;
0049 int status;
0050 pthread_rwlockattr_t attr;
0051
0052 pthread_rwlockattr_init( &attr );
0053 benchmark_timer_initialize();
0054 status = pthread_rwlock_init( &rwlock, &attr );
0055 end_time = benchmark_timer_read();
0056 rtems_test_assert( status == 0 );
0057
0058 put_time(
0059 "pthread_rwlock_init: only case",
0060 end_time,
0061 1,
0062 0,
0063 0
0064 );
0065
0066 }
0067
0068 static void benchmark_pthread_rwlock_rdlock(void)
0069 {
0070 benchmark_timer_t end_time;
0071 int status;
0072
0073 benchmark_timer_initialize();
0074 status = pthread_rwlock_rdlock(&rwlock);
0075 end_time = benchmark_timer_read();
0076 rtems_test_assert( status == 0 );
0077
0078 put_time(
0079 "pthread_rwlock_rdlock: available",
0080 end_time,
0081 1,
0082 0,
0083 0
0084 );
0085
0086 }
0087
0088 static void benchmark_pthread_rwlock_unlock(int print)
0089 {
0090 benchmark_timer_t end_time;
0091 int status;
0092
0093 benchmark_timer_initialize();
0094 status = pthread_rwlock_unlock(&rwlock);
0095 end_time = benchmark_timer_read();
0096 rtems_test_assert( status == 0 );
0097 if ( print == 1 ){
0098 put_time(
0099 "pthread_rwlock_unlock: available",
0100 end_time,
0101 1,
0102 0,
0103 0
0104 );
0105 }
0106 }
0107
0108 static void benchmark_pthread_rwlock_tryrdlock(void)
0109 {
0110 benchmark_timer_t end_time;
0111 int status;
0112
0113 benchmark_timer_initialize();
0114 status = pthread_rwlock_tryrdlock(&rwlock);
0115 end_time = benchmark_timer_read();
0116 rtems_test_assert( status == 0 || status == EBUSY );
0117 if (status == EBUSY) {
0118 put_time(
0119 "pthread_rwlock_tryrdlock: not available",
0120 end_time,
0121 1,
0122 0,
0123 0
0124 );
0125 } else if (status == 0) {
0126 put_time(
0127 "pthread_rwlock_tryrdlock: available",
0128 end_time,
0129 1,
0130 0,
0131 0
0132 );
0133 }
0134 }
0135
0136 static void benchmark_pthread_rwlock_timedrdlock(void)
0137 {
0138 benchmark_timer_t end_time;
0139 int status;
0140
0141 benchmark_timer_initialize();
0142 status = pthread_rwlock_timedrdlock(&rwlock, 0);
0143 end_time = benchmark_timer_read();
0144 rtems_test_assert( status == 0 );
0145
0146 put_time(
0147 "pthread_rwlock_timedrdlock: available",
0148 end_time,
0149 1,
0150 0,
0151 0
0152 );
0153
0154 }
0155
0156 static void benchmark_pthread_rwlock_wrlock(void)
0157 {
0158 benchmark_timer_t end_time;
0159 int status;
0160
0161 benchmark_timer_initialize();
0162 status = pthread_rwlock_wrlock(&rwlock);
0163 end_time = benchmark_timer_read();
0164 rtems_test_assert( status == 0 );
0165
0166 put_time(
0167 "pthread_rwlock_wrlock: available",
0168 end_time,
0169 1,
0170 0,
0171 0
0172 );
0173
0174 }
0175
0176 static void benchmark_pthread_rwlock_trywrlock(void)
0177 {
0178 benchmark_timer_t end_time;
0179 int status;
0180
0181 benchmark_timer_initialize();
0182 status = pthread_rwlock_trywrlock(&rwlock);
0183 end_time = benchmark_timer_read();
0184
0185 rtems_test_assert( status == 0 || status == EBUSY );
0186 if ( status == EBUSY ) {
0187 put_time(
0188 "pthread_rwlock_trywrlock: not available ",
0189 end_time,
0190 1,
0191 0,
0192 0
0193 );
0194 } else if ( status == 0 ) {
0195 put_time(
0196 "pthread_rwlock_trywrlock: available",
0197 end_time,
0198 1,
0199 0,
0200 0
0201 );
0202 }
0203 }
0204
0205 static void benchmark_pthread_rwlock_timedwrlock(void)
0206 {
0207 benchmark_timer_t end_time;
0208 int status;
0209
0210 benchmark_timer_initialize();
0211 status = pthread_rwlock_timedwrlock(&rwlock,0);
0212 end_time = benchmark_timer_read();
0213 rtems_test_assert( status == 0 );
0214
0215 put_time(
0216 "pthread_rwlock_timedwrlock: available",
0217 end_time,
0218 1,
0219 0,
0220 0
0221 );
0222 }
0223
0224 static void benchmark_pthread_rwlock_destroy(void)
0225 {
0226 benchmark_timer_t end_time;
0227 int status;
0228
0229 benchmark_timer_initialize();
0230 status = pthread_rwlock_destroy(&rwlock);
0231 end_time = benchmark_timer_read();
0232 rtems_test_assert( status == 0 );
0233
0234 put_time(
0235 "pthread_rwlock_destroy: only case",
0236 end_time,
0237 1,
0238 0,
0239 0
0240 );
0241 }
0242
0243 void *POSIX_Init(
0244 void *argument
0245 )
0246 {
0247
0248 TEST_BEGIN();
0249
0250
0251 benchmark_pthread_rwlock_init();
0252
0253 benchmark_pthread_rwlock_rdlock();
0254
0255 benchmark_pthread_rwlock_unlock(0);
0256
0257 benchmark_pthread_rwlock_tryrdlock();
0258
0259 benchmark_pthread_rwlock_unlock(0);
0260
0261 benchmark_pthread_rwlock_timedrdlock();
0262
0263 benchmark_pthread_rwlock_unlock(0);
0264
0265 benchmark_pthread_rwlock_wrlock();
0266
0267 benchmark_pthread_rwlock_tryrdlock();
0268
0269 benchmark_pthread_rwlock_unlock(0);
0270
0271 benchmark_pthread_rwlock_trywrlock();
0272
0273 benchmark_pthread_rwlock_trywrlock();
0274
0275 benchmark_pthread_rwlock_unlock(0);
0276
0277 benchmark_pthread_rwlock_timedwrlock();
0278
0279 benchmark_pthread_rwlock_unlock(1);
0280
0281 benchmark_pthread_rwlock_destroy();
0282
0283 TEST_END();
0284
0285 rtems_test_exit(0);
0286 }
0287
0288
0289
0290 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0291 #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
0292
0293 #define CONFIGURE_MAXIMUM_POSIX_THREADS 1
0294 #define CONFIGURE_POSIX_INIT_THREAD_TABLE
0295
0296 #define CONFIGURE_INIT
0297
0298 #include <rtems/confdefs.h>
0299