1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2014. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.com/license/LICENSE. |
---|
8 | */ |
---|
9 | |
---|
10 | #ifdef HAVE_CONFIG_H |
---|
11 | #include "config.h" |
---|
12 | #endif |
---|
13 | |
---|
14 | #define _GNU_SOURCE |
---|
15 | #include <tmacros.h> |
---|
16 | #include <errno.h> |
---|
17 | #include <sched.h> |
---|
18 | #include <pthread.h> |
---|
19 | #include <rtems/posix/pthreadimpl.h> |
---|
20 | |
---|
21 | /* forward declarations to avoid warnings */ |
---|
22 | void *POSIX_Init(void *argument); |
---|
23 | |
---|
24 | #if HAVE_DECL_PTHREAD_GETATTR_NP |
---|
25 | |
---|
26 | |
---|
27 | void *Thread_1(void *argument); |
---|
28 | |
---|
29 | pthread_t Init_id; |
---|
30 | pthread_t Thread_id; |
---|
31 | pthread_attr_t Thread_attr; |
---|
32 | int max_priority; |
---|
33 | |
---|
34 | void *Thread_1( |
---|
35 | void *argument |
---|
36 | ) |
---|
37 | { |
---|
38 | pthread_attr_t attr; |
---|
39 | struct sched_param param; |
---|
40 | int sc; |
---|
41 | int value; |
---|
42 | |
---|
43 | puts("Thread - pthread_getattr_np - Verify value"); |
---|
44 | sc = pthread_getattr_np( Thread_id, &attr ); |
---|
45 | rtems_test_assert( sc == 0 ); |
---|
46 | rtems_test_assert( ! rtems_pthread_attribute_compare(&attr, &Thread_attr) ); |
---|
47 | |
---|
48 | param.sched_priority = max_priority; |
---|
49 | |
---|
50 | puts( "Thread - pthread_setschedparam: Setting highest priority SCHED_FIFO" ); |
---|
51 | sc = pthread_setschedparam( Thread_id, SCHED_FIFO, ¶m ); |
---|
52 | rtems_test_assert( !sc ); |
---|
53 | |
---|
54 | puts("Thread - Detach"); |
---|
55 | sc = pthread_detach( Thread_id ); |
---|
56 | rtems_test_assert( !sc ); |
---|
57 | |
---|
58 | puts("Thread - pthread_getattr_np"); |
---|
59 | sc = pthread_getattr_np( Thread_id, &attr ); |
---|
60 | rtems_test_assert( !sc ); |
---|
61 | |
---|
62 | puts("Thread - Verify SCHED_FIFO policy"); |
---|
63 | sc = pthread_attr_getschedpolicy( &attr, &value ); |
---|
64 | rtems_test_assert( !sc ); |
---|
65 | rtems_test_assert( value == SCHED_FIFO ); |
---|
66 | |
---|
67 | puts("Thread - Verify max priority"); |
---|
68 | sc = pthread_attr_getschedparam( &attr, ¶m ); |
---|
69 | rtems_test_assert( !sc ); |
---|
70 | rtems_test_assert( param.sched_priority == max_priority ); |
---|
71 | |
---|
72 | puts("Thread - Verify detached"); |
---|
73 | sc = pthread_attr_getdetachstate( &attr, &value ); |
---|
74 | rtems_test_assert( value == PTHREAD_CREATE_DETACHED ); |
---|
75 | |
---|
76 | return NULL; /* just so the compiler thinks we returned something */ |
---|
77 | } |
---|
78 | |
---|
79 | void *POSIX_Init( |
---|
80 | void *ignored |
---|
81 | ) |
---|
82 | { |
---|
83 | int sc; |
---|
84 | pthread_attr_t attribute; |
---|
85 | void *stackaddr; |
---|
86 | size_t stacksize; |
---|
87 | size_t guardsize; |
---|
88 | struct sched_param param; |
---|
89 | |
---|
90 | puts( "\n\n*** POSIX ATTRIBUTE TEST 1 ***" ); |
---|
91 | |
---|
92 | /* Initialize thread id */ |
---|
93 | Init_id = pthread_self(); |
---|
94 | max_priority = sched_get_priority_max( SCHED_FIFO ); |
---|
95 | |
---|
96 | puts( "Init - pthread_getattr_np - attr NULL - EINVAL" ); |
---|
97 | sc = pthread_getattr_np( Init_id, NULL ); |
---|
98 | rtems_test_assert( sc == EINVAL ); |
---|
99 | |
---|
100 | puts( "Init - pthread_getattr_np - invalid id - ESRCH" ); |
---|
101 | sc = pthread_getattr_np( 0xffff, &attribute ); |
---|
102 | rtems_test_assert( sc == ESRCH ); |
---|
103 | |
---|
104 | |
---|
105 | /* init task attributes */ |
---|
106 | puts("Init - pthread_attr_init"); |
---|
107 | sc = pthread_attr_init(&Thread_attr); |
---|
108 | rtems_test_assert(!sc); |
---|
109 | |
---|
110 | puts("Init - pthread_attr_setinheritsched - PTHREAD_EXPLICIT_SCHED"); |
---|
111 | sc = pthread_attr_setinheritsched( &Thread_attr, PTHREAD_EXPLICIT_SCHED ); |
---|
112 | rtems_test_assert(!sc); |
---|
113 | rtems_test_assert( Thread_attr.inheritsched == PTHREAD_EXPLICIT_SCHED ); |
---|
114 | |
---|
115 | puts("Init - pthread_attr_setschedpolicy to SCHED_RR"); |
---|
116 | sc = pthread_attr_setschedpolicy(&Thread_attr, SCHED_RR); |
---|
117 | rtems_test_assert(!sc); |
---|
118 | |
---|
119 | puts("Init - pthread_attr_setschedparam to minimum priority + 2"); |
---|
120 | param.sched_priority = sched_get_priority_min( SCHED_RR ) + 2; |
---|
121 | sc = pthread_attr_setschedparam( &Thread_attr, ¶m ); |
---|
122 | rtems_test_assert(!sc); |
---|
123 | |
---|
124 | puts("Init - pthread_attr_getstack"); |
---|
125 | sc = pthread_attr_getstack( &Thread_attr, &stackaddr, &stacksize ); |
---|
126 | rtems_test_assert(!sc); |
---|
127 | |
---|
128 | stacksize *= 2; |
---|
129 | puts("Init - pthread_attr_setstack double the stacksize"); |
---|
130 | sc = pthread_attr_setstacksize( &Thread_attr, stacksize ); |
---|
131 | rtems_test_assert(!sc); |
---|
132 | |
---|
133 | puts("Init - pthread_attr_getguardsize"); |
---|
134 | sc = pthread_attr_getguardsize( &Thread_attr, &guardsize ); |
---|
135 | rtems_test_assert(!sc); |
---|
136 | |
---|
137 | guardsize *= 2; |
---|
138 | puts("Init - pthread_attr_setguardsize double the guardsize"); |
---|
139 | sc = pthread_attr_setguardsize( &Thread_attr, guardsize ); |
---|
140 | rtems_test_assert(!sc); |
---|
141 | |
---|
142 | puts("Init - raise priority to max"); |
---|
143 | param.sched_priority = max_priority; |
---|
144 | sc = pthread_setschedparam( Init_id, SCHED_RR, ¶m ); |
---|
145 | rtems_test_assert( !sc ); |
---|
146 | |
---|
147 | puts("Init - pthread_create"); |
---|
148 | sc = pthread_create( &Thread_id, &Thread_attr, Thread_1, NULL ); |
---|
149 | rtems_test_assert( !sc ); |
---|
150 | |
---|
151 | puts("Init - Lower priority"); |
---|
152 | fflush(stdout); |
---|
153 | param.sched_priority = sched_get_priority_min( SCHED_RR ); |
---|
154 | sc = pthread_setschedparam( Init_id, SCHED_RR, ¶m ); |
---|
155 | rtems_test_assert(!sc); |
---|
156 | |
---|
157 | #if 0 |
---|
158 | sc = pthread_join( Thread_id, NULL ); |
---|
159 | rtems_test_assert( !sc ); |
---|
160 | #endif |
---|
161 | |
---|
162 | puts( "*** END OF POSIX ATTRIBUTE TEST 1 ***" ); |
---|
163 | rtems_test_exit(0); |
---|
164 | return NULL; /* just so the compiler thinks we returned something */ |
---|
165 | } |
---|
166 | #else |
---|
167 | void *POSIX_Init( |
---|
168 | void *ignored |
---|
169 | ) |
---|
170 | { |
---|
171 | puts( "\n\n*** POSIX ATTRIBUTE TEST 1 ***" ); |
---|
172 | puts( " pthread_getattr_np NOT supported" ); |
---|
173 | puts( "*** END OF POSIX ATTRIBUTE TEST 1 ***" ); |
---|
174 | rtems_test_exit(0); |
---|
175 | return NULL; /* just so the compiler thinks we returned something */ |
---|
176 | } |
---|
177 | |
---|
178 | #endif |
---|
179 | /* configuration information */ |
---|
180 | |
---|
181 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
182 | #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER |
---|
183 | |
---|
184 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 2 |
---|
185 | |
---|
186 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
187 | |
---|
188 | #define CONFIGURE_INIT |
---|
189 | #include <rtems/confdefs.h> |
---|
190 | |
---|
191 | /* global variables */ |
---|