1 /* This test is designed to test event flag suspension timeout processing.  */
2 
3 #include   <stdio.h>
4 #include   "tx_api.h"
5 
6 static unsigned long   thread_0_counter =  0;
7 static TX_THREAD       thread_0;
8 static unsigned long   thread_1_counter =  0;
9 static TX_THREAD       thread_1;
10 static unsigned long   thread_2_counter =  0;
11 static TX_THREAD       thread_2;
12 static unsigned long   thread_3_counter =  0;
13 static TX_THREAD       thread_3;
14 
15 
16 static TX_EVENT_FLAGS_GROUP group_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 static void    thread_3_entry(ULONG thread_input);
25 
26 
27 /* Prototype for test control return.  */
28 void  test_control_return(UINT status);
29 
30 
event_set_notify(TX_EVENT_FLAGS_GROUP * group)31 static void event_set_notify(TX_EVENT_FLAGS_GROUP *group)
32 {
33 
34     /* Not necessary to do anything in this function.  */
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_event_flag_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 status.  */
63     if (status != TX_SUCCESS)
64     {
65 
66         printf("Running Event Flag 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             16, 16, 100, TX_DONT_START);
73     pointer = pointer + TEST_STACK_SIZE_PRINTF;
74     status += tx_thread_create(&thread_3, "thread 3", thread_3_entry, 3,
75             pointer, TEST_STACK_SIZE_PRINTF,
76             18, 18, 100, TX_DONT_START);
77     pointer = pointer + TEST_STACK_SIZE_PRINTF;
78 
79     /* Check status.  */
80     if (status != TX_SUCCESS)
81     {
82 
83         printf("Running Event Flag Suspension Timeout Test.......................... ERROR #2\n");
84         test_control_return(1);
85     }
86 
87     status =  tx_thread_create(&thread_2, "thread 2", thread_2_entry, 1,
88             pointer, TEST_STACK_SIZE_PRINTF,
89             16, 16, 100, TX_DONT_START);
90     pointer = pointer + TEST_STACK_SIZE_PRINTF;
91 
92     /* Check status.  */
93     if (status != TX_SUCCESS)
94     {
95 
96         printf("Running Event Flag Suspension Timeout Test.......................... ERROR #3\n");
97         test_control_return(1);
98     }
99 
100     /* Create event flag group 0.  */
101     status =  tx_event_flags_create(&group_0, "group 0");
102 
103     /* Check status.  */
104     if (status != TX_SUCCESS)
105     {
106 
107         printf("Running Event Flag Suspension Timeout Test.......................... ERROR #4\n");
108         test_control_return(1);
109     }
110 
111     /* Register the event set notify function.  */
112     status =  tx_event_flags_set_notify(&group_0, event_set_notify);
113 
114 #ifndef TX_DISABLE_NOTIFY_CALLBACKS
115 
116     /* Check status.  */
117     if (status != TX_SUCCESS)
118     {
119 
120         printf("Running Event Flag Suspension Timeout Test.......................... ERROR #5\n");
121         test_control_return(1);
122     }
123 #else
124 
125     /* Check status.  */
126     if (status != TX_FEATURE_NOT_ENABLED)
127     {
128 
129         printf("Running Event Flag Suspension Timeout Test.......................... ERROR #6\n");
130         test_control_return(1);
131     }
132 
133 #endif
134 
135 }
136 
137 
138 
139 /* Define the test threads.  */
140 
thread_0_entry(ULONG thread_input)141 static void    thread_0_entry(ULONG thread_input)
142 {
143 
144 ULONG   actual_events;
145 UINT    status;
146 
147 
148     /* Inform user.  */
149     printf("Running Event Flag Suspension Timeout Test.......................... ");
150 
151     /* Increment run counter.  */
152     thread_0_counter++;
153 
154     /* Set event flag 0. */
155     tx_event_flags_set(&group_0, 0x00000001, TX_OR);
156 
157     /* Resume thread 3.  */
158     tx_thread_resume(&thread_3);
159     tx_thread_sleep(1);     /* Thread 3 should now be suspended on group 0.  */
160     tx_event_flags_set(&group_0, 0x00000002, TX_OR);
161 
162     /* Start everything on a new timer.  */
163     tx_thread_sleep(2);
164     tx_thread_resume(&thread_1);
165     tx_thread_resume(&thread_2);
166     tx_thread_sleep(1);
167     status =  tx_event_flags_get(&group_0, 0x00000001, TX_AND_CLEAR, &actual_events, TX_WAIT_FOREVER);
168 
169     /* Check the status.  */
170     if (status != TX_SUCCESS)
171     {
172 
173         /* Event flag error.  */
174         printf("ERROR #6a\n");
175         test_control_return(1);
176     }
177 
178     /* Sleep for 63 ticks.  */
179     tx_thread_sleep(63);
180 
181     /* Check the run counters.  */
182     if ((thread_1_counter != 33) || (thread_2_counter != 13))
183     {
184 
185         /* Event flag error.  */
186         printf("ERROR #7\n");
187         test_control_return(1);
188     }
189 
190     /* Successful test.  */
191     printf("SUCCESS!\n");
192     test_control_return(0);
193 }
194 
195 
thread_1_entry(ULONG thread_input)196 static void    thread_1_entry(ULONG thread_input)
197 {
198 
199 UINT    status;
200 ULONG   actual_events;
201 
202 
203 
204     /* Wait for event flags.  */
205     while(1)
206     {
207 
208         /* Increment run counter.  */
209         thread_1_counter++;
210 
211         /* Attempt to get events from event flag group.  AND option.  */
212         status =  tx_event_flags_get(&group_0, 0x80000000, TX_AND_CLEAR, &actual_events, 2);
213 
214         /* Check status.  */
215         if (status != TX_NO_EVENTS)
216             return;
217     }
218 }
219 
220 
thread_2_entry(ULONG thread_input)221 static void    thread_2_entry(ULONG thread_input)
222 {
223 
224 UINT    status;
225 //ULONG   event_flag = 1;
226 ULONG   actual_events;
227 
228     /* Wait for event flags.  */
229     while(1)
230     {
231 
232         /* Increment run counter.  */
233         thread_2_counter++;
234 
235         /* Attempt to get events from event flag group.  AND option.  */
236         status =  tx_event_flags_get(&group_0, 0x00008000, TX_AND_CLEAR, &actual_events, 5);
237 
238         /* Check status.  */
239         if (status != TX_NO_EVENTS)
240             return;
241     }
242 }
243 
244 
thread_3_entry(ULONG thread_input)245 static void    thread_3_entry(ULONG thread_input)
246 {
247 
248 UINT    status;
249 //ULONG   event_flag = 1;
250 ULONG   actual_events;
251 
252     /* Wait for event flags.  */
253     while(1)
254     {
255 
256         /* Increment run counter.  */
257         thread_3_counter++;
258 
259         /* Attempt to get events from event flag group.  AND option.  */
260         status =  tx_event_flags_get(&group_0, 0x00000002, TX_AND, &actual_events, 5);
261 
262         /* Check status.  */
263         if (status != TX_NO_EVENTS)
264             return;
265     }
266 }
267