1 /* This case tests websocket send ability when there are chain packets. */
2 #include "tx_api.h"
3 #include "nx_api.h"
4
5 extern void test_control_return(UINT);
6
7 #if !defined(NX_DISABLE_IPV4) && defined(__PRODUCT_NETXDUO__) && !defined(NX_DISABLE_PACKET_CHAIN)
8 #include "nx_websocket_client.h"
9 #include "netx_websocket_common_process.c"
10
11 #define DEMO_STACK_SIZE 4096
12 #define PACKET_SIZE 1536
13 #define TOTAL_SIZE DEMO_STACK_SIZE + (PACKET_SIZE * 8) + 2048 + 1024
14
15 /* Define device drivers. */
16 extern void _nx_ram_network_driver_1024(NX_IP_DRIVER *driver_req_ptr);
17
18 static UINT test_done = NX_FALSE;
19
20 static TX_THREAD client_thread;
21 static NX_PACKET_POOL client_pool;
22 static NX_TCP_SOCKET test_client;
23 static NX_IP client_ip;
24
25 static NX_TCP_SOCKET test_server;
26 static NX_PACKET_POOL server_pool;
27 static TX_THREAD server_thread;
28 static NX_IP server_ip;
29 static UINT test_server_start = 0;
30 static UINT test_client_stop = 0;
31
32 /* Set up the websocket global variables */
33 static NX_WEBSOCKET_CLIENT client_websocket;
34 static UCHAR *client_websocket_host;
35 static UINT client_websocket_host_length;
36 static UCHAR *client_websocket_uri_path;
37 static UINT client_websocket_uri_path_length;
38
39
40 static void thread_client_entry(ULONG thread_input);
41 static void thread_server_entry(ULONG thread_input);
42
43 #define TEST_SERVER_ADDRESS IP_ADDRESS(1,2,3,4)
44 #define TEST_CLIENT_ADDRESS IP_ADDRESS(1,2,3,5)
45 #define TEST_SERVER_PORT 80
46
47 #define TEST_HOST_NAME "1.2.3.4"
48 #define TEST_URI_PATH "/test"
49 #define TEST_PROTOCOL "test"
50
51 static UCHAR server_switch_101[] =
52 {
53 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0x20, // HTTP1.1/
54 0x31, 0x30, 0x31, 0x20, 0x53, 0x77, 0x69, 0x74, 0x63, 0x68, 0x69, 0x6e, 0x67, 0x20, // 101 Switching
55 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x73, 0x0d, 0x0a, // Protocols\r\n
56 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x3a, 0x20, // Upgrade:
57 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x0d, 0x0a, // WebSocket\r\n
58 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, // Connection:
59 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x0d, 0x0a, // Upgrade\r\n
60 0x53, 0x65, 0x63, 0x2d, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, 0x65, // Sec-WebSocket-Protocol:
61 0x74, 0x2d, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x3a, 0x20,
62 0x74, 0x65, 0x73, 0x74, 0x0d, 0x0a, // test
63 0x53, 0x65, 0x63, 0x2d, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, // Sec-WebSocket-Accept:
64 0x65, 0x74, 0x2d, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x3a, 0x20,
65 0x35, 0x75, 0x31, 0x6c, 0x55, 0x72, 0x32, 0x57, 0x68, 0x70, 0x34, 0x64, 0x44, 0x57, 0x6e, // 5u1lUr2Whp4dDWnskk9JcJZobO0=
66 0x73, 0x6b, 0x6b, 0x39, 0x4a, 0x63, 0x4a, 0x5a, 0x6f, 0x62, 0x4f, 0x30, 0x3d, 0x0d, 0x0a,
67 0x0d, 0x0a,
68 };
69
70 static UCHAR server_response_16_bit_normal_frame[] =
71 {
72 0x82, 0x7E, 0x01, 0x00,
73 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
74 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
75 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
76 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
77 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
78 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
79 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
80 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
81 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
82 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
83 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
84 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
85 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
86 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
87 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
88 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
89 };
90
91 /* Below 3 packets compose one complete frame */
92 static UCHAR client_send_frame_packet_1[] =
93 {
94 0x82, 0x7E, 0x01, 0x00, 0x11, 0x22, 0x33, 0x44, // header
95 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
96 };
97
98 static UCHAR client_send_frame_packet_2[] =
99 {
100 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
101 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
102 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
103 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
104 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
105 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
106 };
107
108 static UCHAR client_send_frame_packet_3[] =
109 {
110 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
111 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
112 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
113 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
114 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
115 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
116 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
117 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
118 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
119 };
120
121 static UCHAR server_test_data[] =
122 {
123 0x82, 0x00,
124 };
125
126 static ULONG error_counter;
127
128 extern void SET_ERROR_COUNTER(ULONG *error_counter, CHAR *filename, int line_number);
129
130 #define TEST_LOOP 2
131
132 #ifdef CTEST
test_application_define(void * first_unused_memory)133 VOID test_application_define(void *first_unused_memory)
134 #else
135 void netx_websocket_send_chain_packets_test_application_define(void *first_unused_memory)
136 #endif
137 {
138 CHAR *pointer;
139 UINT status;
140
141
142 error_counter = 0;
143
144 /* Setup the working pointer. */
145 pointer = (CHAR *) first_unused_memory;
146
147 /* Create a helper thread for the server. */
148 tx_thread_create(&server_thread, "Test Server thread", thread_server_entry, 0,
149 pointer, DEMO_STACK_SIZE,
150 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
151
152 pointer = pointer + DEMO_STACK_SIZE;
153
154 /* Initialize the NetX system. */
155 nx_system_initialize();
156
157 /* Create the server packet pool. */
158 status = nx_packet_pool_create(&server_pool, "Test Server Packet Pool", PACKET_SIZE,
159 pointer, PACKET_SIZE * 8);
160 pointer = pointer + PACKET_SIZE * 8;
161 if (status)
162 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
163
164 /* Create an IP instance. */
165 status = nx_ip_create(&server_ip, "Test Server IP", TEST_SERVER_ADDRESS,
166 0xFFFFFF00UL, &server_pool, _nx_ram_network_driver_1024,
167 pointer, 2048, 1);
168 pointer = pointer + 2048;
169 if (status)
170 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
171
172 /* Enable ARP and supply ARP cache memory for the server IP instance. */
173 status = nx_arp_enable(&server_ip, (void *) pointer, 1024);
174 pointer = pointer + 1024;
175 if (status)
176 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
177
178 /* Enable TCP traffic. */
179 status = nx_tcp_enable(&server_ip);
180 if (status)
181 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
182
183 /* Create the Test Client thread. */
184 status = tx_thread_create(&client_thread, "Test Client", thread_client_entry, 0,
185 pointer, DEMO_STACK_SIZE,
186 6, 6, TX_NO_TIME_SLICE, TX_AUTO_START);
187 pointer = pointer + DEMO_STACK_SIZE;
188 if (status)
189 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
190
191 /* Create the Client packet pool. */
192 status = nx_packet_pool_create(&client_pool, "Test Client Packet Pool", PACKET_SIZE,
193 pointer, PACKET_SIZE * 8);
194 pointer = pointer + PACKET_SIZE * 8;
195 if (status)
196 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
197
198 /* Create an IP instance. */
199 status = nx_ip_create(&client_ip, "Test Client IP", TEST_CLIENT_ADDRESS,
200 0xFFFFFF00UL, &client_pool, _nx_ram_network_driver_1024,
201 pointer, 2048, 1);
202 pointer = pointer + 2048;
203 if (status)
204 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
205
206 status = nx_arp_enable(&client_ip, (void *) pointer, 1024);
207 pointer = pointer + 1024;
208 if (status)
209 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
210
211 /* Enable TCP traffic. */
212 status = nx_tcp_enable(&client_ip);
213 if (status)
214 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
215 }
216
thread_client_entry(ULONG thread_input)217 void thread_client_entry(ULONG thread_input)
218 {
219 UINT i, status;
220 NX_PACKET *packet_ptr;
221 NX_PACKET *packet_ptr1;
222 NX_PACKET *packet_ptr2;
223 NX_PACKET *packet_ptr3;
224 NXD_ADDRESS server_ip_address;
225 UINT code;
226
227 /* Create client socket. */
228 status = nx_tcp_socket_create(&client_ip, &test_client, "Client Socket", NX_IP_NORMAL, NX_FRAGMENT_OKAY,
229 NX_IP_TIME_TO_LIVE, 1460, NX_NULL, NX_NULL);
230 if(status)
231 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
232
233 /* Create WebSocket. */
234 status = nx_websocket_client_create(&client_websocket, (UCHAR *)" ", &client_ip, &client_pool);
235
236 /* Check status. */
237 if (status)
238 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
239
240 /* Give IP task and driver a chance to initialize the system. */
241 tx_thread_sleep(NX_IP_PERIODIC_RATE);
242
243 /* Bind and connect to server. */
244 status = nx_tcp_client_socket_bind(&test_client, TEST_SERVER_PORT, NX_IP_PERIODIC_RATE);
245 if(status)
246 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
247
248 /* Wait test server started. */
249 while(!test_server_start)
250 {
251 tx_thread_sleep(NX_IP_PERIODIC_RATE);
252 }
253
254 /* Set server IP address. */
255 server_ip_address.nxd_ip_address.v4 = TEST_SERVER_ADDRESS;
256 server_ip_address.nxd_ip_version = NX_IP_VERSION_V4;
257
258 /* Connect to the server */
259 status = nxd_tcp_client_socket_connect(&test_client, &server_ip_address, TEST_SERVER_PORT, NX_WAIT_FOREVER);
260 if(status)
261 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
262
263 /* Upgrade to websocket */
264 status = nx_websocket_client_connect(&client_websocket, &test_client,
265 TEST_HOST_NAME, sizeof(TEST_HOST_NAME) - 1,
266 (UCHAR *)TEST_URI_PATH, sizeof(TEST_URI_PATH) - 1,
267 (UCHAR *)TEST_PROTOCOL, sizeof(TEST_PROTOCOL) - 1,
268 NX_WAIT_FOREVER);
269
270 if (status)
271 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
272 else
273 {
274 status = nx_packet_allocate(&client_pool, &packet_ptr1, NX_TCP_PACKET, NX_IP_PERIODIC_RATE);
275 if (status)
276 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
277 status = nx_packet_allocate(&client_pool, &packet_ptr2, NX_TCP_PACKET, NX_IP_PERIODIC_RATE);
278 if (status)
279 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
280 status = nx_packet_allocate(&client_pool, &packet_ptr3, NX_TCP_PACKET, NX_IP_PERIODIC_RATE);
281 if (status)
282 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
283
284 /* Copy the contents of the current packet into the new allocated packet; and update the packet length */
285 memcpy((void *)&packet_ptr1 -> nx_packet_prepend_ptr[0], (void *)client_send_frame_packet_1, sizeof(client_send_frame_packet_1));
286 packet_ptr1 -> nx_packet_append_ptr += sizeof(client_send_frame_packet_1);
287 packet_ptr1 -> nx_packet_length = sizeof(client_send_frame_packet_1) + sizeof(client_send_frame_packet_2) + sizeof(client_send_frame_packet_3);
288
289 memcpy((void *)&packet_ptr2 -> nx_packet_prepend_ptr[0], (void *)client_send_frame_packet_2, sizeof(client_send_frame_packet_2));
290 packet_ptr2 -> nx_packet_append_ptr += sizeof(client_send_frame_packet_2);
291 packet_ptr2 -> nx_packet_length = sizeof(client_send_frame_packet_2);
292
293 memcpy((void *)&packet_ptr3 -> nx_packet_prepend_ptr[0], (void *)client_send_frame_packet_3, sizeof(client_send_frame_packet_3));
294 packet_ptr3 -> nx_packet_append_ptr += sizeof(client_send_frame_packet_3);
295 packet_ptr3 -> nx_packet_length = sizeof(client_send_frame_packet_3);
296
297 packet_ptr1 -> nx_packet_next = packet_ptr2;
298 packet_ptr2 -> nx_packet_next = packet_ptr3;
299 packet_ptr3 -> nx_packet_next = NX_NULL;
300 packet_ptr1 -> nx_packet_last = packet_ptr3;
301
302 status = nx_websocket_client_send(&client_websocket, packet_ptr1, NX_WEBSOCKET_OPCODE_BINARY_FRAME, NX_TRUE, NX_WAIT_FOREVER);
303 if (status)
304 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
305
306 /* Receive the responsed data from server. */
307 status = nx_websocket_client_receive(&client_websocket, &packet_ptr, &code, 5 * NX_IP_PERIODIC_RATE);
308 if (status != NX_NO_PACKET)
309 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
310 }
311
312 nx_tcp_client_socket_unbind(&test_client);
313 nx_tcp_socket_delete(&test_client);
314
315 test_done = NX_TRUE;
316 }
317
318 /* Define the helper Test server thread. */
thread_server_entry(ULONG thread_input)319 void thread_server_entry(ULONG thread_input)
320 {
321 UINT i, status;
322 NX_PACKET *packet_ptr;
323
324
325 /* Print out test information banner. */
326 printf("NetX Test: Websocket Send Chain Packets Test.....................................");
327
328 /* Check for earlier error. */
329 if(error_counter)
330 {
331 printf("ERROR!\n");
332 test_control_return(1);
333 }
334
335 /* Give NetX a chance to initialize the system. */
336 tx_thread_sleep(NX_IP_PERIODIC_RATE);
337
338 status = nx_tcp_socket_create(&server_ip, &test_server, "Test Server Socket",
339 NX_IP_NORMAL, NX_FRAGMENT_OKAY, NX_IP_TIME_TO_LIVE, 1460,
340 NX_NULL, NX_NULL);
341
342 status = nx_tcp_server_socket_listen(&server_ip, TEST_SERVER_PORT, &test_server, 5, NX_NULL);
343 if(status)
344 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
345
346 /* Set the flag. */
347 test_server_start = 1;
348
349 /* Accept a connection from test client. */
350 status = nx_tcp_server_socket_accept(&test_server, 5 * NX_IP_PERIODIC_RATE);
351 if(status)
352 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
353
354 for (i = 0; i < TEST_LOOP; i++)
355 {
356
357 /* Receive client data. */
358 status = nx_tcp_socket_receive(&test_server, &packet_ptr, 5 * NX_IP_PERIODIC_RATE);
359 if(status)
360 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
361 else
362 {
363 /* Response data. */
364 switch (i)
365 {
366 case 0:
367 /* Update the value in the field Sec-Protocol-Accept since it is calculated based on a random value */
368 _server_connect_response_process(packet_ptr);
369 memcpy(&server_switch_101[127], connect_key, 28);
370
371 packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr;
372 packet_ptr -> nx_packet_length = 0;
373 nx_packet_data_append(packet_ptr, server_switch_101, sizeof(server_switch_101), &server_pool, NX_IP_PERIODIC_RATE);
374 status = nx_tcp_socket_send(&test_server, packet_ptr, NX_IP_PERIODIC_RATE);
375 if(status)
376 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
377 break;
378 case 1:
379 packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr;
380 packet_ptr -> nx_packet_length = 0;
381 nx_packet_data_append(packet_ptr, server_test_data, sizeof(server_test_data), &server_pool, NX_IP_PERIODIC_RATE);
382 status = nx_tcp_socket_send(&test_server, packet_ptr, NX_IP_PERIODIC_RATE);
383 if(status)
384 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
385 break;
386 default:
387 break;
388 }
389 }
390 }
391
392 /* Wait for test done. */
393 while (test_done == NX_FALSE)
394 {
395 tx_thread_sleep(NX_IP_PERIODIC_RATE);
396 }
397
398 nx_tcp_server_socket_unlisten(&server_ip, TEST_SERVER_PORT);
399 nx_tcp_socket_delete(&test_server);
400
401 if (client_pool.nx_packet_pool_available != client_pool.nx_packet_pool_total)
402 {
403 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
404 }
405 else if (client_pool.nx_packet_pool_invalid_releases)
406 {
407 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
408 }
409
410 if (server_pool.nx_packet_pool_available != server_pool.nx_packet_pool_total)
411 {
412 SET_ERROR_COUNTER(&error_counter, __FILE__, __LINE__);
413 }
414
415 if(error_counter)
416 {
417 printf("ERROR!\n");
418 test_control_return(1);
419 }
420 else
421 {
422 printf("SUCCESS!\n");
423 test_control_return(0);
424 }
425 }
426
427 #else
428
429 #ifdef CTEST
test_application_define(void * first_unused_memory)430 VOID test_application_define(void *first_unused_memory)
431 #else
432 void netx_websocket_send_chain_packets_test_application_define(void *first_unused_memory)
433 #endif
434 {
435
436 /* Print out test information banner. */
437 printf("NetX Test: Websocket Send Chain Packets Test.....................................N/A\n");
438
439 test_control_return(3);
440 }
441 #endif
442
443