1 #include "tls_test_frame.h"
2 
3 INT nx_secure_echo_server_entry(TLS_TEST_INSTANCE* instance_ptr);
4 INT openssl_echo_client_entry(TLS_TEST_INSTANCE* instance_ptr);
5 
6 /* Global demo semaphore. */
7 TLS_TEST_SEMAPHORE* semaphore_echo_server_prepared;
8 
main(INT argc,CHAR * argv[])9 INT main( INT argc, CHAR* argv[])
10 {
11 INT status, exit_status[2];
12 TLS_TEST_INSTANCE *ins0;
13 TLS_TEST_INSTANCE *ins1;
14 
15     /* Create two test instances. */
16     status = tls_test_instance_create(&ins0,                        /* test instance ptr */
17                                       "nx_secure_echo_server",      /* instance name */
18                                       nx_secure_echo_server_entry,  /* test entry */
19                                       0,                            /* delay(seconds) */
20                                       60,                           /* timeout(seconds) */
21                                       1024,                         /* shared buffer size */
22                                       NULL);                        /* reserved */
23     return_value_if_fail(TLS_TEST_SUCCESS == status, status);
24 
25     status = tls_test_instance_create(&ins1,
26                                       "openssl_echo_client",
27                                       openssl_echo_client_entry,
28                                       0,
29                                       60,
30                                       1024,
31                                       NULL);
32     return_value_if_fail(TLS_TEST_SUCCESS == status, status);
33 
34     /* Create a semaphore and set the initial value as 0. */
35     status = tls_test_semaphore_create(&semaphore_echo_server_prepared, 0);
36 
37     /* Create the test director. */
38     TLS_TEST_DIRECTOR *director;
39     status = tls_test_director_create(&director, NULL /* reserved */);
40     return_value_if_fail(TLS_TEST_SUCCESS == status, status);
41 
42     /* Register test instances to the director. */
43     status = tls_test_director_register_test_instance(director, ins0);
44     status += tls_test_director_register_test_instance(director, ins1);
45     return_value_if_fail(TLS_TEST_SUCCESS == status, TLS_TEST_UNKNOWN_TYPE_ERROR);
46 
47     /* Launch test. */
48     status = tls_test_director_test_start(director);
49     return_value_if_fail(TLS_TEST_SUCCESS == status, status);
50 
51     /* Collect exit code. */
52     tls_test_instance_show_exit_status(ins0);
53     tls_test_instance_show_exit_status(ins1);
54 
55     /* Call the verify method to determine whether the test is passed. */
56     status = tls_test_instance_get_exit_status(ins0, &exit_status[0]);
57     show_error_message_if_fail(TLS_TEST_SUCCESS == status);
58     status = tls_test_instance_get_exit_status(ins1, &exit_status[1]);
59     show_error_message_if_fail(TLS_TEST_SUCCESS == status);
60 
61     /* Destroy registered test instances and the director. */
62     tls_test_director_clean_all(director);
63 
64     /* Destroy the semaphore. */
65     tls_test_semaphore_destroy(semaphore_echo_server_prepared);
66 
67     /* Return error if get unexpected test results. */
68     if ((TLS_TEST_NOT_AVAILABLE == exit_status[0]) || (TLS_TEST_NOT_AVAILABLE == exit_status[1]))
69         return TLS_TEST_NOT_AVAILABLE;
70 
71     /* Return the result of verification. */
72     return exit_status[0] | exit_status[1];
73 }
74