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_getinheritsched()
9 *
10 * Steps:
11 * 1.  Initialize a pthread_attr_t object using pthread_attr_init()
12 * 2.  Call pthread_attr_setinheritsched with inheritsched parameter
13 * 3.  Call pthread_attr_getinheritsched to get the inheritsched
14 *
15 */
16
17#include <pthread.h>
18#include <stdio.h>
19#include <stdlib.h>
20#include "posixtest.h"
21
22#define TEST "1-1"
23#define FUNCTION "pthread_attr_getinheritsched"
24#define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
25
26#define EXPLICIT PTHREAD_EXPLICIT_SCHED
27#define INHERIT PTHREAD_INHERIT_SCHED
28
29int verify_inheritsched(pthread_attr_t *attr, int schedtype) {
30	int rc;
31	int inheritsched;
32
33	rc = pthread_attr_getinheritsched(attr, &inheritsched);
34	if( rc != 0) {
35		perror(ERROR_PREFIX "pthread_attr_getinheritsched");
36		exit(PTS_UNRESOLVED);
37	}
38	switch(schedtype) {
39	case INHERIT:
40  		if (inheritsched != INHERIT) {
41    			perror(ERROR_PREFIX "got wrong inheritsched param");
42    			exit(PTS_FAIL);
43  		}
44		break;
45	case EXPLICIT:
46  		if (inheritsched != EXPLICIT) {
47    			perror(ERROR_PREFIX "got wrong inheritsched param");
48    			exit(PTS_FAIL);
49  		}
50		break;
51	}
52        return 0;
53}
54
55int main()
56{
57	int                   rc=0;
58	pthread_attr_t        attr;
59
60	rc = pthread_attr_init(&attr);
61	if( rc != 0) {
62		perror(ERROR_PREFIX "pthread_attr_init");
63		exit(PTS_UNRESOLVED);
64	}
65
66  	rc = pthread_attr_setinheritsched(&attr, INHERIT);
67	if( rc != 0) {
68		perror(ERROR_PREFIX "pthread_attr_setinheritsched");
69		exit(PTS_UNRESOLVED);
70	}
71  	verify_inheritsched(&attr, INHERIT);
72
73  	rc = pthread_attr_setinheritsched(&attr, EXPLICIT);
74	if( rc != 0) {
75		perror(ERROR_PREFIX "pthread_attr_setinheritsched");
76		exit(PTS_UNRESOLVED);
77	}
78  	verify_inheritsched(&attr, EXPLICIT);
79
80  	rc = pthread_attr_destroy(&attr);
81	if( rc != 0) {
82		perror(ERROR_PREFIX "pthread_attr_destroy");
83		exit(PTS_UNRESOLVED);
84	}
85	printf("Test PASS\n");
86	return PTS_PASS;
87}
88
89
90
91
92