1 /* This is the test control routine the NetX TCP/IP stack. All tests are dispatched from this routine. */
2
3 #include "tx_api.h"
4 #include "fx_api.h"
5 #include "nx_api.h"
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include "nx_ram_network_driver_test_1500.h"
9
10 /*
11 #define NETXTEST_TIMEOUT_DISABLE
12 */
13
14 #define TEST_STACK_SIZE 4096
15
16 /* 1 minute. */
17 #define TEST_TIMEOUT_LOW (60 * NX_IP_PERIODIC_RATE)
18 /* 15 minutes. */
19 #define TEST_TIMEOUT_MID (900 * NX_IP_PERIODIC_RATE)
20 /* 120 minutes. */
21 #define TEST_TIMEOUT_HIGH (7200 * NX_IP_PERIODIC_RATE)
22
23 /* Define the test control ThreadX objects... */
24
25 TX_THREAD test_control_thread;
26 #ifndef NETXTEST_TIMEOUT_DISABLE
27 TX_SEMAPHORE test_control_sema;
28 #endif
29
30 /* Define the test control global variables. */
31
32 ULONG test_control_return_status;
33 ULONG test_control_successful_tests;
34 ULONG test_control_failed_tests;
35 ULONG test_control_warning_tests;
36 ULONG test_control_na_tests;
37
38 /* Remember the start of free memory. */
39
40 UCHAR *test_free_memory_ptr;
41
42 extern volatile UINT _tx_thread_preempt_disable;
43
44 /* Define test entry pointer type. */
45
46 typedef struct TEST_ENTRY_STRUCT
47 {
48 VOID (*test_entry)(void *);
49 UINT timeout;
50 } TEST_ENTRY;
51
52
53 /* Define the prototypes for the test entry points. */
54 void netx_https_api_test(void*);
55 void netx_web_basic_test_application_define(void *);
56 void netx_web_basic_ecc_test_application_define(void *);
57 void netx_web_put_basic_test_application_define(void *);
58 void netx_web_post_basic_test_application_define(void *);
59 void netx_web_delete_basic_test_application_define(void *);
60 void netx_web_head_basic_test_application_define(void *);
61 void netx_web_request_in_multiple_packets_test_application_define(void *);
62 void netx_web_basic_authenticate_test_application_define(void *);
63 void netx_web_if_modified_since_test_application_define(void *);
64 void netx_web_status_400_test_application_define(void *);
65 void netx_web_status_404_test_application_define(void *);
66 void netx_web_status_501_test_application_define(void *);
67 void netx_web_get_content_length_test_application_define(void *);
68 void netx_web_get_put_referred_URI_test_application_define(void *);
69 void netx_web_multipart_fragment_test_application_define(void *);
70 void netx_web_multipart_underflow_test_application_define(void *);
71 void netx_web_multiple_sessions_test_application_define(void *);
72 void netx_web_multiple_sessions_timeout_test_application_define(void *);
73 void netx_web_response_in_multiple_packets_test_application_define(void *);
74 void netx_web_connect_three_times_test_application_define(void *);
75 void netx_web_keep_alive_test_application_define(void *);
76 void netx_web_digest_authenticate_test_application_define(void *);
77 void netx_web_digest_authenticate_test_2_application_define(void *);
78 void netx_web_server_content_process_test_application_define(void *);
79 void netx_web_concurrent_sessions_test_application_define(void *);
80 void netx_web_post_basic_test_application_define(void *first_unused_memory);
81 void netx_web_post_large_packet_test_application_define(void *first_unused_memory);
82 void netx_web_host_field_test_application_define(void *);
83 void netx_web_chunked_request_test_application_define(void *);
84 void netx_web_chunked_request_additional_test_application_define(void *);
85 void netx_web_chunked_response_test_application_define(void *);
86 void netx_web_chunked_response_process_test_application_define(void *);
87 void netx_web_chunked_response_packet_chain_test_application_define(void *);
88 void netx_web_client_cleanup_test_application_define(void *);
89 void netx_web_server_chunked_content_process_test_application_define(void *);
90 void netx_web_packet_allocate_test_application_define(void *);
91 void netx_web_status_code_test_application_define(void *);
92 void netx_web_secure_connect_fail_test_application_define(void *);
93 void netx_web_tcpserver_rst_test_application_define(void *);
94 void netx_web_tcpserver_two_listen_test_application_define(void *);
95 void netx_web_abnormal_test_application_define(void *);
96 void netx_web_client_send_fail_test_application_define(void *);
97 void netx_web_client_receive_no_packet_test_application_define(void *);
98 void netx_web_keep_alive_abnormal_test_application_define(void *);
99 void netx_web_one_session_test_application_define(void *);
100 void netx_web_server_type_get_extended_test_application_define(void *);
101 void netx_web_secure_reconnect_test_application_define(void *);
102 void netx_web_non_block_basic_test_application_define(void *);
103 void netx_web_non_block_reconnect_test_application_define(void *);
104 void netx_web_tcpserver_tls_faile_rst_test_application_define(void *);
105 void netx_web_invalid_release_test_application_define(void *);
106 void netx_web_certifiacet_verify_test_application_define(void *);
107 void netx_web_client_rst_test_application_define(void *);
108 void netx_web_basic_authenticate_empty_test_application_define(void *);
109 void netx_web_digest_authenticate_timeout_test_application_define(void *);
110 void test_application_define(void *);
111
112 /* Define the array of test entry points. */
113
114 TEST_ENTRY test_control_tests[] =
115 {
116 #ifdef CTEST
117 {test_application_define, TEST_TIMEOUT_MID},
118 #else /* CTEST */
119 {netx_https_api_test, TEST_TIMEOUT_MID},
120 {netx_web_basic_test_application_define, TEST_TIMEOUT_LOW},
121 {netx_web_basic_ecc_test_application_define, TEST_TIMEOUT_LOW},
122 {netx_web_basic_authenticate_test_application_define, TEST_TIMEOUT_LOW},
123 {netx_web_request_in_multiple_packets_test_application_define, TEST_TIMEOUT_LOW},
124 {netx_web_if_modified_since_test_application_define, TEST_TIMEOUT_LOW},
125 {netx_web_get_content_length_test_application_define, TEST_TIMEOUT_LOW},
126 {netx_web_multipart_fragment_test_application_define, TEST_TIMEOUT_LOW},
127 {netx_web_multipart_underflow_test_application_define, TEST_TIMEOUT_LOW},
128 {netx_web_status_404_test_application_define, TEST_TIMEOUT_LOW},
129 {netx_web_multiple_sessions_test_application_define, TEST_TIMEOUT_LOW},
130 {netx_web_multiple_sessions_timeout_test_application_define, TEST_TIMEOUT_LOW},
131 {netx_web_response_in_multiple_packets_test_application_define, TEST_TIMEOUT_LOW},
132 {netx_web_connect_three_times_test_application_define, TEST_TIMEOUT_LOW},
133 {netx_web_put_basic_test_application_define, TEST_TIMEOUT_LOW},
134 {netx_web_post_basic_test_application_define, TEST_TIMEOUT_LOW},
135 {netx_web_head_basic_test_application_define, TEST_TIMEOUT_LOW},
136 {netx_web_delete_basic_test_application_define, TEST_TIMEOUT_LOW},
137 {netx_web_get_put_referred_URI_test_application_define, TEST_TIMEOUT_LOW},
138 {netx_web_digest_authenticate_test_application_define, TEST_TIMEOUT_LOW},
139 {netx_web_digest_authenticate_test_2_application_define, TEST_TIMEOUT_LOW},
140 {netx_web_server_content_process_test_application_define, TEST_TIMEOUT_LOW},
141 {netx_web_concurrent_sessions_test_application_define, TEST_TIMEOUT_MID},
142 {netx_web_post_large_packet_test_application_define, TEST_TIMEOUT_LOW},
143 {netx_web_host_field_test_application_define, TEST_TIMEOUT_LOW},
144 {netx_web_chunked_response_test_application_define, TEST_TIMEOUT_LOW},
145 {netx_web_chunked_request_test_application_define, TEST_TIMEOUT_LOW},
146 {netx_web_chunked_request_additional_test_application_define, TEST_TIMEOUT_LOW},
147 {netx_web_chunked_response_process_test_application_define, TEST_TIMEOUT_LOW},
148 {netx_web_chunked_response_packet_chain_test_application_define, TEST_TIMEOUT_LOW},
149 {netx_web_client_cleanup_test_application_define, TEST_TIMEOUT_LOW},
150 {netx_web_keep_alive_test_application_define, TEST_TIMEOUT_LOW},
151 {netx_web_server_chunked_content_process_test_application_define, TEST_TIMEOUT_LOW},
152 {netx_web_packet_allocate_test_application_define, TEST_TIMEOUT_LOW},
153 {netx_web_status_code_test_application_define, TEST_TIMEOUT_MID},
154 {netx_web_secure_connect_fail_test_application_define,TEST_TIMEOUT_LOW},
155 {netx_web_tcpserver_rst_test_application_define,TEST_TIMEOUT_LOW},
156 {netx_web_tcpserver_two_listen_test_application_define,TEST_TIMEOUT_LOW},
157 {netx_web_abnormal_test_application_define, TEST_TIMEOUT_LOW},
158 {netx_web_client_send_fail_test_application_define, TEST_TIMEOUT_LOW},
159 {netx_web_client_receive_no_packet_test_application_define, TEST_TIMEOUT_LOW},
160 {netx_web_keep_alive_abnormal_test_application_define, TEST_TIMEOUT_LOW},
161 {netx_web_one_session_test_application_define, TEST_TIMEOUT_LOW},
162 {netx_web_server_type_get_extended_test_application_define, TEST_TIMEOUT_LOW},
163 {netx_web_secure_reconnect_test_application_define, TEST_TIMEOUT_LOW},
164 {netx_web_non_block_basic_test_application_define, TEST_TIMEOUT_LOW},
165 {netx_web_non_block_reconnect_test_application_define, TEST_TIMEOUT_LOW},
166 {netx_web_tcpserver_tls_faile_rst_test_application_define, TEST_TIMEOUT_LOW},
167 {netx_web_invalid_release_test_application_define, TEST_TIMEOUT_LOW},
168 {netx_web_certifiacet_verify_test_application_define, TEST_TIMEOUT_LOW},
169 {netx_web_client_rst_test_application_define, TEST_TIMEOUT_LOW},
170 {netx_web_basic_authenticate_empty_test_application_define, TEST_TIMEOUT_LOW},
171 {netx_web_digest_authenticate_timeout_test_application_define, TEST_TIMEOUT_LOW},
172
173 /* Not support. */
174 #if 0
175 {netx_web_status_400_test_application_define, TEST_TIMEOUT_LOW},
176 {netx_web_status_501_test_application_define, TEST_TIMEOUT_LOW},
177 #endif
178 #endif /* CTEST */
179 {TX_NULL, TEST_TIMEOUT_LOW},
180 };
181
182 /* Define thread prototypes. */
183
184 void test_control_thread_entry(ULONG thread_input);
185 void test_control_return(UINT status);
186 void test_control_cleanup(void);
187 void _nx_ram_network_driver_reset(void);
188
189 /* Define necessary external references. */
190
191 #ifdef __ghs
192 extern TX_MUTEX __ghLockMutex;
193 #endif
194
195 extern TX_TIMER *_tx_timer_created_ptr;
196 extern ULONG _tx_timer_created_count;
197 #ifndef TX_TIMER_PROCESS_IN_ISR
198 extern TX_THREAD _tx_timer_thread;
199 #endif
200 extern TX_THREAD *_tx_thread_created_ptr;
201 extern ULONG _tx_thread_created_count;
202 extern TX_SEMAPHORE *_tx_semaphore_created_ptr;
203 extern ULONG _tx_semaphore_created_count;
204 extern TX_QUEUE *_tx_queue_created_ptr;
205 extern ULONG _tx_queue_created_count;
206 extern TX_MUTEX *_tx_mutex_created_ptr;
207 extern ULONG _tx_mutex_created_count;
208 extern TX_EVENT_FLAGS_GROUP *_tx_event_flags_created_ptr;
209 extern ULONG _tx_event_flags_created_count;
210 extern TX_BYTE_POOL *_tx_byte_pool_created_ptr;
211 extern ULONG _tx_byte_pool_created_count;
212 extern TX_BLOCK_POOL *_tx_block_pool_created_ptr;
213 extern ULONG _tx_block_pool_created_count;
214
215 extern NX_PACKET_POOL * _nx_packet_pool_created_ptr;
216 extern ULONG _nx_packet_pool_created_count;
217 extern NX_IP * _nx_ip_created_ptr;
218 extern ULONG _nx_ip_created_count;
219
220 /* Define main entry point. */
221
main()222 int main()
223 {
224 /* Enter the ThreadX kernel. */
225 tx_kernel_enter();
226
227
228 return 0;
229 }
230
231 //#define TEST_FREE_MEMORY_POOL_SIZE (100 * 1024)
232 //static ULONG test_free_memory_pool[TEST_FREE_MEMORY_POOL_SIZE / sizeof(ULONG)];
233 /* Define what the initial system looks like. */
234
tx_application_define(void * first_unused_memory)235 void tx_application_define(void *first_unused_memory)
236 {
237 UCHAR *pointer;
238
239 /* Setup a pointer to the first unused memory. */
240 pointer = (UCHAR *) first_unused_memory;
241
242 /* Create the test control thread. */
243 tx_thread_create(&test_control_thread, "test control thread", test_control_thread_entry, 0,
244 pointer, TEST_STACK_SIZE,
245 0, 0, TX_NO_TIME_SLICE, TX_AUTO_START);
246 pointer = pointer + TEST_STACK_SIZE;
247
248 #ifndef NETXTEST_TIMEOUT_DISABLE
249 /* Create the test control semaphore. */
250 tx_semaphore_create(&test_control_sema, "HTTPS Test control semaphore", 0);
251 #endif
252
253 /* Remember the free memory pointer. */
254 //test_free_memory_ptr = (UCHAR*)test_free_memory_pool;
255 test_free_memory_ptr = pointer;
256
257 fx_system_initialize();
258 }
259
260 /* Define the test control thread. This thread is responsible for dispatching all of the
261 tests in the ThreadX test suite. */
262
test_control_thread_entry(ULONG thread_input)263 void test_control_thread_entry(ULONG thread_input)
264 {
265 UINT i;
266
267 /* Loop to process all tests... */
268 i = 0;
269 while (test_control_tests[i].test_entry != TX_NULL)
270 {
271
272 /* Dispatch the test. */
273 (test_control_tests[i++].test_entry)(test_free_memory_ptr);
274
275 if (test_control_return_status != 3)
276 {
277
278 #ifdef NETXTEST_TIMEOUT_DISABLE
279 /* Suspend control test to allow test to run. */
280 tx_thread_suspend(&test_control_thread);
281 #else
282 if(tx_semaphore_get(&test_control_sema, test_control_tests[i - 1].timeout))
283 {
284
285 /* Test case timeouts. */
286 printf("ERROR!\n");
287 test_control_failed_tests++;
288
289 }
290 #endif
291 }
292 else
293 test_control_return_status = 0;
294
295 /* Test finished, cleanup in preparation for the next test. */
296 test_control_cleanup();
297 fflush(stdout);
298 }
299
300 /* Finished with all tests, print results and return! */
301 printf("**** Testing Complete ****\n");
302 printf("**** Test Summary: Tests Passed: %lu Tests Warning: %lu Tests Failed: %lu\n", test_control_successful_tests, test_control_warning_tests, test_control_failed_tests);
303 #if 0
304 fclose(stream);
305 #endif
306 #ifdef BATCH_TEST
307 exit(test_control_failed_tests);
308 #endif
309
310
311 }
312
test_control_return(UINT status)313 void test_control_return(UINT status)
314 {
315 UINT old_posture = TX_INT_ENABLE;
316
317 /* Save the status in a global. */
318 test_control_return_status = status;
319
320 /* Ensure interrupts are enabled. */
321 old_posture = tx_interrupt_control(TX_INT_ENABLE);
322
323 /* Determine if it was successful or not. */
324 if((status == 1) || (_tx_thread_preempt_disable) || (old_posture == TX_INT_DISABLE))
325 test_control_failed_tests++;
326 else if(status == 2)
327 test_control_warning_tests++;
328 else if(status == 0)
329 test_control_successful_tests++;
330 else if(status == 3)
331 test_control_na_tests++;
332
333 #ifdef NETXTEST_TIMEOUT_DISABLE
334 /* Resume the control thread to fully exit the test. */
335 tx_thread_resume(&test_control_thread);
336 #else
337 if(test_control_return_status != 3)
338 tx_semaphore_put(&test_control_sema);
339 #endif
340 }
341
test_control_cleanup(void)342 void test_control_cleanup(void)
343 {
344 TX_MUTEX *mutex_ptr;
345 TX_THREAD *thread_ptr;
346
347 /* Clean timer used by RAM driver. */
348 _nx_ram_network_driver_timer_clean();
349
350 /* Delete all IP instances. */
351 while (_nx_ip_created_ptr)
352 {
353
354 /* Delete all UDP sockets. */
355 while (_nx_ip_created_ptr -> nx_ip_udp_created_sockets_ptr)
356 {
357
358 /* Make sure the UDP socket is unbound. */
359 nx_udp_socket_unbind(_nx_ip_created_ptr -> nx_ip_udp_created_sockets_ptr);
360
361 /* Delete the UDP socket. */
362 nx_udp_socket_delete(_nx_ip_created_ptr -> nx_ip_udp_created_sockets_ptr);
363 }
364
365 /* Delete all TCP sockets. */
366 while (_nx_ip_created_ptr -> nx_ip_tcp_created_sockets_ptr)
367 {
368
369 /* Disconnect. */
370 nx_tcp_socket_disconnect(_nx_ip_created_ptr -> nx_ip_tcp_created_sockets_ptr, NX_NO_WAIT);
371
372 /* Make sure the TCP client socket is unbound. */
373 nx_tcp_client_socket_unbind(_nx_ip_created_ptr -> nx_ip_tcp_created_sockets_ptr);
374
375 /* Make sure the TCP server socket is unaccepted. */
376 nx_tcp_server_socket_unaccept(_nx_ip_created_ptr -> nx_ip_tcp_created_sockets_ptr);
377
378 /* Delete the TCP socket. */
379 nx_tcp_socket_delete(_nx_ip_created_ptr -> nx_ip_tcp_created_sockets_ptr);
380 }
381
382 /* Clear all listen requests. */
383 while (_nx_ip_created_ptr -> nx_ip_tcp_active_listen_requests)
384 {
385
386 /* Make sure the TCP server socket is unlistened. */
387 nx_tcp_server_socket_unlisten(_nx_ip_created_ptr, (_nx_ip_created_ptr -> nx_ip_tcp_active_listen_requests) -> nx_tcp_listen_port);
388 }
389
390 /* Delete the IP instance. */
391 nx_ip_delete(_nx_ip_created_ptr);
392 }
393
394 /* Delete all the packet pools. */
395 while (_nx_packet_pool_created_ptr)
396 {
397 nx_packet_pool_delete(_nx_packet_pool_created_ptr);
398 }
399
400 /* Reset the RAM driver. */
401 _nx_ram_network_driver_reset();
402
403 /* Delete all queues. */
404 while(_tx_queue_created_ptr)
405 {
406
407 /* Delete queue. */
408 tx_queue_delete(_tx_queue_created_ptr);
409 }
410
411 /* Delete all semaphores. */
412 while(_tx_semaphore_created_ptr)
413 {
414 #ifndef NETXTEST_TIMEOUT_DISABLE
415 if(_tx_semaphore_created_ptr != &test_control_sema)
416 {
417
418 /* Delete semaphore. */
419 tx_semaphore_delete(_tx_semaphore_created_ptr);
420 }
421 else if(_tx_semaphore_created_count == 1)
422 break;
423 else
424 {
425 /* Delete semaphore. */
426 tx_semaphore_delete(_tx_semaphore_created_ptr -> tx_semaphore_created_next);
427 }
428 #else
429 /* Delete semaphore. */
430 tx_semaphore_delete(_tx_semaphore_created_ptr);
431 #endif
432 }
433
434 /* Delete all event flag groups. */
435 while(_tx_event_flags_created_ptr)
436 {
437
438 /* Delete event flag group. */
439 tx_event_flags_delete(_tx_event_flags_created_ptr);
440 }
441
442 /* Delete all byte pools. */
443 while(_tx_byte_pool_created_ptr)
444 {
445
446 /* Delete byte pool. */
447 tx_byte_pool_delete(_tx_byte_pool_created_ptr);
448 }
449
450 /* Delete all block pools. */
451 while(_tx_block_pool_created_ptr)
452 {
453
454 /* Delete block pool. */
455 tx_block_pool_delete(_tx_block_pool_created_ptr);
456 }
457
458 /* Delete all timers. */
459 while(_tx_timer_created_ptr)
460 {
461
462 /* Deactivate timer. */
463 tx_timer_deactivate(_tx_timer_created_ptr);
464
465 /* Delete timer. */
466 tx_timer_delete(_tx_timer_created_ptr);
467 }
468
469 /* Delete all mutexes (except for system mutex). */
470 while(_tx_mutex_created_ptr)
471 {
472
473 /* Setup working mutex pointer. */
474 mutex_ptr = _tx_mutex_created_ptr;
475
476 #ifdef __ghs
477
478 /* Determine if the mutex is the GHS system mutex. If so, don't delete! */
479 if(mutex_ptr == &__ghLockMutex)
480 {
481
482 /* Move to next mutex. */
483 mutex_ptr = mutex_ptr -> tx_mutex_created_next;
484 }
485
486 /* Determine if there are no more mutexes to delete. */
487 if(_tx_mutex_created_count == 1)
488 break;
489 #endif
490
491 /* Delete mutex. */
492 tx_mutex_delete(mutex_ptr);
493 }
494
495 /* Delete all threads, except for timer thread, and test control thread. */
496 while (_tx_thread_created_ptr)
497 {
498
499 /* Setup working pointer. */
500 thread_ptr = _tx_thread_created_ptr;
501
502 #ifdef TX_TIMER_PROCESS_IN_ISR
503
504 /* Determine if there are more threads to delete. */
505 if(_tx_thread_created_count == 1)
506 break;
507
508 /* Determine if this thread is the test control thread. */
509 if(thread_ptr == &test_control_thread)
510 {
511
512 /* Move to the next thread pointer. */
513 thread_ptr = thread_ptr -> tx_thread_created_next;
514 }
515 #else
516
517 /* Determine if there are more threads to delete. */
518 if(_tx_thread_created_count == 2)
519 break;
520
521 /* Move to the thread not protected. */
522 while ((thread_ptr == &_tx_timer_thread) || (thread_ptr == &test_control_thread))
523 {
524
525 /* Yes, move to the next thread. */
526 thread_ptr = thread_ptr -> tx_thread_created_next;
527 }
528 #endif
529
530 /* First terminate the thread to ensure it is ready for deletion. */
531 tx_thread_terminate(thread_ptr);
532
533 /* Delete the thread. */
534 tx_thread_delete(thread_ptr);
535 }
536
537 /* At this point, only the test control thread and the system timer thread and/or mutex should still be
538 in the system. */
539
540
541 }
542
SET_ERROR_COUNTER(ULONG * error_counter,CHAR * filename,int line_number)543 void SET_ERROR_COUNTER(ULONG *error_counter, CHAR *filename, int line_number)
544 {
545 *error_counter = (*error_counter) + 1;
546
547 printf("Error: File %s:%d\n", filename, line_number);
548
549
550
551 }
552