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