Browse Source

cleanup tests (winsock)

nodeinfo-routing-update
jeka 7 months ago
parent
commit
de053a00c0
  1. 3
      lib/u_async.c
  2. 63
      run_tests.bat
  3. 2
      src/utun.c
  4. 6
      tests/bench_uasync_timeouts.c
  5. 2
      tests/test_bgp_route_exchange.c
  6. 2
      tests/test_etcp_100_packets.c
  7. 2
      tests/test_etcp_api.c
  8. 2
      tests/test_etcp_simple_traffic.c
  9. 2
      tests/test_etcp_two_instances.c
  10. 2
      tests/test_ll_queue.c
  11. 2
      tests/test_memory_pool_and_config.c
  12. 2
      tests/test_pkt_normalizer_etcp.c
  13. 4
      tests/test_pkt_normalizer_standalone.c
  14. 2
      tests/test_routing_mesh.c
  15. 9
      tests/test_u_async_comprehensive.c
  16. 3
      tests/test_u_async_performance.c

3
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;

63
run_tests.bat

@ -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

2
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

6
tests/bench_uasync_timeouts.c

@ -4,7 +4,6 @@
#include <stdlib.h>
#include <time.h>
#include "../lib/platform_compat.h"
#include "../lib/socket_compat.h"
#include <stdint.h>
@ -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,7 +206,6 @@ int main(void) {
printf("=== Test 1: Zero timeouts WITHOUT sockets ===\n\n");
socket_platform_init();
ua = uasync_create();
if (!ua) {
@ -252,7 +247,6 @@ int main(void) {
printf("=== Test 2: Zero timeouts WITH %d sockets ===\n\n", NUM_SOCKETS);
socket_platform_init();
ua = uasync_create();
if (!ua) {

2
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);

2
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);

2
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);

2
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);

2
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);

2
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);

2
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);

2
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);

4
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");

2
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();

9
tests/test_u_async_comprehensive.c

@ -8,7 +8,6 @@
#include <string.h>
#include <assert.h>
#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);

3
tests/test_u_async_performance.c

@ -8,7 +8,6 @@
#include <string.h>
#include <stdint.h>
#include "../lib/platform_compat.h"
#include "../lib/socket_compat.h"
#include <sys/time.h>
@ -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");

Loading…
Cancel
Save