1 /* This test is designed to test immediate response queue services including create
2 and delete. This test is for queue sizes of 1 ULONG. Two queues are used one with
3 a capacity of 1 message and another with a capacity of 3 messages. */
4
5 #include <stdio.h>
6 #include "tx_api.h"
7
8
9 /* Define the ISR dispatch. */
10
11 extern VOID (*test_isr_dispatch)(void);
12
13
14 static unsigned long thread_0_counter = 0;
15 static TX_THREAD thread_0;
16 static TX_THREAD thread_1;
17
18
19 static TX_TIMER timer_0;
20
21
22 static unsigned long error = 0;
23 static unsigned long timer_executed = 0;
24 static unsigned long isr_executed = 0;
25
26 static TX_QUEUE queue_0;
27 static TX_QUEUE queue_1;
28 static TX_QUEUE queue_2;
29 static TX_QUEUE queue_3;
30
31
32 /* Define the external reference to the status for queue create from initialization. */
33
34 extern UINT test_queue_from_init;
35
36
37 /* Define thread prototypes. */
38
39 static void thread_0_entry(ULONG thread_input);
40 static void thread_1_entry(ULONG thread_input);
41
42
43 UINT _txe_queue_create(TX_QUEUE *queue_ptr, CHAR *name_ptr, UINT message_size,
44 VOID *queue_start, ULONG queue_size, UINT queue_control_block_size);
45
46
47 /* Prototype for test control return. */
48
49 void test_control_return(UINT status);
50
51
52 /* Define the timer for this test. */
53
timer_entry(ULONG i)54 static void timer_entry(ULONG i)
55 {
56
57 #ifndef TX_DISABLE_ERROR_CHECKING
58
59 UINT status;
60 CHAR *pointer;
61 ULONG source = 1234;
62 ULONG destination;
63
64
65 /* Determine if calling queue create from initialization was successful. */
66 if (test_queue_from_init != TX_SUCCESS)
67 {
68
69 /* Error! */
70 error++;
71 }
72
73 /* Attempt to create a queue from a timer. */
74 pointer = (CHAR *) 0x3000;
75 status = tx_queue_create(&queue_2, "queue 2", TX_1_ULONG, pointer, 3*sizeof(ULONG));
76
77 /* Check for status. */
78 if (status != TX_CALLER_ERROR)
79 {
80
81 /* Error! */
82 error++;
83 }
84
85 /* Attempt to delete a queue from a timer. */
86 status = tx_queue_delete(&queue_0);
87
88 /* Check for status. */
89 if (status != TX_CALLER_ERROR)
90 {
91
92 /* Error! */
93 error++;
94 }
95
96 /* Attempt to send something with suspension from a timer. */
97 status = tx_queue_front_send(&queue_0, &source, 100);
98
99 /* Check for status. */
100 if (status != TX_WAIT_ERROR)
101 {
102
103 /* Error! */
104 error++;
105 }
106
107 /* Attempt to send something with suspension from a timer. */
108 status = tx_queue_send(&queue_0, &source, 100);
109
110 /* Check for status. */
111 if (status != TX_WAIT_ERROR)
112 {
113
114 /* Error! */
115 error++;
116 }
117
118 /* Attempt to receive something with suspension from a timer. */
119 status = tx_queue_receive(&queue_0, &destination, 100);
120
121 /* Check for status. */
122 if (status != TX_WAIT_ERROR)
123 {
124
125 /* Error! */
126 error++;
127 }
128
129
130 timer_executed = 1;
131 #endif
132 }
133
134 /* Define the ISR dispatch routine. */
135
test_isr(void)136 static void test_isr(void)
137 {
138
139 #ifndef TX_DISABLE_ERROR_CHECKING
140
141 CHAR *pointer;
142 UINT status;
143 ULONG source = 1234;
144 ULONG destination;
145
146
147 /* Attempt to create a queue from an ISR. */
148 pointer = (CHAR *) 0x3000;
149 status = tx_queue_create(&queue_2, "queue 2", TX_1_ULONG, pointer, 3*sizeof(ULONG));
150
151 /* Check for status. */
152 if (status != TX_CALLER_ERROR)
153 {
154
155 /* Error! */
156 error++;
157 }
158
159 /* Attempt to delete a queue from an ISR. */
160 status = tx_queue_delete(&queue_0);
161
162 /* Check for status. */
163 if (status != TX_CALLER_ERROR)
164 {
165
166 /* Error! */
167 error++;
168 }
169
170 /* Attempt to send something with suspension from an ISR. */
171 status = tx_queue_front_send(&queue_0, &source, 100);
172
173 /* Check for status. */
174 if (status != TX_WAIT_ERROR)
175 {
176
177 /* Error! */
178 error++;
179 }
180
181 /* Attempt to send something with suspension from an ISR. */
182 status = tx_queue_send(&queue_0, &source, 100);
183
184 /* Check for status. */
185 if (status != TX_WAIT_ERROR)
186 {
187
188 /* Error! */
189 error++;
190 }
191
192 /* Attempt to receive something with suspension from an ISR. */
193 status = tx_queue_receive(&queue_0, &destination, 100);
194
195 /* Check for status. */
196 if (status != TX_WAIT_ERROR)
197 {
198
199 /* Error! */
200 error++;
201 }
202
203 isr_executed = 1;
204 #endif
205 }
206
207
208
209 /* Define what the initial system looks like. */
210
211 #ifdef CTEST
test_application_define(void * first_unused_memory)212 void test_application_define(void *first_unused_memory)
213 #else
214 void threadx_queue_basic_application_define(void *first_unused_memory)
215 #endif
216 {
217
218 UINT status;
219 CHAR *pointer;
220
221
222 /* Put first available memory address into a character pointer. */
223 pointer = (CHAR *) first_unused_memory;
224
225 /* Put system definition stuff in here, e.g. thread creates and other assorted
226 create information. */
227 status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
228 pointer, TEST_STACK_SIZE_PRINTF,
229 16, 16, 100, TX_AUTO_START);
230 pointer = pointer + TEST_STACK_SIZE_PRINTF;
231
232 status += tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
233 pointer, TEST_STACK_SIZE_PRINTF,
234 18, 18, 100, TX_DONT_START);
235 pointer = pointer + TEST_STACK_SIZE_PRINTF;
236
237
238 /* Check for status. */
239 if (status != TX_SUCCESS)
240 {
241
242 printf("Running Queue One Word Queue Test................................... ERROR #1\n");
243 test_control_return(1);
244 }
245
246 /* Create the queues. */
247 status = tx_queue_create(&queue_0, "queue 0", TX_1_ULONG, pointer, sizeof(ULONG));
248 pointer = pointer + sizeof(ULONG);
249
250 /* Check for status. */
251 if (status != TX_SUCCESS)
252 {
253
254 printf("Running Queue One Word Queue Test................................... ERROR #2\n");
255 test_control_return(1);
256 }
257
258 status = tx_queue_create(&queue_1, "queue 1", TX_1_ULONG, pointer, 3*sizeof(ULONG));
259 pointer = pointer + 3*sizeof(ULONG);
260
261 /* Check for status. */
262 if (status != TX_SUCCESS)
263 {
264
265 printf("Running Queue One Word Queue Test................................... ERROR #3\n");
266 test_control_return(1);
267 }
268 }
269
270
271
272 /* Define the test threads. */
273
thread_0_entry(ULONG thread_input)274 static void thread_0_entry(ULONG thread_input)
275 {
276
277 UINT status;
278 ULONG source_message = 0x12345678UL;
279 ULONG dest_message;
280 ULONG expected_message;
281 #ifndef TX_DISABLE_ERROR_CHECKING
282 CHAR *pointer;
283 #endif
284
285 /* Inform user. */
286 printf("Running Queue One Word Queue Test................................... ");
287
288 /* Increment thread 0 counter. */
289 thread_0_counter++;
290
291 #ifndef TX_DISABLE_ERROR_CHECKING
292
293 /* Attempt to create with NULL queue. */
294 pointer = (CHAR *) 0x3000;
295 status = tx_queue_create(TX_NULL, "queue 1", TX_1_ULONG, pointer, 3*sizeof(ULONG));
296
297 /* Check for status. */
298 if (status != TX_QUEUE_ERROR)
299 {
300
301 /* Queue error. */
302 printf("ERROR #4\n");
303 test_control_return(1);
304 }
305
306 /* Attempt to create with bad sized queue control block. */
307 status = _txe_queue_create(&queue_3, "queue 3", TX_1_ULONG, pointer, 3*sizeof(ULONG), (sizeof(TX_QUEUE)+1));
308
309 /* Check for status. */
310 if (status != TX_QUEUE_ERROR)
311 {
312
313 /* Queue error. */
314 printf("ERROR #5\n");
315 test_control_return(1);
316 }
317
318 /* Attempt to create with bad sized message. */
319 status = tx_queue_create(&queue_3, "queue 3", 0, pointer, 3*sizeof(ULONG));
320
321 /* Check for status. */
322 if (status != TX_SIZE_ERROR)
323 {
324
325 /* Queue error. */
326 printf("ERROR #6\n");
327 test_control_return(1);
328 }
329
330 /* Attempt to create a queue that has already been created. */
331 pointer = (CHAR *) 0x3000;
332 status = tx_queue_create(&queue_0, "queue 1", TX_1_ULONG, pointer, 3*sizeof(ULONG));
333
334 /* Check for status. */
335 if (status != TX_QUEUE_ERROR)
336 {
337
338 /* Queue error. */
339 printf("ERROR #7\n");
340 test_control_return(1);
341 }
342
343 /* Attempt to create a queue with an invalid message size. */
344 pointer = (CHAR *) 0x3000;
345 status = tx_queue_create(&queue_2, "queue 2", 47, pointer, 3*sizeof(ULONG));
346
347 /* Check for status. */
348 if (status != TX_SIZE_ERROR)
349 {
350
351 /* Queue error. */
352 printf("ERROR #8\n");
353 test_control_return(1);
354 }
355
356 /* Attempt to create a queue with a NULL queue area. */
357 status = tx_queue_create(&queue_2, "queue 2", TX_1_ULONG, TX_NULL, 3*sizeof(ULONG));
358
359 /* Check for status. */
360 if (status != TX_PTR_ERROR)
361 {
362
363 /* Queue error. */
364 printf("ERROR #9\n");
365 test_control_return(1);
366 }
367
368 /* Attempt to create a queue with a too small queue area. */
369 pointer = (CHAR *) 0x3000;
370 status = tx_queue_create(&queue_2, "queue 2", TX_1_ULONG, pointer, 1);
371
372 /* Check for status. */
373 if (status != TX_SIZE_ERROR)
374 {
375
376 /* Queue error. */
377 printf("ERROR #10\n");
378 test_control_return(1);
379 }
380
381 /* Attempt to delete a NULL pointer. */
382 status = tx_queue_delete(TX_NULL);
383
384 /* Check for status. */
385 if (status != TX_QUEUE_ERROR)
386 {
387
388 /* Queue error. */
389 printf("ERROR #11\n");
390 test_control_return(1);
391 }
392
393 /* Attempt to delete a non-created queue. */
394 queue_2.tx_queue_id = 0;
395 status = tx_queue_delete(&queue_2);
396
397 /* Check for status. */
398 if (status != TX_QUEUE_ERROR)
399 {
400
401 /* Queue error. */
402 printf("ERROR #12\n");
403 test_control_return(1);
404 }
405
406 /* Attempt to flush a NULL pointer. */
407 status = tx_queue_flush(TX_NULL);
408
409 /* Check for status. */
410 if (status != TX_QUEUE_ERROR)
411 {
412
413 /* Queue error. */
414 printf("ERROR #13\n");
415 test_control_return(1);
416 }
417
418 /* Attempt to flush a non-created queue. */
419 queue_2.tx_queue_id = 0;
420 status = tx_queue_flush(&queue_2);
421
422 /* Check for status. */
423 if (status != TX_QUEUE_ERROR)
424 {
425
426 /* Queue error. */
427 printf("ERROR #14\n");
428 test_control_return(1);
429 }
430
431 /* Attempt to send something to the front of a non-queue. */
432 status = tx_queue_front_send(TX_NULL, &source_message, TX_NO_WAIT);
433
434 /* Check for status. */
435 if (status != TX_QUEUE_ERROR)
436 {
437
438 /* Queue error. */
439 printf("ERROR #15\n");
440 test_control_return(1);
441 }
442
443 /* Attempt to send something to the front of a non-created queue. */
444 queue_2.tx_queue_id = 0;
445 status = tx_queue_front_send(&queue_2, &source_message, TX_NO_WAIT);
446
447 /* Check for status. */
448 if (status != TX_QUEUE_ERROR)
449 {
450
451 /* Queue error. */
452 printf("ERROR #16\n");
453 test_control_return(1);
454 }
455
456 /* Attempt to send something with a NULL source pointer. */
457 status = tx_queue_front_send(&queue_0, TX_NULL, TX_NO_WAIT);
458
459 /* Check for status. */
460 if (status != TX_PTR_ERROR)
461 {
462
463 /* Queue error. */
464 printf("ERROR #17\n");
465 test_control_return(1);
466 }
467
468 /* Attempt to send something to a non-queue. */
469 status = tx_queue_send(TX_NULL, &source_message, TX_NO_WAIT);
470
471 /* Check for status. */
472 if (status != TX_QUEUE_ERROR)
473 {
474
475 /* Queue error. */
476 printf("ERROR #18\n");
477 test_control_return(1);
478 }
479
480 /* Attempt to send something to a non-created queue. */
481 queue_2.tx_queue_id = 0;
482 status = tx_queue_send(&queue_2, &source_message, TX_NO_WAIT);
483
484 /* Check for status. */
485 if (status != TX_QUEUE_ERROR)
486 {
487
488 /* Queue error. */
489 printf("ERROR #19\n");
490 test_control_return(1);
491 }
492
493 /* Attempt to send something with a NULL source pointer. */
494 status = tx_queue_send(&queue_0, TX_NULL, TX_NO_WAIT);
495
496 /* Check for status. */
497 if (status != TX_PTR_ERROR)
498 {
499
500 /* Queue error. */
501 printf("ERROR #20\n");
502 test_control_return(1);
503 }
504
505 /* Attempt to receive something from a non-queue. */
506 status = tx_queue_receive(TX_NULL, &dest_message, TX_NO_WAIT);
507
508 /* Check for status. */
509 if (status != TX_QUEUE_ERROR)
510 {
511
512 /* Queue error. */
513 printf("ERROR #21\n");
514 test_control_return(1);
515 }
516
517 /* Attempt to receive something from a non-created queue. */
518 queue_2.tx_queue_id = 0;
519 status = tx_queue_receive(&queue_2, &dest_message, TX_NO_WAIT);
520
521 /* Check for status. */
522 if (status != TX_QUEUE_ERROR)
523 {
524
525 /* Queue error. */
526 printf("ERROR #22\n");
527 test_control_return(1);
528 }
529
530 /* Attempt to receive something to a NULL destination. */
531 status = tx_queue_receive(&queue_0, TX_NULL, TX_NO_WAIT);
532
533 /* Check for status. */
534 if (status != TX_PTR_ERROR)
535 {
536
537 /* Queue error. */
538 printf("ERROR #23\n");
539 test_control_return(1);
540 }
541 #endif
542
543 /* Place something on queue 0. */
544 status = tx_queue_send(&queue_0, &source_message, TX_NO_WAIT);
545
546 if (status != TX_SUCCESS)
547 {
548
549 /* Queue error. */
550 printf("ERROR #24\n");
551 test_control_return(1);
552 }
553
554 /* Attempt to place something on a full queue. */
555 status = tx_queue_send(&queue_0, &source_message, TX_NO_WAIT);
556
557 /* Should be an error. */
558 if (status != TX_QUEUE_FULL)
559 {
560
561 /* Queue error. */
562 printf("ERROR #25\n");
563 test_control_return(1);
564 }
565
566 /* Attempt to receive something from queue 0. */
567 status = tx_queue_receive(&queue_0, &dest_message, TX_NO_WAIT);
568
569 /* Should be successful and dest_message should equal source. */
570 if ((status != TX_SUCCESS) || (source_message != dest_message))
571 {
572
573 /* Queue error. */
574 printf("ERROR #26\n");
575 test_control_return(1);
576 }
577
578 /* Attempt to receive something from an empty queue. */
579 status = tx_queue_receive(&queue_0, &dest_message, TX_NO_WAIT);
580
581 /* Should be an error. */
582 if (status != TX_QUEUE_EMPTY)
583 {
584
585 /* Queue error. */
586 printf("ERROR #27\n");
587 test_control_return(1);
588 }
589
590 /* Make sure we can do the same thing again! */
591 source_message++;
592
593 /* Place something on queue 0. */
594 status = tx_queue_send(&queue_0, &source_message, TX_NO_WAIT);
595
596 if (status != TX_SUCCESS)
597 {
598
599 /* Queue error. */
600 printf("ERROR #28\n");
601 test_control_return(1);
602 }
603
604 /* Attempt to place something on a full queue. */
605 status = tx_queue_send(&queue_0, &source_message, TX_NO_WAIT);
606
607 /* Should be an error. */
608 if (status != TX_QUEUE_FULL)
609 {
610
611 /* Queue error. */
612 printf("ERROR #29\n");
613 test_control_return(1);
614 }
615
616 /* Attempt to receive something from queue 0. */
617 status = tx_queue_receive(&queue_0, &dest_message, TX_NO_WAIT);
618
619 /* Should be successful and dest_message should equal source. */
620 if ((status != TX_SUCCESS) || (source_message != dest_message))
621 {
622
623 /* Queue error. */
624 printf("ERROR #30\n");
625 test_control_return(1);
626 }
627
628 /* Attempt to receive something from an empty queue. */
629 status = tx_queue_receive(&queue_0, &dest_message, TX_NO_WAIT);
630
631 /* Should be an error. */
632 if (status != TX_QUEUE_EMPTY)
633 {
634
635 /* Queue error. */
636 printf("ERROR #31\n");
637 test_control_return(1);
638 }
639
640 /* Now we need to do the same thing with the queue with three entries. */
641
642 source_message++;
643 expected_message = source_message;
644
645 /* Place something on queue 1. */
646 status = tx_queue_send(&queue_1, &source_message, TX_NO_WAIT);
647 source_message++;
648 status += tx_queue_send(&queue_1, &source_message, TX_NO_WAIT);
649 source_message++;
650 status += tx_queue_send(&queue_1, &source_message, TX_NO_WAIT);
651 source_message++;
652
653 if (status != TX_SUCCESS)
654 {
655
656 /* Queue error. */
657 printf("ERROR #32\n");
658 test_control_return(1);
659 }
660
661 /* Attempt to place something on a full queue. */
662 status = tx_queue_send(&queue_1, &source_message, TX_NO_WAIT);
663
664 /* Should be an error. */
665 if (status != TX_QUEUE_FULL)
666 {
667
668 /* Queue error. */
669 printf("ERROR #33\n");
670 test_control_return(1);
671 }
672
673 /* Attempt to receive something from queue 1. */
674 status = tx_queue_receive(&queue_1, &dest_message, TX_NO_WAIT);
675
676 /* Should be successful and dest_message should equal source. */
677 if ((status != TX_SUCCESS) || (expected_message++ != dest_message))
678 {
679
680 /* Queue error. */
681 printf("ERROR #34\n");
682 test_control_return(1);
683 }
684
685 /* Attempt to receive something from queue 1. */
686 status = tx_queue_receive(&queue_1, &dest_message, TX_NO_WAIT);
687
688 /* Should be successful and dest_message should equal source. */
689 if ((status != TX_SUCCESS) || (expected_message++ != dest_message))
690 {
691
692 /* Queue error. */
693 printf("ERROR #35\n");
694 test_control_return(1);
695 }
696
697 /* Attempt to receive something from queue 1. */
698 status = tx_queue_receive(&queue_1, &dest_message, TX_NO_WAIT);
699
700 /* Should be successful and dest_message should equal source. */
701 if ((status != TX_SUCCESS) || (expected_message++ != dest_message))
702 {
703
704 /* Queue error. */
705 printf("ERROR #36\n");
706 test_control_return(1);
707 }
708
709 /* Attempt to receive something from an empty queue. */
710 status = tx_queue_receive(&queue_1, &dest_message, TX_NO_WAIT);
711
712 /* Should be an error. */
713 if (status != TX_QUEUE_EMPTY)
714 {
715
716 /* Queue error. */
717 printf("ERROR #37\n");
718 test_control_return(1);
719 }
720
721 /* Make sure we can do the same thing again! */
722
723 /* Place something on queue 1. */
724 status = tx_queue_send(&queue_1, &source_message, TX_NO_WAIT);
725 source_message++;
726 status += tx_queue_send(&queue_1, &source_message, TX_NO_WAIT);
727 source_message++;
728 status += tx_queue_send(&queue_1, &source_message, TX_NO_WAIT);
729 source_message++;
730
731 if (status != TX_SUCCESS)
732 {
733
734 /* Queue error. */
735 printf("ERROR #38\n");
736 test_control_return(1);
737 }
738
739 /* Attempt to place something on a full queue. */
740 status = tx_queue_send(&queue_1, &source_message, TX_NO_WAIT);
741
742 /* Should be an error. */
743 if (status != TX_QUEUE_FULL)
744 {
745
746 /* Queue error. */
747 printf("ERROR #39\n");
748 test_control_return(1);
749 }
750
751 /* Attempt to receive something from queue 1. */
752 status = tx_queue_receive(&queue_1, &dest_message, TX_NO_WAIT);
753
754 /* Should be successful and dest_message should equal source. */
755 if ((status != TX_SUCCESS) || (expected_message++ != dest_message))
756 {
757
758 /* Queue error. */
759 printf("ERROR #40\n");
760 test_control_return(1);
761 }
762
763 /* Attempt to receive something from queue 1. */
764 status = tx_queue_receive(&queue_1, &dest_message, TX_NO_WAIT);
765
766 /* Should be successful and dest_message should equal source. */
767 if ((status != TX_SUCCESS) || (expected_message++ != dest_message))
768 {
769
770 /* Queue error. */
771 printf("ERROR #41\n");
772 test_control_return(1);
773 }
774
775 /* Attempt to receive something from queue 1. */
776 status = tx_queue_receive(&queue_1, &dest_message, TX_NO_WAIT);
777
778 /* Should be successful and dest_message should equal source. */
779 if ((status != TX_SUCCESS) || (expected_message++ != dest_message))
780 {
781
782 /* Queue error. */
783 printf("ERROR #42\n");
784 test_control_return(1);
785 }
786
787 /* Attempt to receive something from an empty queue. */
788 status = tx_queue_receive(&queue_1, &dest_message, TX_NO_WAIT);
789
790 /* Should be an error. */
791 if (status != TX_QUEUE_EMPTY)
792 {
793
794 /* Queue error. */
795 printf("ERROR #43\n");
796 test_control_return(1);
797 }
798
799
800 #ifndef TX_DISABLE_ERROR_CHECKING
801
802 /* Create a timer for the test. */
803 tx_timer_create(&timer_0, "timer 0", timer_entry, 0, 1, 1, TX_AUTO_ACTIVATE);
804
805 /* Setup the ISR. */
806 test_isr_dispatch = test_isr;
807
808 /* Sleep for a bit... */
809 tx_thread_sleep(3);
810
811 /* Resume thread 1 so that we can take an interrupt on top of it. */
812 tx_thread_resume(&thread_1);
813
814 /* Sleep for a bit... */
815 tx_thread_sleep(3);
816
817 /* Clear the ISR. */
818 test_isr_dispatch = TX_NULL;
819
820 /* Test for error. */
821 if ((error) || (timer_executed != 1) || (isr_executed != 1))
822 {
823
824 /* Queue error. */
825 printf("ERROR #44\n");
826 test_control_return(1);
827 }
828
829 #endif
830
831 /* Delete the queues. */
832 status = tx_queue_delete(&queue_1);
833 if (status != TX_SUCCESS)
834 {
835
836 /* Queue error. */
837 printf("ERROR #45\n");
838 test_control_return(1);
839 }
840
841 status = tx_queue_delete(&queue_0);
842 if (status != TX_SUCCESS)
843 {
844
845 /* Queue error. */
846 printf("ERROR #46\n");
847 test_control_return(1);
848 }
849 else
850 {
851
852 /* Successful test. */
853 printf("SUCCESS!\n");
854 test_control_return(0);
855 }
856 }
857
thread_1_entry(ULONG thread_input)858 static void thread_1_entry(ULONG thread_input)
859 {
860
861 while(1)
862 {
863
864 tx_thread_relinquish();
865 }
866 }
867
868