1 /* This test is designed to test event flag suspension and resumption of two threads
2 waiting on the same event flag set with the consumption. */
3
4 #include <stdio.h>
5 #include "tx_api.h"
6
7 static unsigned long thread_0_counter = 0;
8 static TX_THREAD thread_0;
9 static unsigned long thread_1_counter = 0;
10 static TX_THREAD thread_1;
11 static unsigned long thread_2_counter = 0;
12 static TX_THREAD thread_2;
13 static unsigned long thread_3_counter = 0;
14 static TX_THREAD thread_3;
15
16
17 static TX_EVENT_FLAGS_GROUP group_0;
18
19
20 /* Define thread prototypes. */
21
22 static void thread_0_entry(ULONG thread_input);
23 static void thread_1_entry(ULONG thread_input);
24 static void thread_2_entry(ULONG thread_input);
25 static void thread_3_entry(ULONG thread_input);
26
27
28 /* Prototype for test control return. */
29 void test_control_return(UINT status);
30
31
event_set_notify(TX_EVENT_FLAGS_GROUP * group)32 static void event_set_notify(TX_EVENT_FLAGS_GROUP *group)
33 {
34
35 /* Not necessary to do anything in this function. */
36 }
37
38
39 /* Define what the initial system looks like. */
40
41 #ifdef CTEST
test_application_define(void * first_unused_memory)42 void test_application_define(void *first_unused_memory)
43 #else
44 void threadx_event_flag_suspension_consume_application_define(void *first_unused_memory)
45 #endif
46 {
47
48 UINT status;
49 CHAR *pointer;
50
51
52 /* Put first available memory address into a character pointer. */
53 pointer = (CHAR *) first_unused_memory;
54
55 /* Put system definition stuff in here, e.g. thread creates and other assorted
56 create information. */
57
58 status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
59 pointer, TEST_STACK_SIZE_PRINTF,
60 17, 17, 100, TX_AUTO_START);
61 pointer = pointer + TEST_STACK_SIZE_PRINTF;
62
63 /* Check status. */
64 if (status != TX_SUCCESS)
65 {
66
67 printf("Running Event Flag Suspension/Consumption Test...................... ERROR #1\n");
68 test_control_return(1);
69 }
70
71 status = tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
72 pointer, TEST_STACK_SIZE_PRINTF,
73 16, 16, 100, TX_AUTO_START);
74 pointer = pointer + TEST_STACK_SIZE_PRINTF;
75
76 /* Check status. */
77 if (status != TX_SUCCESS)
78 {
79
80 printf("Running Event Flag Suspension/Consumption Test...................... ERROR #2\n");
81 test_control_return(1);
82 }
83
84 status = tx_thread_create(&thread_2, "thread 2", thread_2_entry, 1,
85 pointer, TEST_STACK_SIZE_PRINTF,
86 16, 16, 100, TX_AUTO_START);
87 pointer = pointer + TEST_STACK_SIZE_PRINTF;
88
89 /* Check status. */
90 if (status != TX_SUCCESS)
91 {
92
93 printf("Running Event Flag Suspension/Consumption Test...................... ERROR #3\n");
94 test_control_return(1);
95 }
96
97 status = tx_thread_create(&thread_3, "thread 3", thread_3_entry, 1,
98 pointer, TEST_STACK_SIZE_PRINTF,
99 16, 16, 100, TX_AUTO_START);
100 pointer = pointer + TEST_STACK_SIZE_PRINTF;
101
102 /* Check status. */
103 if (status != TX_SUCCESS)
104 {
105
106 printf("Running Event Flag Suspension/Consumption Test...................... ERROR #4\n");
107 test_control_return(1);
108 }
109
110 /* Create event flag group 0. */
111 status = tx_event_flags_create(&group_0, "group 0");
112
113 /* Check status. */
114 if (status != TX_SUCCESS)
115 {
116
117 printf("Running Event Flag Suspension/Consumption Test...................... ERROR #5\n");
118 test_control_return(1);
119 }
120
121 /* Register the event set notify function. */
122 status = tx_event_flags_set_notify(&group_0, event_set_notify);
123
124 #ifndef TX_DISABLE_NOTIFY_CALLBACKS
125
126 /* Check status. */
127 if (status != TX_SUCCESS)
128 {
129
130 printf("Running Event Flag Suspension/Consumption Test...................... ERROR #6\n");
131 test_control_return(1);
132 }
133 #else
134
135 /* Check status. */
136 if (status != TX_FEATURE_NOT_ENABLED)
137 {
138
139 printf("Running Event Flag Suspension/Consumption Test...................... ERROR #7\n");
140 test_control_return(1);
141 }
142
143 #endif
144
145 }
146
147
148
149 /* Define the test threads. */
150
thread_0_entry(ULONG thread_input)151 static void thread_0_entry(ULONG thread_input)
152 {
153
154 UINT status;
155 ULONG event_flag = 1;
156 int i;
157
158
159 /* Inform user. */
160 printf("Running Event Flag Suspension/Consumption Test...................... ");
161
162 /* Set all event flags. */
163 for (i = 0; i < 32; i++)
164 {
165
166 /* Increment run counter. */
167 thread_0_counter++;
168
169 /* Set event flag. */
170 status = tx_event_flags_set(&group_0, event_flag, TX_OR);
171
172 /* Check status. */
173 if (status != TX_SUCCESS)
174 {
175
176 /* Event flag error. */
177 printf("ERROR #8\n");
178 test_control_return(1);
179 }
180
181 /* Check the thread counters... */
182 if ((i < 31) && ((thread_1_counter != 1) || (thread_2_counter != 1) || (thread_3_counter != 1)))
183 {
184
185 /* Event flag error. */
186 printf("ERROR #9\n");
187 test_control_return(1);
188 }
189 if ((i == 31) && ((thread_1_counter != 2) || (thread_2_counter != 2) || (thread_3_counter != 2)))
190 {
191
192 /* Event flag error. */
193 printf("ERROR #10\n");
194 test_control_return(1);
195 }
196
197 /* Shift event flag up one bit. */
198 event_flag = event_flag << 1;
199
200 /* Check for 0. */
201 if (event_flag == 0)
202 event_flag = 1;
203 }
204
205 /* Successful test. */
206 printf("SUCCESS!\n");
207 test_control_return(0);
208 }
209
210
thread_1_entry(ULONG thread_input)211 static void thread_1_entry(ULONG thread_input)
212 {
213
214 UINT status;
215 //ULONG event_flag = 1;
216 ULONG actual_events;
217
218 /* Wait for event flags. */
219 while(1)
220 {
221
222 /* Increment run counter. */
223 thread_1_counter++;
224
225 /* Attempt to get events from event flag group. AND option. */
226 status = tx_event_flags_get(&group_0, 0x80008000, TX_AND_CLEAR, &actual_events, TX_WAIT_FOREVER);
227
228 /* Check status. */
229 if ((status != TX_SUCCESS) || (actual_events != 0xFFFFFFFFUL))
230 return;
231 }
232 }
233
234
thread_2_entry(ULONG thread_input)235 static void thread_2_entry(ULONG thread_input)
236 {
237
238 UINT status;
239 //ULONG event_flag = 1;
240 ULONG actual_events;
241
242 /* Wait for event flags. */
243 while(1)
244 {
245
246 /* Increment run counter. */
247 thread_2_counter++;
248
249 /* Attempt to get events from event flag group. AND option. */
250 status = tx_event_flags_get(&group_0, 0x80008000, TX_AND, &actual_events, TX_WAIT_FOREVER);
251
252 /* Check status. */
253 if ((status != TX_SUCCESS) || (actual_events != 0xFFFFFFFFUL))
254 return;
255 }
256 }
257
258
thread_3_entry(ULONG thread_input)259 static void thread_3_entry(ULONG thread_input)
260 {
261
262 UINT status;
263 //ULONG event_flag = 1;
264 ULONG actual_events;
265
266 /* Wait for event flags. */
267 while(1)
268 {
269
270 /* Increment run counter. */
271 thread_3_counter++;
272
273 /* Attempt to get events from event flag group. AND option. */
274 status = tx_event_flags_get(&group_0, 0x80008000, TX_AND, &actual_events, TX_WAIT_FOREVER);
275
276 /* Check status. */
277 if ((status != TX_SUCCESS) || (actual_events != 0xFFFFFFFFUL))
278 return;
279 }
280 }
281
282