1 /* This test is designed to test the queue information services. */
2
3 #include <stdio.h>
4 #include "tx_api.h"
5 #include "tx_queue.h"
6
7
8 static unsigned long thread_0_counter = 0;
9 static TX_THREAD thread_0;
10
11 static TX_QUEUE queue_0;
12 static TX_QUEUE queue_1;
13 static TX_QUEUE queue_2;
14
15
16 /* Define thread prototypes. */
17
18 static void thread_0_entry(ULONG thread_input);
19
20
21 UINT _tx_queue_performance_info_get(TX_QUEUE *queue_ptr, ULONG *messages_sent, ULONG *messages_received,
22 ULONG *empty_suspensions, ULONG *full_suspensions, ULONG *full_errors, ULONG *timeouts);
23
24 /* Prototype for test control return. */
25 void test_control_return(UINT status);
26
27
28 /* Define what the initial system looks like. */
29
30 #ifdef CTEST
test_application_define(void * first_unused_memory)31 void test_application_define(void *first_unused_memory)
32 #else
33 void threadx_queue_information_application_define(void *first_unused_memory)
34 #endif
35 {
36
37 UINT status;
38 CHAR *pointer;
39
40
41 /* Put first available memory address into a character pointer. */
42 pointer = (CHAR *) first_unused_memory;
43
44 /* Put system definition stuff in here, e.g. thread creates and other assorted
45 create information. */
46 status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
47 pointer, TEST_STACK_SIZE_PRINTF,
48 16, 16, 100, TX_AUTO_START);
49 pointer = pointer + TEST_STACK_SIZE_PRINTF;
50
51 /* Check for status. */
52 if (status != TX_SUCCESS)
53 {
54
55 printf("Running Queue Information Test...................................... ERROR #1\n");
56 test_control_return(1);
57 }
58
59 /* Create the queues. */
60 status = tx_queue_create(&queue_0, "queue 0", TX_1_ULONG, pointer, sizeof(ULONG));
61 pointer = pointer + sizeof(ULONG);
62
63 /* Check for status. */
64 if (status != TX_SUCCESS)
65 {
66
67 printf("Running Queue Information Test...................................... ERROR #2\n");
68 test_control_return(1);
69 }
70
71 status = tx_queue_create(&queue_1, "queue 1", TX_1_ULONG, pointer, 3*sizeof(ULONG));
72 pointer = pointer + 3*sizeof(ULONG);
73
74 /* Check for status. */
75 if (status != TX_SUCCESS)
76 {
77
78 printf("Running Queue Information Test...................................... ERROR #3\n");
79 test_control_return(1);
80 }
81 }
82
83
84
85 /* Define the test threads. */
86
thread_0_entry(ULONG thread_input)87 static void thread_0_entry(ULONG thread_input)
88 {
89
90 UINT status;
91 ULONG source_message = 0x12345678UL;
92 ULONG dest_message;
93 ULONG expected_message;
94 CHAR *name;
95 ULONG enqueued;
96 ULONG available_storage;
97 TX_THREAD *first_suspended;
98 ULONG suspended_count;
99 TX_QUEUE *next_queue;
100 ULONG messages_sent;
101 ULONG messages_received;
102 ULONG empty_suspensions;
103 ULONG full_suspensions;
104 ULONG full_errors;
105 ULONG timeouts;
106
107
108 /* Inform user. */
109 printf("Running Queue Information Test...................................... ");
110
111 /* Increment thread 0 counter. */
112 thread_0_counter++;
113
114 #ifndef TX_DISABLE_ERROR_CHECKING
115
116 /* Attempt to get info from a non-queue. */
117 status = tx_queue_info_get(TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL);
118
119 if (status != TX_QUEUE_ERROR)
120 {
121
122 /* Queue error. */
123 printf("ERROR #\n");
124 test_control_return(1);
125 }
126
127 /* Attempt to get info from a non-created queue. */
128 queue_2.tx_queue_id = 0;
129 status = tx_queue_info_get(&queue_2, TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL);
130
131 if (status != TX_QUEUE_ERROR)
132 {
133
134 /* Queue error. */
135 printf("ERROR #4\n");
136 test_control_return(1);
137 }
138 #endif
139
140 /* Place something on queue 0. */
141 status = tx_queue_send(&queue_0, &source_message, TX_NO_WAIT);
142
143 if (status != TX_SUCCESS)
144 {
145
146 /* Queue error. */
147 printf("ERROR #5\n");
148 test_control_return(1);
149 }
150
151 /* Attempt to place something on a full queue. */
152 status = tx_queue_send(&queue_0, &source_message, TX_NO_WAIT);
153
154 /* Should be an error. */
155 if (status != TX_QUEUE_FULL)
156 {
157
158 /* Queue error. */
159 printf("ERROR #6\n");
160 test_control_return(1);
161 }
162
163 /* Attempt to receive something from queue 0. */
164 status = tx_queue_receive(&queue_0, &dest_message, TX_NO_WAIT);
165
166 /* Should be successful and dest_message should equal source. */
167 if ((status != TX_SUCCESS) || (source_message != dest_message))
168 {
169
170 /* Queue error. */
171 printf("ERROR #7\n");
172 test_control_return(1);
173 }
174
175 /* Attempt to receive something from an empty queue. */
176 status = tx_queue_receive(&queue_0, &dest_message, TX_NO_WAIT);
177
178 /* Should be an error. */
179 if (status != TX_QUEUE_EMPTY)
180 {
181
182 /* Queue error. */
183 printf("ERROR #8\n");
184 test_control_return(1);
185 }
186
187 /* Make sure we can do the same thing again! */
188 source_message++;
189
190 /* Place something on queue 0. */
191 status = tx_queue_send(&queue_0, &source_message, TX_NO_WAIT);
192
193 if (status != TX_SUCCESS)
194 {
195
196 /* Queue error. */
197 printf("ERROR #9\n");
198 test_control_return(1);
199 }
200
201 /* Attempt to place something on a full queue. */
202 status = tx_queue_send(&queue_0, &source_message, TX_NO_WAIT);
203
204 /* Should be an error. */
205 if (status != TX_QUEUE_FULL)
206 {
207
208 /* Queue error. */
209 printf("ERROR #10\n");
210 test_control_return(1);
211 }
212
213 /* Attempt to receive something from queue 0. */
214 status = tx_queue_receive(&queue_0, &dest_message, TX_NO_WAIT);
215
216 /* Should be successful and dest_message should equal source. */
217 if ((status != TX_SUCCESS) || (source_message != dest_message))
218 {
219
220 /* Queue error. */
221 printf("ERROR #11\n");
222 test_control_return(1);
223 }
224
225 /* Attempt to receive something from an empty queue. */
226 status = tx_queue_receive(&queue_0, &dest_message, TX_NO_WAIT);
227
228 /* Should be an error. */
229 if (status != TX_QUEUE_EMPTY)
230 {
231
232 /* Queue error. */
233 printf("ERROR #12\n");
234 test_control_return(1);
235 }
236
237 /* Now we need to do the same thing with the queue with three entries. */
238
239 source_message++;
240 expected_message = source_message;
241
242 /* Place something on queue 1. */
243 status = tx_queue_send(&queue_1, &source_message, TX_NO_WAIT);
244 source_message++;
245 status += tx_queue_send(&queue_1, &source_message, TX_NO_WAIT);
246 source_message++;
247 status += tx_queue_send(&queue_1, &source_message, TX_NO_WAIT);
248 source_message++;
249
250 if (status != TX_SUCCESS)
251 {
252
253 /* Queue error. */
254 printf("ERROR #13\n");
255 test_control_return(1);
256 }
257
258 /* Attempt to place something on a full queue. */
259 status = tx_queue_send(&queue_1, &source_message, TX_NO_WAIT);
260
261 /* Should be an error. */
262 if (status != TX_QUEUE_FULL)
263 {
264
265 /* Queue error. */
266 printf("ERROR #14\n");
267 test_control_return(1);
268 }
269
270 /* Attempt to receive something from queue 1. */
271 status = tx_queue_receive(&queue_1, &dest_message, TX_NO_WAIT);
272
273 /* Should be successful and dest_message should equal source. */
274 if ((status != TX_SUCCESS) || (expected_message++ != dest_message))
275 {
276
277 /* Queue error. */
278 printf("ERROR #15\n");
279 test_control_return(1);
280 }
281
282 /* Attempt to receive something from queue 1. */
283 status = tx_queue_receive(&queue_1, &dest_message, TX_NO_WAIT);
284
285 /* Should be successful and dest_message should equal source. */
286 if ((status != TX_SUCCESS) || (expected_message++ != dest_message))
287 {
288
289 /* Queue error. */
290 printf("ERROR #16\n");
291 test_control_return(1);
292 }
293
294 /* Attempt to receive something from queue 1. */
295 status = tx_queue_receive(&queue_1, &dest_message, TX_NO_WAIT);
296
297 /* Should be successful and dest_message should equal source. */
298 if ((status != TX_SUCCESS) || (expected_message++ != dest_message))
299 {
300
301 /* Queue error. */
302 printf("ERROR #17\n");
303 test_control_return(1);
304 }
305
306 /* Attempt to receive something from an empty queue. */
307 status = tx_queue_receive(&queue_1, &dest_message, TX_NO_WAIT);
308
309 /* Should be an error. */
310 if (status != TX_QUEUE_EMPTY)
311 {
312
313 /* Queue error. */
314 printf("ERROR #18\n");
315 test_control_return(1);
316 }
317
318 /* Make sure we can do the same thing again! */
319
320 /* Place something on queue 1. */
321 status = tx_queue_send(&queue_1, &source_message, TX_NO_WAIT);
322 source_message++;
323 status += tx_queue_send(&queue_1, &source_message, TX_NO_WAIT);
324 source_message++;
325 status += tx_queue_send(&queue_1, &source_message, TX_NO_WAIT);
326 source_message++;
327
328 if (status != TX_SUCCESS)
329 {
330
331 /* Queue error. */
332 printf("ERROR #19\n");
333 test_control_return(1);
334 }
335
336 /* Attempt to place something on a full queue. */
337 status = tx_queue_send(&queue_1, &source_message, TX_NO_WAIT);
338
339 /* Should be an error. */
340 if (status != TX_QUEUE_FULL)
341 {
342
343 /* Queue error. */
344 printf("ERROR #20\n");
345 test_control_return(1);
346 }
347
348 /* Attempt to receive something from queue 1. */
349 status = tx_queue_receive(&queue_1, &dest_message, TX_NO_WAIT);
350
351 /* Should be successful and dest_message should equal source. */
352 if ((status != TX_SUCCESS) || (expected_message++ != dest_message))
353 {
354
355 /* Queue error. */
356 printf("ERROR #21\n");
357 test_control_return(1);
358 }
359
360 /* Attempt to receive something from queue 1. */
361 status = tx_queue_receive(&queue_1, &dest_message, TX_NO_WAIT);
362
363 /* Should be successful and dest_message should equal source. */
364 if ((status != TX_SUCCESS) || (expected_message++ != dest_message))
365 {
366
367 /* Queue error. */
368 printf("ERROR #22\n");
369 test_control_return(1);
370 }
371
372 /* Attempt to receive something from queue 1. */
373 status = tx_queue_receive(&queue_1, &dest_message, TX_NO_WAIT);
374
375 /* Should be successful and dest_message should equal source. */
376 if ((status != TX_SUCCESS) || (expected_message++ != dest_message))
377 {
378
379 /* Queue error. */
380 printf("ERROR #23\n");
381 test_control_return(1);
382 }
383
384 /* Attempt to receive something from an empty queue. */
385 status = tx_queue_receive(&queue_1, &dest_message, TX_NO_WAIT);
386
387 /* Should be an error. */
388 if (status != TX_QUEUE_EMPTY)
389 {
390
391 /* Queue error. */
392 printf("ERROR #24\n");
393 test_control_return(1);
394 }
395
396 /* Get queue information. */
397 status = tx_queue_info_get(&queue_0, TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL);
398 status += tx_queue_info_get(&queue_0, &name, &enqueued, &available_storage, &first_suspended, &suspended_count, &next_queue);
399
400 /* Check for errors. */
401 if ((status != TX_SUCCESS) || (enqueued != queue_0.tx_queue_enqueued) || (available_storage != queue_0.tx_queue_available_storage) ||
402 (first_suspended != queue_0.tx_queue_suspension_list) || (suspended_count != queue_0.tx_queue_suspended_count) ||
403 (next_queue != queue_0.tx_queue_created_next))
404 {
405
406 /* Queue error. */
407 printf("ERROR #25\n");
408 test_control_return(1);
409 }
410
411 #ifdef TX_QUEUE_ENABLE_PERFORMANCE_INFO
412
413 /* Test null pointer for queue performance info get. */
414 status = _tx_queue_performance_info_get(TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL);
415
416 /* Should be an error! */
417 if (status != TX_PTR_ERROR)
418 {
419
420 /* Queue error. */
421 printf("ERROR #26\n");
422 test_control_return(1);
423 }
424
425 /* Get performance information. */
426 status = tx_queue_performance_info_get(&queue_0, TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL);
427 status += tx_queue_performance_info_get(&queue_0, &messages_sent, &messages_received, &empty_suspensions, &full_suspensions, &full_errors, &timeouts);
428
429 /* Check for errors. */
430 if ((status != TX_SUCCESS) || (messages_sent != queue_0.tx_queue_performance_messages_sent_count) || (messages_received != queue_0.tx_queue_performance_messages_received_count) ||
431 (empty_suspensions != queue_0.tx_queue_performance_empty_suspension_count) || (full_suspensions != queue_0.tx_queue_performance_full_suspension_count) ||
432 (full_errors != queue_0.tx_queue_performance_full_error_count) || (timeouts != queue_0.tx_queue_performance_timeout_count))
433 {
434
435 /* Queue error. */
436 printf("ERROR #27\n");
437 test_control_return(1);
438 }
439
440 /* Get system performance information. */
441 status = tx_queue_performance_system_info_get(TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL);
442 status += tx_queue_performance_system_info_get(&messages_sent, &messages_received, &empty_suspensions, &full_suspensions, &full_errors, &timeouts);
443
444 /* Check for errors. */
445 if ((status != TX_SUCCESS) || (messages_sent != _tx_queue_performance_messages_sent_count) || (messages_received != _tx_queue_performance__messages_received_count) ||
446 (empty_suspensions != _tx_queue_performance_empty_suspension_count) || (full_suspensions != _tx_queue_performance_full_suspension_count) ||
447 (full_errors != _tx_queue_performance_full_error_count) || (timeouts != _tx_queue_performance_timeout_count))
448 {
449
450 /* Queue error. */
451 printf("ERROR #28\n");
452 test_control_return(1);
453 }
454
455 #else
456
457 /* Get performance information. */
458 status = tx_queue_performance_info_get(&queue_0, &messages_sent, &messages_received, &empty_suspensions, &full_suspensions, &full_errors, &timeouts);
459
460 /* Should be an error! */
461 if (status != TX_FEATURE_NOT_ENABLED)
462 {
463
464 /* Queue error. */
465 printf("ERROR #29\n");
466 test_control_return(1);
467 }
468
469 /* Get performance information. */
470 status = tx_queue_performance_info_get(TX_NULL, &messages_sent, &messages_received, &empty_suspensions, &full_suspensions, &full_errors, &timeouts);
471
472 /* Should be an error! */
473 if (status != TX_FEATURE_NOT_ENABLED)
474 {
475
476 /* Queue error. */
477 printf("ERROR #30\n");
478 test_control_return(1);
479 }
480
481 /* Get performance information. */
482 status = tx_queue_performance_info_get(TX_NULL, TX_NULL, &messages_received, &empty_suspensions, &full_suspensions, &full_errors, &timeouts);
483
484 /* Should be an error! */
485 if (status != TX_FEATURE_NOT_ENABLED)
486 {
487
488 /* Queue error. */
489 printf("ERROR #31\n");
490 test_control_return(1);
491 }
492
493 /* Get performance information. */
494 status = tx_queue_performance_info_get(TX_NULL, TX_NULL, TX_NULL, &empty_suspensions, &full_suspensions, &full_errors, &timeouts);
495
496 /* Should be an error! */
497 if (status != TX_FEATURE_NOT_ENABLED)
498 {
499
500 /* Queue error. */
501 printf("ERROR #32\n");
502 test_control_return(1);
503 }
504
505 /* Get performance information. */
506 status = tx_queue_performance_info_get(TX_NULL, TX_NULL, TX_NULL, TX_NULL, &full_suspensions, &full_errors, &timeouts);
507
508 /* Should be an error! */
509 if (status != TX_FEATURE_NOT_ENABLED)
510 {
511
512 /* Queue error. */
513 printf("ERROR #33\n");
514 test_control_return(1);
515 }
516
517 /* Get performance information. */
518 status = tx_queue_performance_info_get(TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL, &full_errors, &timeouts);
519
520 /* Should be an error! */
521 if (status != TX_FEATURE_NOT_ENABLED)
522 {
523
524 /* Queue error. */
525 printf("ERROR #34\n");
526 test_control_return(1);
527 }
528
529 /* Get performance information. */
530 status = tx_queue_performance_info_get(TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL, &timeouts);
531
532 /* Should be an error! */
533 if (status != TX_FEATURE_NOT_ENABLED)
534 {
535
536 /* Queue error. */
537 printf("ERROR #35\n");
538 test_control_return(1);
539 }
540
541 /* Get performance information. */
542 status = tx_queue_performance_info_get(TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL);
543
544 /* Should be an error! */
545 if (status != TX_FEATURE_NOT_ENABLED)
546 {
547
548 /* Queue error. */
549 printf("ERROR #36\n");
550 test_control_return(1);
551 }
552
553 /* Get system performance information. */
554 status = tx_queue_performance_system_info_get(&messages_sent, &messages_received, &empty_suspensions, &full_suspensions, &full_errors, &timeouts);
555
556 /* Should be an error! */
557 if (status != TX_FEATURE_NOT_ENABLED)
558 {
559
560 /* Queue error. */
561 printf("ERROR #37\n");
562 test_control_return(1);
563 }
564
565 /* Get system performance information. */
566 status = tx_queue_performance_system_info_get(TX_NULL, &messages_received, &empty_suspensions, &full_suspensions, &full_errors, &timeouts);
567
568 /* Should be an error! */
569 if (status != TX_FEATURE_NOT_ENABLED)
570 {
571
572 /* Queue error. */
573 printf("ERROR #38\n");
574 test_control_return(1);
575 }
576
577 /* Get system performance information. */
578 status = tx_queue_performance_system_info_get(TX_NULL, TX_NULL, &empty_suspensions, &full_suspensions, &full_errors, &timeouts);
579
580 /* Should be an error! */
581 if (status != TX_FEATURE_NOT_ENABLED)
582 {
583
584 /* Queue error. */
585 printf("ERROR #39\n");
586 test_control_return(1);
587 }
588
589 /* Get system performance information. */
590 status = tx_queue_performance_system_info_get(TX_NULL, TX_NULL, TX_NULL, &full_suspensions, &full_errors, &timeouts);
591
592 /* Should be an error! */
593 if (status != TX_FEATURE_NOT_ENABLED)
594 {
595
596 /* Queue error. */
597 printf("ERROR #40\n");
598 test_control_return(1);
599 }
600
601 /* Get system performance information. */
602 status = tx_queue_performance_system_info_get(TX_NULL, TX_NULL, TX_NULL, TX_NULL, &full_errors, &timeouts);
603
604 /* Should be an error! */
605 if (status != TX_FEATURE_NOT_ENABLED)
606 {
607
608 /* Queue error. */
609 printf("ERROR #41\n");
610 test_control_return(1);
611 }
612
613 /* Get system performance information. */
614 status = tx_queue_performance_system_info_get(TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL, &timeouts);
615
616 /* Should be an error! */
617 if (status != TX_FEATURE_NOT_ENABLED)
618 {
619
620 /* Queue error. */
621 printf("ERROR #42\n");
622 test_control_return(1);
623 }
624
625 /* Get system performance information. */
626 status = tx_queue_performance_system_info_get(TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL, TX_NULL);
627
628 /* Should be an error! */
629 if (status != TX_FEATURE_NOT_ENABLED)
630 {
631
632 /* Queue error. */
633 printf("ERROR #43\n");
634 test_control_return(1);
635 }
636
637 #endif
638
639 /* Delete the queues. */
640 status = tx_queue_delete(&queue_1);
641 if (status != TX_SUCCESS)
642 {
643
644 /* Queue error. */
645 printf("ERROR #44\n");
646 test_control_return(1);
647 }
648
649 status = tx_queue_delete(&queue_0);
650 if (status != TX_SUCCESS)
651 {
652
653 /* Queue error. */
654 printf("ERROR #45\n");
655 test_control_return(1);
656 }
657 else
658 {
659
660 /* Successful test. */
661 printf("SUCCESS!\n");
662 test_control_return(0);
663 }
664 }
665