1 /* This test is designed to test immediate response queue services including create
2 and delete. This test is for queue sizes of 2 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 typedef struct QUEUE_MEMORY_TEST_STRUCT
9 {
10 ULONG first;
11 ULONG second;
12 TX_QUEUE queue;
13 ULONG first_middle;
14 ULONG second_middle;
15 ULONG queue_area[2048/sizeof(ULONG)];
16 ULONG next_to_last;
17 ULONG last;
18
19 } QUEUE_MEMORY_TEST;
20
21 static QUEUE_MEMORY_TEST queue_memory;
22
23 static unsigned long thread_0_counter = 0;
24 static TX_THREAD thread_0;
25
26 static TX_QUEUE queue_0;
27 static TX_QUEUE queue_1;
28
29
30 /* Define thread prototypes. */
31
32 static void thread_0_entry(ULONG thread_input);
33
34
35 /* Prototype for test control return. */
36 void test_control_return(UINT status);
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_queue_basic_two_word_application_define(void *first_unused_memory)
45 #endif
46 {
47
48 UINT status;
49 CHAR *pointer;
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 16, 16, 100, TX_AUTO_START);
60 pointer = pointer + TEST_STACK_SIZE_PRINTF;
61
62 /* Check for status. */
63 if (status != TX_SUCCESS)
64 {
65
66 printf("Running Queue Two Word Test......................................... ERROR #1\n");
67 test_control_return(1);
68 }
69
70 /* Create the queues. */
71 status = tx_queue_create(&queue_0, "queue 0", TX_2_ULONG, pointer, 2*sizeof(ULONG));
72 pointer = pointer + (2*sizeof(ULONG));
73
74 /* Check for status. */
75 if (status != TX_SUCCESS)
76 {
77
78 printf("Running Queue Two Word Test......................................... ERROR #2\n");
79 test_control_return(1);
80 }
81
82 status = tx_queue_create(&queue_1, "queue 1", TX_2_ULONG, pointer, 2*3*sizeof(ULONG));
83 pointer = pointer + 2*3*sizeof(ULONG);
84
85 /* Check for status. */
86 if (status != TX_SUCCESS)
87 {
88
89 printf("Running Queue Two Word Test......................................... ERROR #3\n");
90 test_control_return(1);
91 }
92 }
93
94
95
96
97
98 /* Define the test threads. */
99
thread_0_entry(ULONG thread_input)100 static void thread_0_entry(ULONG thread_input)
101 {
102
103 UINT status;
104 ULONG source_message[2];
105 ULONG dest_message[2];
106 ULONG expected_message[2];
107
108
109 /* Inform user. */
110 printf("Running Queue Two Word Test......................................... ");
111
112 /* Perform queue memory test. */
113 queue_memory.first = 0x11223344;
114 queue_memory.second = 0x55667788;
115 queue_memory.first_middle = 0x21314151;
116 queue_memory.second_middle= 0x61718191;
117 queue_memory.next_to_last = 0x99aabbcc;
118 queue_memory.last = 0xddeeff00;
119
120 /* Create the queue. */
121 status = tx_queue_create(&queue_memory.queue, "queue memory", TX_2_ULONG, &queue_memory.queue_area[0], (2048*sizeof(ULONG))/sizeof(ULONG));
122 tx_queue_delete(&queue_memory.queue);
123
124 /* Check for status. */
125 if ((status != TX_SUCCESS) ||
126 (queue_memory.first != 0x11223344) ||
127 (queue_memory.second != 0x55667788) ||
128 (queue_memory.first_middle != 0x21314151) ||
129 (queue_memory.second_middle != 0x61718191) ||
130 (queue_memory.next_to_last != 0x99aabbcc) ||
131 (queue_memory.last != 0xddeeff00))
132 {
133 /* Queue error. */
134 printf("ERROR #4\n");
135 test_control_return(1);
136 }
137
138 source_message[0] = 0x01234567;
139 source_message[1] = 0x89ABCDEF;
140
141 /* Increment thread 0 counter. */
142 thread_0_counter++;
143
144 /* Place something on queue 0. */
145 status = tx_queue_send(&queue_0, source_message, TX_NO_WAIT);
146
147 if (status != TX_SUCCESS)
148 {
149
150 /* Queue error. */
151 printf("ERROR #5\n");
152 test_control_return(1);
153 }
154
155 /* Attempt to place something on a full queue. */
156 status = tx_queue_send(&queue_0, source_message, TX_NO_WAIT);
157
158 /* Should be an error. */
159 if (status != TX_QUEUE_FULL)
160 {
161
162 /* Queue error. */
163 printf("ERROR #6\n");
164 test_control_return(1);
165 }
166
167 /* Attempt to receive something from queue 0. */
168 status = tx_queue_receive(&queue_0, dest_message, TX_NO_WAIT);
169
170 /* Should be successful and dest_message should equal source. */
171 if ((status != TX_SUCCESS) || (source_message[0] != dest_message[0]) ||
172 (source_message[1] != dest_message[1]))
173 {
174
175 /* Queue error. */
176 printf("ERROR #7\n");
177 test_control_return(1);
178 }
179
180 /* Attempt to receive something from an empty queue. */
181 status = tx_queue_receive(&queue_0, dest_message, TX_NO_WAIT);
182
183 /* Should be an error. */
184 if (status != TX_QUEUE_EMPTY)
185 {
186
187 /* Queue error. */
188 printf("ERROR #8\n");
189 test_control_return(1);
190 }
191
192 /* Make sure we can do the same thing again! */
193 source_message[0]++;
194 source_message[1]++;
195
196 /* Place something on queue 0. */
197 status = tx_queue_send(&queue_0, source_message, TX_NO_WAIT);
198
199 if (status != TX_SUCCESS)
200 {
201
202 /* Queue error. */
203 printf("ERROR #9\n");
204 test_control_return(1);
205 }
206
207 /* Attempt to place something on a full queue. */
208 status = tx_queue_send(&queue_0, source_message, TX_NO_WAIT);
209
210 /* Should be an error. */
211 if (status != TX_QUEUE_FULL)
212 {
213
214 /* Queue error. */
215 printf("ERROR #10\n");
216 test_control_return(1);
217 }
218
219 /* Attempt to receive something from queue 0. */
220 status = tx_queue_receive(&queue_0, dest_message, TX_NO_WAIT);
221
222 /* Should be successful and dest_message should equal source. */
223 if ((status != TX_SUCCESS) || (source_message[0] != dest_message[0]) ||
224 (source_message[1] != dest_message[1]))
225 {
226
227 /* Queue error. */
228 printf("ERROR #11\n");
229 test_control_return(1);
230 }
231
232 /* Attempt to receive something from an empty queue. */
233 status = tx_queue_receive(&queue_0, dest_message, TX_NO_WAIT);
234
235 /* Should be an error. */
236 if (status != TX_QUEUE_EMPTY)
237 {
238
239 /* Queue error. */
240 printf("ERROR #12\n");
241 test_control_return(1);
242 }
243
244 /* Now we need to do the same thing with the queue with three entries. */
245
246 source_message[0]++;
247 source_message[1]++;
248 expected_message[0] = source_message[0];
249 expected_message[1] = source_message[1];
250
251 /* Place something on queue 1. */
252 status = tx_queue_send(&queue_1, source_message, TX_NO_WAIT);
253 source_message[0]++;
254 source_message[1]++;
255 status += tx_queue_send(&queue_1, source_message, TX_NO_WAIT);
256 source_message[0]++;
257 source_message[1]++;
258 status += tx_queue_send(&queue_1, source_message, TX_NO_WAIT);
259 source_message[0]++;
260 source_message[1]++;
261
262
263 if (status != TX_SUCCESS)
264 {
265
266 /* Queue error. */
267 printf("ERROR #13\n");
268 test_control_return(1);
269 }
270
271 /* Attempt to place something on a full queue. */
272 status = tx_queue_send(&queue_1, source_message, TX_NO_WAIT);
273
274 /* Should be an error. */
275 if (status != TX_QUEUE_FULL)
276 {
277
278 /* Queue error. */
279 printf("ERROR #14\n");
280 test_control_return(1);
281 }
282
283 /* Attempt to receive something from queue 1. */
284 status = tx_queue_receive(&queue_1, dest_message, TX_NO_WAIT);
285
286 /* Should be successful and dest_message should equal source. */
287 if ((status != TX_SUCCESS) || (expected_message[0] != dest_message[0]) ||
288 (expected_message[1] != dest_message[1]))
289 {
290
291 /* Queue error. */
292 printf("ERROR #15\n");
293 test_control_return(1);
294 }
295
296 expected_message[0]++;
297 expected_message[1]++;
298
299 /* Attempt to receive something from queue 1. */
300 status = tx_queue_receive(&queue_1, dest_message, TX_NO_WAIT);
301
302 /* Should be successful and dest_message should equal source. */
303 if ((status != TX_SUCCESS) || (expected_message[0] != dest_message[0]) ||
304 (expected_message[1] != dest_message[1]))
305 {
306
307 /* Queue error. */
308 printf("ERROR #16\n");
309 test_control_return(1);
310 }
311
312 expected_message[0]++;
313 expected_message[1]++;
314
315 /* Attempt to receive something from queue 1. */
316 status = tx_queue_receive(&queue_1, dest_message, TX_NO_WAIT);
317
318 /* Should be successful and dest_message should equal source. */
319 if ((status != TX_SUCCESS) || (expected_message[0] != dest_message[0]) ||
320 (expected_message[1] != dest_message[1]))
321 {
322
323 /* Queue error. */
324 printf("ERROR #17\n");
325 test_control_return(1);
326 }
327
328 expected_message[0]++;
329 expected_message[1]++;
330
331 /* Attempt to receive something from an empty queue. */
332 status = tx_queue_receive(&queue_1, dest_message, TX_NO_WAIT);
333
334 /* Should be an error. */
335 if (status != TX_QUEUE_EMPTY)
336 {
337
338 /* Queue error. */
339 printf("ERROR #18\n");
340 test_control_return(1);
341 }
342
343 /* Make sure we can do the same thing again! */
344
345 /* Place something on queue 1. */
346 status = tx_queue_send(&queue_1, source_message, TX_NO_WAIT);
347 source_message[0]++;
348 source_message[1]++;
349 status += tx_queue_send(&queue_1, source_message, TX_NO_WAIT);
350 source_message[0]++;
351 source_message[1]++;
352 status += tx_queue_send(&queue_1, source_message, TX_NO_WAIT);
353 source_message[0]++;
354 source_message[1]++;
355
356 if (status != TX_SUCCESS)
357 {
358
359 /* Queue error. */
360 printf("ERROR #19\n");
361 test_control_return(1);
362 }
363
364 /* Attempt to place something on a full queue. */
365 status = tx_queue_send(&queue_1, source_message, TX_NO_WAIT);
366
367 /* Should be an error. */
368 if (status != TX_QUEUE_FULL)
369 {
370
371 /* Queue error. */
372 printf("ERROR #20\n");
373 test_control_return(1);
374 }
375
376 /* Attempt to receive something from queue 1. */
377 status = tx_queue_receive(&queue_1, dest_message, TX_NO_WAIT);
378
379 /* Should be successful and dest_message should equal source. */
380 if ((status != TX_SUCCESS) || (expected_message[0] != dest_message[0]) ||
381 (expected_message[1] != dest_message[1]))
382 {
383
384 /* Queue error. */
385 printf("ERROR #21\n");
386 test_control_return(1);
387 }
388
389 expected_message[0]++;
390 expected_message[1]++;
391
392 /* Attempt to receive something from queue 1. */
393 status = tx_queue_receive(&queue_1, dest_message, TX_NO_WAIT);
394
395 /* Should be successful and dest_message should equal source. */
396 if ((status != TX_SUCCESS) || (expected_message[0] != dest_message[0]) ||
397 (expected_message[1] != dest_message[1]))
398 {
399
400 /* Queue error. */
401 printf("ERROR #22\n");
402 test_control_return(1);
403 }
404
405 expected_message[0]++;
406 expected_message[1]++;
407
408 /* Attempt to receive something from queue 1. */
409 status = tx_queue_receive(&queue_1, dest_message, TX_NO_WAIT);
410
411 /* Should be successful and dest_message should equal source. */
412 if ((status != TX_SUCCESS) || (expected_message[0] != dest_message[0]) ||
413 (expected_message[1] != dest_message[1]))
414 {
415
416 /* Queue error. */
417 printf("ERROR #23\n");
418 test_control_return(1);
419 }
420
421 expected_message[0]++;
422 expected_message[1]++;
423
424 /* Attempt to receive something from an empty queue. */
425 status = tx_queue_receive(&queue_1, dest_message, TX_NO_WAIT);
426
427 /* Should be an error. */
428 if (status != TX_QUEUE_EMPTY)
429 {
430
431 /* Queue error. */
432 printf("ERROR #24\n");
433 test_control_return(1);
434 }
435
436 /* Delete the queues. */
437 status = tx_queue_delete(&queue_1);
438 if (status != TX_SUCCESS)
439 {
440
441 /* Queue error. */
442 printf("ERROR #25\n");
443 test_control_return(1);
444 }
445
446 status = tx_queue_delete(&queue_0);
447 if (status != TX_SUCCESS)
448 {
449
450 /* Queue error. */
451 printf("ERROR #26\n");
452 test_control_return(1);
453 }
454 else
455 {
456
457 /* Successful test. */
458 printf("SUCCESS!\n");
459 test_control_return(0);
460 }
461 }
462
463
464