Home | History | Annotate | Download | only in pthread_attr_getscope
      1 /*
      2  * Copyright (c) 2004, Intel Corporation. All rights reserved.
      3  * Created by:  crystal.xiong REMOVE-THIS AT intel DOT com
      4  * This file is licensed under the GPL license.  For the full content
      5  * of this license, see the COPYING file at the top level of this
      6  * source tree.
      7 
      8  * Test pthread_attr_getscope()
      9  *
     10  * Steps:
     11  * 1.  Initialize a pthread_attr_t object using pthread_attr_init()
     12  * 2.  Call pthread_attr_setscope with contentionscope parameter
     13  * 3.  Call pthread_attr_getscope to get the contentionscope
     14 
     15  * NOTE: The contension scope value is a may requirement.
     16  *
     17  */
     18 
     19 #include <pthread.h>
     20 #include <stdio.h>
     21 #include <stdlib.h>
     22 #include "posixtest.h"
     23 
     24 #define TEST "1-1"
     25 #define FUNCTION "pthread_attr_getscope"
     26 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
     27 
     28 #define SYSTEMSCOPE PTHREAD_SCOPE_SYSTEM
     29 #define PROCESSSCOPE PTHREAD_SCOPE_PROCESS
     30 
     31 int verify_scope(pthread_attr_t * attr, int scopetype)
     32 {
     33 	int rc;
     34 	int scope;
     35 
     36 	rc = pthread_attr_getscope(attr, &scope);
     37 	if (rc != 0) {
     38 		perror(ERROR_PREFIX "pthread_attr_getscope");
     39 		exit(PTS_UNRESOLVED);
     40 	}
     41 	switch (scopetype) {
     42 	case SYSTEMSCOPE:
     43 		if (scope != SYSTEMSCOPE) {
     44 			perror(ERROR_PREFIX "got wrong scope param");
     45 			exit(PTS_FAIL);
     46 		}
     47 		break;
     48 	case PROCESSSCOPE:
     49 		if (scope != PROCESSSCOPE) {
     50 			perror(ERROR_PREFIX "got wrong scope param");
     51 			exit(PTS_FAIL);
     52 		}
     53 		break;
     54 	}
     55 	return 0;
     56 }
     57 
     58 int main(void)
     59 {
     60 	int rc = 0;
     61 	pthread_attr_t attr;
     62 
     63 	rc = pthread_attr_init(&attr);
     64 	if (rc != 0) {
     65 		perror(ERROR_PREFIX "pthread_attr_init");
     66 		exit(PTS_UNRESOLVED);
     67 	}
     68 
     69 	rc = pthread_attr_setscope(&attr, SYSTEMSCOPE);
     70 	if (rc != 0) {
     71 		perror(ERROR_PREFIX "PTHREAD_SCOPE_SYSTEM is not supported");
     72 	} else {
     73 		verify_scope(&attr, SYSTEMSCOPE);
     74 	}
     75 	rc = pthread_attr_setscope(&attr, PROCESSSCOPE);
     76 	if (rc != 0) {
     77 		perror(ERROR_PREFIX "PTHREAD_SCOPE_SYSTEM is not supported");
     78 	} else {
     79 		verify_scope(&attr, PROCESSSCOPE);
     80 	}
     81 
     82 	rc = pthread_attr_destroy(&attr);
     83 	if (rc != 0) {
     84 		perror(ERROR_PREFIX "pthread_attr_destroy");
     85 		exit(PTS_UNRESOLVED);
     86 	}
     87 	printf("Test PASSED\n");
     88 	return PTS_PASS;
     89 }
     90