5353#include <string.h>
5454
5555/* Define mygetopt variables (used by mygetopt_long in test.h) */
56+ #ifndef NO_MAIN_DRIVER
5657int myoptind = 0 ;
5758char * myoptarg = NULL ;
59+ #endif
5860
5961#ifdef _WIN32
6062 #include <winsock2.h>
@@ -84,15 +86,6 @@ char* myoptarg = NULL;
8486#define MAX_PATH_LEN 256
8587#define MAX_CERTS 16
8688
87- /* Simple logging macro */
88- #define LOG_ERROR (...) \
89- do { \
90- if (got_signal) \
91- fprintf(stderr, "Shutdown requested, exiting loop\n"); \
92- else \
93- fprintf(stderr, __VA_ARGS__); \
94- } while (0)
95-
9689
9790#define LOG_MSG (...) \
9891 do { \
@@ -109,6 +102,21 @@ static void sig_handler(int sig)
109102 (void )sig ;
110103 got_signal = 1 ;
111104}
105+
106+ /* Simple logging macro */
107+ #define LOG_ERROR (...) \
108+ do { \
109+ if (got_signal) \
110+ fprintf(stderr, "Shutdown requested, exiting loop\n"); \
111+ else \
112+ fprintf(stderr, __VA_ARGS__); \
113+ } while (0)
114+ #else
115+ /* Simple logging macro */
116+ #define LOG_ERROR (...) \
117+ do { \
118+ fprintf(stderr, __VA_ARGS__); \
119+ } while (0)
112120#endif
113121
114122/* Index file entry structure */
@@ -737,6 +745,8 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
737745 }
738746 }
739747
748+ myoptind = 0 ; /* reset for test cases */
749+
740750 /* Validate required options */
741751 if (opts .certFile == NULL ) {
742752 LOG_ERROR ("Error: CA certificate required (-c)\n" );
@@ -855,9 +865,32 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
855865 }
856866 }
857867
868+ #ifdef USE_WINDOWS_API
869+ if (opts .port == 0 ) {
870+ /* Generate random port for testing */
871+ opts .port = GetRandomPort ();
872+ }
873+ #endif /* USE_WINDOWS_API */
874+
858875 /* Create and listen on server socket */
859876 tcp_listen (& sockfd , & opts .port , 1 , 0 , 0 );
860877
878+ #ifndef SINGLE_THREADED
879+ /* Signal readiness via tcp_ready if provided (for in-process testing) */
880+ if (myargs -> signal != NULL ) {
881+ tcp_ready * ready = myargs -> signal ;
882+ #ifdef WOLFSSL_COND
883+ THREAD_CHECK_RET (wolfSSL_CondStart (& ready -> cond ));
884+ #endif
885+ ready -> ready = 1 ;
886+ ready -> port = opts .port ;
887+ #ifdef WOLFSSL_COND
888+ THREAD_CHECK_RET (wolfSSL_CondSignal (& ready -> cond ));
889+ THREAD_CHECK_RET (wolfSSL_CondEnd (& ready -> cond ));
890+ #endif
891+ }
892+ #endif /* !SINGLE_THREADED */
893+
861894 /* Write ready file if requested */
862895 if (opts .readyFile != NULL ) {
863896 XFILE rf = XFOPEN (opts .readyFile , "w" );
@@ -1007,10 +1040,6 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
10071040 if (caKeyDer )
10081041 XFREE (caKeyDer , NULL , DYNAMIC_TYPE_TMP_BUFFER );
10091042
1010- #ifdef _WIN32
1011- WSACleanup ();
1012- #endif
1013-
10141043 myargs -> return_code = ret ;
10151044#ifndef WOLFSSL_THREAD_VOID_RETURN
10161045 return (THREAD_RETURN )0 ;
@@ -1025,6 +1054,8 @@ int main(int argc, char** argv)
10251054 func_args args ;
10261055 int ret ;
10271056
1057+ StartTCP ();
1058+
10281059#ifdef HAVE_WNR
10291060 if (wc_InitNetRandom (wnrConfigFile , NULL , 5000 ) != 0 ) {
10301061 err_sys ("Whitewood netRandom global config failed" );
0 commit comments