1 /* This test is designed to test the event flag group information gathering services. */
2
3 #include <stdio.h>
4 #include "tx_api.h"
5 #include "tx_event_flags.h"
6
7
8 static TX_THREAD thread_0;
9
10
11 static TX_EVENT_FLAGS_GROUP group_0;
12 static TX_EVENT_FLAGS_GROUP group_1;
13 static TX_EVENT_FLAGS_GROUP group_2;
14
15
16
17 /* Define thread prototypes. */
18
19 static void thread_0_entry(ULONG thread_input);
20
21
22 UINT _tx_event_flags_performance_info_get(TX_EVENT_FLAGS_GROUP *group_ptr, ULONG *sets, ULONG *gets,
23 ULONG *suspensions, ULONG *timeouts);
24
25
26 /* Prototype for test control return. */
27
28 void test_control_return(UINT status);
29
30
event_set_notify(TX_EVENT_FLAGS_GROUP * group)31 static void event_set_notify(TX_EVENT_FLAGS_GROUP *group)
32 {
33
34 /* Not necessary to do anything in this function. */
35 }
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_event_flag_information_application_define(void *first_unused_memory)
44 #endif
45 {
46
47 INT 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 17, 17, 100, TX_AUTO_START);
60 pointer = pointer + TEST_STACK_SIZE_PRINTF;
61
62 /* Check status. */
63 if (status != TX_SUCCESS)
64 {
65
66 printf("Running Event Flag Information Test................................. ERROR #1\n");
67 test_control_return(1);
68 }
69
70 /* Create event flag group 0 and 1. */
71 status = tx_event_flags_create(&group_0, "group 0");
72
73 /* Check status. */
74 if (status != TX_SUCCESS)
75 {
76
77 printf("Running Event Flag Information Test................................. ERROR #2\n");
78 test_control_return(1);
79 }
80
81 status = tx_event_flags_create(&group_1, "group 1");
82
83 /* Check status. */
84 if (status != TX_SUCCESS)
85 {
86
87 printf("Running Event Flag Information Test................................. ERROR #3\n");
88 test_control_return(1);
89 }
90
91 /* Register the event set notify function. */
92 status = tx_event_flags_set_notify(&group_0, event_set_notify);
93
94 #ifndef TX_DISABLE_NOTIFY_CALLBACKS
95
96 /* Check status. */
97 if (status != TX_SUCCESS)
98 {
99
100 printf("Running Event Flag Information Test................................. ERROR #4\n");
101 test_control_return(1);
102 }
103 #else
104
105 /* Check status. */
106 if (status != TX_FEATURE_NOT_ENABLED)
107 {
108
109 printf("Running Event Flag Information Test................................. ERROR #5\n");
110 test_control_return(1);
111 }
112
113 #endif
114
115 }
116
117
118
119 /* Define the test threads. */
120
thread_0_entry(ULONG thread_input)121 static void thread_0_entry(ULONG thread_input)
122 {
123
124 UINT status;
125 ULONG actual_events;
126 CHAR *name;
127 ULONG current_flags;
128 TX_THREAD *first_suspended;
129 ULONG suspended_count;
130 TX_EVENT_FLAGS_GROUP *next_group;
131 ULONG sets;
132 ULONG gets;
133 ULONG suspensions;
134 ULONG timeouts;
135
136
137 /* Inform user. */
138 printf("Running Event Flag Information Test................................. ");
139
140 /* Event flags should be created now. */
141
142 /* Attempt to get events from an empty event flag group. AND option. */
143 status = tx_event_flags_get(&group_0, 0x80008000, TX_AND, &actual_events, TX_NO_WAIT);
144
145 /* Check status. */
146 if (status != TX_NO_EVENTS)
147 {
148
149 /* Event flag error. */
150 printf("ERROR #6\n");
151 test_control_return(1);
152 }
153
154 /* Attempt to get events from an empty event flag group. OR option. */
155 status = tx_event_flags_get(&group_0, 0x80008000, TX_OR, &actual_events, TX_NO_WAIT);
156
157 /* Check status. */
158 if (status != TX_NO_EVENTS)
159 {
160
161 /* Event flag error. */
162 printf("ERROR #7\n");
163 test_control_return(1);
164 }
165
166 /* Attempt to get events from an empty event flag group. AND CLEAR option. */
167 status = tx_event_flags_get(&group_0, 0x80008000, TX_AND_CLEAR, &actual_events, TX_NO_WAIT);
168
169 /* Check status. */
170 if (status != TX_NO_EVENTS)
171 {
172
173 /* Event flag error. */
174 printf("ERROR #8\n");
175 test_control_return(1);
176 }
177
178 /* Attempt to get events from an empty event flag group. OR CLEAR option. */
179 status = tx_event_flags_get(&group_0, 0x80008000, TX_OR_CLEAR, &actual_events, TX_NO_WAIT);
180
181 /* Check status. */
182 if (status != TX_NO_EVENTS)
183 {
184
185 /* Event flag error. */
186 printf("ERROR #9\n");
187 test_control_return(1);
188 }
189
190 /* Set the necessary events. */
191 status = tx_event_flags_set(&group_0, 0x80008000, TX_OR);
192
193 /* Check status. */
194 if (status != TX_SUCCESS)
195 {
196
197 /* Event flag error. */
198 printf("ERROR #10\n");
199 test_control_return(1);
200 }
201
202 /* Just for fun, clear bit 15. */
203 status = tx_event_flags_set(&group_0, 0x80000000, TX_AND);
204
205 /* Check status. */
206 if (status != TX_SUCCESS)
207 {
208
209 /* Event flag error. */
210 printf("ERROR #11\n");
211 test_control_return(1);
212 }
213
214 /* Set bit 15 again. */
215 status = tx_event_flags_set(&group_0, 0x00008000, TX_OR);
216
217 /* Check status. */
218 if (status != TX_SUCCESS)
219 {
220
221 /* Event flag error. */
222 printf("ERROR #12\n");
223 test_control_return(1);
224 }
225
226 /* Now attemp to retrieve events... */
227
228 /* Attempt to get events from event flag group. AND option. */
229 status = tx_event_flags_get(&group_0, 0x80008000, TX_AND, &actual_events, TX_NO_WAIT);
230
231 /* Check status. */
232 if ((status != TX_SUCCESS) || (actual_events != 0x80008000UL))
233 {
234
235 /* Event flag error. */
236 printf("ERROR #13\n");
237 test_control_return(1);
238 }
239
240 /* Attempt to get events from event flag group. OR option. */
241 status = tx_event_flags_get(&group_0, 0x80008000, TX_OR, &actual_events, TX_NO_WAIT);
242
243 /* Check status. */
244 if ((status != TX_SUCCESS) || (actual_events != 0x80008000UL))
245 {
246
247 /* Event flag error. */
248 printf("ERROR #14\n");
249 test_control_return(1);
250 }
251
252 /* Attempt to get events from event flag group. AND CLEAR option. */
253 status = tx_event_flags_get(&group_0, 0x80008000, TX_AND_CLEAR, &actual_events, TX_NO_WAIT);
254
255 /* Check status. */
256 if ((status != TX_SUCCESS) || (actual_events != 0x80008000UL))
257 {
258
259 /* Event flag error. */
260 printf("ERROR #15\n");
261 test_control_return(1);
262 }
263
264 /* Attempt to get events from an empty event flag group. OR CLEAR option. */
265 status = tx_event_flags_get(&group_0, 0x80008000, TX_OR_CLEAR, &actual_events, TX_NO_WAIT);
266
267 /* Check status. */
268 if (status != TX_NO_EVENTS)
269 {
270
271 /* Event flag error. */
272 printf("ERROR #16\n");
273 test_control_return(1);
274 }
275
276 /* Put event flags back in the group. */
277
278 /* Set the necessary events. */
279 status = tx_event_flags_set(&group_0, 0x80008000, TX_OR);
280
281 /* Check status. */
282 if (status != TX_SUCCESS)
283 {
284
285 /* Event flag error. */
286 printf("ERROR #17\n");
287 test_control_return(1);
288 }
289
290 /* Attempt to get events from event flag group. OR CLEAR option. */
291 status = tx_event_flags_get(&group_0, 0x00008000, TX_OR_CLEAR, &actual_events, TX_NO_WAIT);
292
293 /* Check status. */
294 if ((status != TX_SUCCESS) || (actual_events != 0x80008000UL))
295 {
296
297 /* Event flag error. */
298 printf("ERROR #18\n");
299 test_control_return(1);
300 }
301
302 /* Attempt to get events from event flag group. OR CLEAR option. */
303 status = tx_event_flags_get(&group_0, 0x80008000, TX_OR_CLEAR, &actual_events, TX_NO_WAIT);
304
305 /* Check status. */
306 if ((status != TX_SUCCESS) || (actual_events != 0x80000000UL))
307 {
308
309 /* Event flag error. */
310 printf("ERROR #19\n");
311 test_control_return(1);
312 }
313
314 #ifndef TX_DISABLE_ERROR_CHECKING
315
316 /* Get information with a NULL pointer. */
317 status = tx_event_flags_info_get(TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL);
318
319 /* Check status. */
320 if (status != TX_GROUP_ERROR)
321 {
322
323 /* Event flag error. */
324 printf("ERROR #20\n");
325 test_control_return(1);
326 }
327
328 /* Get information from a non-created group. */
329 group_2.tx_event_flags_group_id = 0;
330 status = tx_event_flags_info_get(&group_2, TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL);
331
332 /* Check status. */
333 if (status != TX_GROUP_ERROR)
334 {
335
336 /* Event flag error. */
337 printf("ERROR #21\n");
338 test_control_return(1);
339 }
340
341 #endif
342
343 /* Get information about the event flag group. */
344 status = tx_event_flags_info_get(&group_0, TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL);
345 status += tx_event_flags_info_get(&group_0, &name, ¤t_flags, &first_suspended, &suspended_count, &next_group);
346
347 /* Check the status. */
348 if ((status != TX_SUCCESS) || (current_flags != group_0.tx_event_flags_group_current) || (first_suspended != TX_NULL) || (suspended_count != 0) || (next_group != &group_1))
349 {
350
351 /* Event flag error. */
352 printf("ERROR #22\n");
353 test_control_return(1);
354 }
355
356 #ifdef TX_EVENT_FLAGS_ENABLE_PERFORMANCE_INFO
357
358 /* Get performance information with NULL pointer. */
359 status = _tx_event_flags_performance_info_get(TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL);
360
361 /* Check the status. */
362 if (status != TX_PTR_ERROR)
363 {
364
365 /* Event flag error. */
366 printf("ERROR #23\n");
367 test_control_return(1);
368 }
369
370 /* Get performance information on the event flag group. */
371 status = tx_event_flags_performance_info_get(&group_0, TX_NULL, TX_NULL, TX_NULL, TX_NULL);
372 status += tx_event_flags_performance_info_get(&group_0, &sets, &gets, &suspensions, &timeouts);
373
374 /* Check the status. */
375 if ((status != TX_SUCCESS) || (sets != group_0.tx_event_flags_group_performance_set_count) || (gets != group_0.tx_event_flags_group__performance_get_count) ||
376 (suspensions != group_0.tx_event_flags_group___performance_suspension_count) || (timeouts != group_0.tx_event_flags_group____performance_timeout_count))
377 {
378
379 /* Event flag error. */
380 printf("ERROR #24\n");
381 test_control_return(1);
382 }
383
384 /* Get system performance information on all event flags groups. */
385 status = tx_event_flags_performance_system_info_get(TX_NULL, TX_NULL, TX_NULL, TX_NULL);
386 status += tx_event_flags_performance_system_info_get(&sets, &gets, &suspensions, &timeouts);
387
388 /* Check the status. */
389 if ((status != TX_SUCCESS) || (sets != _tx_event_flags_performance_set_count) || (gets != _tx_event_flags_performance_get_count) ||
390 (suspensions != _tx_event_flags_performance_suspension_count) || (timeouts != _tx_event_flags_performance_timeout_count))
391 {
392
393 /* Event flag error. */
394 printf("ERROR #25\n");
395 test_control_return(1);
396 }
397
398 #else
399
400 /* Get performance information on the event flag group. */
401 status = tx_event_flags_performance_info_get(&group_0, &sets, &gets, &suspensions, &timeouts);
402
403 /* Check the status. */
404 if (status != TX_FEATURE_NOT_ENABLED)
405 {
406
407 /* Event flag error. */
408 printf("ERROR #26\n");
409 test_control_return(1);
410 }
411
412 /* Get performance information on the event flag group. */
413 status = tx_event_flags_performance_info_get(TX_NULL, &sets, &gets, &suspensions, &timeouts);
414
415 /* Check the status. */
416 if (status != TX_FEATURE_NOT_ENABLED)
417 {
418
419 /* Event flag error. */
420 printf("ERROR #27\n");
421 test_control_return(1);
422 }
423
424 /* Get performance information on the event flag group. */
425 status = tx_event_flags_performance_info_get(TX_NULL, TX_NULL, &gets, &suspensions, &timeouts);
426
427 /* Check the status. */
428 if (status != TX_FEATURE_NOT_ENABLED)
429 {
430
431 /* Event flag error. */
432 printf("ERROR #28\n");
433 test_control_return(1);
434 }
435
436 /* Get performance information on the event flag group. */
437 status = tx_event_flags_performance_info_get(TX_NULL, TX_NULL, TX_NULL, &suspensions, &timeouts);
438
439 /* Check the status. */
440 if (status != TX_FEATURE_NOT_ENABLED)
441 {
442
443 /* Event flag error. */
444 printf("ERROR #29\n");
445 test_control_return(1);
446 }
447
448 /* Get performance information on the event flag group. */
449 status = tx_event_flags_performance_info_get(TX_NULL, TX_NULL, TX_NULL, TX_NULL, &timeouts);
450
451 /* Check the status. */
452 if (status != TX_FEATURE_NOT_ENABLED)
453 {
454
455 /* Event flag error. */
456 printf("ERROR #30\n");
457 test_control_return(1);
458 }
459
460 /* Get performance information on the event flag group. */
461 status = tx_event_flags_performance_info_get(TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL);
462
463 /* Check the status. */
464 if (status != TX_FEATURE_NOT_ENABLED)
465 {
466
467 /* Event flag error. */
468 printf("ERROR #31\n");
469 test_control_return(1);
470 }
471
472 /* Get system performance information on all event flags groups. */
473 status = tx_event_flags_performance_system_info_get(&sets, &gets, &suspensions, &timeouts);
474
475 /* Check the status. */
476 if (status != TX_FEATURE_NOT_ENABLED)
477 {
478
479 /* Event flag error. */
480 printf("ERROR #32\n");
481 test_control_return(1);
482 }
483
484 /* Get system performance information on all event flags groups. */
485 status = tx_event_flags_performance_system_info_get(TX_NULL, &gets, &suspensions, &timeouts);
486
487 /* Check the status. */
488 if (status != TX_FEATURE_NOT_ENABLED)
489 {
490
491 /* Event flag error. */
492 printf("ERROR #33\n");
493 test_control_return(1);
494 }
495
496 /* Get system performance information on all event flags groups. */
497 status = tx_event_flags_performance_system_info_get(TX_NULL, TX_NULL, &suspensions, &timeouts);
498
499 /* Check the status. */
500 if (status != TX_FEATURE_NOT_ENABLED)
501 {
502
503 /* Event flag error. */
504 printf("ERROR #34\n");
505 test_control_return(1);
506 }
507
508 /* Get system performance information on all event flags groups. */
509 status = tx_event_flags_performance_system_info_get(TX_NULL, TX_NULL, TX_NULL, &timeouts);
510
511 /* Check the status. */
512 if (status != TX_FEATURE_NOT_ENABLED)
513 {
514
515 /* Event flag error. */
516 printf("ERROR #35\n");
517 test_control_return(1);
518 }
519
520 /* Get system performance information on all event flags groups. */
521 status = tx_event_flags_performance_system_info_get(TX_NULL, TX_NULL, TX_NULL, TX_NULL);
522
523 /* Check the status. */
524 if (status != TX_FEATURE_NOT_ENABLED)
525 {
526
527 /* Event flag error. */
528 printf("ERROR #36\n");
529 test_control_return(1);
530 }
531 #endif
532
533 /* Delete both event flag groups. */
534 status = tx_event_flags_delete(&group_0);
535
536 /* Check the status. */
537 if (status != TX_SUCCESS)
538 {
539
540 /* Event flag error. */
541 printf("ERROR #37\n");
542 test_control_return(1);
543 }
544
545 status = tx_event_flags_delete(&group_1);
546
547 /* Check the status. */
548 if (status != TX_SUCCESS)
549 {
550
551 /* Event flag error. */
552 printf("ERROR #38\n");
553 test_control_return(1);
554 }
555 else
556 {
557
558 /* Successful test. */
559 printf("SUCCESS!\n");
560 test_control_return(0);
561 }
562 }
563