1 /* This test is designed to test the queue flush operation on a queue that has no 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 TX_QUEUE queue_0;
11
12
13 /* Define thread prototypes. */
14
15 static void thread_0_entry(ULONG thread_input);
16
17
18 /* Prototype for test control return. */
19
20 void test_control_return(UINT status);
21
22
queue_notify(TX_QUEUE * queue_ptr)23 static void queue_notify(TX_QUEUE *queue_ptr)
24 {
25
26 }
27
28
29 /* Define what the initial system looks like. */
30
31 #ifdef CTEST
test_application_define(void * first_unused_memory)32 void test_application_define(void *first_unused_memory)
33 #else
34 void threadx_queue_flush_no_suspension_application_define(void *first_unused_memory)
35 #endif
36 {
37
38 UINT status;
39 CHAR *pointer;
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
47 status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
48 pointer, TEST_STACK_SIZE_PRINTF,
49 17, 17, 100, TX_AUTO_START);
50 pointer = pointer + TEST_STACK_SIZE_PRINTF;
51
52 /* Check for status. */
53 if (status != TX_SUCCESS)
54 {
55
56 printf("Running Queue Flush No Suspension Test.............................. ERROR #1\n");
57 test_control_return(1);
58 }
59
60 /* Create the queue. */
61 status = tx_queue_create(&queue_0, "queue 0", TX_2_ULONG, pointer, 3*2*sizeof(ULONG));
62 pointer = pointer + 3*2*sizeof(ULONG);
63
64 /* Check for status. */
65 if (status != TX_SUCCESS)
66 {
67
68 printf("Running Queue Flush No Suspension Test.............................. ERROR #2\n");
69 test_control_return(1);
70 }
71
72 /* Setup queue send notification. */
73 status = tx_queue_send_notify(&queue_0, queue_notify);
74
75 #ifndef TX_DISABLE_NOTIFY_CALLBACKS
76
77 /* Check for status. */
78 if (status != TX_SUCCESS)
79 {
80
81 printf("Running Queue Flush No Suspension Test.............................. ERROR #3\n");
82 test_control_return(1);
83 }
84 #else
85
86 /* Check for status. */
87 if (status != TX_FEATURE_NOT_ENABLED)
88 {
89
90 printf("Running Queue Flush No Suspension Test.............................. ERROR #4\n");
91 test_control_return(1);
92 }
93
94 #endif
95
96 }
97
98
99
100 /* Define the test threads. */
101
thread_0_entry(ULONG thread_input)102 static void thread_0_entry(ULONG thread_input)
103 {
104
105 ULONG message[2] = {0x12345678, 0};
106 UINT status;
107
108
109 /* Inform user. */
110 printf("Running Queue Flush No Suspension Test.............................. ");
111
112 /* Fill up the queue. */
113 status = tx_queue_send(&queue_0, &message[0], TX_NO_WAIT);
114
115 /* Check for status. */
116 if (status != TX_SUCCESS)
117 {
118
119 printf("ERROR #5\n");
120 test_control_return(1);
121 }
122
123 status = tx_queue_send(&queue_0, &message[0], TX_NO_WAIT);
124
125 /* Check for status. */
126 if (status != TX_SUCCESS)
127 {
128
129 printf("ERROR #6\n");
130 test_control_return(1);
131 }
132
133 status = tx_queue_send(&queue_0, &message[0], TX_NO_WAIT);
134
135
136 /* Check for status. */
137 if (status != TX_SUCCESS)
138 {
139
140 printf("ERROR #7\n");
141 test_control_return(1);
142 }
143
144 /* Flush queue 0 to make more room. */
145 status = tx_queue_flush(&queue_0);
146
147 /* Check for status. */
148 if (status != TX_SUCCESS)
149 {
150
151 printf("ERROR #8\n");
152 test_control_return(1);
153 }
154
155
156 /* Fill up the queue. */
157 status = tx_queue_send(&queue_0, &message[2], TX_NO_WAIT);
158
159 /* Check for status. */
160 if (status != TX_SUCCESS)
161 {
162
163 printf("ERROR #9\n");
164 test_control_return(1);
165 }
166
167 status = tx_queue_send(&queue_0, &message[2], TX_NO_WAIT);
168
169 /* Check for status. */
170 if (status != TX_SUCCESS)
171 {
172
173 printf("ERROR #10\n");
174 test_control_return(1);
175 }
176
177 status = tx_queue_send(&queue_0, &message[2], TX_NO_WAIT);
178
179
180 /* Check for status. */
181 if (status != TX_SUCCESS)
182 {
183
184 printf("ERROR #11\n");
185 test_control_return(1);
186 }
187
188 /* Flush queue again to empty and then flush to test on an empty queue. */
189 status = tx_queue_flush(&queue_0);
190
191 /* Check for status. */
192 if (status != TX_SUCCESS)
193 {
194
195 printf("ERROR #12\n");
196 test_control_return(1);
197 }
198
199 status = tx_queue_flush(&queue_0);
200
201 /* Check for status. */
202 if (status != TX_SUCCESS)
203 {
204
205 printf("ERROR #13\n");
206 test_control_return(1);
207 }
208
209 /* Success if we get here. */
210 printf("SUCCESS!\n");
211 test_control_return(0);
212
213 /* Increment the thread counter. */
214 thread_0_counter++;
215 }
216
217