1 /* This test is designed to test simple event flag group creation, deletion, gets and
2 sets. */
3
4 #include <stdio.h>
5 #include "tx_api.h"
6
7
8 typedef struct EVENT_FLAG_MEMORY_TEST_STRUCT
9 {
10 ULONG first;
11 ULONG second;
12 TX_EVENT_FLAGS_GROUP event_flags;
13 ULONG next_to_last;
14 ULONG last;
15
16 } EVENT_FLAG_MEMORY_TEST;
17
18 static EVENT_FLAG_MEMORY_TEST event_flag_memory;
19
20
21 /* Define external reference to the event flag create call from initialization. */
22
23 extern UINT test_event_flags_from_init;
24
25
26 /* Define the ISR dispatch. */
27
28 extern VOID (*test_isr_dispatch)(void);
29
30
31 static TX_THREAD thread_0;
32 static TX_THREAD thread_1;
33 static TX_TIMER timer_0;
34
35 static unsigned long error = 0;
36 static unsigned long timer_executed = 0;
37 static unsigned long isr_executed = 0;
38
39 static TX_EVENT_FLAGS_GROUP group_0;
40 static TX_EVENT_FLAGS_GROUP group_1;
41 static TX_EVENT_FLAGS_GROUP group_2;
42 static TX_EVENT_FLAGS_GROUP group_3;
43
44
45 /* Define thread prototypes. */
46
47 static void thread_0_entry(ULONG thread_input);
48 static void thread_1_entry(ULONG thread_input);
49 UINT _txe_event_flags_create(TX_EVENT_FLAGS_GROUP *group_ptr, CHAR *name_ptr, UINT event_control_block_size);
50
51
52 /* Prototype for test control return. */
53
54 void test_control_return(UINT status);
55
56
event_set_notify(TX_EVENT_FLAGS_GROUP * group)57 static void event_set_notify(TX_EVENT_FLAGS_GROUP *group)
58 {
59
60 /* Not necessary to do anything in this function. */
61 }
62
63
64 /* Define the timer for this test. */
65
timer_entry(ULONG i)66 static void timer_entry(ULONG i)
67 {
68
69 #ifndef TX_DISABLE_ERROR_CHECKING
70
71 UINT status;
72 ULONG actual_events;
73
74
75 /* Determine if calling event flag create from initialization was successful. */
76 if (test_event_flags_from_init != TX_SUCCESS)
77 {
78
79 /* Error! */
80 error++;
81 }
82
83 /* Attempt to create an event flag group from a timer. */
84 status = tx_event_flags_create(&group_2, "group 2");
85
86 /* Check status. */
87 if (status != TX_CALLER_ERROR)
88 {
89
90 /* Error! */
91 error++;
92 }
93
94 /* Try to delete an event flags group from a timer. */
95 status = tx_event_flags_delete(&group_0);
96
97 /* Check status. */
98 if (status != TX_CALLER_ERROR)
99 {
100
101 /* Error! */
102 error++;
103 }
104
105 /* Get events with suspendsion from a timer. */
106 status = tx_event_flags_get(&group_0, 0x80008000, 14, &actual_events, 100);
107
108 /* Check status. */
109 if (status != TX_WAIT_ERROR)
110 {
111
112 /* Error! */
113 error++;
114 }
115
116 timer_executed = 1;
117 #endif
118 }
119
120 /* Define the ISR dispatch routine. */
121
test_isr(void)122 static void test_isr(void)
123 {
124
125 #ifndef TX_DISABLE_ERROR_CHECKING
126
127 UINT status;
128 ULONG actual_events;
129
130
131 /* Attempt to create an event flag group from an ISR. */
132 status = tx_event_flags_create(&group_2, "group 2");
133
134 /* Check status. */
135 if (status != TX_CALLER_ERROR)
136 {
137
138 /* Error! */
139 error++;
140 }
141
142 /* Attempt to delete an event flags group from an ISR. */
143 status = tx_event_flags_delete(&group_0);
144
145 if (status != TX_CALLER_ERROR)
146 {
147
148 /* Error! */
149 error++;
150 }
151
152 /* Get events with suspendsion from an ISR. */
153 status = tx_event_flags_get(&group_0, 0x80008000, 14, &actual_events, 100);
154
155 /* Check status. */
156 if (status != TX_WAIT_ERROR)
157 {
158
159 /* Error! */
160 error++;
161 }
162
163
164 isr_executed = 1;
165 #endif
166 }
167
168
169 /* Define what the initial system looks like. */
170
171 #ifdef CTEST
test_application_define(void * first_unused_memory)172 void test_application_define(void *first_unused_memory)
173 #else
174 void threadx_event_flag_basic_application_define(void *first_unused_memory)
175 #endif
176 {
177
178 INT status;
179 CHAR *pointer;
180
181
182 /* Put first available memory address into a character pointer. */
183 pointer = (CHAR *) first_unused_memory;
184
185 /* Put system definition stuff in here, e.g. thread creates and other assorted
186 create information. */
187
188 status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
189 pointer, TEST_STACK_SIZE_PRINTF,
190 17, 17, 100, TX_AUTO_START);
191 pointer = pointer + TEST_STACK_SIZE_PRINTF;
192
193 /* Check status. */
194 if (status != TX_SUCCESS)
195 {
196
197 printf("Running Event Flag Basic Test....................................... ERROR #1\n");
198 test_control_return(1);
199 }
200
201 status = tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
202 pointer, TEST_STACK_SIZE_PRINTF,
203 18, 18, 100, TX_DONT_START);
204 pointer = pointer + TEST_STACK_SIZE_PRINTF;
205
206 /* Check status. */
207 if (status != TX_SUCCESS)
208 {
209
210 printf("Running Event Flag Basic Test....................................... ERROR #2\n");
211 test_control_return(1);
212 }
213
214 /* Create event flag group 0 and 1. */
215 status = tx_event_flags_create(&group_0, "group 0");
216
217 /* Check status. */
218 if (status != TX_SUCCESS)
219 {
220
221 printf("Running Event Flag Basic Test....................................... ERROR #3\n");
222 test_control_return(1);
223 }
224
225 status = tx_event_flags_create(&group_1, "group 1");
226
227 /* Check status. */
228 if (status != TX_SUCCESS)
229 {
230
231 printf("Running Event Flag Basic Test....................................... ERROR #4\n");
232 test_control_return(1);
233 }
234
235 /* Register the event set notify function. */
236 status = tx_event_flags_set_notify(&group_0, event_set_notify);
237
238 #ifndef TX_DISABLE_NOTIFY_CALLBACKS
239
240 /* Check status. */
241 if (status != TX_SUCCESS)
242 {
243
244 printf("Running Event Flag Basic Test....................................... ERROR #5\n");
245 test_control_return(1);
246 }
247 #else
248
249 /* Check status. */
250 if (status != TX_FEATURE_NOT_ENABLED)
251 {
252
253 printf("Running Event Flag Basic Test....................................... ERROR #6\n");
254 test_control_return(1);
255 }
256
257 #endif
258
259 /* Un-register the event set notify function. */
260 status = tx_event_flags_set_notify(&group_0, TX_NULL);
261
262 #ifndef TX_DISABLE_NOTIFY_CALLBACKS
263
264 /* Check status. */
265 if (status != TX_SUCCESS)
266 {
267
268 printf("Running Event Flag Basic Test....................................... ERROR #5a\n");
269 test_control_return(1);
270 }
271 #else
272
273 /* Check status. */
274 if (status != TX_FEATURE_NOT_ENABLED)
275 {
276
277 printf("Running Event Flag Basic Test....................................... ERROR #6a\n");
278 test_control_return(1);
279 }
280 #endif
281
282 }
283
284
285
286 /* Define the test threads. */
287
thread_0_entry(ULONG thread_input)288 static void thread_0_entry(ULONG thread_input)
289 {
290
291 UINT status;
292 ULONG actual_events;
293
294
295 /* Inform user. */
296 printf("Running Event Flag Basic Test....................................... ");
297
298 /* Perform event flag memory test. */
299 event_flag_memory.first = 0x11223344;
300 event_flag_memory.second = 0x55667788;
301 event_flag_memory.next_to_last = 0x99aabbcc;
302 event_flag_memory.last = 0xddeeff00;
303
304 /* Create the event flag group. */
305 status = tx_event_flags_create(&event_flag_memory.event_flags, "group memory");
306 tx_event_flags_delete(&event_flag_memory.event_flags);
307
308 /* Check for status. */
309 if ((status != TX_SUCCESS) ||
310 (event_flag_memory.first != 0x11223344) ||
311 (event_flag_memory.second != 0x55667788) ||
312 (event_flag_memory.next_to_last != 0x99aabbcc) ||
313 (event_flag_memory.last != 0xddeeff00))
314 {
315
316 /* Event flag error. */
317 printf("ERROR #7\n");
318 test_control_return(1);
319 }
320
321 /* Event flags should be created now. */
322
323 #ifndef TX_DISABLE_ERROR_CHECKING
324
325 /* Try to create with a NULL pointer. */
326 status = tx_event_flags_create(TX_NULL, "group 0");
327
328 /* Check status. */
329 if (status != TX_GROUP_ERROR)
330 {
331
332 /* Event flag error. */
333 printf("ERROR #8\n");
334 test_control_return(1);
335 }
336
337 /* Try to create with a bad size. */
338 status = _txe_event_flags_create(&group_3, "group 3", (sizeof(TX_EVENT_FLAGS_GROUP)+1));
339
340 /* Check status. */
341 if (status != TX_GROUP_ERROR)
342 {
343
344 /* Event flag error. */
345 printf("ERROR #9\n");
346 test_control_return(1);
347 }
348
349 /* Try to create an already created group. */
350 status = tx_event_flags_create(&group_0, "group 0");
351
352 /* Check status. */
353 if (status != TX_GROUP_ERROR)
354 {
355
356 /* Event flag error. */
357 printf("ERROR #10\n");
358 test_control_return(1);
359 }
360
361 /* Delete with a NULL pointer. */
362 status = tx_event_flags_delete(TX_NULL);
363
364 /* Check the status. */
365 if (status != TX_GROUP_ERROR)
366 {
367
368 /* Event flag error. */
369 printf("ERROR #11\n");
370 test_control_return(1);
371 }
372
373 /* Delete with a non-created pointer. */
374 group_2.tx_event_flags_group_id = 0;
375 status = tx_event_flags_delete(&group_2);
376
377 /* Check the status. */
378 if (status != TX_GROUP_ERROR)
379 {
380
381 /* Event flag error. */
382 printf("ERROR #12\n");
383 test_control_return(1);
384 }
385
386 /* Get events with a null group pointer. */
387 status = tx_event_flags_get(TX_NULL, 0x80008000, TX_AND, &actual_events, TX_NO_WAIT);
388
389 /* Check status. */
390 if (status != TX_GROUP_ERROR)
391 {
392
393 /* Event flag error. */
394 printf("ERROR #13\n");
395 test_control_return(1);
396 }
397
398 /* Get events with a non-created group pointer. */
399 group_2.tx_event_flags_group_id = 0;
400 status = tx_event_flags_get(&group_2, 0x80008000, TX_AND, &actual_events, TX_NO_WAIT);
401
402 /* Check status. */
403 if (status != TX_GROUP_ERROR)
404 {
405
406 /* Event flag error. */
407 printf("ERROR #14\n");
408 test_control_return(1);
409 }
410
411 /* Get events with a null flags retun pointer. */
412 status = tx_event_flags_get(&group_0, 0x80008000, TX_AND, TX_NULL, TX_NO_WAIT);
413
414 /* Check status. */
415 if (status != TX_PTR_ERROR)
416 {
417
418 /* Event flag error. */
419 printf("ERROR #15\n");
420 test_control_return(1);
421 }
422
423 /* Get events with a bad option. */
424 status = tx_event_flags_get(&group_0, 0x80008000, 14, &actual_events, TX_NO_WAIT);
425
426 /* Check status. */
427 if (status != TX_OPTION_ERROR)
428 {
429
430 /* Event flag error. */
431 printf("ERROR #16\n");
432 test_control_return(1);
433 }
434
435 /* Set evetns with a NULL group pointer. */
436 status = tx_event_flags_set(TX_NULL, 0x80008000, TX_OR);
437
438 /* Check status. */
439 if (status != TX_GROUP_ERROR)
440 {
441
442 /* Event flag error. */
443 printf("ERROR #17\n");
444 test_control_return(1);
445 }
446
447 /* Set events with a non-created group pointer. */
448 group_2.tx_event_flags_group_id = 0;
449 status = tx_event_flags_set(&group_2, 0x80008000, TX_OR);
450
451 /* Check status. */
452 if (status != TX_GROUP_ERROR)
453 {
454
455 /* Event flag error. */
456 printf("ERROR #18\n");
457 test_control_return(1);
458 }
459
460 /* Set events with a bad option. */
461 status = tx_event_flags_set(&group_0, 0x80008000, 14);
462
463 /* Check status. */
464 if (status != TX_OPTION_ERROR)
465 {
466
467 /* Event flag error. */
468 printf("ERROR #19\n");
469 test_control_return(1);
470 }
471
472 /* Attempt to register the event set notify function with a NULL group pointer. */
473 status = tx_event_flags_set_notify(TX_NULL, event_set_notify);
474
475 /* Check status. */
476 if (status != TX_GROUP_ERROR)
477 {
478
479 /* Event flag error. */
480 printf("ERROR #20\n");
481 test_control_return(1);
482 }
483
484 /* Attempt to register the event set notify function with a non-created group pointer. */
485 group_2.tx_event_flags_group_id = 0;
486 status = tx_event_flags_set_notify(&group_2, event_set_notify);
487
488 /* Check status. */
489 if (status != TX_GROUP_ERROR)
490 {
491
492 /* Event flag error. */
493 printf("ERROR #21\n");
494 test_control_return(1);
495 }
496 #endif
497
498 /* Attempt to get events from an empty event flag group. AND option. */
499 status = tx_event_flags_get(&group_0, 0x80008000, TX_AND, &actual_events, TX_NO_WAIT);
500
501 /* Check status. */
502 if (status != TX_NO_EVENTS)
503 {
504
505 /* Event flag error. */
506 printf("ERROR #22\n");
507 test_control_return(1);
508 }
509
510 /* Attempt to get events from an empty event flag group. OR option. */
511 status = tx_event_flags_get(&group_0, 0x80008000, TX_OR, &actual_events, TX_NO_WAIT);
512
513 /* Check status. */
514 if (status != TX_NO_EVENTS)
515 {
516
517 /* Event flag error. */
518 printf("ERROR #23\n");
519 test_control_return(1);
520 }
521
522 /* Attempt to get events from an empty event flag group. AND CLEAR option. */
523 status = tx_event_flags_get(&group_0, 0x80008000, TX_AND_CLEAR, &actual_events, TX_NO_WAIT);
524
525 /* Check status. */
526 if (status != TX_NO_EVENTS)
527 {
528
529 /* Event flag error. */
530 printf("ERROR #24\n");
531 test_control_return(1);
532 }
533
534 /* Attempt to get events from an empty event flag group. OR CLEAR option. */
535 status = tx_event_flags_get(&group_0, 0x80008000, TX_OR_CLEAR, &actual_events, TX_NO_WAIT);
536
537 /* Check status. */
538 if (status != TX_NO_EVENTS)
539 {
540
541 /* Event flag error. */
542 printf("ERROR #25\n");
543 test_control_return(1);
544 }
545
546 /* Set the necessary events. */
547 status = tx_event_flags_set(&group_0, 0x80008000, TX_OR);
548
549 /* Check status. */
550 if (status != TX_SUCCESS)
551 {
552
553 /* Event flag error. */
554 printf("ERROR #26\n");
555 test_control_return(1);
556 }
557
558 /* Just for fun, clear bit 15. */
559 status = tx_event_flags_set(&group_0, 0x80000000, TX_AND);
560
561 /* Check status. */
562 if (status != TX_SUCCESS)
563 {
564
565 /* Event flag error. */
566 printf("ERROR #27\n");
567 test_control_return(1);
568 }
569
570 /* Set bit 15 again. */
571 status = tx_event_flags_set(&group_0, 0x00008000, TX_OR);
572
573 /* Check status. */
574 if (status != TX_SUCCESS)
575 {
576
577 /* Event flag error. */
578 printf("ERROR #28\n");
579 test_control_return(1);
580 }
581
582 /* Now attemp to retrieve events... */
583
584 /* Attempt to get events from event flag group. AND option. */
585 status = tx_event_flags_get(&group_0, 0x80008000, TX_AND, &actual_events, TX_NO_WAIT);
586
587 /* Check status. */
588 if ((status != TX_SUCCESS) || (actual_events != 0x80008000UL))
589 {
590
591 /* Event flag error. */
592 printf("ERROR #29\n");
593 test_control_return(1);
594 }
595
596 /* Attempt to get events from event flag group. OR option. */
597 status = tx_event_flags_get(&group_0, 0x80008000, TX_OR, &actual_events, TX_NO_WAIT);
598
599 /* Check status. */
600 if ((status != TX_SUCCESS) || (actual_events != 0x80008000UL))
601 {
602
603 /* Event flag error. */
604 printf("ERROR #30\n");
605 test_control_return(1);
606 }
607
608 /* Attempt to get events from event flag group. AND CLEAR option. */
609 status = tx_event_flags_get(&group_0, 0x80008000, TX_AND_CLEAR, &actual_events, TX_NO_WAIT);
610
611 /* Check status. */
612 if ((status != TX_SUCCESS) || (actual_events != 0x80008000UL))
613 {
614
615 /* Event flag error. */
616 printf("ERROR #31\n");
617 test_control_return(1);
618 }
619
620 /* Attempt to get events from an empty event flag group. OR CLEAR option. */
621 status = tx_event_flags_get(&group_0, 0x80008000, TX_OR_CLEAR, &actual_events, TX_NO_WAIT);
622
623 /* Check status. */
624 if (status != TX_NO_EVENTS)
625 {
626
627 /* Event flag error. */
628 printf("ERROR #32\n");
629 test_control_return(1);
630 }
631
632 /* Put event flags back in the group. */
633
634 /* Set the necessary events. */
635 status = tx_event_flags_set(&group_0, 0x80008000, TX_OR);
636
637 /* Check status. */
638 if (status != TX_SUCCESS)
639 {
640
641 /* Event flag error. */
642 printf("ERROR #33\n");
643 test_control_return(1);
644 }
645
646 /* Attempt to get events from event flag group. OR CLEAR option. */
647 status = tx_event_flags_get(&group_0, 0x00008000, TX_OR_CLEAR, &actual_events, TX_NO_WAIT);
648
649 /* Check status. */
650 if ((status != TX_SUCCESS) || (actual_events != 0x80008000UL))
651 {
652
653 /* Event flag error. */
654 printf("ERROR #34\n");
655 test_control_return(1);
656 }
657
658 /* Attempt to get events from event flag group. OR CLEAR option. */
659 status = tx_event_flags_get(&group_0, 0x80008000, TX_OR_CLEAR, &actual_events, TX_NO_WAIT);
660
661 /* Check status. */
662 if ((status != TX_SUCCESS) || (actual_events != 0x80000000UL))
663 {
664
665 /* Event flag error. */
666 printf("ERROR #35\n");
667 test_control_return(1);
668 }
669
670
671 #ifndef TX_DISABLE_ERROR_CHECKING
672
673 /* Create a timer for the test. */
674 tx_timer_create(&timer_0, "timer 0", timer_entry, 0, 1, 1, TX_AUTO_ACTIVATE);
675
676 /* Setup the ISR. */
677 test_isr_dispatch = test_isr;
678
679 /* Sleep for a bit... */
680 tx_thread_sleep(3);
681
682 /* Now resume thread 1. */
683 tx_thread_resume(&thread_1);
684
685 /* Sleep for a bit... */
686 tx_thread_sleep(3);
687
688 /* Clear the ISR. */
689 test_isr_dispatch = TX_NULL;
690
691 /* Test for error. */
692 if ((error) || (timer_executed != 1) || (isr_executed != 1))
693 {
694
695 /* Block memory error. */
696 printf("ERROR #36\n");
697 test_control_return(1);
698 }
699
700 #endif
701
702 /* Delete both event flag groups. */
703 status = tx_event_flags_delete(&group_0);
704
705 /* Check the status. */
706 if (status != TX_SUCCESS)
707 {
708
709 /* Event flag error. */
710 printf("ERROR #37\n");
711 test_control_return(1);
712 }
713
714 status = tx_event_flags_delete(&group_1);
715
716 /* Check the status. */
717 if (status != TX_SUCCESS)
718 {
719
720 /* Event flag error. */
721 printf("ERROR #38\n");
722 test_control_return(1);
723 }
724 else
725 {
726
727 /* Successful test. */
728 printf("SUCCESS!\n");
729 test_control_return(0);
730 }
731 }
732
733
thread_1_entry(ULONG thread_input)734 static void thread_1_entry(ULONG thread_input)
735 {
736
737 while(1)
738 {
739
740 tx_thread_relinquish();
741 }
742 }
743
744