1 /* Define the ThreadX SMP relinquish 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_relinquish_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 Relinquish 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, TX_NO_TIME_SLICE, 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 Relinquish 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, TX_NO_TIME_SLICE, 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 Relinquish 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, TX_NO_TIME_SLICE, 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 Relinquish 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, TX_NO_TIME_SLICE, 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 Relinquish 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, TX_NO_TIME_SLICE, 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 Relinquish 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, TX_NO_TIME_SLICE, 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 Relinquish 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, TX_NO_TIME_SLICE, 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 Relinquish Test......................................... ERROR #8\n");
180         test_control_return(1);
181     }
182 
183     status =  tx_thread_create(&thread_31h, "thread 31h", thread_31h_entry, 0,
184             pointer, TEST_STACK_SIZE_PRINTF,
185             31, 31, TX_NO_TIME_SLICE, TX_DONT_START);
186     pointer =  pointer + TEST_STACK_SIZE_PRINTF;
187     status +=   tx_thread_smp_core_exclude(&thread_31h, 0);      /* Any core.  */
188 
189     /* Check status.  */
190     if (status != TX_SUCCESS)
191     {
192 
193         printf("Running SMP Relinquish Test......................................... ERROR #9\n");
194         test_control_return(1);
195     }
196 
197     /* Clear all the counters.  */
198     thread_31a_counter =   0;
199     thread_31b_counter =   0;
200     thread_31c_counter =   0;
201     thread_31d_counter =   0;
202     thread_31e_counter =   0;
203     thread_31f_counter =   0;
204     thread_31g_counter =   0;
205     thread_31h_counter =   0;
206 
207 	/* Resume thread 0.  */
208     status =  tx_thread_resume(&thread_0);
209 
210 	/* Check status.  */
211     if (status != TX_SUCCESS)
212     {
213 
214         printf("Running SMP Relinquish Test......................................... ERROR #10\n");
215         test_control_return(1);
216     }
217 }
218 
219 
220 
221 /* Define the test threads.  */
222 
thread_0_entry(ULONG thread_input)223 static void    thread_0_entry(ULONG thread_input)
224 {
225 
226 UINT    status;
227 
228 
229 
230     /* Inform user.  */
231     printf("Running SMP Relinquish Test......................................... ");
232 
233     /* Resume all the same priority threads.  */
234     status =  tx_thread_resume(&thread_31a);
235     status += tx_thread_resume(&thread_31b);
236     status += tx_thread_resume(&thread_31c);
237     status += tx_thread_resume(&thread_31d);
238     status += tx_thread_resume(&thread_31e);
239     status += tx_thread_resume(&thread_31f);
240     status += tx_thread_resume(&thread_31g);
241     status += tx_thread_resume(&thread_31h);
242 
243     /* Now sleep for 10 ticks to let see if all the threads execute.  */
244     tx_thread_sleep(10);
245 
246     /* Now check and make sure all the threads ran.  */
247     if ((status != TX_SUCCESS) || (thread_31a_counter == 0) || (thread_31b_counter == 0) || (thread_31c_counter == 0) || (thread_31d_counter == 0) ||
248         (thread_31e_counter == 0) || (thread_31f_counter == 0) || (thread_31g_counter == 0) || (thread_31h_counter == 0))
249     {
250 
251         /* Execution error.  */
252         printf("ERROR #31\n");
253         test_control_return(1);
254     }
255 
256     /* Successful test.  */
257     printf("SUCCESS!\n");
258 
259     test_control_return(0);
260 }
261 
262 
thread_31a_entry(ULONG thread_input)263 static void    thread_31a_entry(ULONG thread_input)
264 {
265 
266     while(1)
267     {
268 
269         tx_thread_relinquish();
270 
271         thread_31a_counter++;
272     }
273 }
274 
275 
thread_31b_entry(ULONG thread_input)276 static void    thread_31b_entry(ULONG thread_input)
277 {
278 
279     while(1)
280     {
281 
282         tx_thread_relinquish();
283 
284         thread_31b_counter++;
285     }
286 }
287 
288 
thread_31c_entry(ULONG thread_input)289 static void    thread_31c_entry(ULONG thread_input)
290 {
291 
292     while(1)
293     {
294 
295         tx_thread_relinquish();
296 
297         thread_31c_counter++;
298     }
299 }
300 
301 
thread_31d_entry(ULONG thread_input)302 static void    thread_31d_entry(ULONG thread_input)
303 {
304 
305     while(1)
306     {
307 
308         tx_thread_relinquish();
309 
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_relinquish();
322 
323         thread_31e_counter++;
324     }
325 }
326 
327 
thread_31f_entry(ULONG thread_input)328 static void    thread_31f_entry(ULONG thread_input)
329 {
330 
331     while(1)
332     {
333 
334         tx_thread_relinquish();
335 
336         thread_31f_counter++;
337     }
338 }
339 
340 
thread_31g_entry(ULONG thread_input)341 static void    thread_31g_entry(ULONG thread_input)
342 {
343 
344     while(1)
345     {
346 
347         tx_thread_relinquish();
348 
349         thread_31g_counter++;
350     }
351 }
352 
353 
thread_31h_entry(ULONG thread_input)354 static void    thread_31h_entry(ULONG thread_input)
355 {
356 
357     while(1)
358     {
359 
360         tx_thread_relinquish();
361 
362         thread_31h_counter++;
363     }
364 }
365 
366