1 /* This test is designed to see if multiple non-current threads can be suspended.
2 The order the suspension and resumption occurs makes sure everything is working
3 right. Thread execution should remain predictable even after suspension and
4 resumption of threads within a priority group. */
5
6 #include <stdio.h>
7 #include "tx_api.h"
8
9 static unsigned long thread_0_counter = 0;
10 static TX_THREAD thread_0;
11
12 static unsigned long thread_1_counter = 0;
13 static TX_THREAD thread_1;
14
15 static unsigned long thread_2_counter = 0;
16 static TX_THREAD thread_2;
17
18 static unsigned long thread_3_counter = 0;
19 static TX_THREAD thread_3;
20
21 static unsigned long thread_4_counter = 0;
22 static TX_THREAD thread_4;
23
24
25 /* Define thread prototypes. */
26
27 static void thread_0_entry(ULONG thread_input);
28 static void thread_1_entry(ULONG thread_input);
29 static void thread_2_entry(ULONG thread_input);
30 static void thread_3_entry(ULONG thread_input);
31 static void thread_4_entry(ULONG thread_input);
32
33
34 /* Prototype for test control return. */
35 void test_control_return(UINT status);
36
37
38 /* Define what the initial system looks like. */
39
40 #ifdef CTEST
test_application_define(void * first_unused_memory)41 void test_application_define(void *first_unused_memory)
42 #else
43 void threadx_thread_multiple_non_current_suspension_application_define(void *first_unused_memory)
44 #endif
45 {
46
47 UINT status;
48 CHAR *pointer;
49
50
51 /* Put first available memory address into a character pointer. */
52 pointer = (CHAR *) first_unused_memory;
53
54 /* Put system definition stuff in here, e.g. thread creates and other assorted
55 create information. */
56
57 status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
58 pointer, TEST_STACK_SIZE_PRINTF,
59 16, 16, TX_NO_TIME_SLICE, TX_AUTO_START);
60 pointer = pointer + TEST_STACK_SIZE_PRINTF;
61
62 /* Check for status. */
63 if (status != TX_SUCCESS)
64 {
65
66 printf("Running Thread Non-Current Suspend Test............................. ERROR #1\n");
67 test_control_return(1);
68 }
69
70 status = tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
71 pointer, TEST_STACK_SIZE_PRINTF,
72 16, 16, TX_NO_TIME_SLICE, TX_DONT_START);
73 pointer = pointer + TEST_STACK_SIZE_PRINTF;
74
75 /* Check for status. */
76 if (status != TX_SUCCESS)
77 {
78
79 printf("Running Thread Non-Current Suspend Test............................. ERROR #2\n");
80 test_control_return(1);
81 }
82
83 status = tx_thread_create(&thread_2, "thread 2", thread_2_entry, 2,
84 pointer, TEST_STACK_SIZE_PRINTF,
85 16, 16, TX_NO_TIME_SLICE, TX_DONT_START);
86 pointer = pointer + TEST_STACK_SIZE_PRINTF;
87
88 /* Check for status. */
89 if (status != TX_SUCCESS)
90 {
91
92 printf("Running Thread Non-Current Suspend Test............................. ERROR #3\n");
93 test_control_return(1);
94 }
95
96 status = tx_thread_create(&thread_3, "thread 3", thread_3_entry, 3,
97 pointer, TEST_STACK_SIZE_PRINTF,
98 15, 15, TX_NO_TIME_SLICE, TX_DONT_START);
99 pointer = pointer + TEST_STACK_SIZE_PRINTF;
100
101 /* Check for status. */
102 if (status != TX_SUCCESS)
103 {
104
105 printf("Running Thread Non-Current Suspend Test............................. ERROR #4\n");
106 test_control_return(1);
107 }
108
109 status = tx_thread_create(&thread_4, "thread 4", thread_4_entry, 4,
110 pointer, TEST_STACK_SIZE_PRINTF,
111 16, 16, TX_NO_TIME_SLICE, TX_DONT_START);
112 pointer = pointer + TEST_STACK_SIZE_PRINTF;
113
114 /* Check for status. */
115 if (status != TX_SUCCESS)
116 {
117
118 printf("Running Thread Non-Current Suspend Test............................. ERROR #5\n");
119 test_control_return(1);
120 }
121 }
122
123
124
125 /* Define the test threads. */
126
thread_0_entry(ULONG thread_input)127 static void thread_0_entry(ULONG thread_input)
128 {
129
130 UINT status;
131
132 /* Inform user. */
133 printf("Running Thread Non-Current Suspend Test............................. ");
134
135 /* Wakeup all other threads at same priority. */
136 status = tx_thread_resume(&thread_1);
137 status += tx_thread_resume(&thread_2);
138
139 /* Check for good status. */
140 if (status != TX_SUCCESS)
141 {
142
143 /* Thread Suspend error. */
144 printf("ERROR #6\n");
145 test_control_return(1);
146 }
147
148 /* Wakeup thread with preempt. */
149 status = tx_thread_resume(&thread_3);
150
151 /* Check for good status and proper counters. */
152 if ((status != TX_SUCCESS) || (thread_3_counter != 1) || (thread_1_counter) ||
153 (thread_2_counter) || (thread_4_counter))
154 {
155
156 /* Thread Suspend error. */
157 printf("ERROR #7\n");
158 test_control_return(1);
159 }
160
161 /* Suspend thread 1. */
162 status = tx_thread_suspend(&thread_1);
163
164 /* Resume thread 4. */
165 status += tx_thread_resume(&thread_4);
166
167 /* Check for good status and proper counters. */
168 if ((status != TX_SUCCESS) || (thread_3_counter != 1) || (thread_1_counter) ||
169 (thread_2_counter) || (thread_4_counter))
170 {
171
172 /* Thread Suspend error. */
173 printf("ERROR #8\n");
174 test_control_return(1);
175 }
176
177 /* Relinquish to thread 2 and 4 before we get back. */
178 tx_thread_relinquish();
179
180 /* Check for good status and proper counters. */
181 if ((status != TX_SUCCESS) || (thread_3_counter != 1) || (thread_1_counter) ||
182 (thread_2_counter != 1) || (thread_4_counter != 1))
183 {
184
185 /* Thread Suspend error. */
186 printf("ERROR #9\n");
187 test_control_return(1);
188 }
189
190 /* Increment thread 0 counter. */
191 thread_0_counter++;
192
193 /* Successful Thread Suspend non-current thread test. */
194 printf("SUCCESS!\n");
195 test_control_return(0);
196 }
197
thread_1_entry(ULONG thread_input)198 static void thread_1_entry(ULONG thread_input)
199 {
200
201 thread_1_counter++;
202 }
203
thread_2_entry(ULONG thread_input)204 static void thread_2_entry(ULONG thread_input)
205 {
206 if (thread_4_counter == 0)
207 thread_2_counter++;
208 }
209
thread_3_entry(ULONG thread_input)210 static void thread_3_entry(ULONG thread_input)
211 {
212
213 thread_3_counter++;
214 }
215
thread_4_entry(ULONG thread_input)216 static void thread_4_entry(ULONG thread_input)
217 {
218
219 if (thread_2_counter == 1)
220 thread_4_counter++;
221 }
222
223