@@ -214,6 +214,9 @@ void *thread_top_term(void *p1)
214
214
}
215
215
216
216
if (id >= 2 ) {
217
+ if (IS_ENABLED (CONFIG_PTHREAD_DYNAMIC_STACK )) {
218
+ zassert_false (pthread_detach (self ), "failed to set detach state" );
219
+ }
217
220
ret = pthread_detach (self );
218
221
if (id == 2 ) {
219
222
zassert_equal (ret , EINVAL , "re-detached thread!" );
@@ -301,18 +304,20 @@ void test_posix_pthread_execution(void)
301
304
ret = pthread_setname_np (NULL , thr_name );
302
305
zassert_equal (ret , ESRCH , "uninitialized setname!" );
303
306
304
- /* TESTPOINT: Try creating thread before attr init */
305
- ret = pthread_create (& newthread [0 ], & attr [0 ],
306
- thread_top_exec , NULL );
307
- zassert_equal (ret , EINVAL , "thread created before attr init!" );
307
+ if (!IS_ENABLED (CONFIG_PTHREAD_DYNAMIC_STACK )) {
308
+ /* TESTPOINT: Try creating thread before attr init */
309
+ ret = pthread_create (& newthread [0 ], & attr [0 ],
310
+ thread_top_exec , NULL );
311
+ zassert_equal (ret , EINVAL , "thread created before attr init!" );
312
+ }
308
313
309
314
for (i = 0 ; i < N_THR_E ; i ++ ) {
310
315
ret = pthread_attr_init (& attr [i ]);
311
316
if (ret != 0 ) {
312
317
zassert_false (pthread_attr_destroy (& attr [i ]),
313
- "Unable to destroy pthread object attrib" );
318
+ "Unable to destroy pthread object attrib" );
314
319
zassert_false (pthread_attr_init (& attr [i ]),
315
- "Unable to create pthread object attrib" );
320
+ "Unable to create pthread object attrib" );
316
321
}
317
322
318
323
/* TESTPOINTS: Retrieve set stack attributes and compare */
@@ -333,11 +338,16 @@ void test_posix_pthread_execution(void)
333
338
pthread_attr_setschedparam (& attr [i ], & schedparam );
334
339
pthread_attr_getschedparam (& attr [i ], & getschedparam );
335
340
zassert_equal (schedparam .sched_priority ,
336
- getschedparam .sched_priority ,
337
- "scheduling priorities do not match!" );
341
+ getschedparam .sched_priority ,
342
+ "scheduling priorities do not match!" );
338
343
339
- ret = pthread_create (& newthread [i ], & attr [i ], thread_top_exec ,
340
- INT_TO_POINTER (i ));
344
+ if (IS_ENABLED (CONFIG_PTHREAD_DYNAMIC_STACK )) {
345
+ ret = pthread_create (& newthread [i ], NULL , thread_top_exec ,
346
+ INT_TO_POINTER (i ));
347
+ } else {
348
+ ret = pthread_create (& newthread [i ], & attr [i ], thread_top_exec ,
349
+ INT_TO_POINTER (i ));
350
+ }
341
351
342
352
/* TESTPOINT: Check if thread is created successfully */
343
353
zassert_false (ret , "Number of threads exceed max limit" );
@@ -429,8 +439,13 @@ void test_posix_pthread_termination(void)
429
439
schedparam .sched_priority = 2 ;
430
440
pthread_attr_setschedparam (& attr [i ], & schedparam );
431
441
pthread_attr_setstack (& attr [i ], & stack_t [i ][0 ], STACKS );
432
- ret = pthread_create (& newthread [i ], & attr [i ], thread_top_term ,
433
- INT_TO_POINTER (i ));
442
+ if (IS_ENABLED (CONFIG_PTHREAD_DYNAMIC_STACK )) {
443
+ ret = pthread_create (& newthread [i ], NULL , thread_top_term ,
444
+ INT_TO_POINTER (i ));
445
+ } else {
446
+ ret = pthread_create (& newthread [i ], & attr [i ], thread_top_term ,
447
+ INT_TO_POINTER (i ));
448
+ }
434
449
435
450
zassert_false (ret , "Not enough space to create new thread" );
436
451
}
@@ -464,3 +479,29 @@ void test_posix_pthread_termination(void)
464
479
ret = pthread_getschedparam (newthread [N_THR_T /2 ], & policy , & schedparam );
465
480
zassert_equal (ret , ESRCH , "got attr from terminated thread!" );
466
481
}
482
+
483
+ #ifdef CONFIG_PTHREAD_DYNAMIC_STACK
484
+ static void * fun (void * arg )
485
+ {
486
+ * ((uint32_t * )arg ) = 0xB105F00D ;
487
+ return NULL ;
488
+ }
489
+
490
+ void test_posix_thread_attr_stacksize (void )
491
+ {
492
+ uint32_t x = 0 ;
493
+ pthread_attr_t attr ;
494
+ pthread_t th ;
495
+
496
+ /* TESTPOINT: specify a custom stack size via pthread_attr_t */
497
+ zassert_equal (0 , pthread_attr_init (& attr ), "" );
498
+ zassert_equal (0 , pthread_attr_setstacksize (& attr , 256 ), "" );
499
+ zassert_equal (0 , pthread_create (& th , & attr , fun , & x ), "" );
500
+ zassert_equal (0 , pthread_join (th , NULL ), "" );
501
+ zassert_equal (0xB105F00D , x , "" );
502
+ }
503
+ #else
504
+ void test_posix_thread_attr_stacksize (void )
505
+ {
506
+ }
507
+ #endif
0 commit comments