1 /* This test is designed to test thread terminate when the terminated thread is suspeded
2 on a queue. */
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 TX_QUEUE queue_0;
14
15
16 /* Define thread prototypes. */
17
18 static void thread_0_entry(ULONG thread_input);
19 static void thread_1_entry(ULONG thread_input);
20
21
22 /* Prototype for test control return. */
23 void test_control_return(UINT status);
24
25
queue_notify(TX_QUEUE * queue_ptr)26 static void queue_notify(TX_QUEUE *queue_ptr)
27 {
28
29 }
30
31
32 /* Define what the initial system looks like. */
33
34 #ifdef CTEST
test_application_define(void * first_unused_memory)35 void test_application_define(void *first_unused_memory)
36 #else
37 void threadx_queue_thread_terminate_application_define(void *first_unused_memory)
38 #endif
39 {
40
41 UINT status;
42 CHAR *pointer;
43
44
45 /* Put first available memory address into a character pointer. */
46 pointer = (CHAR *) first_unused_memory;
47
48 /* Put system definition stuff in here, e.g. thread creates and other assorted
49 create information. */
50
51 status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
52 pointer, TEST_STACK_SIZE_PRINTF,
53 17, 17, 100, TX_AUTO_START);
54 pointer = pointer + TEST_STACK_SIZE_PRINTF;
55
56 /* Check for status. */
57 if (status != TX_SUCCESS)
58 {
59
60 printf("Running Queue Thread Terminate Test................................. ERROR #1\n");
61 test_control_return(1);
62 }
63
64 status = tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
65 pointer, TEST_STACK_SIZE_PRINTF,
66 16, 16, 100, TX_AUTO_START);
67 pointer = pointer + TEST_STACK_SIZE_PRINTF;
68
69 /* Check for status. */
70 if (status != TX_SUCCESS)
71 {
72
73 printf("Running Queue Thread Terminate Test................................. ERROR #2\n");
74 test_control_return(1);
75 }
76
77 /* Create the queue. */
78 status = tx_queue_create(&queue_0, "queue 0", TX_2_ULONG, pointer, 3*2*sizeof(ULONG));
79 pointer = pointer + 3*2*sizeof(ULONG);
80
81 /* Check for status. */
82 if (status != TX_SUCCESS)
83 {
84
85 printf("Running Queue Thread Terminate Test................................. ERROR #3\n");
86 test_control_return(1);
87 }
88
89 /* Setup queue send notification. */
90 status = tx_queue_send_notify(&queue_0, queue_notify);
91
92 #ifndef TX_DISABLE_NOTIFY_CALLBACKS
93
94 /* Check for status. */
95 if (status != TX_SUCCESS)
96 {
97
98 printf("Running Queue Thread Terminate Test................................. ERROR #4\n");
99 test_control_return(1);
100 }
101 #else
102
103 /* Check for status. */
104 if (status != TX_FEATURE_NOT_ENABLED)
105 {
106
107 printf("Running Queue Thread Terminate Test................................. ERROR #5\n");
108 test_control_return(1);
109 }
110
111 #endif
112
113 }
114
115
116
117 /* Define the test threads. */
118
thread_0_entry(ULONG thread_input)119 static void thread_0_entry(ULONG thread_input)
120 {
121
122 UINT status;
123
124
125 /* Inform user. */
126 printf("Running Queue Thread Terminate Test................................. ");
127
128 /* Increment the thread counter. */
129 thread_0_counter++;
130
131 /* Make sure thread 1 is suspended on the queue. */
132 if (thread_1.tx_thread_state != TX_QUEUE_SUSP)
133 {
134
135 /* Queue error. */
136 printf("ERROR #6\n");
137 test_control_return(1);
138 }
139
140 /* Terminate thread 1 which is suspended on queue 0. */
141 status = tx_thread_terminate(&thread_1);
142
143 /* Check status and make sure thread 1 is terminated. */
144 if ((status != TX_SUCCESS) || (thread_1.tx_thread_state != TX_TERMINATED) ||
145 (thread_1_counter != 0) || (queue_0.tx_queue_suspended_count))
146 {
147
148 /* Queue error. */
149 printf("ERROR #7\n");
150 test_control_return(1);
151 }
152 else
153 {
154
155 /* Successful test. */
156 printf("SUCCESS!\n");
157 test_control_return(0);
158 }
159 }
160
161
thread_1_entry(ULONG thread_input)162 static void thread_1_entry(ULONG thread_input)
163 {
164 UINT status;
165 ULONG dest_message[2];
166
167
168 /* Loop forever! */
169 while(1)
170 {
171
172
173 /* Receive message from empty queue. */
174 status = tx_queue_receive(&queue_0, &dest_message[0], TX_WAIT_FOREVER);
175
176 if (status != TX_QUEUE_EMPTY)
177 break;
178
179 /* Increment the thread counter. */
180 thread_1_counter++;
181 }
182 }
183
184