File indexing completed on 2025-05-11 08:24:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifdef HAVE_CONFIG_H
0018 #include "config.h"
0019 #endif
0020
0021 #include <timesys.h>
0022 #include <rtems/btimer.h>
0023 #include "test_support.h"
0024 #include <tmacros.h>
0025 #include <pthread.h>
0026 #include <timesys.h>
0027 #include <sched.h>
0028
0029 #define GUARDSIZE_TEST_VALUE 512
0030 #define STACKSIZE_TEST_VALUE 1024
0031
0032 const char rtems_test_name[] = "PSXTMTHREADATTR01";
0033
0034
0035 static void *POSIX_Init(void *argument);
0036
0037 static pthread_attr_t attr;
0038 static size_t guardsize = GUARDSIZE_TEST_VALUE;
0039 static size_t stacksize = STACKSIZE_TEST_VALUE;
0040 static struct sched_param param;
0041 static void *stackaddr;
0042
0043 static void benchmark_create_pthread_attr(void)
0044 {
0045 benchmark_timer_t end_time;
0046 int status;
0047
0048 benchmark_timer_initialize();
0049 status = pthread_attr_init(&attr);
0050 end_time = benchmark_timer_read();
0051 rtems_test_assert( status == 0 );
0052
0053 put_time(
0054 "pthread_attr_init: only case",
0055 end_time,
0056 1,
0057 0,
0058 0
0059 );
0060
0061 }
0062
0063 static void benchmark_pthread_attr_setdetachstate(void)
0064 {
0065 benchmark_timer_t end_time;
0066 int status;
0067
0068 benchmark_timer_initialize();
0069 status = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
0070 end_time = benchmark_timer_read();
0071 rtems_test_assert( status == 0 );
0072
0073 put_time(
0074 "pthread_attr_setdetachstate: only case",
0075 end_time,
0076 1,
0077 0,
0078 0
0079 );
0080
0081 }
0082
0083 static void benchmark_pthread_attr_getdetachstate(void)
0084 {
0085 benchmark_timer_t end_time;
0086 int status;
0087 int detachstate;
0088
0089 benchmark_timer_initialize();
0090 status = pthread_attr_getdetachstate(&attr, &detachstate);
0091 end_time = benchmark_timer_read();
0092 rtems_test_assert( status == 0 );
0093 rtems_test_assert( detachstate == PTHREAD_CREATE_DETACHED );
0094
0095 put_time(
0096 "pthread_attr_getdetachstate: only case",
0097 end_time,
0098 1,
0099 0,
0100 0
0101 );
0102
0103 }
0104
0105 static void benchmark_pthread_attr_setguardsize(void)
0106 {
0107 benchmark_timer_t end_time;
0108 int status;
0109
0110 benchmark_timer_initialize();
0111 status = pthread_attr_setguardsize(&attr, guardsize);
0112 end_time = benchmark_timer_read();
0113 rtems_test_assert( status == 0 );
0114
0115 put_time(
0116 "pthread_attr_setguardsize: only case",
0117 end_time,
0118 1,
0119 0,
0120 0
0121 );
0122
0123 }
0124
0125 static void benchmark_pthread_attr_getguardsize(void)
0126 {
0127 benchmark_timer_t end_time;
0128 int status;
0129 size_t tmp_guardsize;
0130
0131 benchmark_timer_initialize();
0132 status = pthread_attr_getguardsize(&attr, &tmp_guardsize);
0133 end_time = benchmark_timer_read();
0134 rtems_test_assert( status == 0 );
0135 rtems_test_assert( tmp_guardsize == guardsize );
0136
0137 put_time(
0138 "pthread_attr_getguardsize: only case",
0139 end_time,
0140 1,
0141 0,
0142 0
0143 );
0144
0145 }
0146
0147 static void benchmark_pthread_attr_setinheritsched(void)
0148 {
0149 benchmark_timer_t end_time;
0150 int status;
0151
0152 benchmark_timer_initialize();
0153 status = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
0154 end_time = benchmark_timer_read();
0155 rtems_test_assert( status == 0 );
0156
0157 put_time(
0158 "pthread_attr_setinheritsched: only case",
0159 end_time,
0160 1,
0161 0,
0162 0
0163 );
0164
0165 }
0166
0167 static void benchmark_pthread_attr_getinheritsched(void)
0168 {
0169 benchmark_timer_t end_time;
0170 int status;
0171 int inheritsched;
0172
0173 benchmark_timer_initialize();
0174 status = pthread_attr_getinheritsched(&attr, &inheritsched);
0175 end_time = benchmark_timer_read();
0176 rtems_test_assert( status == 0 );
0177 rtems_test_assert( inheritsched == PTHREAD_EXPLICIT_SCHED );
0178
0179 put_time(
0180 "pthread_attr_getinheritsched: only case",
0181 end_time,
0182 1,
0183 0,
0184 0
0185 );
0186
0187 }
0188
0189 static void benchmark_pthread_attr_setschedparam(void)
0190 {
0191 benchmark_timer_t end_time;
0192 int status;
0193
0194 status = pthread_attr_setschedparam(&attr, ¶m);
0195 rtems_test_assert( status == 0 );
0196 param.sched_priority = sched_get_priority_min( SCHED_RR ) + 2;
0197 benchmark_timer_initialize();
0198 status = pthread_attr_setschedparam(&attr, ¶m);
0199 end_time = benchmark_timer_read();
0200 rtems_test_assert( status == 0 );
0201
0202 put_time(
0203 "pthread_attr_setschedparam: only case",
0204 end_time,
0205 1,
0206 0,
0207 0
0208 );
0209
0210 }
0211
0212 static void benchmark_pthread_attr_getschedparam(void)
0213 {
0214 benchmark_timer_t end_time;
0215 int status;
0216 struct sched_param tmp_param;
0217
0218 status = pthread_attr_getschedparam(&attr, &tmp_param);
0219 rtems_test_assert( status == 0 );
0220 tmp_param.sched_priority = sched_get_priority_min( SCHED_RR ) + 2;
0221 benchmark_timer_initialize();
0222 status = pthread_attr_getschedparam(&attr, &tmp_param);
0223 end_time = benchmark_timer_read();
0224 rtems_test_assert( status == 0 );
0225 rtems_test_assert( tmp_param.sched_priority == param.sched_priority );
0226
0227 put_time(
0228 "pthread_attr_getschedparam: only case",
0229 end_time,
0230 1,
0231 0,
0232 0
0233 );
0234
0235 }
0236
0237 static void benchmark_pthread_attr_setschedpolicy(void)
0238 {
0239 benchmark_timer_t end_time;
0240 int status;
0241
0242 benchmark_timer_initialize();
0243 status = pthread_attr_setschedpolicy(&attr, SCHED_RR);
0244 end_time = benchmark_timer_read();
0245 rtems_test_assert( status == 0 );
0246
0247 put_time(
0248 "pthread_attr_setschedpolicy: only case",
0249 end_time,
0250 1,
0251 0,
0252 0
0253 );
0254
0255 }
0256
0257 static void benchmark_pthread_attr_getschedpolicy(void)
0258 {
0259 benchmark_timer_t end_time;
0260 int status;
0261 int policy;
0262
0263 benchmark_timer_initialize();
0264 status = pthread_attr_getschedpolicy(&attr, &policy);
0265 end_time = benchmark_timer_read();
0266 rtems_test_assert( status == 0 );
0267 rtems_test_assert( policy == SCHED_RR );
0268
0269 put_time(
0270 "pthread_attr_getschedpolicy: only case",
0271 end_time,
0272 1,
0273 0,
0274 0
0275 );
0276
0277 }
0278
0279 static void benchmark_pthread_attr_setscope(void)
0280 {
0281 benchmark_timer_t end_time;
0282 int status;
0283
0284 benchmark_timer_initialize();
0285 status = pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS);
0286 end_time = benchmark_timer_read();
0287 rtems_test_assert( status == 0 );
0288
0289 put_time(
0290 "pthread_attr_setscope: only case",
0291 end_time,
0292 1,
0293 0,
0294 0
0295 );
0296
0297 }
0298
0299 static void benchmark_pthread_attr_getscope(void)
0300 {
0301 benchmark_timer_t end_time;
0302 int status;
0303 int scope;
0304
0305 benchmark_timer_initialize();
0306 status = pthread_attr_getscope(&attr, &scope);
0307 end_time = benchmark_timer_read();
0308 rtems_test_assert( status == 0 );
0309 rtems_test_assert( scope == PTHREAD_SCOPE_PROCESS );
0310
0311 put_time(
0312 "pthread_attr_getscope: only case",
0313 end_time,
0314 1,
0315 0,
0316 0
0317 );
0318
0319 }
0320
0321 static void benchmark_pthread_attr_setstack(void)
0322 {
0323 benchmark_timer_t end_time;
0324 int status;
0325
0326 benchmark_timer_initialize();
0327 status = pthread_attr_setstack(&attr, stackaddr, stacksize);
0328 end_time = benchmark_timer_read();
0329 rtems_test_assert( status == 0 );
0330
0331 put_time(
0332 "pthread_attr_setstack: only case",
0333 end_time,
0334 1,
0335 0,
0336 0
0337 );
0338
0339 }
0340
0341 static void benchmark_pthread_attr_getstack(void)
0342 {
0343 benchmark_timer_t end_time;
0344 int status;
0345 size_t tmp_stacksize;
0346
0347 benchmark_timer_initialize();
0348 status = pthread_attr_getstack(&attr, &stackaddr, &tmp_stacksize);
0349 end_time = benchmark_timer_read();
0350 rtems_test_assert( status == 0 );
0351 rtems_test_assert(tmp_stacksize == stacksize);
0352
0353 put_time(
0354 "pthread_attr_getstack: only case",
0355 end_time,
0356 1,
0357 0,
0358 0
0359 );
0360
0361 }
0362
0363 static void benchmark_destroy_pthread_attr(void)
0364 {
0365 benchmark_timer_t end_time;
0366 int status;
0367
0368 benchmark_timer_initialize();
0369 status = pthread_attr_destroy(&attr);
0370 end_time = benchmark_timer_read();
0371 rtems_test_assert( status == 0 );
0372
0373 put_time(
0374 "pthread_attr_destroy: only case",
0375 end_time,
0376 1,
0377 0,
0378 0
0379 );
0380
0381 }
0382
0383 static void *POSIX_Init(
0384 void *argument
0385 )
0386 {
0387 TEST_BEGIN();
0388
0389 benchmark_create_pthread_attr();
0390 benchmark_pthread_attr_setdetachstate();
0391 benchmark_pthread_attr_getdetachstate();
0392 benchmark_pthread_attr_setguardsize();
0393 benchmark_pthread_attr_getguardsize();
0394 benchmark_pthread_attr_setinheritsched();
0395 benchmark_pthread_attr_getinheritsched();
0396 benchmark_pthread_attr_setschedparam();
0397 benchmark_pthread_attr_getschedparam();
0398 benchmark_pthread_attr_setschedpolicy();
0399 benchmark_pthread_attr_getschedpolicy();
0400 benchmark_pthread_attr_setscope();
0401 benchmark_pthread_attr_getscope();
0402 benchmark_pthread_attr_setstack();
0403 benchmark_pthread_attr_getstack();
0404 benchmark_destroy_pthread_attr();
0405
0406 TEST_END();
0407 rtems_test_exit(0);
0408 }
0409
0410
0411
0412 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0413 #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
0414
0415
0416
0417 #define CONFIGURE_MAXIMUM_POSIX_THREADS 1
0418 #define CONFIGURE_POSIX_INIT_THREAD_TABLE
0419
0420 #define CONFIGURE_INIT
0421
0422 #include <rtems/confdefs.h>
0423