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_getschedpolicy()
9 *
10 * Steps:
11 * 1. Initialize a pthread_attr_t object using pthread_attr_init()
12 * 2. Call pthread_attr_setschedpolicy with policy parameter
13 * 3. Call pthread_attr_getschedpolicy to get the policy
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_getschedpolicy"
24 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
25
26 #define FIFOPOLICY SCHED_FIFO
27 #define RRPOLICY SCHED_RR
28 #define OTHERPOLICY SCHED_OTHER
29
verify_policy(pthread_attr_t * attr,int policytype)30 int verify_policy(pthread_attr_t * attr, int policytype)
31 {
32 int rc;
33 int policy;
34
35 rc = pthread_attr_getschedpolicy(attr, &policy);
36 if (rc != 0) {
37 printf(ERROR_PREFIX "pthread_attr_getschedpolicy\n");
38 exit(PTS_UNRESOLVED);
39 }
40 switch (policytype) {
41 case SCHED_FIFO:
42 if (policy != FIFOPOLICY) {
43 printf(ERROR_PREFIX "got wrong policy param\n");
44 exit(PTS_FAIL);
45 }
46 break;
47 case SCHED_RR:
48 if (policy != RRPOLICY) {
49 printf(ERROR_PREFIX "got wrong policy param\n");
50 exit(PTS_FAIL);
51 }
52 break;
53 case SCHED_OTHER:
54 if (policy != OTHERPOLICY) {
55 printf(ERROR_PREFIX "got wrong policy param\n");
56 exit(PTS_FAIL);
57 }
58 break;
59 }
60 return 0;
61 }
62
main(void)63 int main(void)
64 {
65 int rc = 0;
66 pthread_attr_t attr;
67
68 rc = pthread_attr_init(&attr);
69 if (rc != 0) {
70 printf(ERROR_PREFIX "pthread_attr_init\n");
71 exit(PTS_UNRESOLVED);
72 }
73
74 rc = pthread_attr_setschedpolicy(&attr, FIFOPOLICY);
75 if (rc != 0) {
76 printf(ERROR_PREFIX "pthread_attr_setschedpolicy\n");
77 exit(PTS_UNRESOLVED);
78 }
79 verify_policy(&attr, FIFOPOLICY);
80
81 rc = pthread_attr_setschedpolicy(&attr, RRPOLICY);
82 if (rc != 0) {
83 printf(ERROR_PREFIX "pthread_attr_setschedpolicy\n");
84 exit(PTS_UNRESOLVED);
85 }
86 verify_policy(&attr, RRPOLICY);
87
88 rc = pthread_attr_setschedpolicy(&attr, OTHERPOLICY);
89 if (rc != 0) {
90 printf(ERROR_PREFIX "pthread_attr_setschedpolicy\n");
91 exit(PTS_UNRESOLVED);
92 }
93 verify_policy(&attr, OTHERPOLICY);
94
95 rc = pthread_attr_destroy(&attr);
96 if (rc != 0) {
97 printf(ERROR_PREFIX "pthread_attr_destroy\n");
98 exit(PTS_UNRESOLVED);
99 }
100 printf("Test PASSED\n");
101 return PTS_PASS;
102 }
103