1 /* This test is designed to test the queue flush operation on a queue that has two threads
2 suspended on it. */
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
10 static unsigned long thread_1_counter = 0;
11 static TX_THREAD thread_1;
12
13 static unsigned long thread_2_counter = 0;
14 static TX_THREAD thread_2;
15
16 static TX_QUEUE queue_0;
17
18
19 /* Define thread prototypes. */
20
21 static void thread_0_entry(ULONG thread_input);
22 static void thread_1_entry(ULONG thread_input);
23 static void thread_2_entry(ULONG thread_input);
24
25
26 /* Prototype for test control return. */
27
28 void test_control_return(UINT status);
29
30
queue_notify(TX_QUEUE * queue_ptr)31 static void queue_notify(TX_QUEUE *queue_ptr)
32 {
33
34 }
35
36
37 /* Define what the initial system looks like. */
38
39 #ifdef CTEST
test_application_define(void * first_unused_memory)40 void test_application_define(void *first_unused_memory)
41 #else
42 void threadx_queue_flush_application_define(void *first_unused_memory)
43 #endif
44 {
45
46 UINT status;
47 CHAR *pointer;
48
49 /* Put first available memory address into a character pointer. */
50 pointer = (CHAR *) first_unused_memory;
51
52 /* Put system definition stuff in here, e.g. thread creates and other assorted
53 create information. */
54
55 status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
56 pointer, TEST_STACK_SIZE_PRINTF,
57 17, 17, 100, TX_AUTO_START);
58 pointer = pointer + TEST_STACK_SIZE_PRINTF;
59
60 /* Check for status. */
61 if (status != TX_SUCCESS)
62 {
63
64 printf("Running Queue Flush w/Suspended Threads Test........................ ERROR #1\n");
65 test_control_return(1);
66 }
67
68 status = tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
69 pointer, TEST_STACK_SIZE_PRINTF,
70 17, 17, 100, TX_AUTO_START);
71 pointer = pointer + TEST_STACK_SIZE_PRINTF;
72
73 /* Check for status. */
74 if (status != TX_SUCCESS)
75 {
76
77 printf("Running Queue Flush w/Suspended Threads Test........................ ERROR #2\n");
78 test_control_return(1);
79 }
80
81 status = tx_thread_create(&thread_2, "thread 2", thread_2_entry, 1,
82 pointer, TEST_STACK_SIZE_PRINTF,
83 17, 17, 100, TX_AUTO_START);
84 pointer = pointer + TEST_STACK_SIZE_PRINTF;
85
86 /* Check for status. */
87 if (status != TX_SUCCESS)
88 {
89
90 printf("Running Queue Flush w/Suspended Threads Test........................ ERROR #3\n");
91 test_control_return(1);
92 }
93
94
95 /* Create the queue. */
96 status = tx_queue_create(&queue_0, "queue 0", TX_2_ULONG, pointer, 3*2*sizeof(ULONG));
97 pointer = pointer + 3*2*sizeof(ULONG);
98
99 /* Check for status. */
100 if (status != TX_SUCCESS)
101 {
102
103 printf("Running Queue Flush w/Suspended Threads Test........................ ERROR #4\n");
104 test_control_return(1);
105 }
106
107 /* Setup queue send notification. */
108 status = tx_queue_send_notify(&queue_0, queue_notify);
109
110 #ifndef TX_DISABLE_NOTIFY_CALLBACKS
111
112 /* Check for status. */
113 if (status != TX_SUCCESS)
114 {
115
116 printf("Running Queue Flush w/Suspended Threads Test........................ ERROR #5\n");
117 test_control_return(1);
118 }
119 #else
120
121 /* Check for status. */
122 if (status != TX_FEATURE_NOT_ENABLED)
123 {
124
125 printf("Running Queue Flush w/Suspended Threads Test........................ ERROR #6\n");
126 test_control_return(1);
127 }
128
129 #endif
130
131 }
132
133
134
135 /* Define the test threads. */
136
thread_0_entry(ULONG thread_input)137 static void thread_0_entry(ULONG thread_input)
138 {
139
140 ULONG message[2] = {0x12345678, 0};
141 UINT status;
142
143
144 /* Inform user. */
145 printf("Running Queue Flush w/Suspended Threads Test........................ ");
146
147 /* Fill up the queue. */
148 status = tx_queue_send(&queue_0, &message[0], TX_NO_WAIT);
149
150 /* Check for status. */
151 if (status != TX_SUCCESS)
152 {
153
154 printf("ERROR #7\n");
155 test_control_return(1);
156 }
157
158 status = tx_queue_send(&queue_0, &message[0], TX_NO_WAIT);
159
160 /* Check for status. */
161 if (status != TX_SUCCESS)
162 {
163
164 printf("ERROR #8\n");
165 test_control_return(1);
166 }
167
168 status = tx_queue_send(&queue_0, &message[0], TX_NO_WAIT);
169
170
171 /* Check for status. */
172 if (status != TX_SUCCESS)
173 {
174
175 printf("ERROR #9\n");
176 test_control_return(1);
177 }
178
179 /* Relinquish to get other threads suspended on the queue full. */
180 tx_thread_relinquish();
181
182 /* Flush queue 0 which has the threads suspended on it. */
183 status = tx_queue_flush(&queue_0);
184
185 /* Check for status. */
186 if (status != TX_SUCCESS)
187 {
188
189 printf("ERROR #10\n");
190 test_control_return(1);
191 }
192
193 /* Relinquish to let other threads run and finish! */
194 tx_thread_relinquish();
195
196 /* Determine if the queue flush test was successful. */
197 if ((thread_1_counter == 1) && (thread_2_counter == 1))
198 {
199
200 /* Successful queue flush test. */
201 printf("SUCCESS!\n");
202 test_control_return(0);
203 }
204 else
205 {
206
207 /* Queue Flush error. */
208 printf("ERROR #11\n");
209 test_control_return(1);
210 }
211
212 /* Increment the thread counter. */
213 thread_0_counter++;
214 }
215
216
thread_1_entry(ULONG thread_input)217 static void thread_1_entry(ULONG thread_input)
218 {
219 UINT status;
220 ULONG message[2] = {0x1, 0};
221
222
223 /* Receive message from empty queue. */
224 status = tx_queue_send(&queue_0, &message[0], TX_WAIT_FOREVER);
225
226 if (status != TX_SUCCESS)
227 return;
228
229 /* Increment the thread counter. */
230 thread_1_counter++;
231 }
232
233
thread_2_entry(ULONG thread_input)234 static void thread_2_entry(ULONG thread_input)
235 {
236 UINT status;
237 ULONG message[2] = {0x2, 0};
238
239
240 /* Receive message from empty queue. */
241 status = tx_queue_send(&queue_0, &message[0], TX_WAIT_FOREVER);
242
243 if (status != TX_SUCCESS)
244 return;
245
246 /* Increment the thread counter. */
247 thread_2_counter++;
248 }
249
250