source: rtems/testsuites/psxtests/psxgetattrnp01/init.c @ b422aa3f

5
Last change on this file since b422aa3f was b422aa3f, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 26, 2018 at 2:05:45 PM

tests: Remove configure feature checks

Update #3409.

  • Property mode set to 100644
File size: 7.5 KB
Line 
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.org/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
21const char rtems_test_name[] = "PSXGETATTRNP 1";
22
23/* forward declarations to avoid warnings */
24void *POSIX_Init(void *argument);
25
26void *Thread_1(void *argument);
27
28pthread_t           Init_id;
29pthread_t           Thread_id;
30pthread_attr_t      Thread_attr;
31int                 max_priority;
32
33static int attribute_compare(
34  const pthread_attr_t *attr1,
35  const pthread_attr_t *attr2
36)
37{
38  if ( attr1->is_initialized  !=  attr2->is_initialized )
39    return 1;
40
41  if (
42    attr1->stackaddr != NULL &&
43      attr2->stackaddr != NULL &&
44      attr1->stackaddr != attr2->stackaddr )
45    return 1;
46
47  if (
48    attr1->stacksize != 0 &&
49      attr2->stacksize != 0 &&
50       attr1->stacksize != attr2->stacksize )
51    return 1;
52
53  if ( attr1->contentionscope != attr2->contentionscope )
54    return 1;
55
56  if ( attr1->inheritsched != attr2->inheritsched )
57    return 1;
58
59  if ( attr1->schedpolicy != attr2->schedpolicy )
60    return 1;
61
62  if ( attr1->schedparam.sched_priority != attr2->schedparam.sched_priority )
63    return 1;
64
65  if ( attr1->guardsize != attr2->guardsize )
66    return 1;
67
68  #if defined(_POSIX_THREAD_CPUTIME)
69    if ( attr1->cputime_clock_allowed != attr2->cputime_clock_allowed )
70      return 1;
71  #endif
72
73  if ( attr1->detachstate != attr2->detachstate )
74    return 1;
75
76  if ( attr1->affinitysetsize != attr2->affinitysetsize )
77    return 1;
78
79  if (!CPU_EQUAL_S(
80    attr1->affinitysetsize,
81    attr1->affinityset,
82    attr2->affinityset
83  ))
84    return 1;
85
86  if (!CPU_EQUAL_S(
87    attr1->affinitysetsize,
88    &attr1->affinitysetpreallocated,
89    &attr2->affinitysetpreallocated
90  ))
91    return 1;
92
93  return 0;
94}
95
96void *Thread_1(
97  void *argument
98)
99{
100  pthread_attr_t      attr;
101  struct sched_param  param;
102  int                 sc;
103  int                 value;
104  void               *stackaddr;
105  size_t              stacksize;
106  cpu_set_t           set;
107
108  puts("Thread - pthread_getattr_np - Verify value");
109  sc = pthread_getattr_np( Thread_id, &attr );
110  rtems_test_assert( sc == 0 );
111  rtems_test_assert( ! attribute_compare(&attr, &Thread_attr) );
112
113  param.sched_priority = max_priority;
114
115  puts( "Thread - pthread_setschedparam: Setting highest priority SCHED_FIFO" );
116  sc = pthread_setschedparam( Thread_id, SCHED_FIFO, &param );
117  rtems_test_assert( !sc );
118
119  puts("Thread - Detach");
120  sc = pthread_detach( Thread_id );
121  rtems_test_assert( !sc );
122
123  puts("Thread - pthread_getattr_np");
124  sc = pthread_getattr_np( Thread_id, &attr );
125  rtems_test_assert( !sc );
126
127  puts("Thread - Verify get stack");
128  stackaddr = NULL;
129  stacksize = 0;
130  sc = pthread_attr_getstack( &attr, &stackaddr, &stacksize );
131  rtems_test_assert( sc == 0 );
132  rtems_test_assert( stackaddr != NULL );
133  rtems_test_assert( stacksize != 0 );
134
135  puts("Thread - Verify contention scope");
136  sc = pthread_attr_getscope( &attr, &value );
137  rtems_test_assert( sc == 0 );
138  rtems_test_assert( value == PTHREAD_SCOPE_PROCESS );
139
140  puts("Thread - Verify explicit scheduler");
141  sc = pthread_attr_getinheritsched( &attr, &value );
142  rtems_test_assert( sc == 0 );
143  rtems_test_assert( value == PTHREAD_EXPLICIT_SCHED );
144
145  puts("Thread - Verify SCHED_FIFO policy");
146  sc = pthread_attr_getschedpolicy( &attr, &value );
147  rtems_test_assert( !sc );
148  rtems_test_assert( value == SCHED_FIFO );
149
150  puts("Thread - Verify max priority");
151  sc = pthread_attr_getschedparam( &attr, &param );
152  rtems_test_assert( !sc );
153  rtems_test_assert( param.sched_priority == max_priority );
154
155  puts("Thread - Verify detached");
156  sc = pthread_attr_getdetachstate( &attr, &value );
157  rtems_test_assert( sc == 0 );
158  rtems_test_assert( value == PTHREAD_CREATE_DETACHED );
159
160  puts("Thread - Verify affinity");
161  CPU_ZERO( &set );
162  sc = pthread_attr_getaffinity_np( &attr, sizeof( set ), &set );
163  rtems_test_assert( sc == 0 );
164  rtems_test_assert( CPU_ISSET( 0, &set ) );
165  rtems_test_assert( !CPU_ISSET( 1, &set ) );
166
167  puts("Thread - Destroy");
168  sc = pthread_attr_destroy( &attr );
169  rtems_test_assert( sc == 0 );
170
171  return NULL; /* just so the compiler thinks we returned something */
172}
173
174void *POSIX_Init(
175  void *ignored
176)
177{
178  int                 sc;
179  pthread_attr_t      attribute;
180  void               *stackaddr;
181  size_t              stacksize;
182  size_t              guardsize;
183  struct sched_param  param;
184  cpu_set_t           set;
185
186  TEST_BEGIN();
187
188  /* Initialize thread id */
189  Init_id = pthread_self();
190  max_priority = sched_get_priority_max( SCHED_FIFO );
191
192  puts( "Init - pthread_getattr_np - attr NULL - EINVAL" );
193  sc = pthread_getattr_np( Init_id, NULL );
194  rtems_test_assert( sc == EINVAL );
195
196  puts( "Init - pthread_getattr_np - invalid id - ESRCH" );
197  sc = pthread_getattr_np( 0xffff, &attribute );
198  rtems_test_assert( sc == ESRCH );
199
200
201  /* init task attributes */
202  puts("Init - pthread_attr_init");
203  sc = pthread_attr_init(&Thread_attr);
204  rtems_test_assert(!sc);
205
206  puts("Init - pthread_attr_setaffinity_np");
207  CPU_ZERO( &set );
208  CPU_SET( 0, &set );
209  sc = pthread_attr_setaffinity_np( &Thread_attr, sizeof( set ), &set );
210  rtems_test_assert(!sc);
211
212  puts("Init - pthread_attr_setinheritsched - PTHREAD_EXPLICIT_SCHED");
213  sc = pthread_attr_setinheritsched( &Thread_attr, PTHREAD_EXPLICIT_SCHED );
214  rtems_test_assert(!sc);
215  rtems_test_assert( Thread_attr.inheritsched == PTHREAD_EXPLICIT_SCHED );
216
217  puts("Init - pthread_attr_setschedpolicy to SCHED_RR");
218  sc = pthread_attr_setschedpolicy(&Thread_attr, SCHED_RR);
219  rtems_test_assert(!sc);
220
221  puts("Init - pthread_attr_setschedparam to minimum priority + 2");
222  param.sched_priority = sched_get_priority_min( SCHED_RR ) + 2;
223  sc = pthread_attr_setschedparam( &Thread_attr, &param );
224  rtems_test_assert(!sc);
225
226  puts("Init - pthread_attr_getstack");
227  sc = pthread_attr_getstack( &Thread_attr, &stackaddr, &stacksize );
228  rtems_test_assert(!sc);
229
230  stacksize *= 2;
231  puts("Init - pthread_attr_setstack double the stacksize");
232  sc = pthread_attr_setstacksize( &Thread_attr, stacksize );
233  rtems_test_assert(!sc);
234
235  puts("Init - pthread_attr_getguardsize");
236  sc = pthread_attr_getguardsize( &Thread_attr, &guardsize );
237  rtems_test_assert(!sc);
238
239  guardsize *= 2;
240  puts("Init - pthread_attr_setguardsize double the guardsize");
241  sc = pthread_attr_setguardsize( &Thread_attr, guardsize );
242  rtems_test_assert(!sc);
243
244  puts("Init - raise priority to max");
245  param.sched_priority = max_priority;
246  sc = pthread_setschedparam( Init_id, SCHED_RR, &param );
247  rtems_test_assert( !sc );
248
249 puts("Init - pthread_create");
250  sc = pthread_create( &Thread_id, &Thread_attr, Thread_1, NULL );
251  rtems_test_assert( !sc );
252
253  puts("Init - Lower priority");
254  fflush(stdout);
255  param.sched_priority = sched_get_priority_min( SCHED_RR );
256  sc = pthread_setschedparam( Init_id, SCHED_RR, &param );
257  rtems_test_assert(!sc);
258
259#if 0
260  sc = pthread_join( Thread_id, NULL );
261  rtems_test_assert( !sc );
262#endif
263
264  TEST_END();
265  rtems_test_exit(0);
266  return NULL; /* just so the compiler thinks we returned something */
267}
268
269/* configuration information */
270
271#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
272#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
273
274#define CONFIGURE_MAXIMUM_POSIX_THREADS  2
275
276#define CONFIGURE_POSIX_INIT_THREAD_TABLE
277
278#define CONFIGURE_INIT
279#include <rtems/confdefs.h>
280
281/* global variables */
Note: See TracBrowser for help on using the repository browser.