@@ -237,165 +237,6 @@ ZTEST(pthread_attr, test_pthread_attr_setschedpolicy)
237237 can_create_thread (& attr );
238238}
239239
240- ZTEST (pthread_attr , test_pthread_attr_getstack )
241- {
242- void * stackaddr = (void * )BIOS_FOOD ;
243- size_t stacksize = BIOS_FOOD ;
244-
245- /* degenerate cases */
246- {
247- if (false) {
248- /* undefined behaviour */
249- zassert_equal (pthread_attr_getstack (NULL , NULL , NULL ), EINVAL );
250- zassert_equal (pthread_attr_getstack (NULL , NULL , & stacksize ), EINVAL );
251- zassert_equal (pthread_attr_getstack (NULL , & stackaddr , NULL ), EINVAL );
252- zassert_equal (pthread_attr_getstack (NULL , & stackaddr , & stacksize ), EINVAL );
253- zassert_equal (pthread_attr_getstack (& uninit_attr , & stackaddr , & stacksize ),
254- EINVAL );
255- }
256- zassert_equal (pthread_attr_getstack (& attr , NULL , NULL ), EINVAL );
257- zassert_equal (pthread_attr_getstack (& attr , NULL , & stacksize ), EINVAL );
258- zassert_equal (pthread_attr_getstack (& attr , & stackaddr , NULL ), EINVAL );
259- }
260-
261- zassert_ok (pthread_attr_getstack (& attr , & stackaddr , & stacksize ));
262- zassert_not_equal (stackaddr , (void * )BIOS_FOOD );
263- zassert_not_equal (stacksize , BIOS_FOOD );
264- }
265-
266- ZTEST (pthread_attr , test_pthread_attr_setstack )
267- {
268- void * stackaddr ;
269- size_t stacksize ;
270- void * new_stackaddr ;
271- size_t new_stacksize ;
272-
273- /* valid values */
274- zassert_ok (pthread_attr_getstack (& attr , & stackaddr , & stacksize ));
275-
276- /* degenerate cases */
277- {
278- if (false) {
279- /* undefined behaviour */
280- zassert_equal (pthread_attr_setstack (NULL , NULL , 0 ), EACCES );
281- zassert_equal (pthread_attr_setstack (NULL , NULL , stacksize ), EINVAL );
282- zassert_equal (pthread_attr_setstack (NULL , stackaddr , 0 ), EINVAL );
283- zassert_equal (pthread_attr_setstack (NULL , stackaddr , stacksize ), EINVAL );
284- zassert_equal (pthread_attr_setstack ((pthread_attr_t * )& uninit_attr ,
285- stackaddr , stacksize ),
286- EINVAL );
287- }
288- zassert_equal (pthread_attr_setstack (& attr , NULL , 0 ), EACCES );
289- zassert_equal (pthread_attr_setstack (& attr , NULL , stacksize ), EACCES );
290- zassert_equal (pthread_attr_setstack (& attr , stackaddr , 0 ), EINVAL );
291- }
292-
293- /* ensure we can create and join a thread with the default attrs */
294- can_create_thread (& attr );
295-
296- /* set stack / addr to the current values of stack / addr */
297- zassert_ok (pthread_attr_setstack (& attr , stackaddr , stacksize ));
298- can_create_thread (& attr );
299-
300- /* qemu_x86 seems to be unable to set thread stacks to be anything less than 4096 */
301- if (!IS_ENABLED (CONFIG_X86 )) {
302- /*
303- * check we can set a smaller stacksize
304- * should not require dynamic reallocation
305- * size may get rounded up to some alignment internally
306- */
307- zassert_ok (pthread_attr_setstack (& attr , stackaddr , stacksize - 1 ));
308- /* ensure we read back the same values as we specified */
309- zassert_ok (pthread_attr_getstack (& attr , & new_stackaddr , & new_stacksize ));
310- zassert_equal (new_stackaddr , stackaddr );
311- zassert_equal (new_stacksize , stacksize - 1 );
312- can_create_thread (& attr );
313- }
314-
315- if (IS_ENABLED (DYNAMIC_THREAD_ALLOC )) {
316- /* ensure we can set a dynamic stack */
317- k_thread_stack_t * stack ;
318-
319- stack = k_thread_stack_alloc (2 * stacksize , 0 );
320- zassert_not_null (stack );
321-
322- zassert_ok (pthread_attr_setstack (& attr , (void * )stack , 2 * stacksize ));
323- /* ensure we read back the same values as we specified */
324- zassert_ok (pthread_attr_getstack (& attr , & new_stackaddr , & new_stacksize ));
325- zassert_equal (new_stackaddr , (void * )stack );
326- zassert_equal (new_stacksize , 2 * stacksize );
327- can_create_thread (& attr );
328- }
329- }
330-
331- ZTEST (pthread_attr , test_pthread_attr_getstacksize )
332- {
333- size_t stacksize = BIOS_FOOD ;
334-
335- /* degenerate cases */
336- {
337- if (false) {
338- /* undefined behaviour */
339- zassert_equal (pthread_attr_getstacksize (NULL , NULL ), EINVAL );
340- zassert_equal (pthread_attr_getstacksize (NULL , & stacksize ), EINVAL );
341- zassert_equal (pthread_attr_getstacksize (& uninit_attr , & stacksize ), EINVAL );
342- }
343- zassert_equal (pthread_attr_getstacksize (& attr , NULL ), EINVAL );
344- }
345-
346- zassert_ok (pthread_attr_getstacksize (& attr , & stacksize ));
347- zassert_not_equal (stacksize , BIOS_FOOD );
348- }
349-
350- ZTEST (pthread_attr , test_pthread_attr_setstacksize )
351- {
352- size_t stacksize ;
353- size_t new_stacksize ;
354-
355- /* valid size */
356- zassert_ok (pthread_attr_getstacksize (& attr , & stacksize ));
357-
358- /* degenerate cases */
359- {
360- if (false) {
361- /* undefined behaviour */
362- zassert_equal (pthread_attr_setstacksize (NULL , 0 ), EINVAL );
363- zassert_equal (pthread_attr_setstacksize (NULL , stacksize ), EINVAL );
364- zassert_equal (pthread_attr_setstacksize ((pthread_attr_t * )& uninit_attr ,
365- stacksize ),
366- EINVAL );
367- }
368- zassert_equal (pthread_attr_setstacksize (& attr , 0 ), EINVAL );
369- }
370-
371- /* ensure we can spin up a thread with the default stack size */
372- can_create_thread (& attr );
373-
374- /* set stack / addr to the current values of stack / addr */
375- zassert_ok (pthread_attr_setstacksize (& attr , stacksize ));
376- /* ensure we can read back the values we just set */
377- zassert_ok (pthread_attr_getstacksize (& attr , & new_stacksize ));
378- zassert_equal (new_stacksize , stacksize );
379- can_create_thread (& attr );
380-
381- /* qemu_x86 seems to be unable to set thread stacks to be anything less than 4096 */
382- if (!IS_ENABLED (CONFIG_X86 )) {
383- zassert_ok (pthread_attr_setstacksize (& attr , stacksize - 1 ));
384- /* ensure we can read back the values we just set */
385- zassert_ok (pthread_attr_getstacksize (& attr , & new_stacksize ));
386- zassert_equal (new_stacksize , stacksize - 1 );
387- can_create_thread (& attr );
388- }
389-
390- if (IS_ENABLED (CONFIG_DYNAMIC_THREAD_ALLOC )) {
391- zassert_ok (pthread_attr_setstacksize (& attr , 2 * stacksize ));
392- /* ensure we read back the same values as we specified */
393- zassert_ok (pthread_attr_getstacksize (& attr , & new_stacksize ));
394- zassert_equal (new_stacksize , 2 * stacksize );
395- can_create_thread (& attr );
396- }
397- }
398-
399240ZTEST (pthread_attr , test_pthread_attr_getscope )
400241{
401242 int contentionscope = BIOS_FOOD ;
0 commit comments