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 "nx_api.h"
5 #include "nx_secure_tls.h"
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include "nx_secure_tls.h"
9 #include "nx_ram_network_driver_test_1500.h"
10 
11 /* Check version definitions. */
12 #ifndef __PRODUCT_NETX_SECURE__
13 #error "__PRODUCT_NETX_SECURE__ is not defined."
14 #endif /* __PRODUCT_NETX_SECURE__ */
15 
16 #if defined(EXPECTED_MAJOR_VERSION) && ( !defined(__NETX_SECURE_MAJOR_VERSION__) || (__NETX_SECURE_MAJOR_VERSION__ != EXPECTED_MAJOR_VERSION))
17 #error "__NETX_SECURE_MAJOR_VERSION__"
18 #endif /* EXPECTED_MAJOR_VERSION */
19 
20 #if defined(EXPECTED_MINOR_VERSION) && ( !defined(__NETX_SECURE_MINOR_VERSION__) || (__NETX_SECURE_MINOR_VERSION__ != EXPECTED_MINOR_VERSION))
21 #error "__NETX_SECURE_MINOR_VERSION__"
22 #endif /* EXPECTED_MINOR_VERSION */
23 
24 #if defined(__linux__) && defined(USE_FORK)
25 #undef __suseconds_t_defined
26 #undef _STRUCT_TIMEVAL
27 #undef _SYS_SELECT_H
28 #include <unistd.h>
29 #include <signal.h>
30 #include <sys/wait.h>
31 #include <sys/poll.h>
32 
33 void fork_child();
34 #endif
35 
36 /*
37 #define NETXTEST_TIMEOUT_DISABLE
38 */
39 
40  FILE *stream;
41 
42 #define TEST_STACK_SIZE         4096
43 
44 /* 1 minute. */
45 #define TEST_TIMEOUT_LOW        (60 * NX_IP_PERIODIC_RATE)
46 /* 15 minutes. */
47 #define TEST_TIMEOUT_MID        (900 * NX_IP_PERIODIC_RATE)
48 /* 120 minutes. */
49 #define TEST_TIMEOUT_HIGH       (7200 * NX_IP_PERIODIC_RATE)
50 
51 /* Define the test control ThreadX objects...  */
52 
53 TX_THREAD       test_control_thread;
54 #ifndef NETXTEST_TIMEOUT_DISABLE
55 TX_SEMAPHORE    test_control_sema;
56 #endif
57 
58 /* Define the test control global variables.   */
59 
60 ULONG           test_control_return_status;
61 ULONG           test_control_successful_tests;
62 ULONG           test_control_failed_tests;
63 ULONG           test_control_warning_tests;
64 ULONG           test_control_na_tests;
65 
66 /* Remember the start of free memory.  */
67 
68 UCHAR           *test_free_memory_ptr;
69 
70 extern volatile UINT   _tx_thread_preempt_disable;
71 
72 /* Define test entry pointer type.  */
73 
74 typedef  struct TEST_ENTRY_STRUCT
75 {
76     VOID        (*test_entry)(void *);
77     UINT        timeout;
78 } TEST_ENTRY;
79 
80 
81 /* Define the prototypes for the test entry points.  */
82 VOID nx_secure_tls_session_receive_coverage_test_application_define(void *);
83 VOID nx_secure_tls_send_record_coverage_test_application_define(void *);
84 void nx_secure_tls_client_handshake_coverage_test_application_define(void *);
85 void nx_secure_tls_finished_hash_coverage_test_application_define(void *);
86 void nx_secure_tls_generate_key_coverage_test_application_define(void *);
87 void nx_secure_tls_generate_premaster_coverage_test_application_define(void *);
88 void nx_secure_tls_handshake_hash_coverage_test_application_define(void *);
89 void nx_secure_tls_ecc_generate_keys_coverage_test_application_define(void *);
90 void nx_secure_tls_session_renegotiate_coverage_test_application_define(void*);
91 void nx_secure_tls_session_keys_set_coverage_test_application_define(void*);
92 void nx_secure_tls_newest_supported_version_test_application_define(void *);
93 void nx_secure_tls_verify_mac_test_application_define(void*);
94 void nx_secure_sha224_test_application_define(void *);
95 void nx_secure_sha256_test_application_define(void *);
96 void nx_secure_sha256_rfc_test_application_define(void *);
97 void nx_secure_sha384_test_application_define(void *);
98 void nx_secure_sha512_test_application_define(void *);
99 void nx_secure_hmac_md5_test_application_define(void *);
100 void nx_secure_hmac_sha1_test_application_define(void *);
101 void nx_secure_hmac_sha224_test_application_define(void *);
102 void nx_secure_hmac_sha256_test_application_define(void *);
103 void nx_secure_hmac_sha384_test_application_define(void *);
104 void nx_secure_hmac_sha512_test_application_define(void *);
105 void nx_secure_x509_certificate_initialize_test_application_define(void *first_unused_memory);
106 void nx_secure_x509_certificate_verify_test_application_define(void *first_unused_memory);
107 void nx_secure_x509_crl_verify_test_application_define(void *first_unused_memory);
108 void nx_secure_x509_parse_test_application_define(void *);
109 void nx_secure_x509_list_test_application_define(void *);
110 void nx_secure_x509_store_test_application_define(void *);
111 void nx_secure_x509_name_check_test_application_define(void *);
112 void nx_secure_x509_crl_test_application_define(void *);
113 void nx_secure_x509_error_checking_test_application_define(void *first_unused_memory);
114 void nx_secure_x509_expiration_check_test_application_define(void *);
115 void nx_secure_x509_key_usage_test_application_define(void *first_unused_memory);
116 void nx_secure_x509_pkcs7_decode_coverage_test_application_define(void *);
117 void nx_secure_rsa_test_application_define(void *);
118 void nx_secure_aes_test_application_define(void *first_unused_memory);
119 void nx_secure_aes_ccm_test_application_define(void *first_unused_memory);
120 void nx_secure_des_test_application_define(void *first_unused_memory);
121 void nx_secure_3des_test_application_define(void *first_unused_memory);
122 void nx_secure_tls_handshake_header_test_application_define(void *);
123 void nx_secure_tls_header_test_application_define(void *);
124 void nx_secure_phash_prf_test_application_define(void *);
125 void nx_secure_tls_two_way_test_application_define(void *first_unused_memory);
126 void nx_secure_tls_two_way_test_version_1_1_application_define(void *first_unused_memory);
127 void nx_secure_tls_ciphersuites_test_application_define(void *);
128 void nx_secure_tls_cert_verify_test_application_define(void *first_unused_memory);
129 void nx_secure_tls_session_sni_extension_test_application_define(void*);
130 void nx_secure_tls_certificate_coverage_test_application_define(void *);
131 void nx_secure_tls_no_remote_certs_allocated_test_application_define(void *first_unused_memory);
132 void nx_secure_tls_partial_remote_certs_allocated_test_application_define(void *first_unused_memory);
133 void nx_secure_tls_process_certificate_verify_test_application_define(void *first_unused_memory);
134 void nx_secure_tls_client_handshake_test_application_define(void *first_unused_memory);
135 void nx_secure_tls_clienthello_extension_test_application_define(void *first_unused_memory);
136 void nx_secure_tls_coverage_test_application_define(void *first_unused_memory);
137 void nx_secure_tls_coverage_2_test_application_define(void *first_unused_memory);
138 void nx_secure_tls_coverage_3_test_application_define(void *first_unused_memory);
139 void nx_secure_tls_alert_test_application_define(void *first_unused_memory);
140 void nx_secure_tls_error_checking_test_application_define(void *first_unused_memory);
141 void nx_secure_tls_error_checking_2_test_application_define(void *first_unused_memory);
142 void nx_secure_tls_tcp_fragment_test_application_define(void *first_unused_memory);
143 void nx_secure_tls_user_defined_key_test_application_define(void *first_unused_memory);
144 void nx_secure_tls_no_client_cert_test_application_define(void *first_unused_memory);
145 void nx_secure_tls_hash_coverage_test_application_define(void *);
146 void nx_secure_tls_handshake_fail_test_application_define(void *first_unused_memory);
147 void nx_secure_tls_handshake_fragmentation_test_application_define(void *first_unused_memory);
148 void nx_secure_tls_handshake_fragmentation_ecc_test_application_define(void *first_unused_memory);
149 void nx_secure_tls_packet_chain_test_application_define(void *first_unused_memory);
150 void nx_secure_tls_receive_alert_test_application_define(void *first_unused_memory);
151 void nx_secure_tls_receive_test_application_define(void *first_unused_memory);
152 void nx_secure_tls_record_decrypt_coverage_test_application_define(void *);
153 void nx_secure_tls_record_encrypt_coverage_test_application_define(void *);
154 void nx_secure_tls_record_layer_version_test_application_define(void *first_unused_memory);
155 void nx_secure_tls_record_length_test_application_define(void *first_unused_memory);
156 void nx_secure_tls_server_key_exchange_coverage_test_application_define(void *);
157 void nx_secure_tls_serverhello_coverage_test_application_define(void *);
158 void nx_secure_tls_serverhello_extension_test_application_define(void *first_unused_memory);
159 void nx_secure_tls_metadata_size_application_define(void *first_unused_memory);
160 void nx_secure_tls_multiple_handshake_msg_test_application_define(void *first_unused_memory);
161 void nx_secure_tls_multithread_test_application_define(void *first_unused_memory);
162 void nx_secure_tls_unrecognized_ciphersuite_test_application_define(void *first_unused_memory);
163 void nx_secure_tls_unsupported_ciphersuites_test_application_define(void *first_unused_memory);
164 void nx_secure_tls_non_blocking_test_application_define(void *first_unused_memory);
165 void nx_secure_tls_ecc_basic_test_application_define(void *first_unused_memory);
166 void nx_secure_tls_ecc_protocol_version_test_application_define(void *first_unused_memory);
167 void nx_secure_tls_ecc_client_cert_test_application_define(void *first_unused_memory);
168 void nx_secure_tls_ecc_ciphersuites_test_application_define(void *first_unused_memory);
169 void nx_secure_tls_ecc_curves_test_application_define(void *first_unused_memory);
170 void nx_secure_tls_ecc_crl_test_application_define(void *first_unused_memory);
171 void nx_secure_tls_ecc_packet_chain_test_application_define(void *first_unused_memory);
172 void nx_secure_tls_ecc_point_format_test_application_define(void *first_unused_memory);
173 void nx_secure_tls_shutdown_test_application_define(void *first_unused_memory);
174 void nx_secure_distingushed_name_compare_test_application_define(void *first_unused_memory);
175 void nx_secure_dtls_nxe_api_test_application_define(void *);
176 void nx_secure_dtls_basic_test_application_define(void *);
177 void nx_secure_dtls_error_checking_test_application_define(void *first_unused_memory);
178 void nx_secure_dtls_sliding_window_test_application_define(void *first_unused_memory);
179 void nx_secure_dtls_retransmit_test_application_define(void *);
180 void nx_secure_dtls_retransmit_interval_test_application_define(void *);
181 void nx_secure_dtls_retransmit_change_cipher_spec_test_application_define(void *);
182 void nx_secure_dtls_handshake_fail_test_application_define(void *first_unused_memory);
183 void nx_secure_dtls_ciphersuites_test_application_define(void *);
184 void nx_secure_dtls_ecjpake_test_application_define(void *);
185 void nx_secure_dtls_multiple_sessions_receive_test_application_define(void *);
186 void nx_secure_dtls_multiple_sessions_connect_test_application_define(void *);
187 void nx_secure_dtls_multiple_sessions_reuse_test_application_define(void *);
188 void nx_secure_dtls_multiple_sessions_connect_fail_test_application_define(void *);
189 void nx_secure_dtls_multiple_sessions_send_test_application_define(void *);
190 void nx_secure_dtls_multiple_sessions_retransmit_test_application_define(void *);
191 void nx_secure_dtls_multiple_sessions_ecjpake_test_application_define(void *);
192 void nx_secure_dtls_multiple_ip_address_test_application_define(void *);
193 void nx_secure_dtls_no_free_sessions_test_application_define(void *);
194 void nx_secure_dtls_concurrent_sessions_test_application_define(void *);
195 void nx_secure_dtls_concurrent_sessions_retransmit_test_application_define(void *);
196 void nx_secure_dtls_abort_waiting_test_application_define(void *);
197 void nx_secure_dtls_fragment_test_application_define(void *);
198 void nx_secure_dtls_abnormal_test_application_define(void *);
199 void nx_secure_dtls_out_of_order_test_application_define(void *);
200 void nx_secure_dtls_version_1_0_test_application_define(void *);
201 void nx_secure_dtls_ecc_basic_test_application_define(void *);
202 void nx_secure_dtls_ecc_ciphersuites_test_application_define(void *);
203 void nx_secure_dtls_ecc_curves_test_application_define(void *);
204 void nx_secure_dtls_ecc_client_cert_test_application_define(void *);
205 void nx_secure_ec_test_application_define(void *first_unused_memory);
206 void nx_secure_ecjpake_self_test_application_define(void *first_unused_memory);
207 void nx_secure_ecdh_self_test_application_define(void *first_unused_memory);
208 void nx_secure_ecdh_test_application_define(void *first_unused_memory);
209 void nx_secure_ecdsa_test_application_define(void *first_unused_memory);
210 void nx_secure_tls_nxe_api_test_application_define(void *first_unused_memory);
211 void nx_secure_tls_server_handshake_test_application_define(void *first_unused_memory);
212 void nx_secure_tls_cert_callback_fail_test_application_define(void *first_unused_memory);
213 void nx_secure_tls_send_and_receive_record_test_application_define(void *first_unused_memory);
214 void nx_secure_tls_branch_test_application_define(void *first_unused_memory);
215 void nx_secure_crypto_self_test_application_define(void *first_unused_memory);
216 void nx_secure_crypto_cleanup_test_application_define(void *first_unused_memory);
217 void nx_secure_crypto_method_cleanup_test_application_define(void *first_unused_memory);
218 void nx_secure_tls_certificate_verify_test_application_define(void *first_unused_memory);
219 void nx_secure_tls_rsa_4096_test_application_define(void *first_unused_memory);
220 void nx_secure_tls_rsa_private_key_test_application_define(void *first_unused_memory);
221 void nx_secure_tls_serverhello_session_id_test_application_define(void *first_unused_memory);
222 void nx_secure_hkdf_test_application_define(void *first_unused_memory);
223 void nx_secure_tls_1_3_before_key_generation_test_application_define(void *first_unused_memory);
224 void nx_secure_tls_1_3_ciphersuites_test_application_define(void *);
225 void nx_secure_tls_1_3_clienthello_length_checking_test_application_define(void *first_unused_memory);
226 void nx_secure_tls_1_3_handshake_fail_test_application_define(void *);
227 void nx_secure_tls_1_3_hello_retry_cookie_test_application_define(void *);
228 void nx_secure_tls_1_3_invalid_client_state_test_application_define(void *first_unused_memory);
229 void nx_secure_tls_1_3_key_share_test_application_define(void *);
230 void nx_secure_tls_1_3_provisioned_psk_test_application_define(void *);
231 void nx_secure_tls_1_3_receive_invalid_server_handshake_message_test_application_define(void *);
232 void nx_secure_tls_1_3_serverhello_length_checking_test_application_define(void *first_unused_memory);
233 void nx_secure_tls_1_3_session_create_ext_test_application_define(void *first_unused_memory);
234 void nx_secure_tls_1_3_version_negotiation_test_application_define(void *);
235 void nx_secure_tls_client_ca_select_test_application_define(void *);
236 void nx_secure_tls_send_plaintext_alert_after_key_generation_test_application_define(void *first_unused_memory);
237 void nx_secure_tls_session_create_ext_test_application_define(void *first_unused_memory);
238 void nx_secure_tls_empty_clienthello_extension_test_application_define(void *first_unused_memory);
239 void nx_secure_tls_packet_trim_test_application_define(void *first_unused_memory);
240 void nx_secure_tls_payload_size_test_application_define(void *first_unused_memory);
241 void nx_secure_tls_process_changecipherspec_test_application_define(void *first_unused_memory);
242 void nx_secure_tls_process_certificate_request_test_application_define(void *first_unused_memory);
243 void nx_secure_tls_process_finished_test_application_define(void *first_unused_memory);
244 void nx_secure_tls_process_record_test_application_define(void *first_unused_memory);
245 void nx_secure_tls_send_certificate_test_application_define(void *first_unused_memory);
246 void nx_secure_tls_send_client_hello_test_application_define(void *first_unused_memory);
247 void nx_secure_tls_server_cipher_priority_test_application_define(void *first_unused_memory);
248 void nx_secure_tls_session_delete_test_application_define(void *first_unused_memory);
249 void nx_secure_tls_session_start_test_application_define(void *first_unused_memory);
250 void test_application_define(void *first_unused_memory);
251 void nx_secure_tls_hash_record_coverage_test_application_define(void *first_unused_memory);
252 
253 
254 #define INCLUDE_TWO_WAY_TEST 1
255 
256 #ifdef NX_SECURE_TLS_CLIENT_DISABLED
257 #undef INCLUDE_TWO_WAY_TEST
258 #define INCLUDE_TWO_WAY_TEST 0
259 #endif
260 
261 #ifdef NX_SECURE_TLS_SERVER_DISABLED
262 #undef INCLUDE_TWO_WAY_TEST
263 #define INCLUDE_TWO_WAY_TEST 0
264 #endif
265 
266 /* Define the array of test entry points.  */
267 
268 TEST_ENTRY  test_control_tests[] =
269 {
270 
271 #ifdef CTEST
272     {test_application_define, TEST_TIMEOUT_HIGH},
273 #else /* ifdef CTEST */
274     {nx_secure_tls_session_receive_coverage_test_application_define, TEST_TIMEOUT_LOW},
275     {nx_secure_tls_send_record_coverage_test_application_define, TEST_TIMEOUT_LOW},
276     {nx_secure_tls_client_handshake_coverage_test_application_define, TEST_TIMEOUT_LOW},
277     {nx_secure_tls_handshake_hash_coverage_test_application_define, TEST_TIMEOUT_LOW},
278     {nx_secure_tls_generate_premaster_coverage_test_application_define, TEST_TIMEOUT_LOW},
279     {nx_secure_tls_generate_key_coverage_test_application_define, TEST_TIMEOUT_LOW},
280     {nx_secure_tls_finished_hash_coverage_test_application_define, TEST_TIMEOUT_LOW},
281     {nx_secure_tls_ecc_generate_keys_coverage_test_application_define, TEST_TIMEOUT_LOW},
282     {nx_secure_tls_session_renegotiate_coverage_test_application_define, TEST_TIMEOUT_LOW},
283     {nx_secure_tls_session_keys_set_coverage_test_application_define, TEST_TIMEOUT_LOW},
284     {nx_secure_tls_newest_supported_version_test_application_define, TEST_TIMEOUT_LOW},
285     {nx_secure_tls_verify_mac_test_application_define, TEST_TIMEOUT_LOW},
286     {nx_secure_tls_hash_record_coverage_test_application_define, TEST_TIMEOUT_LOW},
287     {nx_secure_tls_branch_test_application_define, TEST_TIMEOUT_LOW},
288     {nx_secure_tls_error_checking_test_application_define, TEST_TIMEOUT_LOW},
289     {nx_secure_tls_error_checking_2_test_application_define, TEST_TIMEOUT_LOW},
290     {nx_secure_tls_two_way_test_application_define, TEST_TIMEOUT_LOW},
291     {nx_secure_tls_no_client_cert_test_application_define, TEST_TIMEOUT_LOW},
292     {nx_secure_tls_two_way_test_version_1_1_application_define, TEST_TIMEOUT_LOW},
293     {nx_secure_distingushed_name_compare_test_application_define, TEST_TIMEOUT_LOW},
294     {nx_secure_tls_cert_callback_fail_test_application_define, TEST_TIMEOUT_LOW},
295     {nx_secure_tls_certificate_coverage_test_application_define, TEST_TIMEOUT_LOW},
296     {nx_secure_tls_ciphersuites_test_application_define, TEST_TIMEOUT_LOW},
297     {nx_secure_tls_server_cipher_priority_test_application_define, TEST_TIMEOUT_LOW},
298     {nx_secure_tls_client_handshake_test_application_define, TEST_TIMEOUT_MID},
299     {nx_secure_tls_clienthello_extension_test_application_define, TEST_TIMEOUT_LOW},
300     {nx_secure_tls_session_sni_extension_test_application_define, TEST_TIMEOUT_MID},
301     {nx_secure_tls_coverage_test_application_define, TEST_TIMEOUT_MID},
302     {nx_secure_tls_coverage_2_test_application_define, TEST_TIMEOUT_MID},
303     {nx_secure_tls_coverage_3_test_application_define, TEST_TIMEOUT_MID},
304     {nx_secure_tls_server_handshake_test_application_define, TEST_TIMEOUT_MID},
305     {nx_secure_tls_tcp_fragment_test_application_define, TEST_TIMEOUT_LOW},
306     {nx_secure_tls_user_defined_key_test_application_define, TEST_TIMEOUT_LOW},
307     {nx_secure_tls_alert_test_application_define, TEST_TIMEOUT_LOW},
308     {nx_secure_tls_hash_coverage_test_application_define, TEST_TIMEOUT_LOW},
309     {nx_secure_tls_handshake_header_test_application_define, TEST_TIMEOUT_LOW},
310     {nx_secure_tls_header_test_application_define, TEST_TIMEOUT_LOW},
311     {nx_secure_tls_handshake_fail_test_application_define, TEST_TIMEOUT_LOW},
312     {nx_secure_tls_packet_chain_test_application_define, TEST_TIMEOUT_LOW},
313     {nx_secure_tls_receive_alert_test_application_define, TEST_TIMEOUT_LOW},
314     {nx_secure_tls_receive_test_application_define, TEST_TIMEOUT_LOW},
315     {nx_secure_tls_record_decrypt_coverage_test_application_define, TEST_TIMEOUT_LOW},
316     {nx_secure_tls_record_encrypt_coverage_test_application_define, TEST_TIMEOUT_LOW},
317     {nx_secure_tls_record_layer_version_test_application_define, TEST_TIMEOUT_LOW},
318     {nx_secure_tls_record_length_test_application_define, TEST_TIMEOUT_LOW},
319     {nx_secure_tls_server_key_exchange_coverage_test_application_define, TEST_TIMEOUT_LOW},
320     {nx_secure_tls_serverhello_coverage_test_application_define, TEST_TIMEOUT_LOW},
321     {nx_secure_tls_serverhello_extension_test_application_define, TEST_TIMEOUT_LOW},
322     {nx_secure_tls_send_and_receive_record_test_application_define, TEST_TIMEOUT_LOW},
323     {nx_secure_tls_certificate_verify_test_application_define, TEST_TIMEOUT_LOW},
324     {nx_secure_tls_no_remote_certs_allocated_test_application_define, TEST_TIMEOUT_LOW},
325     {nx_secure_tls_partial_remote_certs_allocated_test_application_define, TEST_TIMEOUT_LOW},
326     {nx_secure_tls_process_certificate_verify_test_application_define, TEST_TIMEOUT_LOW},
327     {nx_secure_tls_rsa_4096_test_application_define, TEST_TIMEOUT_LOW},
328     {nx_secure_tls_rsa_private_key_test_application_define, TEST_TIMEOUT_LOW},
329     {nx_secure_tls_send_plaintext_alert_after_key_generation_test_application_define, TEST_TIMEOUT_LOW},
330     {nx_secure_tls_serverhello_session_id_test_application_define, TEST_TIMEOUT_LOW},
331     {nx_secure_tls_metadata_size_application_define, TEST_TIMEOUT_LOW},
332     {nx_secure_tls_multiple_handshake_msg_test_application_define, TEST_TIMEOUT_LOW},
333     {nx_secure_tls_multithread_test_application_define, TEST_TIMEOUT_LOW},
334     {nx_secure_tls_unrecognized_ciphersuite_test_application_define, TEST_TIMEOUT_LOW},
335     {nx_secure_tls_unsupported_ciphersuites_test_application_define, TEST_TIMEOUT_LOW},
336     {nx_secure_tls_non_blocking_test_application_define, TEST_TIMEOUT_LOW},
337     {nx_secure_tls_ecc_basic_test_application_define, TEST_TIMEOUT_LOW},
338     {nx_secure_tls_ecc_protocol_version_test_application_define, TEST_TIMEOUT_LOW},
339     {nx_secure_tls_ecc_client_cert_test_application_define, TEST_TIMEOUT_LOW},
340     {nx_secure_tls_ecc_ciphersuites_test_application_define, TEST_TIMEOUT_LOW},
341     {nx_secure_tls_ecc_curves_test_application_define, TEST_TIMEOUT_LOW},
342     {nx_secure_tls_ecc_crl_test_application_define, TEST_TIMEOUT_LOW},
343     {nx_secure_tls_ecc_packet_chain_test_application_define, TEST_TIMEOUT_LOW},
344     {nx_secure_tls_ecc_point_format_test_application_define, TEST_TIMEOUT_LOW},
345     {nx_secure_tls_empty_clienthello_extension_test_application_define, TEST_TIMEOUT_LOW},
346     {nx_secure_tls_handshake_fragmentation_test_application_define, TEST_TIMEOUT_LOW},
347     {nx_secure_tls_1_3_before_key_generation_test_application_define, TEST_TIMEOUT_LOW},
348     {nx_secure_tls_1_3_ciphersuites_test_application_define, TEST_TIMEOUT_LOW},
349     {nx_secure_tls_1_3_clienthello_length_checking_test_application_define, TEST_TIMEOUT_LOW},
350     {nx_secure_tls_1_3_handshake_fail_test_application_define, TEST_TIMEOUT_LOW},
351     {nx_secure_tls_1_3_hello_retry_cookie_test_application_define, TEST_TIMEOUT_LOW},
352     {nx_secure_tls_1_3_invalid_client_state_test_application_define, TEST_TIMEOUT_LOW},
353     {nx_secure_tls_1_3_key_share_test_application_define, TEST_TIMEOUT_LOW},
354     {nx_secure_tls_1_3_serverhello_length_checking_test_application_define, TEST_TIMEOUT_LOW},
355     {nx_secure_tls_1_3_session_create_ext_test_application_define, TEST_TIMEOUT_LOW},
356     {nx_secure_tls_1_3_provisioned_psk_test_application_define, TEST_TIMEOUT_LOW},
357     {nx_secure_tls_1_3_receive_invalid_server_handshake_message_test_application_define, TEST_TIMEOUT_LOW},
358     {nx_secure_tls_1_3_version_negotiation_test_application_define, TEST_TIMEOUT_LOW},
359     {nx_secure_tls_cert_verify_test_application_define, TEST_TIMEOUT_LOW},
360     {nx_secure_tls_client_ca_select_test_application_define, TEST_TIMEOUT_LOW},
361     {nx_secure_tls_packet_trim_test_application_define, TEST_TIMEOUT_LOW},
362     {nx_secure_tls_process_changecipherspec_test_application_define, TEST_TIMEOUT_LOW},
363     {nx_secure_tls_process_certificate_request_test_application_define, TEST_TIMEOUT_LOW},
364     {nx_secure_tls_process_finished_test_application_define, TEST_TIMEOUT_LOW},
365     {nx_secure_tls_process_record_test_application_define, TEST_TIMEOUT_LOW},
366     {nx_secure_tls_session_create_ext_test_application_define, TEST_TIMEOUT_LOW},
367     {nx_secure_tls_shutdown_test_application_define, TEST_TIMEOUT_LOW},
368     {nx_secure_tls_send_certificate_test_application_define, TEST_TIMEOUT_LOW},
369     {nx_secure_tls_send_client_hello_test_application_define, TEST_TIMEOUT_LOW},
370     {nx_secure_tls_session_delete_test_application_define, TEST_TIMEOUT_LOW},
371     {nx_secure_tls_session_start_test_application_define, TEST_TIMEOUT_LOW},
372     {nx_secure_x509_certificate_initialize_test_application_define, TEST_TIMEOUT_LOW},
373     {nx_secure_x509_certificate_verify_test_application_define, TEST_TIMEOUT_LOW},
374     {nx_secure_x509_crl_verify_test_application_define, TEST_TIMEOUT_LOW},
375     {nx_secure_x509_parse_test_application_define, TEST_TIMEOUT_LOW},
376     {nx_secure_x509_list_test_application_define, TEST_TIMEOUT_LOW},
377     {nx_secure_x509_store_test_application_define, TEST_TIMEOUT_LOW},
378     {nx_secure_x509_name_check_test_application_define, TEST_TIMEOUT_LOW},
379     {nx_secure_x509_crl_test_application_define, TEST_TIMEOUT_LOW},
380     {nx_secure_x509_error_checking_test_application_define, TEST_TIMEOUT_LOW},
381     {nx_secure_x509_expiration_check_test_application_define, TEST_TIMEOUT_LOW},
382     {nx_secure_x509_key_usage_test_application_define, TEST_TIMEOUT_LOW},
383     {nx_secure_x509_pkcs7_decode_coverage_test_application_define, TEST_TIMEOUT_LOW},
384 
385 #ifndef CERT_BUILD
386     {nx_secure_dtls_nxe_api_test_application_define, TEST_TIMEOUT_LOW},
387     {nx_secure_dtls_basic_test_application_define, TEST_TIMEOUT_MID},
388     {nx_secure_dtls_error_checking_test_application_define, TEST_TIMEOUT_MID},
389     {nx_secure_dtls_sliding_window_test_application_define, TEST_TIMEOUT_MID},
390     {nx_secure_dtls_retransmit_test_application_define, TEST_TIMEOUT_LOW},
391     {nx_secure_dtls_retransmit_interval_test_application_define, TEST_TIMEOUT_MID},
392     {nx_secure_dtls_retransmit_change_cipher_spec_test_application_define, TEST_TIMEOUT_LOW},
393     {nx_secure_dtls_ciphersuites_test_application_define, TEST_TIMEOUT_LOW},
394     {nx_secure_dtls_handshake_fail_test_application_define, TEST_TIMEOUT_MID},
395     {nx_secure_dtls_ecjpake_test_application_define, TEST_TIMEOUT_LOW},
396     {nx_secure_dtls_multiple_sessions_receive_test_application_define, TEST_TIMEOUT_LOW},
397     {nx_secure_dtls_multiple_sessions_connect_test_application_define, TEST_TIMEOUT_LOW},
398     {nx_secure_dtls_multiple_sessions_connect_fail_test_application_define, TEST_TIMEOUT_LOW},
399     {nx_secure_dtls_multiple_sessions_send_test_application_define, TEST_TIMEOUT_LOW},
400     {nx_secure_dtls_multiple_sessions_retransmit_test_application_define, TEST_TIMEOUT_MID},
401     {nx_secure_dtls_multiple_sessions_ecjpake_test_application_define, TEST_TIMEOUT_LOW},
402     {nx_secure_dtls_multiple_ip_address_test_application_define, TEST_TIMEOUT_LOW},
403     {nx_secure_dtls_no_free_sessions_test_application_define, TEST_TIMEOUT_MID},
404     {nx_secure_dtls_concurrent_sessions_test_application_define, TEST_TIMEOUT_LOW},
405     {nx_secure_dtls_concurrent_sessions_retransmit_test_application_define, TEST_TIMEOUT_MID},
406     {nx_secure_dtls_abort_waiting_test_application_define, TEST_TIMEOUT_LOW},
407     {nx_secure_dtls_fragment_test_application_define, TEST_TIMEOUT_LOW},
408     {nx_secure_dtls_abnormal_test_application_define, TEST_TIMEOUT_LOW},
409     {nx_secure_dtls_out_of_order_test_application_define, TEST_TIMEOUT_MID},
410     {nx_secure_dtls_version_1_0_test_application_define, TEST_TIMEOUT_MID},
411     {nx_secure_dtls_multiple_sessions_reuse_test_application_define, TEST_TIMEOUT_MID},
412     {nx_secure_dtls_ecc_basic_test_application_define, TEST_TIMEOUT_MID},
413     {nx_secure_dtls_ecc_ciphersuites_test_application_define, TEST_TIMEOUT_MID},
414     {nx_secure_dtls_ecc_curves_test_application_define, TEST_TIMEOUT_MID},
415     {nx_secure_dtls_ecc_client_cert_test_application_define, TEST_TIMEOUT_MID},
416 #endif /* CERT_BUILD */
417     {nx_secure_tls_nxe_api_test_application_define, TEST_TIMEOUT_LOW},
418     {nx_secure_crypto_self_test_application_define, TEST_TIMEOUT_LOW},
419     {nx_secure_crypto_cleanup_test_application_define, TEST_TIMEOUT_LOW},
420     /* Crypto test. */
421     {nx_secure_hkdf_test_application_define, TEST_TIMEOUT_LOW},
422     {nx_secure_sha224_test_application_define, TEST_TIMEOUT_LOW},
423     {nx_secure_sha256_test_application_define, TEST_TIMEOUT_LOW},
424     {nx_secure_sha256_rfc_test_application_define, TEST_TIMEOUT_LOW},
425     {nx_secure_sha384_test_application_define, TEST_TIMEOUT_LOW},
426     {nx_secure_sha512_test_application_define, TEST_TIMEOUT_LOW},
427     {nx_secure_hmac_md5_test_application_define, TEST_TIMEOUT_LOW},
428     {nx_secure_hmac_sha1_test_application_define, TEST_TIMEOUT_LOW},
429     {nx_secure_hmac_sha224_test_application_define, TEST_TIMEOUT_LOW},
430     {nx_secure_hmac_sha256_test_application_define, TEST_TIMEOUT_LOW},
431     {nx_secure_hmac_sha384_test_application_define, TEST_TIMEOUT_LOW},
432     {nx_secure_hmac_sha512_test_application_define, TEST_TIMEOUT_LOW},
433     {nx_secure_rsa_test_application_define, TEST_TIMEOUT_MID},
434     {nx_secure_aes_test_application_define, TEST_TIMEOUT_LOW},
435     {nx_secure_aes_ccm_test_application_define, TEST_TIMEOUT_LOW},
436     {nx_secure_des_test_application_define, TEST_TIMEOUT_LOW},
437     {nx_secure_3des_test_application_define, TEST_TIMEOUT_LOW},
438     {nx_secure_phash_prf_test_application_define, TEST_TIMEOUT_LOW},
439 #ifndef CERT_BUILD
440     {nx_secure_ec_test_application_define, TEST_TIMEOUT_MID},
441     {nx_secure_ecjpake_self_test_application_define, TEST_TIMEOUT_MID},
442     {nx_secure_ecdh_self_test_application_define, TEST_TIMEOUT_MID},
443     {nx_secure_ecdh_test_application_define, TEST_TIMEOUT_MID},
444     {nx_secure_ecdsa_test_application_define, TEST_TIMEOUT_MID},
445 #endif /* CERT_BUILD */
446     {nx_secure_crypto_method_cleanup_test_application_define, TEST_TIMEOUT_LOW},
447     {nx_secure_tls_payload_size_test_application_define, TEST_TIMEOUT_LOW},
448 #endif /* ifdef CTEST */
449     {TX_NULL, TEST_TIMEOUT_LOW},
450 };
451 
452 /* Define thread prototypes.  */
453 
454 void  test_control_thread_entry(ULONG thread_input);
455 void  test_control_return(UINT status);
456 void  test_control_cleanup(void);
457 void  _nx_ram_network_driver_reset(void);
458 
459 /* Define necessary external references.  */
460 
461 #ifdef __ghs
462 extern TX_MUTEX                 __ghLockMutex;
463 #endif
464 
465 extern TX_TIMER                 *_tx_timer_created_ptr;
466 extern ULONG                    _tx_timer_created_count;
467 #ifndef TX_TIMER_PROCESS_IN_ISR
468 extern TX_THREAD                _tx_timer_thread;
469 #endif
470 extern TX_THREAD                *_tx_thread_created_ptr;
471 extern ULONG                    _tx_thread_created_count;
472 extern TX_SEMAPHORE             *_tx_semaphore_created_ptr;
473 extern ULONG                    _tx_semaphore_created_count;
474 extern TX_QUEUE                 *_tx_queue_created_ptr;
475 extern ULONG                    _tx_queue_created_count;
476 extern TX_MUTEX                 *_tx_mutex_created_ptr;
477 extern ULONG                    _tx_mutex_created_count;
478 extern TX_EVENT_FLAGS_GROUP     *_tx_event_flags_created_ptr;
479 extern ULONG                    _tx_event_flags_created_count;
480 extern TX_BYTE_POOL             *_tx_byte_pool_created_ptr;
481 extern ULONG                    _tx_byte_pool_created_count;
482 extern TX_BLOCK_POOL            *_tx_block_pool_created_ptr;
483 extern ULONG                    _tx_block_pool_created_count;
484 
485 extern NX_PACKET_POOL *         _nx_packet_pool_created_ptr;
486 extern ULONG                    _nx_packet_pool_created_count;
487 extern NX_IP *                  _nx_ip_created_ptr;
488 extern ULONG                    _nx_ip_created_count;
489 
490 /* Define main entry point.  */
491 #define __NETX_SECURE_SP_VERSION__ 1
main()492 int main()
493 {
494 
495 #ifdef NX_CRYPTO_SELF_TEST
496     nx_crypto_initialize();
497 
498     _nx_crypto_method_self_test(0);
499 #endif
500 
501 #if 0
502     /* Reassign "stdout" to "freopen.out": */
503     stream = freopen( "test_result.txt", "w", stdout );
504 #endif
505     /* Print out some test information banners.  */
506     printf("%s\n", _nx_secure_version_id);
507     printf("NetX Secure Version %d.%d\n", __NETX_SECURE_MAJOR_VERSION__,
508            __NETX_SECURE_MINOR_VERSION__);
509     printf("Tested on %s %s\n", __DATE__, __TIME__);
510 
511     fflush(stdout);
512 
513 #if defined(__linux__) && defined(USE_FORK)
514     fork_child();
515 #else
516     /* Enter the ThreadX kernel.  */
517     tx_kernel_enter();
518 #endif
519 
520     return 0;
521 }
522 
523 
524 #if defined(__linux__) && defined(USE_FORK)
525 static pid_t child_pid = -1;
526 static UINT test_index = 0;
527 static int result_fd[2];
528 
kill_child(int sig)529 void kill_child(int sig)
530 {
531 CHAR data[4]={0, 1, 0, 0};
532 
533     printf("ERROR! Kill child process\n");
534     fflush(stdout);
535     write(result_fd[1], data, sizeof(data));
536     exit(1);
537 }
538 
fork_child()539 void fork_child()
540 {
541 INT status;
542 CHAR data[4];
543 struct pollfd fds;
544 
545     while (test_control_tests[test_index].test_entry != TX_NULL)
546     {
547 
548         /* Create pipe for communicating. */
549         pipe(result_fd);
550         fds.fd = result_fd[0];
551         fds.events=POLLIN | POLLOUT | POLLERR;
552 
553         /* Fork test process. */
554         child_pid = fork();
555         if (child_pid > 0)
556         {
557             wait(&status);
558             poll(&fds, 1, 0);
559             if (fds.revents & POLLIN)
560             {
561                 read(result_fd[0], data, sizeof(data));
562                 test_control_successful_tests += (ULONG)data[0];
563                 test_control_failed_tests += (ULONG)data[1];
564                 test_control_warning_tests += (ULONG)data[2];
565                 test_control_na_tests += (ULONG)data[3];
566             }
567             else
568             {
569 
570                 /* The child process crashes. */
571                 printf("ERROR! Child process crashed\n");
572                 test_control_failed_tests++;
573             }
574 
575             fflush(stdout);
576 
577             test_index++;
578         }
579         else
580         {
581 
582             /* Setup SIGALRM callback function. */
583             signal(SIGALRM, (void (*)(int))kill_child);
584 
585             /* Initialize the results. */
586             test_control_successful_tests = 0;
587             test_control_failed_tests = 0;
588             test_control_warning_tests = 0;
589             test_control_na_tests = 0;
590 
591             /* Setup timeout alarm. */
592             alarm(test_control_tests[test_index].timeout / NX_IP_PERIODIC_RATE);
593 
594             /* Enter the ThreadX kernel.  */
595             tx_kernel_enter();
596             return;
597         }
598     }
599 
600     /* Finished with all tests, print results and return!  */
601     printf("**** Testing Complete ****\n");
602     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);
603 #ifdef BATCH_TEST
604     exit(test_control_failed_tests);
605 #endif
606 }
607 
608 /* Define what the initial system looks like.  */
609 
tx_application_define(void * first_unused_memory)610 void    tx_application_define(void *first_unused_memory)
611 {
612 
613     /* Dispatch the test.  */
614     (test_control_tests[test_index].test_entry)(first_unused_memory);
615 }
616 
test_control_return(UINT status)617 void  test_control_return(UINT status)
618 {
619 UINT    old_posture = TX_INT_ENABLE;
620 INT     exit_code = status;
621 CHAR    data[4];
622 
623     fflush(stdout);
624 
625     /* Initialize result through pipe. */
626     data[0] = (CHAR)test_control_successful_tests;
627     data[1] = (CHAR)test_control_failed_tests;
628     data[2] = (CHAR)test_control_warning_tests;
629     data[3] = (CHAR)test_control_na_tests;
630 
631     /* Save the status in a global.  */
632     test_control_return_status = status;
633 
634     /* Ensure interrupts are enabled.  */
635     old_posture = tx_interrupt_control(TX_INT_ENABLE);
636 
637     /* Determine if it was successful or not.  */
638     if((status == 1) || (_tx_thread_preempt_disable) || (old_posture == TX_INT_DISABLE))
639     {
640         data[1]++;
641         exit_code = 1;
642     }
643     else if(status == 2)
644     {
645         data[2]++;
646         exit_code = 2;
647     }
648     else if(status == 0)
649     {
650         data[0]++;
651         exit_code = 0;
652     }
653     else if(status == 3)
654     {
655         data[3]++;
656         exit_code = 3;
657     }
658 
659     /* Send result through pipe. */
660     write(result_fd[1], data, sizeof(data));
661     exit(exit_code);
662 }
663 
664 #else
665 /* Define what the initial system looks like.  */
666 
tx_application_define(void * first_unused_memory)667 void    tx_application_define(void *first_unused_memory)
668 {
669     UCHAR    *pointer;
670 
671     /* Setup a pointer to the first unused memory.  */
672     pointer = (UCHAR *)   first_unused_memory;
673 
674     /* Create the test control thread.  */
675     tx_thread_create(&test_control_thread, "test control thread", test_control_thread_entry, 0,
676         pointer, TEST_STACK_SIZE,
677         0, 0, TX_NO_TIME_SLICE, TX_AUTO_START);
678     pointer = pointer + TEST_STACK_SIZE;
679 
680 #ifndef NETXTEST_TIMEOUT_DISABLE
681     /* Create the test control semaphore.  */
682     tx_semaphore_create(&test_control_sema, "Test control semaphore", 0);
683 #endif
684 
685     /* Remember the free memory pointer.  */
686     test_free_memory_ptr = pointer;
687 }
688 
689 /* Define the test control thread.  This thread is responsible for dispatching all of the
690 tests in the ThreadX test suite.  */
691 
test_control_thread_entry(ULONG thread_input)692 void  test_control_thread_entry(ULONG thread_input)
693 {
694     UINT    i;
695 
696     /* Loop to process all tests...  */
697     i = 0;
698     while (test_control_tests[i].test_entry != TX_NULL)
699     {
700 
701         /* Dispatch the test.  */
702         (test_control_tests[i++].test_entry)(test_free_memory_ptr);
703 
704         if (test_control_return_status != 3)
705         {
706 
707 #ifdef NETXTEST_TIMEOUT_DISABLE
708             /* Suspend control test to allow test to run.  */
709             tx_thread_suspend(&test_control_thread);
710 #else
711             if(tx_semaphore_get(&test_control_sema, test_control_tests[i - 1].timeout))
712             {
713 
714                 /* Test case timeouts. */
715                 printf("ERROR! Test case timeout\n");
716                 test_control_failed_tests++;
717 
718             }
719 #endif
720         }
721         else
722             test_control_return_status = 0;
723 
724         /* Test finished, cleanup in preparation for the next test.  */
725         test_control_cleanup();
726         fflush(stdout);
727     }
728 
729     /* Finished with all tests, print results and return!  */
730     printf("**** Testing Complete ****\n");
731     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);
732 #if 0
733     fclose(stream);
734 #endif
735 #ifdef BATCH_TEST
736     exit(test_control_failed_tests);
737 #endif
738 
739 }
740 
test_control_return(UINT status)741 void  test_control_return(UINT status)
742 {
743     UINT    old_posture = TX_INT_ENABLE;
744 
745     /* Save the status in a global.  */
746     test_control_return_status = status;
747 
748     /* Ensure interrupts are enabled.  */
749     old_posture = tx_interrupt_control(TX_INT_ENABLE);
750 
751     /* Determine if it was successful or not.  */
752     if((status == 1) || (_tx_thread_preempt_disable) || (old_posture == TX_INT_DISABLE))
753         test_control_failed_tests++;
754     else if(status == 2)
755         test_control_warning_tests++;
756     else if(status == 0)
757         test_control_successful_tests++;
758     else if(status == 3)
759         test_control_na_tests++;
760 
761 #ifdef NETXTEST_TIMEOUT_DISABLE
762     /* Resume the control thread to fully exit the test.  */
763     tx_thread_resume(&test_control_thread);
764 #else
765     if(test_control_return_status != 3)
766         tx_semaphore_put(&test_control_sema);
767 #endif
768 }
769 
test_control_cleanup(void)770 void  test_control_cleanup(void)
771 {
772     TX_MUTEX        *mutex_ptr;
773     TX_THREAD       *thread_ptr;
774 
775     /* Clean timer used by RAM driver. */
776     _nx_ram_network_driver_timer_clean();
777 
778     /* Delete all IP instances.   */
779     while (_nx_ip_created_ptr)
780     {
781 
782         /* Delete all UDP sockets.  */
783         while (_nx_ip_created_ptr -> nx_ip_udp_created_sockets_ptr)
784         {
785 
786             /* Make sure the UDP socket is unbound.  */
787             nx_udp_socket_unbind(_nx_ip_created_ptr -> nx_ip_udp_created_sockets_ptr);
788 
789             /* Delete the UDP socket.  */
790             nx_udp_socket_delete(_nx_ip_created_ptr -> nx_ip_udp_created_sockets_ptr);
791         }
792 
793         /* Delete all TCP sockets.  */
794         while (_nx_ip_created_ptr -> nx_ip_tcp_created_sockets_ptr)
795         {
796 
797             /* Disconnect.  */
798             nx_tcp_socket_disconnect(_nx_ip_created_ptr -> nx_ip_tcp_created_sockets_ptr, NX_NO_WAIT);
799 
800             /* Make sure the TCP client socket is unbound.  */
801             nx_tcp_client_socket_unbind(_nx_ip_created_ptr -> nx_ip_tcp_created_sockets_ptr);
802 
803             /* Make sure the TCP server socket is unaccepted.  */
804             nx_tcp_server_socket_unaccept(_nx_ip_created_ptr -> nx_ip_tcp_created_sockets_ptr);
805 
806             /* Delete the TCP socket.  */
807             nx_tcp_socket_delete(_nx_ip_created_ptr -> nx_ip_tcp_created_sockets_ptr);
808         }
809 
810         /* Clear all listen requests.  */
811         while (_nx_ip_created_ptr -> nx_ip_tcp_active_listen_requests)
812         {
813 
814             /* Make sure the TCP server socket is unlistened.  */
815             nx_tcp_server_socket_unlisten(_nx_ip_created_ptr, (_nx_ip_created_ptr -> nx_ip_tcp_active_listen_requests) -> nx_tcp_listen_port);
816         }
817 
818         /* Delete the IP instance.  */
819         nx_ip_delete(_nx_ip_created_ptr);
820     }
821 
822     /* Delete all the packet pools.  */
823     while (_nx_packet_pool_created_ptr)
824     {
825         nx_packet_pool_delete(_nx_packet_pool_created_ptr);
826     }
827 
828     /* Reset the RAM driver.  */
829     _nx_ram_network_driver_reset();
830 
831     /* Delete all queues.  */
832     while(_tx_queue_created_ptr)
833     {
834 
835         /* Delete queue.  */
836         tx_queue_delete(_tx_queue_created_ptr);
837     }
838 
839     /* Delete all semaphores.  */
840     while(_tx_semaphore_created_ptr)
841     {
842 #ifndef NETXTEST_TIMEOUT_DISABLE
843         if(_tx_semaphore_created_ptr != &test_control_sema)
844         {
845 
846             /* Delete semaphore.  */
847             tx_semaphore_delete(_tx_semaphore_created_ptr);
848         }
849         else if(_tx_semaphore_created_count == 1)
850             break;
851         else
852         {
853             /* Delete semaphore.  */
854             tx_semaphore_delete(_tx_semaphore_created_ptr -> tx_semaphore_created_next);
855         }
856 #else
857         /* Delete semaphore.  */
858         tx_semaphore_delete(_tx_semaphore_created_ptr);
859 #endif
860     }
861 
862     /* Delete all event flag groups.  */
863     while(_tx_event_flags_created_ptr)
864     {
865 
866         /* Delete event flag group.  */
867         tx_event_flags_delete(_tx_event_flags_created_ptr);
868     }
869 
870     /* Delete all byte pools.  */
871     while(_tx_byte_pool_created_ptr)
872     {
873 
874         /* Delete byte pool.  */
875         tx_byte_pool_delete(_tx_byte_pool_created_ptr);
876     }
877 
878     /* Delete all block pools.  */
879     while(_tx_block_pool_created_ptr)
880     {
881 
882         /* Delete block pool.  */
883         tx_block_pool_delete(_tx_block_pool_created_ptr);
884     }
885 
886     /* Delete all timers.  */
887     while(_tx_timer_created_ptr)
888     {
889 
890         /* Deactivate timer.  */
891         tx_timer_deactivate(_tx_timer_created_ptr);
892 
893         /* Delete timer.  */
894         tx_timer_delete(_tx_timer_created_ptr);
895     }
896 
897     /* Delete all mutexes (except for system mutex).  */
898     while(_tx_mutex_created_ptr)
899     {
900 
901         /* Setup working mutex pointer.  */
902         mutex_ptr = _tx_mutex_created_ptr;
903 
904 #ifdef __ghs
905 
906         /* Determine if the mutex is the GHS system mutex.  If so, don't delete!  */
907         if(mutex_ptr == &__ghLockMutex)
908         {
909 
910             /* Move to next mutex.  */
911             mutex_ptr = mutex_ptr -> tx_mutex_created_next;
912         }
913 
914         /* Determine if there are no more mutexes to delete.  */
915         if(_tx_mutex_created_count == 1)
916             break;
917 #endif
918 
919         /* Delete mutex.  */
920         tx_mutex_delete(mutex_ptr);
921     }
922 
923     /* Delete all threads, except for timer thread, and test control thread.  */
924     while (_tx_thread_created_ptr)
925     {
926 
927         /* Setup working pointer.  */
928         thread_ptr = _tx_thread_created_ptr;
929 
930 #ifdef TX_TIMER_PROCESS_IN_ISR
931 
932         /* Determine if there are more threads to delete.  */
933         if(_tx_thread_created_count == 1)
934             break;
935 
936         /* Determine if this thread is the test control thread.  */
937         if(thread_ptr == &test_control_thread)
938         {
939 
940             /* Move to the next thread pointer.  */
941             thread_ptr = thread_ptr -> tx_thread_created_next;
942         }
943 #else
944 
945         /* Determine if there are more threads to delete.  */
946         if(_tx_thread_created_count == 2)
947             break;
948 
949         /* Move to the thread not protected.  */
950         while ((thread_ptr == &_tx_timer_thread) || (thread_ptr == &test_control_thread))
951         {
952 
953             /* Yes, move to the next thread.  */
954             thread_ptr = thread_ptr -> tx_thread_created_next;
955         }
956 #endif
957 
958         /* First terminate the thread to ensure it is ready for deletion.  */
959         tx_thread_terminate(thread_ptr);
960 
961         /* Delete the thread.  */
962         tx_thread_delete(thread_ptr);
963     }
964 
965     /* At this point, only the test control thread and the system timer thread and/or mutex should still be
966     in the system.  */
967 
968 #ifdef NX_PCAP_ENABLE
969     /* Close the pcap file.  */
970     close_pcap_file();
971 #endif
972 }
973 #endif
974