1 /* This test is designed to test queue full and empty suspension with timeouts on queues
2 that supports 3 messages that are each 2 ULONG in size. */
3
4 #include <stdio.h>
5 #include "tx_api.h"
6
7 //static unsigned long thread_0_counter = 0;
8 static TX_THREAD thread_0;
9 static unsigned long thread_1_counter = 0;
10
11 static TX_THREAD thread_1;
12
13 static TX_THREAD thread_2;
14 static unsigned long thread_2_counter = 0;
15
16 static TX_QUEUE queue_0;
17 static TX_QUEUE queue_1;
18
19
20 /* Define thread prototypes. */
21
22 static void thread_0_entry(ULONG thread_input);
23 static void thread_1_entry(ULONG thread_input);
24 static void thread_2_entry(ULONG thread_input);
25
26
27 /* Prototype for test control return. */
28
29 void test_control_return(UINT status);
30
31
queue_notify(TX_QUEUE * queue_ptr)32 static void queue_notify(TX_QUEUE *queue_ptr)
33 {
34
35 }
36
37
38 /* Define what the initial system looks like. */
39
40 #ifdef CTEST
test_application_define(void * first_unused_memory)41 void test_application_define(void *first_unused_memory)
42 #else
43 void threadx_queue_suspension_timeout_application_define(void *first_unused_memory)
44 #endif
45 {
46
47 UINT status;
48 CHAR *pointer;
49
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 17, 17, 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 Suspension Timeout Test............................... ERROR #1\n");
67 test_control_return(1);
68 }
69
70 status = tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
71 pointer, TEST_STACK_SIZE_PRINTF,
72 17, 17, 100, TX_AUTO_START);
73 pointer = pointer + TEST_STACK_SIZE_PRINTF;
74
75 /* Check for status. */
76 if (status != TX_SUCCESS)
77 {
78
79 printf("Running Queue Suspension Timeout Test............................... ERROR #2\n");
80 test_control_return(1);
81 }
82
83 status = tx_thread_create(&thread_2, "thread 2", thread_2_entry, 2,
84 pointer, TEST_STACK_SIZE_PRINTF,
85 17, 17, 100, TX_AUTO_START);
86 pointer = pointer + TEST_STACK_SIZE_PRINTF;
87
88 /* Check for status. */
89 if (status != TX_SUCCESS)
90 {
91
92 printf("Running Queue Suspension Timeout Test............................... ERROR #3\n");
93 test_control_return(1);
94 }
95
96 /* Create the queues. */
97 status = tx_queue_create(&queue_0, "queue 0", TX_2_ULONG, pointer, 3*2*sizeof(ULONG));
98 pointer = pointer + 3*2*sizeof(ULONG);
99
100 /* Check for status. */
101 if (status != TX_SUCCESS)
102 {
103
104 printf("Running Queue Suspension Timeout Test............................... ERROR #4\n");
105 test_control_return(1);
106 }
107
108 status = tx_queue_create(&queue_1, "queue 1", TX_2_ULONG, pointer, 3*2*sizeof(ULONG));
109 pointer = pointer + 3*2*sizeof(ULONG);
110
111 /* Check for status. */
112 if (status != TX_SUCCESS)
113 {
114
115 printf("Running Queue Suspension Timeout Test............................... ERROR #5\n");
116 test_control_return(1);
117 }
118
119 /* Setup queue send notification. */
120 status = tx_queue_send_notify(&queue_0, queue_notify);
121
122 #ifndef TX_DISABLE_NOTIFY_CALLBACKS
123
124 /* Check for status. */
125 if (status != TX_SUCCESS)
126 {
127
128 printf("Running Queue Suspension Timeout Test............................... ERROR #6\n");
129 test_control_return(1);
130 }
131 #else
132
133 /* Check for status. */
134 if (status != TX_FEATURE_NOT_ENABLED)
135 {
136
137 printf("Running Queue Suspension Timeout Test............................... ERROR #7\n");
138 test_control_return(1);
139 }
140
141 #endif
142
143 }
144
145
146
147 /* Define the test threads. */
148
thread_0_entry(ULONG thread_input)149 static void thread_0_entry(ULONG thread_input)
150 {
151
152 UINT status;
153 ULONG source_message[2] = {0x12345678, 0};
154
155
156 /* Inform user. */
157 printf("Running Queue Suspension Timeout Test............................... ");
158
159 /* Fill the queue with an initial 3 messages! */
160 status = tx_queue_send(&queue_0, &source_message[0], TX_NO_WAIT);
161 source_message[0]++;
162 status += tx_queue_send(&queue_0, &source_message[0], TX_NO_WAIT);
163 source_message[0]++;
164 status += tx_queue_send(&queue_0, &source_message[0], TX_NO_WAIT);
165 source_message[0]++;
166
167 /* Check status and run count of other thread. */
168 if ((status != TX_SUCCESS) || (thread_1_counter != 0))
169 {
170
171 /* Queue error. */
172 printf("ERROR #8\n");
173 test_control_return(1);
174 }
175
176 /* Send message to the front of the queue that should cause this thread to suspend. The timeout
177 should cause it to resume with a TX_QUEUE_FULL error code. */
178 status = tx_queue_front_send(&queue_0, &source_message[0], 3);
179
180 if ((status != TX_QUEUE_FULL) || (thread_1_counter != 0) || (thread_2_counter != 0))
181 {
182
183 /* Queue error. */
184 printf("ERROR #9a\n");
185 test_control_return(1);
186 }
187
188 /* Send message that should cause this thread to suspend. The timeout
189 should cause it to resume with a TX_QUEUE_FULL error code. */
190 status = tx_queue_send(&queue_0, &source_message[0], 32);
191
192 if ((status != TX_QUEUE_FULL) || (thread_1_counter != 1) || (thread_2_counter != 1))
193 {
194
195 /* Queue error. */
196 printf("ERROR #9\n");
197 test_control_return(1);
198 }
199 else
200 {
201
202 /* Successful test. */
203 printf("SUCCESS!\n");
204 test_control_return(0);
205 }
206 }
207
208
thread_1_entry(ULONG thread_input)209 static void thread_1_entry(ULONG thread_input)
210 {
211 UINT status;
212 ULONG dest_message[2];
213
214
215 /* Loop forever! */
216 while(1)
217 {
218
219
220 /* Receive message from empty queue with suspension and timeout.
221 We should wakeup after the timeout expires with an empty status. */
222 status = tx_queue_receive(&queue_1, &dest_message[0], 20);
223
224 if (status != TX_QUEUE_EMPTY)
225 break;
226
227 /* Increment the thread counter. */
228 thread_1_counter++;
229 }
230 }
231
232
thread_2_entry(ULONG thread_input)233 static void thread_2_entry(ULONG thread_input)
234 {
235 UINT status;
236 ULONG dest_message[2];
237
238
239 /* Loop forever! */
240 while(1)
241 {
242
243
244 /* Receive message from empty queue with suspension and timeout.
245 We should wakeup after the timeout expires with an empty status. */
246 status = tx_queue_receive(&queue_1, &dest_message[0], 20);
247
248 if (status != TX_QUEUE_EMPTY)
249 break;
250
251 /* Increment the thread counter. */
252 thread_2_counter++;
253 }
254 }
255