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