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