[8abb230b] | 1 | /* |
---|
| 2 | * COPYRIGHT (c) 2018. |
---|
| 3 | * Himanshu Sekhar Nayak (GCI 2018) |
---|
| 4 | * |
---|
| 5 | * Permission to use, copy, modify, and/or distribute this software |
---|
| 6 | * for any purpose with or without fee is hereby granted. |
---|
| 7 | * |
---|
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
---|
| 9 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
---|
| 10 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR |
---|
| 11 | * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES |
---|
| 12 | * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, |
---|
| 13 | * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, |
---|
| 14 | * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | #ifdef HAVE_CONFIG_H |
---|
| 18 | #include "config.h" |
---|
| 19 | #endif |
---|
| 20 | |
---|
| 21 | #include <timesys.h> |
---|
| 22 | #include <rtems/btimer.h> |
---|
| 23 | #include "test_support.h" |
---|
| 24 | #include <tmacros.h> |
---|
| 25 | #include <pthread.h> |
---|
| 26 | #include <timesys.h> |
---|
| 27 | #include <sched.h> |
---|
| 28 | #define GUARDSIZE_TEST_VALUE 512 |
---|
| 29 | #define STACKSIZE_TEST_VALUE 1024 |
---|
| 30 | |
---|
| 31 | const char rtems_test_name[] = "PSXTMTHREADATTR01"; |
---|
| 32 | |
---|
| 33 | /* forward declarations to avoid warnings */ |
---|
| 34 | static void *POSIX_Init(void *argument); |
---|
| 35 | |
---|
| 36 | static pthread_attr_t attr; |
---|
| 37 | static size_t guardsize = GUARDSIZE_TEST_VALUE; |
---|
| 38 | static size_t stacksize = STACKSIZE_TEST_VALUE; |
---|
| 39 | static struct sched_param param; |
---|
| 40 | static int var = 2; |
---|
| 41 | static void *stackaddr; |
---|
| 42 | |
---|
| 43 | static void benchmark_create_pthread_attr(void) |
---|
| 44 | { |
---|
| 45 | benchmark_timer_t end_time; |
---|
| 46 | int status; |
---|
| 47 | |
---|
| 48 | benchmark_timer_initialize(); |
---|
| 49 | status = pthread_attr_init(&attr); |
---|
| 50 | end_time = benchmark_timer_read(); |
---|
| 51 | rtems_test_assert( status == 0 ); |
---|
| 52 | |
---|
| 53 | put_time( |
---|
| 54 | "pthread_attr_init: only case", |
---|
| 55 | end_time, |
---|
| 56 | 1, /* Only executed once */ |
---|
| 57 | 0, |
---|
| 58 | 0 |
---|
| 59 | ); |
---|
| 60 | |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | static void benchmark_pthread_attr_setdetachstate(void) |
---|
| 64 | { |
---|
| 65 | benchmark_timer_t end_time; |
---|
| 66 | int status; |
---|
| 67 | |
---|
| 68 | benchmark_timer_initialize(); |
---|
| 69 | status = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
---|
| 70 | end_time = benchmark_timer_read(); |
---|
| 71 | rtems_test_assert( status == 0 ); |
---|
| 72 | |
---|
| 73 | put_time( |
---|
| 74 | "pthread_attr_setdetachstate: only case", |
---|
| 75 | end_time, |
---|
| 76 | 1, /* Only executed once */ |
---|
| 77 | 0, |
---|
| 78 | 0 |
---|
| 79 | ); |
---|
| 80 | |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | static void benchmark_pthread_attr_getdetachstate(void) |
---|
| 84 | { |
---|
| 85 | benchmark_timer_t end_time; |
---|
| 86 | int status; |
---|
| 87 | int tmp_var; |
---|
| 88 | |
---|
| 89 | benchmark_timer_initialize(); |
---|
| 90 | status = pthread_attr_getdetachstate(&attr, &tmp_var); |
---|
| 91 | end_time = benchmark_timer_read(); |
---|
| 92 | rtems_test_assert( status == 0 ); |
---|
| 93 | rtems_test_assert( tmp_var == PTHREAD_CREATE_DETACHED ); |
---|
| 94 | |
---|
| 95 | put_time( |
---|
| 96 | "pthread_attr_getdetachstate: only case", |
---|
| 97 | end_time, |
---|
| 98 | 1, /* Only executed once */ |
---|
| 99 | 0, |
---|
| 100 | 0 |
---|
| 101 | ); |
---|
| 102 | |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | static void benchmark_pthread_attr_setguardsize(void) |
---|
| 106 | { |
---|
| 107 | benchmark_timer_t end_time; |
---|
| 108 | int status; |
---|
| 109 | |
---|
| 110 | benchmark_timer_initialize(); |
---|
| 111 | status = pthread_attr_setguardsize(&attr, guardsize); |
---|
| 112 | end_time = benchmark_timer_read(); |
---|
| 113 | rtems_test_assert( status == 0 ); |
---|
| 114 | |
---|
| 115 | put_time( |
---|
| 116 | "pthread_attr_setguardsize: only case", |
---|
| 117 | end_time, |
---|
| 118 | 1, /* Only executed once */ |
---|
| 119 | 0, |
---|
| 120 | 0 |
---|
| 121 | ); |
---|
| 122 | |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | static void benchmark_pthread_attr_getguardsize(void) |
---|
| 126 | { |
---|
| 127 | benchmark_timer_t end_time; |
---|
| 128 | int status; |
---|
| 129 | size_t tmp_guardsize; |
---|
| 130 | |
---|
| 131 | benchmark_timer_initialize(); |
---|
| 132 | status = pthread_attr_getguardsize(&attr, &tmp_guardsize); |
---|
| 133 | end_time = benchmark_timer_read(); |
---|
| 134 | rtems_test_assert( status == 0 ); |
---|
| 135 | rtems_test_assert( tmp_guardsize == guardsize ); |
---|
| 136 | |
---|
| 137 | put_time( |
---|
| 138 | "pthread_attr_getguardsize: only case", |
---|
| 139 | end_time, |
---|
| 140 | 1, /* Only executed once */ |
---|
| 141 | 0, |
---|
| 142 | 0 |
---|
| 143 | ); |
---|
| 144 | |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | static void benchmark_pthread_attr_setinheritsched(void) |
---|
| 148 | { |
---|
| 149 | benchmark_timer_t end_time; |
---|
| 150 | int status; |
---|
| 151 | |
---|
| 152 | benchmark_timer_initialize(); |
---|
| 153 | status = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); |
---|
| 154 | end_time = benchmark_timer_read(); |
---|
| 155 | rtems_test_assert( status == 0 ); |
---|
| 156 | |
---|
| 157 | put_time( |
---|
| 158 | "pthread_attr_setinheritsched: only case", |
---|
| 159 | end_time, |
---|
| 160 | 1, /* Only executed once */ |
---|
| 161 | 0, |
---|
| 162 | 0 |
---|
| 163 | ); |
---|
| 164 | |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | static void benchmark_pthread_attr_getinheritsched(void) |
---|
| 168 | { |
---|
| 169 | benchmark_timer_t end_time; |
---|
| 170 | int status; |
---|
| 171 | int tmp_var; |
---|
| 172 | |
---|
| 173 | benchmark_timer_initialize(); |
---|
| 174 | status = pthread_attr_getinheritsched(&attr, &tmp_var); |
---|
| 175 | end_time = benchmark_timer_read(); |
---|
| 176 | rtems_test_assert( status == 0 ); |
---|
| 177 | rtems_test_assert( tmp_var == PTHREAD_EXPLICIT_SCHED ); |
---|
| 178 | |
---|
| 179 | put_time( |
---|
| 180 | "pthread_attr_getinheritsched: only case", |
---|
| 181 | end_time, |
---|
| 182 | 1, /* Only executed once */ |
---|
| 183 | 0, |
---|
| 184 | 0 |
---|
| 185 | ); |
---|
| 186 | |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | static void benchmark_pthread_attr_setschedparam(void) |
---|
| 190 | { |
---|
| 191 | benchmark_timer_t end_time; |
---|
| 192 | int status; |
---|
| 193 | |
---|
| 194 | status = pthread_attr_setschedparam(&attr, ¶m); |
---|
| 195 | rtems_test_assert( status == 0 ); |
---|
| 196 | param.sched_priority = sched_get_priority_min( SCHED_RR ) + 2; |
---|
| 197 | benchmark_timer_initialize(); |
---|
| 198 | status = pthread_attr_setschedparam(&attr, ¶m); |
---|
| 199 | end_time = benchmark_timer_read(); |
---|
| 200 | rtems_test_assert( status == 0 ); |
---|
| 201 | |
---|
| 202 | put_time( |
---|
| 203 | "pthread_attr_setschedparam: only case", |
---|
| 204 | end_time, |
---|
| 205 | 1, /* Only executed once */ |
---|
| 206 | 0, |
---|
| 207 | 0 |
---|
| 208 | ); |
---|
| 209 | |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | static void benchmark_pthread_attr_getschedparam(void) |
---|
| 213 | { |
---|
| 214 | benchmark_timer_t end_time; |
---|
| 215 | int status; |
---|
| 216 | struct sched_param tmp_param; |
---|
| 217 | |
---|
| 218 | status = pthread_attr_getschedparam(&attr, &tmp_param); |
---|
| 219 | rtems_test_assert( status == 0 ); |
---|
| 220 | tmp_param.sched_priority = sched_get_priority_min( SCHED_RR ) + 2; |
---|
| 221 | benchmark_timer_initialize(); |
---|
| 222 | status = pthread_attr_getschedparam(&attr, &tmp_param); |
---|
| 223 | end_time = benchmark_timer_read(); |
---|
| 224 | rtems_test_assert( status == 0 ); |
---|
| 225 | rtems_test_assert( tmp_param.sched_priority == param.sched_priority ); |
---|
| 226 | |
---|
| 227 | put_time( |
---|
| 228 | "pthread_attr_getschedparam: only case", |
---|
| 229 | end_time, |
---|
| 230 | 1, /* Only executed once */ |
---|
| 231 | 0, |
---|
| 232 | 0 |
---|
| 233 | ); |
---|
| 234 | |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | static void benchmark_pthread_attr_setschedpolicy(void) |
---|
| 238 | { |
---|
| 239 | benchmark_timer_t end_time; |
---|
| 240 | int status; |
---|
| 241 | |
---|
| 242 | benchmark_timer_initialize(); |
---|
| 243 | status = pthread_attr_setschedpolicy(&attr, var); |
---|
| 244 | end_time = benchmark_timer_read(); |
---|
| 245 | rtems_test_assert( status == 0 ); |
---|
| 246 | |
---|
| 247 | put_time( |
---|
| 248 | "pthread_attr_setschedpolicy: only case", |
---|
| 249 | end_time, |
---|
| 250 | 1, /* Only executed once */ |
---|
| 251 | 0, |
---|
| 252 | 0 |
---|
| 253 | ); |
---|
| 254 | |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | static void benchmark_pthread_attr_getschedpolicy(void) |
---|
| 258 | { |
---|
| 259 | benchmark_timer_t end_time; |
---|
| 260 | int status; |
---|
| 261 | int tmp_var; |
---|
| 262 | |
---|
| 263 | benchmark_timer_initialize(); |
---|
| 264 | status = pthread_attr_getschedpolicy(&attr, &tmp_var); |
---|
| 265 | end_time = benchmark_timer_read(); |
---|
| 266 | rtems_test_assert( status == 0 ); |
---|
| 267 | rtems_test_assert( tmp_var == var ); |
---|
| 268 | |
---|
| 269 | put_time( |
---|
| 270 | "pthread_attr_getschedpolicy: only case", |
---|
| 271 | end_time, |
---|
| 272 | 1, /* Only executed once */ |
---|
| 273 | 0, |
---|
| 274 | 0 |
---|
| 275 | ); |
---|
| 276 | |
---|
| 277 | } |
---|
| 278 | |
---|
| 279 | static void benchmark_pthread_attr_setscope(void) |
---|
| 280 | { |
---|
| 281 | benchmark_timer_t end_time; |
---|
| 282 | int status; |
---|
| 283 | |
---|
| 284 | benchmark_timer_initialize(); |
---|
| 285 | status = pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS); |
---|
| 286 | end_time = benchmark_timer_read(); |
---|
| 287 | rtems_test_assert( status == 0 ); |
---|
| 288 | |
---|
| 289 | put_time( |
---|
| 290 | "pthread_attr_setscope: only case", |
---|
| 291 | end_time, |
---|
| 292 | 1, /* Only executed once */ |
---|
| 293 | 0, |
---|
| 294 | 0 |
---|
| 295 | ); |
---|
| 296 | |
---|
| 297 | } |
---|
| 298 | |
---|
| 299 | static void benchmark_pthread_attr_getscope(void) |
---|
| 300 | { |
---|
| 301 | benchmark_timer_t end_time; |
---|
| 302 | int status; |
---|
| 303 | int scope; |
---|
| 304 | |
---|
| 305 | benchmark_timer_initialize(); |
---|
| 306 | status = pthread_attr_getscope(&attr, &scope); |
---|
| 307 | end_time = benchmark_timer_read(); |
---|
| 308 | rtems_test_assert( status == 0 ); |
---|
| 309 | rtems_test_assert( scope == PTHREAD_SCOPE_PROCESS ); |
---|
| 310 | |
---|
| 311 | put_time( |
---|
| 312 | "pthread_attr_getscope: only case", |
---|
| 313 | end_time, |
---|
| 314 | 1, /* Only executed once */ |
---|
| 315 | 0, |
---|
| 316 | 0 |
---|
| 317 | ); |
---|
| 318 | |
---|
| 319 | } |
---|
| 320 | |
---|
| 321 | static void benchmark_pthread_attr_setstack(void) |
---|
| 322 | { |
---|
| 323 | benchmark_timer_t end_time; |
---|
| 324 | int status; |
---|
| 325 | |
---|
| 326 | benchmark_timer_initialize(); |
---|
| 327 | status = pthread_attr_setstack(&attr, stackaddr, stacksize); |
---|
| 328 | end_time = benchmark_timer_read(); |
---|
| 329 | rtems_test_assert( status == 0 ); |
---|
| 330 | |
---|
| 331 | put_time( |
---|
| 332 | "pthread_attr_setstack: only case", |
---|
| 333 | end_time, |
---|
| 334 | 1, /* Only executed once */ |
---|
| 335 | 0, |
---|
| 336 | 0 |
---|
| 337 | ); |
---|
| 338 | |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | static void benchmark_pthread_attr_getstack(void) |
---|
| 342 | { |
---|
| 343 | benchmark_timer_t end_time; |
---|
| 344 | int status; |
---|
| 345 | size_t tmp_stacksize; |
---|
| 346 | |
---|
| 347 | benchmark_timer_initialize(); |
---|
| 348 | status = pthread_attr_getstack(&attr, &stackaddr, &tmp_stacksize); |
---|
| 349 | end_time = benchmark_timer_read(); |
---|
| 350 | rtems_test_assert( status == 0 ); |
---|
| 351 | rtems_test_assert(tmp_stacksize == stacksize); |
---|
| 352 | |
---|
| 353 | put_time( |
---|
| 354 | "pthread_attr_getstack: only case", |
---|
| 355 | end_time, |
---|
| 356 | 1, /* Only executed once */ |
---|
| 357 | 0, |
---|
| 358 | 0 |
---|
| 359 | ); |
---|
| 360 | |
---|
| 361 | } |
---|
| 362 | |
---|
| 363 | static void benchmark_destroy_pthread_attr(void) |
---|
| 364 | { |
---|
| 365 | benchmark_timer_t end_time; |
---|
| 366 | int status; |
---|
| 367 | |
---|
| 368 | benchmark_timer_initialize(); |
---|
| 369 | status = pthread_attr_destroy(&attr); |
---|
| 370 | end_time = benchmark_timer_read(); |
---|
| 371 | rtems_test_assert( status == 0 ); |
---|
| 372 | |
---|
| 373 | put_time( |
---|
| 374 | "pthread_attr_destroy: only case", |
---|
| 375 | end_time, |
---|
| 376 | 1, /* Only executed once */ |
---|
| 377 | 0, |
---|
| 378 | 0 |
---|
| 379 | ); |
---|
| 380 | |
---|
| 381 | } |
---|
| 382 | |
---|
| 383 | static void *POSIX_Init( |
---|
| 384 | void *argument |
---|
| 385 | ) |
---|
| 386 | { |
---|
| 387 | TEST_BEGIN(); |
---|
| 388 | |
---|
| 389 | benchmark_create_pthread_attr(); |
---|
| 390 | benchmark_pthread_attr_setdetachstate(); |
---|
| 391 | benchmark_pthread_attr_getdetachstate(); |
---|
| 392 | benchmark_pthread_attr_setguardsize(); |
---|
| 393 | benchmark_pthread_attr_getguardsize(); |
---|
| 394 | benchmark_pthread_attr_setinheritsched(); |
---|
| 395 | benchmark_pthread_attr_getinheritsched(); |
---|
| 396 | benchmark_pthread_attr_setschedparam(); |
---|
| 397 | benchmark_pthread_attr_getschedparam(); |
---|
| 398 | benchmark_pthread_attr_setschedpolicy(); |
---|
| 399 | benchmark_pthread_attr_getschedpolicy(); |
---|
| 400 | benchmark_pthread_attr_setscope(); |
---|
| 401 | benchmark_pthread_attr_getscope(); |
---|
| 402 | benchmark_pthread_attr_setstack(); |
---|
| 403 | benchmark_pthread_attr_getstack(); |
---|
| 404 | benchmark_destroy_pthread_attr(); |
---|
| 405 | |
---|
| 406 | TEST_END(); |
---|
| 407 | rtems_test_exit(0); |
---|
| 408 | } |
---|
| 409 | |
---|
| 410 | /* configuration information */ |
---|
| 411 | |
---|
| 412 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
| 413 | #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER |
---|
| 414 | |
---|
| 415 | /* configure an instance of the object created/destroyed */ |
---|
| 416 | |
---|
| 417 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 1 |
---|
| 418 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
| 419 | |
---|
| 420 | #define CONFIGURE_INIT |
---|
| 421 | |
---|
| 422 | #include <rtems/confdefs.h> |
---|
| 423 | /* end of file */ |
---|