|
28 | 28 |
|
29 | 29 | K_THREAD_STACK_ARRAY_DEFINE(stack_e, N_THR_E, STACKS); |
30 | 30 | K_THREAD_STACK_ARRAY_DEFINE(stack_t, N_THR_T, STACKS); |
| 31 | +K_THREAD_STACK_ARRAY_DEFINE(stack_1, 1, 32); |
31 | 32 |
|
32 | 33 | void *thread_top_exec(void *p1); |
33 | 34 | void *thread_top_term(void *p1); |
@@ -239,7 +240,7 @@ void test_posix_pthread_execution(void) |
239 | 240 | void *retval, *stackaddr; |
240 | 241 | size_t stacksize; |
241 | 242 | int serial_threads = 0; |
242 | | - const char thr_name[] = "thread name"; |
| 243 | + static const char thr_name[] = "thread name"; |
243 | 244 | char thr_name_buf[CONFIG_THREAD_MAX_NAME_LEN]; |
244 | 245 |
|
245 | 246 | sem_init(&main_sem, 0, 1); |
@@ -402,6 +403,70 @@ void test_posix_pthread_execution(void) |
402 | 403 | printk("Barrier test OK\n"); |
403 | 404 | } |
404 | 405 |
|
| 406 | +void test_posix_pthread_error_condition(void) |
| 407 | +{ |
| 408 | + pthread_attr_t attr; |
| 409 | + struct sched_param param; |
| 410 | + void *stackaddr; |
| 411 | + size_t stacksize; |
| 412 | + int policy, detach; |
| 413 | + static pthread_once_t key = 1; |
| 414 | + |
| 415 | + /* TESTPOINT: invoke pthread APIs with NULL */ |
| 416 | + zassert_equal(pthread_attr_destroy(NULL), EINVAL, |
| 417 | + "pthread destroy NULL error"); |
| 418 | + zassert_equal(pthread_attr_getschedparam(NULL, ¶m), EINVAL, |
| 419 | + "get scheduling param error"); |
| 420 | + zassert_equal(pthread_attr_getstack(NULL, &stackaddr, &stacksize), |
| 421 | + EINVAL, "get stack attributes error"); |
| 422 | + zassert_equal(pthread_attr_getstacksize(NULL, &stacksize), |
| 423 | + EINVAL, "get stack size error"); |
| 424 | + zassert_equal(pthread_attr_setschedpolicy(NULL, 2), |
| 425 | + EINVAL, "set scheduling policy error"); |
| 426 | + zassert_equal(pthread_attr_getschedpolicy(NULL, &policy), |
| 427 | + EINVAL, "get scheduling policy error"); |
| 428 | + zassert_equal(pthread_attr_setdetachstate(NULL, 0), |
| 429 | + EINVAL, "pthread set detach state with NULL error"); |
| 430 | + zassert_equal(pthread_attr_getdetachstate(NULL, &detach), |
| 431 | + EINVAL, "get datach state error"); |
| 432 | + zassert_equal(pthread_detach(NULL), ESRCH, "detach with NULL error"); |
| 433 | + zassert_equal(pthread_attr_init(NULL), ENOMEM, |
| 434 | + "init with NULL error"); |
| 435 | + zassert_equal(pthread_attr_setschedparam(NULL, ¶m), EINVAL, |
| 436 | + "set sched param with NULL error"); |
| 437 | + zassert_equal(pthread_cancel(NULL), ESRCH, |
| 438 | + "cancel NULL error"); |
| 439 | + zassert_equal(pthread_join(NULL, NULL), ESRCH, |
| 440 | + "join with NULL has error"); |
| 441 | + zassert_false(pthread_once(&key, NULL), |
| 442 | + "pthread dynamic package initialization error"); |
| 443 | + zassert_equal(pthread_getschedparam(NULL, &policy, ¶m), ESRCH, |
| 444 | + "get schedparam with NULL error"); |
| 445 | + zassert_equal(pthread_setschedparam(NULL, policy, ¶m), ESRCH, |
| 446 | + "set schedparam with NULL error"); |
| 447 | + |
| 448 | + attr.initialized = 0U; |
| 449 | + zassert_equal(pthread_attr_getdetachstate(&attr, &detach), |
| 450 | + EINVAL, "get datach state error"); |
| 451 | + |
| 452 | + /* Initialise thread attribute to ensure won't be return with init error */ |
| 453 | + pthread_attr_init(&attr); |
| 454 | + zassert_false(pthread_attr_setschedpolicy(&attr, 0), |
| 455 | + "set scheduling policy error"); |
| 456 | + zassert_false(pthread_attr_setschedpolicy(&attr, 1), |
| 457 | + "set scheduling policy error"); |
| 458 | + zassert_equal(pthread_attr_setschedpolicy(&attr, 2), |
| 459 | + EINVAL, "set scheduling policy error"); |
| 460 | + zassert_false(pthread_attr_setdetachstate(&attr, 1), |
| 461 | + "set detach state error"); |
| 462 | + zassert_false(pthread_attr_setdetachstate(&attr, 2), |
| 463 | + "set detach state error"); |
| 464 | + zassert_equal(pthread_attr_setdetachstate(&attr, 3), |
| 465 | + EINVAL, "set detach state error"); |
| 466 | + zassert_false(pthread_attr_getdetachstate(&attr, &detach), |
| 467 | + "get datach state error"); |
| 468 | +} |
| 469 | + |
405 | 470 | void test_posix_pthread_termination(void) |
406 | 471 | { |
407 | 472 | int32_t i, ret; |
@@ -464,3 +529,33 @@ void test_posix_pthread_termination(void) |
464 | 529 | ret = pthread_getschedparam(newthread[N_THR_T/2], &policy, &schedparam); |
465 | 530 | zassert_equal(ret, ESRCH, "got attr from terminated thread!"); |
466 | 531 | } |
| 532 | + |
| 533 | +static void *create_thread1(void *p1) |
| 534 | +{ |
| 535 | + /* do nothing */ |
| 536 | + return NULL; |
| 537 | +} |
| 538 | + |
| 539 | +void test_posix_pthread_create_negative(void) |
| 540 | +{ |
| 541 | + int ret; |
| 542 | + pthread_t pthread1; |
| 543 | + pthread_attr_t attr1; |
| 544 | + |
| 545 | + /* create pthread without attr initialized */ |
| 546 | + ret = pthread_create(&pthread1, NULL, create_thread1, (void *)1); |
| 547 | + zassert_equal(ret, EINVAL, "create thread with NULL successful"); |
| 548 | + |
| 549 | + /* initialized attr without set stack to create thread */ |
| 550 | + ret = pthread_attr_init(&attr1); |
| 551 | + zassert_false(ret, "attr1 initialized failed"); |
| 552 | + |
| 553 | + attr1.stack = NULL; |
| 554 | + ret = pthread_create(&pthread1, &attr1, create_thread1, (void *)1); |
| 555 | + zassert_equal(ret, EINVAL, "create successful with NULL attr"); |
| 556 | + |
| 557 | + /* set stack size 0 to create thread */ |
| 558 | + pthread_attr_setstack(&attr1, &stack_1, 0); |
| 559 | + ret = pthread_create(&pthread1, &attr1, create_thread1, (void *)1); |
| 560 | + zassert_equal(ret, EINVAL, "create thread with 0 size"); |
| 561 | +} |
0 commit comments