summaryrefslogtreecommitdiff
path: root/test/regression/crypto_test/cryptotestcontrol.c
blob: dc905dbabf85c7c8413ca7fa72316b8077532079 (plain)
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
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
/***************************************************************************/
/* Copyright (c) 2024 Microsoft Corporation                                */
/* Copyright (c) 2026 Eclipse ThreadX contributors                         */
/*                                                                         */
/* This program and the accompanying materials are made available under    */
/* the terms of the MIT License which is available at                      */
/* https://opensource.org/licenses/MIT.                                    */
/*                                                                         */
/* SPDX-License-Identifier: MIT                                            */
/***************************************************************************/

/* This is the test control routine the NetX TCP/IP stack.  All tests are dispatched from this routine.  */
#ifndef NX_CRYPTO_STANDALONE_ENABLE
#include "tx_api.h"
#include "nx_api.h"
#else
#include "nx_crypto_port.h"
#endif
#include <stdio.h>
#include "nx_crypto.h"

#if defined(__linux__) && defined(USE_FORK)
#undef __suseconds_t_defined
#undef _STRUCT_TIMEVAL
#undef _SYS_SELECT_H
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
#include <sys/poll.h>

void fork_child();
#endif

/*
#define NETXTEST_TIMEOUT_DISABLE
*/

#ifdef NX_CRYPTO_STANDALONE_ENABLE
#define tx_kernel_enter()  test_application_define(0);
#endif
 FILE *stream;

#define TEST_STACK_SIZE         4096

#ifdef NX_CRYPTO_STANDALONE_ENABLE
#define NX_IP_PERIODIC_RATE  100
#endif

/* 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...  */
#ifndef NX_CRYPTO_STANDALONE_ENABLE
TX_THREAD       test_control_thread;
#ifndef NETXTEST_TIMEOUT_DISABLE
TX_SEMAPHORE    test_control_sema;
#endif
#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;
#ifndef NX_CRYPTO_STANDALONE_ENABLE
extern volatile UINT   _tx_thread_preempt_disable;
#endif
/* 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 nx_secure_3des_test_application_define(void *first_unused_memory);
void nx_secure_3des_error_checking_test_application_define(void *first_unused_memory);
void nx_secure_des_test_application_define(void *first_unused_memory);
void nx_secure_des_error_checking_test_application_define(void *first_unused_memory);
void nx_secure_drbg_test_application_define(void *first_unused_memory);
void nx_secure_ec_test_application_define(void *first_unused_memory);
void nx_secure_ec_additional_test_application_define(void *first_unused_memory);
void nx_secure_ecdh_test_application_define(void *first_unused_memory);
void nx_secure_ecdh_error_checking_test_application_define(void *first_unused_memory);
void nx_secure_ecdh_self_test_application_define(void *first_unused_memory);
void nx_secure_ecdsa_test_application_define(void *first_unused_memory);
void nx_secure_ecdsa_error_checking_test_application_define(void *first_unused_memory);
void nx_secure_ecjpake_self_test_application_define(void *first_unused_memory);
void nx_secure_aes_additional_test_application_define(void *first_unused_memory);
void nx_secure_sha_additional_test_application_define(void *first_unused_memory);
void nx_secure_sha256_test_application_define(void *);
void nx_secure_sha256_rfc_test_application_define(void *);
void nx_secure_sha384_test_application_define(void *);
void nx_secure_sha512_test_application_define(void *);
void nx_secure_hmac_md5_test_application_define(void *first_unused_memory);
void nx_secure_hmac_md5_error_checking_test_application_define(void *first_unused_memory);
void nx_secure_hmac_sha1_test_application_define(void *first_unused_memory);
void nx_secure_hmac_sha256_test_application_define(void *);
void nx_secure_hmac_sha384_test_application_define(void *);
void nx_secure_hmac_sha512_test_application_define(void *);
void nx_secure_huge_number_test_application_define(void *first_unused_memory);
void nx_secure_md5_test_application_define(void *first_unused_memory);
void nx_secure_rsa_test_application_define(void *);
void nx_secure_rsa_error_checking_test_application_define(void *);
void nx_secure_aes_test_application_define(void *first_unused_memory);
void nx_secure_aes_ccm_test_application_define(void *first_unused_memory);
void nx_secure_phash_prf_test_application_define(void *);
void nx_secure_pkcs1_v1_5_test_application_define(void *first_unused_memory);
void test_application_define(void *first_unused_memory);

#define INCLUDE_TWO_WAY_TEST 1

#ifdef NX_SECURE_TLS_CLIENT_DISABLED
#undef INCLUDE_TWO_WAY_TEST
#define INCLUDE_TWO_WAY_TEST 0
#endif

#ifdef NX_SECURE_TLS_SERVER_DISABLED
#undef INCLUDE_TWO_WAY_TEST
#define INCLUDE_TWO_WAY_TEST 0
#endif

/* Define the array of test entry points.  */

TEST_ENTRY  test_control_tests[] =
{

#ifdef CTEST
    {test_application_define, TEST_TIMEOUT_HIGH},
#else /* CTEST */
    /* Crypto test. */
    {nx_secure_des_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_des_error_checking_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_drbg_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_ec_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_ec_additional_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_ecdh_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_ecdh_error_checking_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_ecdh_self_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_ecdsa_test_application_define, TEST_TIMEOUT_MID},
    {nx_secure_ecdsa_error_checking_test_application_define, TEST_TIMEOUT_MID},
    {nx_secure_ecjpake_self_test_application_define, TEST_TIMEOUT_MID},
    {nx_secure_3des_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_3des_error_checking_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_sha256_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_sha256_rfc_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_sha384_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_sha512_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_sha_additional_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_hmac_md5_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_hmac_md5_error_checking_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_hmac_sha1_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_hmac_sha256_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_hmac_sha384_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_hmac_sha512_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_huge_number_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_md5_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_rsa_test_application_define, TEST_TIMEOUT_MID},
    {nx_secure_rsa_error_checking_test_application_define, TEST_TIMEOUT_MID},
    {nx_secure_aes_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_aes_additional_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_aes_ccm_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_phash_prf_test_application_define, TEST_TIMEOUT_LOW},
    {nx_secure_pkcs1_v1_5_test_application_define, TEST_TIMEOUT_LOW},
#endif /* CTEST */
    {NX_CRYPTO_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.  */
#ifndef NX_CRYPTO_STANDALONE_ENABLE
#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;
#endif

/* Define main entry point.  */
int main()
{

#ifdef NX_CRYPTO_SELF_TEST
    nx_crypto_initialize();

    _nx_crypto_method_self_test(0);
#endif

#if 0
    /* Reassign "stdout" to "freopen.out": */
    stream = freopen( "test_result.txt", "w", stdout );
#endif

#if defined(__linux__) && defined(USE_FORK)
    fork_child();
#else

    /* Enter the ThreadX kernel or use the test_application_define mapped to tx_kernel_enter when NX_CRYPTO_STANDALONE_ENABLE  */
    tx_kernel_enter();

#endif

    return 0;
}

#if defined(__linux__) && defined(USE_FORK)
static pid_t child_pid = -1;
static UINT test_index = 0;
static int result_fd[2];

void kill_child(int sig)
{
CHAR data[4]={0, 1, 0, 0};

    printf("killed by SIGALRM!\n");
    fflush(stdout);
    write(result_fd[1], data, sizeof(data));
    exit(1);
}

void fork_child()
{
INT status;
CHAR data[4];
struct pollfd fds;

    while (test_control_tests[test_index].test_entry != NX_CRYPTO_NULL)
    {

        /* Create pipe for communicating. */
        pipe(result_fd);
        fds.fd = result_fd[0];
        fds.events=POLLIN | POLLOUT | POLLERR;

        /* Fork test process. */
        child_pid = fork();
        if (child_pid > 0)
        {
            wait(&status);
            poll(&fds, 1, 0);
            if (fds.revents & POLLIN)
            {
                read(result_fd[0], data, sizeof(data));
                test_control_successful_tests += (ULONG)data[0];
                test_control_failed_tests += (ULONG)data[1];
                test_control_warning_tests += (ULONG)data[2];
                test_control_na_tests += (ULONG)data[3];
            }
            else
            {

                /* The child process crashes. */
                printf("ERROR!\n");
                test_control_failed_tests++;
            }

            fflush(stdout);

            test_index++;
        }
        else
        {

            /* Setup SIGALRM callback function. */
            signal(SIGALRM, (void (*)(int))kill_child);

            /* Initialize the results. */
            test_control_successful_tests = 0;
            test_control_failed_tests = 0;
            test_control_warning_tests = 0;
            test_control_na_tests = 0;

            /* Setup timeout alarm. */
            alarm(test_control_tests[test_index].timeout / NX_IP_PERIODIC_RATE);

            /* Enter the ThreadX kernel.  */
            tx_kernel_enter();
            return;
        }
    }

    /* 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);
#ifdef BATCH_TEST
    exit(test_control_failed_tests);
#endif
}

/* Define what the initial system looks like.  */

void    tx_application_define(void *first_unused_memory)
{

    /* Dispatch the test.  */
    (test_control_tests[test_index].test_entry)(first_unused_memory);
}

void  test_control_return(UINT status)
{
UINT    old_posture = TX_INT_ENABLE;
INT     exit_code = status;
CHAR    data[4];

    fflush(stdout);

    /* Initialize result through pipe. */
    data[0] = (CHAR)test_control_successful_tests;
    data[1] = (CHAR)test_control_failed_tests;
    data[2] = (CHAR)test_control_warning_tests;
    data[3] = (CHAR)test_control_na_tests;

    /* 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))
    {
        data[1]++;
        exit_code = 1;
    }
    else if(status == 2)
    {
        data[2]++;
        exit_code = 2;
    }
    else if(status == 0)
    {
        data[0]++;
        exit_code = 0;
    }
    else if(status == 3)
    {
        data[3]++;
        exit_code = 3;
    }

    /* Send result through pipe. */
    write(result_fd[1], data, sizeof(data));
    exit(exit_code);
}

#else
/* 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;
    
#ifndef NX_CRYPTO_STANDALONE_ENABLE
    /* 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);
#else
    test_control_thread_entry(0);
#endif

    pointer = pointer + TEST_STACK_SIZE;

#ifndef NX_CRYPTO_STANDALONE_ENABLE
#ifndef NETXTEST_TIMEOUT_DISABLE
    /* Create the test control semaphore.  */
    tx_semaphore_create(&test_control_sema, "Test control semaphore", 0);
#endif
#endif

    /* Remember the free memory pointer.  */
    test_free_memory_ptr = pointer;
}

/* 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 != NX_CRYPTO_NULL)
    {

        /* Dispatch the test.  */
        (test_control_tests[i++].test_entry)(test_free_memory_ptr);

        if (test_control_return_status != 3)
        {
#ifndef NX_CRYPTO_STANDALONE_ENABLE
#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
#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)
{
#ifndef NX_CRYPTO_STANDALONE_ENABLE
    UINT    old_posture = TX_INT_ENABLE;
#endif

    /* Save the status in a global.  */
    test_control_return_status = status;
#ifndef NX_CRYPTO_STANDALONE_ENABLE
    /* Ensure interrupts are enabled.  */
    old_posture = tx_interrupt_control(TX_INT_ENABLE);
#endif

    /* Determine if it was successful or not.  */
#ifndef NX_CRYPTO_STANDALONE_ENABLE
    if((status == 1) || (_tx_thread_preempt_disable) || (old_posture == TX_INT_DISABLE))
#else
    if(status == 1) 
#endif
        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++;
#ifndef NX_CRYPTO_STANDALONE_ENABLE
#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
#endif
}

void  test_control_cleanup(void)
{
#ifndef NX_CRYPTO_STANDALONE_ENABLE
    TX_MUTEX        *mutex_ptr;
    TX_THREAD       *thread_ptr;

    /* 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);
    }
#endif

    /* At this point, only the test control thread and the system timer thread and/or mutex should still be
    in the system.  */

#ifdef NX_PCAP_ENABLE
    /* Close the pcap file.  */
    close_pcap_file();
#endif
}
#endif