1 /* Define the ThreadX SMP time-slice test. */
2
3 #include <stdio.h>
4 #include "tx_api.h"
5
6 static TX_THREAD thread_0;
7 static TX_THREAD thread_31a;
8 static TX_THREAD thread_31b;
9 static TX_THREAD thread_31c;
10 static TX_THREAD thread_31d;
11 static TX_THREAD thread_31e;
12 static TX_THREAD thread_31f;
13 static TX_THREAD thread_31g;
14 static TX_THREAD thread_31h;
15
16
17 static ULONG thread_31a_counter;
18 static ULONG thread_31b_counter;
19 static ULONG thread_31c_counter;
20 static ULONG thread_31d_counter;
21 static ULONG thread_31e_counter;
22 static ULONG thread_31f_counter;
23 static ULONG thread_31g_counter;
24 static ULONG thread_31h_counter;
25
26
27 static unsigned long error = 0;
28
29
30 /* Define thread prototypes. */
31
32 static void thread_0_entry(ULONG thread_input);
33 static void thread_31a_entry(ULONG thread_input);
34 static void thread_31b_entry(ULONG thread_input);
35 static void thread_31c_entry(ULONG thread_input);
36 static void thread_31d_entry(ULONG thread_input);
37 static void thread_31e_entry(ULONG thread_input);
38 static void thread_31f_entry(ULONG thread_input);
39 static void thread_31g_entry(ULONG thread_input);
40 static void thread_31h_entry(ULONG thread_input);
41
42
43 /* Prototype for test control return. */
44
45 void test_control_return(UINT status);
46
47
48 /* Define what the initial system looks like. */
49
50 #ifdef CTEST
test_application_define(void * first_unused_memory)51 void test_application_define(void *first_unused_memory)
52 #else
53 void threadx_smp_time_slice_test(void *first_unused_memory)
54 #endif
55 {
56
57 UINT status;
58 CHAR *pointer;
59 UINT i;
60
61
62 /* Put first available memory address into a character pointer. */
63 pointer = (CHAR *) first_unused_memory;
64
65 /* Put system definition stuff in here, e.g. thread creates and other assorted
66 create information. */
67
68 status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
69 pointer, TEST_STACK_SIZE_PRINTF,
70 0, 0, TX_NO_TIME_SLICE, TX_DONT_START);
71 pointer = pointer + TEST_STACK_SIZE_PRINTF;
72 status += tx_thread_smp_core_exclude(&thread_0, 0xE); /* Core 0 only! */
73
74 /* Check status. */
75 if (status != TX_SUCCESS)
76 {
77
78 printf("Running SMP Time-Slice Test......................................... ERROR #1\n");
79 test_control_return(1);
80 }
81
82 status = tx_thread_create(&thread_31a, "thread 31a", thread_31a_entry, 0,
83 pointer, TEST_STACK_SIZE_PRINTF,
84 31, 31, 1, TX_DONT_START);
85 pointer = pointer + TEST_STACK_SIZE_PRINTF;
86 status += tx_thread_smp_core_exclude(&thread_31a, 0); /* Any core. */
87
88 /* Check status. */
89 if (status != TX_SUCCESS)
90 {
91
92 printf("Running SMP Time-Slice Test......................................... ERROR #2\n");
93 test_control_return(1);
94 }
95
96 status = tx_thread_create(&thread_31b, "thread 31b", thread_31b_entry, 0,
97 pointer, TEST_STACK_SIZE_PRINTF,
98 31, 31, 1, TX_DONT_START);
99 pointer = pointer + TEST_STACK_SIZE_PRINTF;
100 status += tx_thread_smp_core_exclude(&thread_31b, 0); /* Any core. */
101
102 /* Check status. */
103 if (status != TX_SUCCESS)
104 {
105
106 printf("Running SMP Time-Slice Test......................................... ERROR #3\n");
107 test_control_return(1);
108 }
109
110
111 status = tx_thread_create(&thread_31c, "thread 31c", thread_31c_entry, 0,
112 pointer, TEST_STACK_SIZE_PRINTF,
113 31, 31, 1, TX_DONT_START);
114 pointer = pointer + TEST_STACK_SIZE_PRINTF;
115 status += tx_thread_smp_core_exclude(&thread_31c, 0); /* Any core. */
116
117 /* Check status. */
118 if (status != TX_SUCCESS)
119 {
120
121 printf("Running SMP Time-Slice Test......................................... ERROR #4\n");
122 test_control_return(1);
123 }
124
125
126 status = tx_thread_create(&thread_31d, "thread 31d", thread_31d_entry, 0,
127 pointer, TEST_STACK_SIZE_PRINTF,
128 31, 31, 1, TX_DONT_START);
129 pointer = pointer + TEST_STACK_SIZE_PRINTF;
130 status += tx_thread_smp_core_exclude(&thread_31d, 0); /* Any core. */
131
132 /* Check status. */
133 if (status != TX_SUCCESS)
134 {
135
136 printf("Running SMP Time-Slice Test......................................... ERROR #5\n");
137 test_control_return(1);
138 }
139
140 status = tx_thread_create(&thread_31e, "thread 31e", thread_31e_entry, 0,
141 pointer, TEST_STACK_SIZE_PRINTF,
142 31, 31, 1, TX_DONT_START);
143 pointer = pointer + TEST_STACK_SIZE_PRINTF;
144 status += tx_thread_smp_core_exclude(&thread_31e, 0); /* Any core. */
145
146 /* Check status. */
147 if (status != TX_SUCCESS)
148 {
149
150 printf("Running SMP Time-Slice Test......................................... ERROR #6\n");
151 test_control_return(1);
152 }
153
154 status = tx_thread_create(&thread_31f, "thread 31f", thread_31f_entry, 0,
155 pointer, TEST_STACK_SIZE_PRINTF,
156 31, 31, 1, TX_DONT_START);
157 pointer = pointer + TEST_STACK_SIZE_PRINTF;
158 status += tx_thread_smp_core_exclude(&thread_31f, 0); /* Any core. */
159
160 /* Check status. */
161 if (status != TX_SUCCESS)
162 {
163
164 printf("Running SMP Time-Slice Test......................................... ERROR #7\n");
165 test_control_return(1);
166 }
167
168
169 status = tx_thread_create(&thread_31g, "thread 31g", thread_31g_entry, 0,
170 pointer, TEST_STACK_SIZE_PRINTF,
171 31, 31, 1, TX_DONT_START);
172 pointer = pointer + TEST_STACK_SIZE_PRINTF;
173 status += tx_thread_smp_core_exclude(&thread_31g, 0); /* Any core. */
174
175 /* Check status. */
176 if (status != TX_SUCCESS)
177 {
178
179 printf("Running SMP Time-Slice Test......................................... ERROR #8\n");
180 test_control_return(1);
181 }
182
183 /* Enable preemption-threshold for this thread to hit branch in tx_thread_time_slice
184 where the expired time-slice thread is replaced by a thread with preemption-threshold
185 enabled. */
186 status = tx_thread_create(&thread_31h, "thread 31h", thread_31h_entry, 0,
187 pointer, TEST_STACK_SIZE_PRINTF,
188 31, 30, 1, TX_DONT_START);
189 pointer = pointer + TEST_STACK_SIZE_PRINTF;
190 status += tx_thread_smp_core_exclude(&thread_31h, 0); /* Any core. */
191
192 /* Check status. */
193 if (status != TX_SUCCESS)
194 {
195
196 printf("Running SMP Time-Slice Test......................................... ERROR #9\n");
197 test_control_return(1);
198 }
199
200 /* Clear all the counters. */
201 thread_31a_counter = 0;
202 thread_31b_counter = 0;
203 thread_31c_counter = 0;
204 thread_31d_counter = 0;
205 thread_31e_counter = 0;
206 thread_31f_counter = 0;
207 thread_31g_counter = 0;
208 thread_31h_counter = 0;
209
210 /* Resume thread 0. */
211 status = tx_thread_resume(&thread_0);
212
213 /* Check status. */
214 if (status != TX_SUCCESS)
215 {
216
217 printf("Running SMP Time-Slice Test......................................... ERROR #10\n");
218 test_control_return(1);
219 }
220 }
221
222
223
224 /* Define the test threads. */
225
thread_0_entry(ULONG thread_input)226 static void thread_0_entry(ULONG thread_input)
227 {
228
229 UINT status;
230
231
232
233 /* Inform user. */
234 printf("Running SMP Time-Slice Test......................................... ");
235
236 /* Resume all the same priority threads. */
237 status = tx_thread_resume(&thread_31a);
238 status += tx_thread_resume(&thread_31b);
239 status += tx_thread_resume(&thread_31c);
240 status += tx_thread_resume(&thread_31d);
241 status += tx_thread_resume(&thread_31e);
242 status += tx_thread_resume(&thread_31f);
243 status += tx_thread_resume(&thread_31g);
244 status += tx_thread_resume(&thread_31h);
245
246 /* Now sleep for 20 ticks to let see if all the threads execute. */
247 tx_thread_sleep(20);
248
249 /* Now check and make sure all the threads ran. */
250 if ((status != TX_SUCCESS) || (thread_31a_counter == 0) || (thread_31b_counter == 0) || (thread_31c_counter == 0) || (thread_31d_counter == 0) ||
251 (thread_31e_counter == 0) || (thread_31f_counter == 0) || (thread_31g_counter == 0) || (thread_31h_counter == 0))
252 {
253
254 /* Execution error. */
255 printf("ERROR #31\n");
256 test_control_return(1);
257 }
258 else
259 {
260
261 /* Successful test. */
262 printf("SUCCESS!\n");
263 test_control_return(0);
264 }
265 }
266
267
thread_31a_entry(ULONG thread_input)268 static void thread_31a_entry(ULONG thread_input)
269 {
270
271 while(1)
272 {
273 tx_thread_identify();
274 thread_31a_counter++;
275 }
276 }
277
278
thread_31b_entry(ULONG thread_input)279 static void thread_31b_entry(ULONG thread_input)
280 {
281
282 while(1)
283 {
284
285 tx_thread_identify();
286 thread_31b_counter++;
287 }
288 }
289
290
thread_31c_entry(ULONG thread_input)291 static void thread_31c_entry(ULONG thread_input)
292 {
293
294 while(1)
295 {
296
297 tx_thread_identify();
298 thread_31c_counter++;
299 }
300 }
301
302
thread_31d_entry(ULONG thread_input)303 static void thread_31d_entry(ULONG thread_input)
304 {
305
306 while(1)
307 {
308
309 tx_thread_identify();
310 thread_31d_counter++;
311 }
312 }
313
314
thread_31e_entry(ULONG thread_input)315 static void thread_31e_entry(ULONG thread_input)
316 {
317
318 while(1)
319 {
320
321 tx_thread_identify();
322 thread_31e_counter++;
323 }
324 }
325
326
thread_31f_entry(ULONG thread_input)327 static void thread_31f_entry(ULONG thread_input)
328 {
329
330 while(1)
331 {
332
333 tx_thread_identify();
334 thread_31f_counter++;
335 }
336 }
337
338
thread_31g_entry(ULONG thread_input)339 static void thread_31g_entry(ULONG thread_input)
340 {
341
342 while(1)
343 {
344
345 tx_thread_identify();
346 thread_31g_counter++;
347 }
348 }
349
350
thread_31h_entry(ULONG thread_input)351 static void thread_31h_entry(ULONG thread_input)
352 {
353
354 while(1)
355 {
356
357 tx_thread_identify();
358 thread_31h_counter++;
359 }
360 }
361
362