diff --git a/lib/u_async.c b/lib/u_async.c index a6707e18..9f74fc04 100644 --- a/lib/u_async.c +++ b/lib/u_async.c @@ -1088,6 +1088,9 @@ static void wakeup_read_callback_posix(int fd, void* arg) { // This ensures the wakeup is a selectable SOCKET. struct UASYNC* uasync_create(void) { + // Initialize socket platform (Winsock on Windows) + socket_platform_init(); + struct UASYNC* ua = calloc(1, sizeof(struct UASYNC)); if (!ua) return NULL; diff --git a/run_tests.bat b/run_tests.bat deleted file mode 100644 index ed3635d4..00000000 --- a/run_tests.bat +++ /dev/null @@ -1,63 +0,0 @@ -@echo off -setlocal enabledelayedexpansion - -echo Running all tests... -echo. - -set passed=0 -set failed=0 -set skipped=0 -set total=0 - -for %%t in ( - test_etcp_crypto - test_crypto - test_etcp_two_instances - test_etcp_simple_traffic - test_etcp_minimal - test_etcp_100_packets - test_pkt_normalizer_etcp - test_pkt_normalizer_standalone - test_etcp_api - test_ll_queue - test_ecc_encrypt - test_intensive_memory_pool - test_memory_pool_and_config - test_packet_dump - test_u_async_comprehensive - test_u_async_performance - test_debug_categories - test_config_debug - test_route_lib - test_bgp_route_exchange - test_routing_mesh - bench_timeout_heap - bench_uasync_timeouts -) do ( - set /a total+=1 - if exist "tests\%%t.exe" ( - echo [RUN] %%t - tests\%%t.exe > tests\%%t.log 2>&1 - if !errorlevel! equ 0 ( - echo [PASS] %%t - set /a passed+=1 - ) else ( - echo [FAIL] %%t - set /a failed+=1 - echo Failed test log for %%t: - type tests\%%t.log - echo. - ) - ) else ( - echo [SKIP] %%t (not built) - set /a skipped+=1 - ) -) - -echo. -echo ========================================== -echo Test Results: %passed% passed, %failed% failed, %skipped% skipped (%total% total) -echo ========================================== - -if %failed% gtr 0 exit /b 1 -exit /b 0 diff --git a/src/utun.c b/src/utun.c index fe42c770..a1307b59 100644 --- a/src/utun.c +++ b/src/utun.c @@ -267,7 +267,7 @@ int main(int argc, char *argv[]) { return 0; } - socket_platform_init(); +// socket_platform_init(); // Initialize global debug system early if configured from command line diff --git a/tests/bench_uasync_timeouts.c b/tests/bench_uasync_timeouts.c index 7a1f1b82..d67027aa 100644 --- a/tests/bench_uasync_timeouts.c +++ b/tests/bench_uasync_timeouts.c @@ -4,7 +4,6 @@ #include #include #include "../lib/platform_compat.h" -#include "../lib/socket_compat.h" #include @@ -49,7 +48,6 @@ static void benchmark_without_sockets(void) { printf("=== Test 1: Zero timeouts WITHOUT sockets ===\n\n"); - socket_platform_init(); ua = uasync_create(); if (!ua) { @@ -106,7 +104,6 @@ static void benchmark_with_sockets(void) { printf("=== Test 2: Zero timeouts WITH %d sockets ===\n\n", NUM_SOCKETS); - socket_platform_init(); ua = uasync_create(); if (!ua) { @@ -192,7 +189,6 @@ static void benchmark_with_sockets(void) { } int main(void) { - socket_platform_init(); double set_time_no_sockets = 0, mainloop_time_no_sockets = 0; double set_time_with_sockets = 0, mainloop_time_with_sockets = 0; @@ -210,8 +206,7 @@ int main(void) { printf("=== Test 1: Zero timeouts WITHOUT sockets ===\n\n"); - socket_platform_init(); - + ua = uasync_create(); if (!ua) { fprintf(stderr, "Failed to create uasync\n"); @@ -252,8 +247,7 @@ int main(void) { printf("=== Test 2: Zero timeouts WITH %d sockets ===\n\n", NUM_SOCKETS); - socket_platform_init(); - + ua = uasync_create(); if (!ua) { fprintf(stderr, "Failed to create uasync\n"); diff --git a/tests/test_bgp_route_exchange.c b/tests/test_bgp_route_exchange.c index 26bddcc7..1ecb4c4e 100644 --- a/tests/test_bgp_route_exchange.c +++ b/tests/test_bgp_route_exchange.c @@ -35,7 +35,6 @@ #include "../src/tun_if.h" #include "../src/secure_channel.h" #include "../lib/u_async.h" -#include "../lib/socket_compat.h" #include "../lib/debug_config.h" #define TEST_TIMEOUT_MS 5000 // 5 seconds timeout @@ -346,7 +345,6 @@ int main() { } debug_config_init(); - socket_platform_init(); debug_set_level(DEBUG_LEVEL_INFO); debug_set_categories(DEBUG_CATEGORY_ROUTING | DEBUG_CATEGORY_ETCP | DEBUG_CATEGORY_BGP); diff --git a/tests/test_etcp_100_packets.c b/tests/test_etcp_100_packets.c index 5492af59..b4df8a8a 100644 --- a/tests/test_etcp_100_packets.c +++ b/tests/test_etcp_100_packets.c @@ -20,7 +20,6 @@ #include "../src/tun_if.h" #include "../src/secure_channel.h" #include "../lib/u_async.h" -#include "../lib/socket_compat.h" #include "../lib/ll_queue.h" #include "../lib/debug_config.h" @@ -396,7 +395,6 @@ int main() { memset(received_packets_back, 0, sizeof(received_packets_back)); debug_config_init(); - socket_platform_init(); debug_set_level(DEBUG_LEVEL_DEBUG); debug_set_categories(DEBUG_CATEGORY_ETCP); diff --git a/tests/test_etcp_api.c b/tests/test_etcp_api.c index 3dd27907..309d2242 100644 --- a/tests/test_etcp_api.c +++ b/tests/test_etcp_api.c @@ -31,7 +31,6 @@ #include "../src/secure_channel.h" #include "../src/pkt_normalizer.h" #include "../lib/u_async.h" -#include "../lib/socket_compat.h" #include "../lib/ll_queue.h" #include "../lib/debug_config.h" @@ -550,7 +549,6 @@ int main() { total_bytes, (float)total_bytes / TOTAL_PACKETS / 1024); debug_config_init(); - socket_platform_init(); debug_set_level(DEBUG_LEVEL_WARN); debug_set_categories(DEBUG_CATEGORY_ALL); diff --git a/tests/test_etcp_simple_traffic.c b/tests/test_etcp_simple_traffic.c index 155b1bef..3d1a6f5b 100644 --- a/tests/test_etcp_simple_traffic.c +++ b/tests/test_etcp_simple_traffic.c @@ -20,7 +20,6 @@ #include "../src/tun_if.h" #include "../src/secure_channel.h" #include "../lib/u_async.h" -#include "../lib/socket_compat.h" #include "../lib/ll_queue.h" #include "../lib/debug_config.h" @@ -362,7 +361,6 @@ int main() { // Enable debug output - MAXIMUM DEBUGGING debug_config_init(); - socket_platform_init(); debug_set_level(DEBUG_LEVEL_TRACE); debug_set_categories(DEBUG_CATEGORY_ALL); debug_enable_function_name(1); diff --git a/tests/test_etcp_two_instances.c b/tests/test_etcp_two_instances.c index e03c5f69..4f742ca0 100644 --- a/tests/test_etcp_two_instances.c +++ b/tests/test_etcp_two_instances.c @@ -20,7 +20,6 @@ #include "../src/tun_if.h" #include "../src/secure_channel.h" #include "../lib/u_async.h" -#include "../lib/socket_compat.h" #include "../lib/debug_config.h" #define TEST_TIMEOUT_MS 3000 // Reduced to 3 seconds for faster testing @@ -253,7 +252,6 @@ int main() { } debug_config_init(); - socket_platform_init(); debug_set_level(DEBUG_LEVEL_TRACE); debug_set_categories(DEBUG_CATEGORY_ALL); diff --git a/tests/test_ll_queue.c b/tests/test_ll_queue.c index 08c37471..1f1a1ff5 100644 --- a/tests/test_ll_queue.c +++ b/tests/test_ll_queue.c @@ -12,7 +12,6 @@ #include "../lib/ll_queue.h" #include "../lib/u_async.h" -#include "../lib/socket_compat.h" #include "../lib/debug_config.h" #include "../lib/memory_pool.h" @@ -274,7 +273,6 @@ static void test_stress(void) { /* ------------------------------------------------------------------ */ int main(void) { debug_config_init(); - socket_platform_init(); debug_set_level(DEBUG_LEVEL_DEBUG); debug_set_categories(DEBUG_CATEGORY_LL_QUEUE); diff --git a/tests/test_memory_pool_and_config.c b/tests/test_memory_pool_and_config.c index cbba191e..4d574a0d 100644 --- a/tests/test_memory_pool_and_config.c +++ b/tests/test_memory_pool_and_config.c @@ -12,7 +12,6 @@ #include "../lib/ll_queue.h" #include "../lib/memory_pool.h" #include "../lib/u_async.h" -#include "../lib/socket_compat.h" #include "../lib/debug_config.h" static int test_callback_count = 0; @@ -29,7 +28,6 @@ static void test_waiter_callback(struct ll_queue* q, void* arg) { int main() { debug_config_init(); - socket_platform_init(); debug_set_level(DEBUG_LEVEL_TRACE); debug_set_categories(DEBUG_CATEGORY_ALL); diff --git a/tests/test_pkt_normalizer_etcp.c b/tests/test_pkt_normalizer_etcp.c index 7e33fc33..7673e58d 100644 --- a/tests/test_pkt_normalizer_etcp.c +++ b/tests/test_pkt_normalizer_etcp.c @@ -21,7 +21,6 @@ #include "../src/secure_channel.h" #include "../src/pkt_normalizer.h" #include "../lib/u_async.h" -#include "../lib/socket_compat.h" #include "../lib/ll_queue.h" #include "../lib/debug_config.h" @@ -523,7 +522,6 @@ int main() { total_bytes, (float)total_bytes / TOTAL_PACKETS / 1024); debug_config_init(); - socket_platform_init(); debug_set_level(DEBUG_LEVEL_WARN); // debug_set_level(DEBUG_LEVEL_DEBUG); // debug_set_level(DEBUG_LEVEL_TRACE); diff --git a/tests/test_pkt_normalizer_standalone.c b/tests/test_pkt_normalizer_standalone.c index e8f713b9..846a5399 100644 --- a/tests/test_pkt_normalizer_standalone.c +++ b/tests/test_pkt_normalizer_standalone.c @@ -7,7 +7,6 @@ #include "../lib/debug_config.h" #include "../lib/u_async.h" -#include "../lib/socket_compat.h" #include "../lib/ll_queue.h" #include "../lib/memory_pool.h" #include "../src/pkt_normalizer.h" @@ -253,8 +252,7 @@ int main() { debug_set_level(DEBUG_LEVEL_INFO); debug_enable_category(DEBUG_CATEGORY_ETCP); - // Initialize Winsock and UASYNC - socket_platform_init(); + // Initialize UASYNC (includes Winsock init on Windows) mock_instance.ua = uasync_create(); if (!mock_instance.ua) { printf("Failed to create UASYNC\n"); diff --git a/tests/test_routing_mesh.c b/tests/test_routing_mesh.c index 637c86e4..8581fd92 100644 --- a/tests/test_routing_mesh.c +++ b/tests/test_routing_mesh.c @@ -20,7 +20,6 @@ #include "../src/tun_if.h" #include "../src/secure_channel.h" #include "../lib/u_async.h" -#include "../lib/socket_compat.h" #include "../lib/debug_config.h" #define TEST_TIMEOUT_MS 10000 // 10 seconds timeout @@ -340,7 +339,6 @@ int main(void) { } debug_config_init(); - socket_platform_init(); debug_set_level(DEBUG_LEVEL_WARN); ua = uasync_create(); diff --git a/tests/test_u_async_comprehensive.c b/tests/test_u_async_comprehensive.c index 47717c6e..874c70a1 100644 --- a/tests/test_u_async_comprehensive.c +++ b/tests/test_u_async_comprehensive.c @@ -8,7 +8,6 @@ #include #include #include "../lib/platform_compat.h" -#include "../lib/socket_compat.h" #include "u_async.h" #include "timeout_heap.h" @@ -139,7 +138,6 @@ static void test_error_callback(void* arg) { static void test_basic_timers(void) { TEST_START("Basic timer functionality"); - socket_platform_init(); uasync_t* ua = uasync_create(); ASSERT_NOT_NULL(ua, "Failed to create uasync instance"); @@ -174,7 +172,6 @@ static void test_basic_timers(void) { static void test_timer_cancellation_races(void) { TEST_START("Timer cancellation race conditions"); - socket_platform_init(); uasync_t* ua = uasync_create(); ASSERT_NOT_NULL(ua, "Failed to create uasync instance"); @@ -228,7 +225,6 @@ static void test_timer_cancellation_races(void) { static void test_immediate_timeouts(void) { TEST_START("Immediate timeout handling"); - socket_platform_init(); uasync_t* ua = uasync_create(); ASSERT_NOT_NULL(ua, "Failed to create uasync instance"); @@ -267,7 +263,6 @@ static void test_immediate_timeouts(void) { static void test_memory_leak_detection(void) { TEST_START("Memory leak detection"); - socket_platform_init(); uasync_t* ua = uasync_create(); ASSERT_NOT_NULL(ua, "Failed to create uasync instance"); @@ -301,7 +296,6 @@ static void test_memory_leak_detection(void) { static void test_socket_management(void) { TEST_START("Socket management efficiency"); - socket_platform_init(); uasync_t* ua = uasync_create(); ASSERT_NOT_NULL(ua, "Failed to create uasync instance"); @@ -350,7 +344,6 @@ static void test_socket_management(void) { static void test_error_handling(void) { TEST_START("Error injection and handling"); - socket_platform_init(); uasync_t* ua = uasync_create(); ASSERT_NOT_NULL(ua, "Failed to create uasync instance"); @@ -387,7 +380,6 @@ static void test_error_handling(void) { static void test_concurrent_operations(void) { TEST_START("Concurrent operations stress test"); - socket_platform_init(); uasync_t* ua = uasync_create(); ASSERT_NOT_NULL(ua, "Failed to create uasync instance"); @@ -499,7 +491,6 @@ static void test_concurrent_operations(void) { /* Main test runner */ int main(void) { debug_config_init(); - socket_platform_init(); debug_set_level(DEBUG_LEVEL_INFO); debug_set_categories(DEBUG_CATEGORY_ALL); diff --git a/tests/test_u_async_performance.c b/tests/test_u_async_performance.c index f7cac118..9df72056 100644 --- a/tests/test_u_async_performance.c +++ b/tests/test_u_async_performance.c @@ -8,7 +8,6 @@ #include #include #include "../lib/platform_compat.h" -#include "../lib/socket_compat.h" #include @@ -41,7 +40,6 @@ static void test_socket_callback(int fd, void* arg) { printf("=== Socket Management Benchmark ===\n"); printf("Testing with %d sockets\n\n", num_sockets); - socket_platform_init(); uasync_t* ua = uasync_create(); if (!ua) { @@ -272,7 +270,6 @@ static void benchmark_scalability(void) { } int main(void) { - socket_platform_init(); printf("lib Socket Management Performance Benchmark\n"); printf("================================================\n\n");