source: rtems/testsuites/smptests/smppsxaffinity01/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: 4.7 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
16#include <tmacros.h>
17#include <errno.h>
18#include <pthread.h>
19#include <sched.h>
20
21const char rtems_test_name[] = "SMPPSXAFFINITY 1";
22
23#define CPU_COUNT 4
24
25pthread_t           Init_id;
26
27/* forward declarations to avoid warnings */
28void *POSIX_Init(void *argument);
29void Validate_attrgetaffinity_errors(void);
30void Validate_attrsetaffinity_errors(void);
31void Validate_attr(void);
32
33void Validate_attrgetaffinity_errors(void)
34{
35  int                 sc;
36  cpu_set_t           cpuset;
37  pthread_attr_t      attr;
38
39  sc = pthread_attr_init( &attr );
40  rtems_test_assert( sc == 0 );
41
42  /* Verify pthread_attr_getaffinity_np validates attr  */
43  puts( "Init - pthread_attr_getaffinity_np - Invalid attr - EINVAL" );
44  sc = pthread_attr_getaffinity_np( NULL, sizeof( cpuset ), &cpuset );
45  rtems_test_assert( sc == EINVAL );
46
47  /* Verify pthread_attr_getaffinity_np validates cpuset */
48  puts( "Init - pthread_attr_getaffinity_np - Invalid attr - EINVAL" );
49  sc = pthread_attr_getaffinity_np( &attr, sizeof( cpuset ), NULL );
50  rtems_test_assert( sc == EINVAL );
51
52  /* Verify pthread_attr_getaffinity_np validates cpusetsize */
53  puts( "Init - pthread_attr_getaffinity_np - Invalid cpusetsize - EINVAL" );
54  sc = pthread_attr_getaffinity_np( &attr, sizeof( cpuset ) * 2 , &cpuset );
55  rtems_test_assert( sc == EINVAL );
56
57  sc = pthread_attr_destroy( &attr );
58  rtems_test_assert( sc == 0 );
59
60  puts( "Init - pthread_attr_getaffinity_np - Not initialized attr - EINVAL" );
61  sc = pthread_attr_getaffinity_np( &attr, sizeof( cpuset ), &cpuset );
62  rtems_test_assert( sc == EINVAL );
63}
64
65void Validate_attrsetaffinity_errors(void)
66{
67  int                 sc;
68  cpu_set_t           cpuset;
69  pthread_attr_t      attr;
70
71  sc = pthread_attr_init( &attr );
72  rtems_test_assert( sc == 0 );
73
74  /* Verify pthread_attr_setaffinity_np validates attr.  */
75  puts( "Init - pthread_attr_setaffinity_np - Invalid attr - EINVAL" );
76  sc = pthread_attr_setaffinity_np( NULL, sizeof( cpuset ), &cpuset );
77  rtems_test_assert( sc == EINVAL );
78
79  /* Verify pthread_attr_setaffinity_np validates cpuset    */
80  puts( "Init - pthread_attr_setaffinity_np - Invalid attr - EINVAL" );
81  sc = pthread_attr_setaffinity_np( &attr, sizeof( cpuset ), NULL );
82  rtems_test_assert( sc == EINVAL );
83
84  /* Verify pthread_attr_setaffinity_np validates cpusetsize */
85  puts( "Init - pthread_attr_setaffinity_np - Invalid cpusetsize - EINVAL" );
86  sc = pthread_attr_setaffinity_np( &attr, sizeof( cpuset ) * 2 , &cpuset );
87  rtems_test_assert( sc == EINVAL );
88
89  sc = pthread_attr_destroy( &attr );
90  rtems_test_assert( sc == 0 );
91
92  puts( "Init - pthread_attr_setaffinity_np - Not initialized attr - EINVAL" );
93  sc = pthread_attr_setaffinity_np( &attr, sizeof( cpuset ), &cpuset  );
94  rtems_test_assert( sc == EINVAL );
95}
96
97void Validate_attr(void )
98{
99  int                 sc;
100  pthread_attr_t      attr;
101  uint32_t            cpus;
102  cpu_set_t           cpuset1;
103  cpu_set_t           cpuset2;
104  int                 i;
105  int                 priority;
106
107  sc = pthread_getattr_np( Init_id, &attr );
108  rtems_test_assert( sc == 0 );
109
110  priority = sched_get_priority_min( SCHED_FIFO );
111  rtems_test_assert( priority != -1 );
112
113
114  cpus = rtems_get_processor_count();
115  puts(
116    "Init - Validate pthread_attr_setaffinity_np and "
117    "pthread_attr_getaffinity_np"
118  );
119
120  /* Set each cpu seperately in the affinity set */
121  for ( i=0; i<cpus; i++ ){
122    CPU_ZERO(&cpuset1);
123    CPU_SET(i, &cpuset1);
124
125    sc = pthread_attr_setaffinity_np( &attr, sizeof(cpu_set_t), &cpuset1 );
126    rtems_test_assert( sc == 0 );
127
128    sc = pthread_attr_getaffinity_np( &attr, sizeof(cpu_set_t), &cpuset2 );
129    rtems_test_assert( sc == 0 );
130
131    rtems_test_assert( CPU_EQUAL(&cpuset1, &cpuset2) );
132  }
133}
134
135void *POSIX_Init(
136  void *ignored
137)
138{
139  TEST_BEGIN();
140
141  /* Initialize thread id */
142  Init_id = pthread_self();
143
144  Validate_attrsetaffinity_errors();
145  Validate_attrgetaffinity_errors();
146  Validate_attr();
147
148  TEST_END();
149  rtems_test_exit(0);
150}
151
152/* configuration information */
153
154#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
155#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
156
157#define CONFIGURE_MAXIMUM_PROCESSORS CPU_COUNT
158
159#define CONFIGURE_SCHEDULER_PRIORITY_AFFINITY_SMP
160
161#define CONFIGURE_MAXIMUM_POSIX_THREADS  1
162
163#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
164
165#define CONFIGURE_POSIX_INIT_THREAD_TABLE
166
167#define CONFIGURE_INIT
168#include <rtems/confdefs.h>
169
170/* global variables */
Note: See TracBrowser for help on using the repository browser.