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