diff --git a/tests/test_etcp_simple_traffic.c b/tests/test_etcp_simple_traffic.c index 61bf960f..da5443dc 100644 --- a/tests/test_etcp_simple_traffic.c +++ b/tests/test_etcp_simple_traffic.c @@ -29,6 +29,10 @@ static uint8_t test_packet_data[PACKET_SIZE]; static int packet_sent = 0; static int packet_received = 0; +// State variables for monitor_and_send (non-static to avoid issues with multiple test runs in same process) +static int connection_checked = 0; +static int packet_sent_flag = 0; + // Function to check if connection is established - UPDATED WITH DEBUG static int is_connection_established(struct UTUN_INSTANCE* inst) { printf("[DEBUG] is_connection_established: Checking instance %p\n", inst); @@ -198,9 +202,6 @@ static void monitor_and_send(void* arg) { return; } - static int connection_checked = 0; - static int packet_sent_flag = 0; - // Check connection if (!connection_checked) { int server_ready = is_connection_established(server_instance); @@ -242,7 +243,13 @@ static void monitor_and_send(void* arg) { // Schedule next check if (!test_completed) { - packet_timeout_id = uasync_set_timeout(server_instance->ua, 100, NULL, monitor_and_send); + void* new_timeout = uasync_set_timeout(server_instance->ua, 100, NULL, monitor_and_send); + if (!new_timeout) { + DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "monitor_and_send: Failed to set timeout - uasync_set_timeout returned NULL"); + printf("[ERROR] Failed to set timeout in monitor_and_send\n"); + fflush(stdout); + } + packet_timeout_id = new_timeout; } } @@ -387,10 +394,18 @@ int main() { int elapsed = 0; int poll_interval = 5; + int check_counter = 0; while (!test_completed && elapsed < TEST_TIMEOUT_MS + 1000) { if (ua) uasync_poll(ua, poll_interval); elapsed += poll_interval; + check_counter++; + + // Check for received packet every 10 iterations (every 50ms) + // This ensures we check even if the timeout callback doesn't fire + if (packet_sent && !packet_received && (check_counter % 10 == 0)) { + check_packet_received(); + } // Quick exit if packet received if (test_completed == 1) {