12c28215423293e443469a07ae7011135d058b671Garrett Cooper/* 20dc076565f772bb1953209fb69ea150b494aaa40robbiew * Copyright (c) 2004, Intel Corporation. All rights reserved. 30dc076565f772bb1953209fb69ea150b494aaa40robbiew * Created by: crystal.xiong REMOVE-THIS AT intel DOT com 40dc076565f772bb1953209fb69ea150b494aaa40robbiew * This file is licensed under the GPL license. For the full content 52c28215423293e443469a07ae7011135d058b671Garrett Cooper * of this license, see the COPYING file at the top level of this 60dc076565f772bb1953209fb69ea150b494aaa40robbiew * source tree. 70dc076565f772bb1953209fb69ea150b494aaa40robbiew 80dc076565f772bb1953209fb69ea150b494aaa40robbiew * Test pthread_attr_setscope() 92c28215423293e443469a07ae7011135d058b671Garrett Cooper * 100dc076565f772bb1953209fb69ea150b494aaa40robbiew * Steps: 110dc076565f772bb1953209fb69ea150b494aaa40robbiew * 1. Initialize a pthread_attr_t object using pthread_attr_init() 122c28215423293e443469a07ae7011135d058b671Garrett Cooper * 2. Call pthread_attr_setscope with unsupported scope 130dc076565f772bb1953209fb69ea150b494aaa40robbiew * parameter 142c28215423293e443469a07ae7011135d058b671Garrett Cooper * 150dc076565f772bb1953209fb69ea150b494aaa40robbiew */ 160dc076565f772bb1953209fb69ea150b494aaa40robbiew 170dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <pthread.h> 180dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <stdio.h> 191823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale#include <string.h> 200dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <errno.h> 210dc076565f772bb1953209fb69ea150b494aaa40robbiew#include "posixtest.h" 220dc076565f772bb1953209fb69ea150b494aaa40robbiew 231823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale#define ERR_MSG(f, rc) printf("Failed: func: %s rc: %s (%u)\n", \ 241823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale f, strerror(rc), rc) 250dc076565f772bb1953209fb69ea150b494aaa40robbiew 261823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morrealeint main(void) 270dc076565f772bb1953209fb69ea150b494aaa40robbiew{ 281823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale int rc1; 291823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale int rc2; 301823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale pthread_attr_t attr; 311823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale int status = PTS_PASS; 320dc076565f772bb1953209fb69ea150b494aaa40robbiew 331823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale rc1 = pthread_attr_init(&attr); 341823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale if (rc1 != 0) { 351823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale ERR_MSG("pthread_attr_init()", rc1); 36b9216b0e62d0e676a76db2fe4764a28c2e266f08Cyril Hrubis return PTS_UNRESOLVED; 370dc076565f772bb1953209fb69ea150b494aaa40robbiew } 380dc076565f772bb1953209fb69ea150b494aaa40robbiew 391823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale rc1 = pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); 401823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale rc2 = pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS); 411823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale if (rc1 || rc2) { 421823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale if (rc1 && rc2) { 431823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale /* at least one must be supported */ 441823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale ERR_MSG("pthread_attr_setscope()", rc1); 451823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale ERR_MSG("pthread_attr_setscope()", rc2); 461823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale } 471823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale if (rc1 && rc1 != ENOTSUP) { 481823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale ERR_MSG("pthread_attr_setscope()", rc1); 491823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale status = PTS_FAIL; 501823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale } 511823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale if (rc2 && rc2 != ENOTSUP) { 521823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale ERR_MSG("pthread_attr_setscope()", rc2); 531823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale status = PTS_FAIL; 541823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale } 550dc076565f772bb1953209fb69ea150b494aaa40robbiew } 561823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale 571823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale pthread_attr_destroy(&attr); 581823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale 591823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale if (status == PTS_PASS) 60de55e5ac14dc3e683117ae84bad34944fa7c38c6Cyril Hrubis printf("Test PASSED\n"); 611823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale return status; 621823a2867305be6dd138ffb398b13cf659caf1a4Peter W Morreale} 63