From d74ab1c1c6978eb413fe1929054e378b5fd0ba15 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Tue, 21 Apr 2026 19:06:45 +0300 Subject: [PATCH] Add name parameter to uasync_set_timeout for timer identification in dumps --- lib/u_async.c | 32 ++++++++++++++++---------- lib/u_async.h | 2 +- net_emulator/net_emulator.c | 2 +- src/dummynet.c | 6 ++--- src/etcp.c | 6 ++--- src/etcp_connections.c | 13 ++++++----- src/etcp_loadbalancer.c | 2 +- src/route_ping.c | 4 ++-- src/utun.c | 2 +- tests/bench_uasync_timeouts.c | 8 +++---- tests/debug_full_test.c | 14 +++++------ tests/detailed_test.c | 6 ++--- tests/test_bgp_route_exchange.c | 8 +++---- tests/test_dummynet.c | 4 ++-- tests/test_etcp_100_packets.c | 6 ++--- tests/test_etcp_api.c | 8 +++---- tests/test_etcp_dummynet.c | 2 +- tests/test_etcp_ping.c | 4 ++-- tests/test_etcp_simple_traffic.c | 6 ++--- tests/test_etcp_two_instances.c | 6 ++--- tests/test_nat_detection.c | 2 +- tests/test_pkt_normalizer_etcp.c | 6 ++--- tests/test_pkt_normalizer_standalone.c | 6 ++--- tests/test_route_ping.c | 2 +- tests/test_routing_mesh.c | 2 +- tests/test_u_async_comprehensive.c | 22 +++++++++--------- tests/test_u_async_timeouts.c | 6 ++--- tests/track_test.c | 8 +++---- 28 files changed, 102 insertions(+), 93 deletions(-) diff --git a/lib/u_async.c b/lib/u_async.c index 87bfa81f..c2267155 100644 --- a/lib/u_async.c +++ b/lib/u_async.c @@ -32,6 +32,7 @@ // Timeout node with safe cancellation struct timeout_node { + char name[16]; void* arg; timeout_callback_t callback; uint64_t expiration_ms; // absolute expiration time in milliseconds @@ -491,22 +492,28 @@ static void get_next_timeout(struct UASYNC* ua, struct timeval* tv) { -// Instance version -void* uasync_set_timeout(struct UASYNC* ua, int timeout_tb, void* arg, timeout_callback_t callback) { - if (!ua || timeout_tb < 0 || !callback) return NULL; - if (!ua->timeout_heap) return NULL; - -// DEBUG_DEBUG(DEBUG_CATEGORY_TIMERS, "uasync_set_timeout: timeout=%d.%d ms, arg=%p, callback=%p", timeout_tb/10, timeout_tb%10, arg, callback); - +// Instance version +void* uasync_set_timeout(struct UASYNC* ua, int timeout_tb, void* arg, timeout_callback_t callback, const char* name) { + if (!ua || timeout_tb < 0 || !callback) return NULL; + if (!ua->timeout_heap) return NULL; + +// DEBUG_DEBUG(DEBUG_CATEGORY_TIMERS, "uasync_set_timeout: timeout=%d.%d ms, arg=%p, callback=%p", timeout_tb/10, timeout_tb%10, arg, callback); + struct timeout_node* node = memory_pool_alloc(ua->timeout_pool); if (!node) { DEBUG_ERROR(DEBUG_CATEGORY_TIMERS, "uasync_set_timeout: failed to allocate node"); return NULL; - } - ua->timer_alloc_count++; - - node->arg = arg; - node->callback = callback; + } + ua->timer_alloc_count++; + + if (name) { + strncpy(node->name, name, sizeof(node->name) - 1); + node->name[sizeof(node->name) - 1] = '\0'; + } else { + node->name[0] = '\0'; + } + node->arg = arg; + node->callback = callback; node->ua = ua; // Calculate expiration time in milliseconds @@ -538,6 +545,7 @@ void* uasync_call_soon(struct UASYNC* ua, void* user_arg, timeout_callback_t cal } ua->timer_alloc_count++; + node->name[0] = '\0'; node->arg = user_arg; node->callback = callback; node->ua = ua; diff --git a/lib/u_async.h b/lib/u_async.h index 468057c8..b54268ff 100644 --- a/lib/u_async.h +++ b/lib/u_async.h @@ -82,7 +82,7 @@ void uasync_destroy(struct UASYNC* ua, int close_fds); uint64_t get_time_tb(void); // Timeouts, timebase = 0.1 mS -void* uasync_set_timeout(struct UASYNC* ua, int timeout_tb, void* user_arg, timeout_callback_t callback); +void* uasync_set_timeout(struct UASYNC* ua, int timeout_tb, void* user_arg, timeout_callback_t callback, const char* name); err_t uasync_cancel_timeout(struct UASYNC* ua, void* t_id); // Immediate execution in next mainloop (FIFO order) diff --git a/net_emulator/net_emulator.c b/net_emulator/net_emulator.c index 4a3de1a2..c1f9db8f 100644 --- a/net_emulator/net_emulator.c +++ b/net_emulator/net_emulator.c @@ -376,7 +376,7 @@ static void socket_callback(int fd, void *user_arg) { u_free(packet); return; } - uasync_set_timeout(ep->emulator->ua, delay_tb, packet, (timeout_callback_t)send_delayed_packet); + uasync_set_timeout(ep->emulator->ua, delay_tb, packet, (timeout_callback_t)send_delayed_packet, "netem_delay"); } // Callback for sending delayed packet diff --git a/src/dummynet.c b/src/dummynet.c index f1a403ab..a2fd21bd 100644 --- a/src/dummynet.c +++ b/src/dummynet.c @@ -158,7 +158,7 @@ static void dummynet_process_queue(struct dummynet* dn, int dir_idx) { if (sarg) { sarg->dn = dn; sarg->dir_idx = dir_idx; - dir->shaper_timer = uasync_set_timeout(dn->ua, delay_tb, sarg, dummynet_shaper_callback); + dir->shaper_timer = uasync_set_timeout(dn->ua, delay_tb, sarg, dummynet_shaper_callback, "dummynet_shaper"); if (dir->shaper_timer) { dir->shaper_timer_set++; } else { @@ -270,7 +270,7 @@ static void dummynet_read_callback(socket_t sock, void* user_arg) { targ->dn = dn; targ->entry = entry; - void* timer = uasync_set_timeout(dn->ua, delay_tb, targ, dummynet_delay_callback); + void* timer = uasync_set_timeout(dn->ua, delay_tb, targ, dummynet_delay_callback, "dummynet_delay"); if (!timer) { DEBUG_ERROR(DEBUG_CATEGORY_DUMMYNET, "Failed to set delay timer"); dir->stats.dropped++; @@ -326,7 +326,7 @@ static void dummynet_delay_callback(void* user_arg) { if (sarg) { sarg->dn = dn; sarg->dir_idx = dir_idx; - dir->shaper_timer = uasync_set_timeout(dn->ua, 0, sarg, dummynet_shaper_callback); + dir->shaper_timer = uasync_set_timeout(dn->ua, 0, sarg, dummynet_shaper_callback, "dummynet_shaper0"); } else { dir->shaper_pending = 0; } diff --git a/src/etcp.c b/src/etcp.c index 51b75e64..6c96947d 100644 --- a/src/etcp.c +++ b/src/etcp.c @@ -606,7 +606,7 @@ static void ack_timeout_check(struct ETCP_CONN* etcp) { // shedule timer int64_t next_timeout=timeout - elapsed; if (next_timeout<0) next_timeout=0; - etcp->retrans_timer = uasync_set_timeout(etcp->instance->ua, next_timeout+10, etcp, ack_timeout_cb); + etcp->retrans_timer = uasync_set_timeout(etcp->instance->ua, next_timeout+10, etcp, ack_timeout_cb, "etcp_retrans"); DEBUG_TRACE(DEBUG_CATEGORY_ETCP, "[%s] retransmission timer set for %llu units", etcp->log_name, next_timeout); return; } @@ -670,7 +670,7 @@ static void ack_response_timer_cb(void* arg) {// проверяем неотпр if (etcp->ack_q->count==0) return;// нечего отправлять etcp_conn_process_send_queue(etcp);// проталкиваем (она же должна отправлять только ack если больше ничего нет) // если ack все еще заняты - обновляем таймаут - if (etcp->ack_q->count) etcp->ack_resp_timer = uasync_set_timeout(etcp->instance->ua, ACK_DELAY_TB, etcp, ack_response_timer_cb); + if (etcp->ack_q->count) etcp->ack_resp_timer = uasync_set_timeout(etcp->instance->ua, ACK_DELAY_TB, etcp, ack_response_timer_cb, "etcp_ack_resp"); // else etcp->ack_resp_timer=NULL; } @@ -1152,7 +1152,7 @@ void etcp_conn_input(struct ETCP_DGRAM* pkt) { queue_data_put_with_index(etcp->ack_q, (struct ll_entry*)p, 0, 4); if (etcp->ack_resp_timer == NULL) { - etcp->ack_resp_timer = uasync_set_timeout(etcp->instance->ua, ACK_DELAY_TB, etcp, ack_response_timer_cb); + etcp->ack_resp_timer = uasync_set_timeout(etcp->instance->ua, ACK_DELAY_TB, etcp, ack_response_timer_cb, "etcp_ack_resp"); DEBUG_TRACE(DEBUG_CATEGORY_ETCP, "[%s] set ack_timer for delayed ACK send", etcp->log_name); } if (((int32_t)(etcp->last_delivered_id-seq)<0) && (queue_find_data_by_index(etcp->recv_q, &seq, 4)==NULL)) {// проверяем есть ли пакет с этим seq diff --git a/src/etcp_connections.c b/src/etcp_connections.c index fd68efff..e10669a3 100644 --- a/src/etcp_connections.c +++ b/src/etcp_connections.c @@ -144,7 +144,7 @@ static void etcp_link_init_timer_cbk(void* arg) { link->init_timeout += link->init_timeout/4 +1; if (link->init_timeout > INIT_TIMEOUT_MAX) link->init_timeout = INIT_TIMEOUT_MAX; } - link->init_timer = uasync_set_timeout(link->etcp->instance->ua, link->init_timeout, link, etcp_link_init_timer_cbk); + link->init_timer = uasync_set_timeout(link->etcp->instance->ua, link->init_timeout, link, etcp_link_init_timer_cbk, "link_init"); if (link->link_state == 1) etcp_link_send_init(link,1);// init (with etcp reset) else etcp_link_send_init(link,0);// no etcp reset (reinit) @@ -154,7 +154,7 @@ void etcp_link_restart_init_timer(struct ETCP_LINK* link) { DEBUG_TRACE(DEBUG_CATEGORY_CONNECTION, ""); if (link->init_timer) uasync_cancel_timeout(link->etcp->instance->ua, link->init_timer); link->init_timeout = INIT_TIMEOUT_INITIAL; - link->init_timer = uasync_set_timeout(link->etcp->instance->ua, link->init_timeout, link, etcp_link_init_timer_cbk); + link->init_timer = uasync_set_timeout(link->etcp->instance->ua, link->init_timeout, link, etcp_link_init_timer_cbk, "link_init"); } void etcp_link_enter_init(struct ETCP_LINK* link) {// @@ -231,7 +231,7 @@ static void start_keepalive_timer(struct ETCP_LINK* link) { } if (link->keepalive_timer == NULL) { - link->keepalive_timer = uasync_set_timeout(link->etcp->instance->ua, link->keepalive_interval * 10, link, keepalive_timer_cb); + link->keepalive_timer = uasync_set_timeout(link->etcp->instance->ua, link->keepalive_interval * 10, link, keepalive_timer_cb, "link_keepalive"); DEBUG_DEBUG(DEBUG_CATEGORY_CONNECTION, "[%s] Keepalive timer started on link %p (interval=%d ms)", link->etcp->log_name, link, link->keepalive_interval); } } @@ -286,7 +286,7 @@ static void keepalive_timer_cb(void* arg) { link->pkt_sent_since_keepalive = 0; restart_timer: - link->keepalive_timer = uasync_set_timeout(link->etcp->instance->ua, link->keepalive_interval * 10, link, keepalive_timer_cb); + link->keepalive_timer = uasync_set_timeout(link->etcp->instance->ua, link->keepalive_interval * 10, link, keepalive_timer_cb, "link_keepalive"); } static uint32_t sockaddr_hash(struct sockaddr_storage* addr) { @@ -766,7 +766,8 @@ void start_stats_timer(struct ETCP_LINK* link) { link->etcp->instance->ua, tb, link, - link_stats_timer_cb + link_stats_timer_cb, + "link_stats" ); } @@ -1039,7 +1040,7 @@ int etcp_send_ping_to_socket(struct UTUN_INSTANCE* instance, struct ETCP_SOCKET* while (last->next) last = last->next; last->next = ctx; } - ctx->timeout_timer = uasync_set_timeout(instance->ua, timeout_ms * 10, ctx, ping_timeout_cbk); + ctx->timeout_timer = uasync_set_timeout(instance->ua, timeout_ms * 10, ctx, ping_timeout_cbk, "ping_timeout"); DEBUG_INFO(DEBUG_CATEGORY_BGP, "ping sent nonce=%016llx timeout=%d ulen=%zu", (unsigned long long)ctx->nonce, timeout_ms, user_data_len); return 0; diff --git a/src/etcp_loadbalancer.c b/src/etcp_loadbalancer.c index 42c0db01..53a314e0 100644 --- a/src/etcp_loadbalancer.c +++ b/src/etcp_loadbalancer.c @@ -136,7 +136,7 @@ void etcp_loadbalancer_send(struct ETCP_DGRAM* dgram) { uint64_t now_tb=get_time_tb(); if (link->shaper_load_time_tb >= now_tb + SHAPER_BURST_DELAY_TB) { uint64_t wait_tb = link->shaper_load_time_tb - now_tb; - link->shaper_timer = uasync_set_timeout(link->etcp->instance->ua, wait_tb, link, shaper_timer_cb); + link->shaper_timer = uasync_set_timeout(link->etcp->instance->ua, wait_tb, link, shaper_timer_cb, "shaper"); if (link->shaper_timer == NULL) DEBUG_ERROR(DEBUG_CATEGORY_TIMERS, "Filed to allocate timer"); DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "[%s] scheduled shaper timer (wait_tb=%llu) BW=%d pkt_size=%d", etcp->log_name, (unsigned long long)wait_tb, link->bandwidth, pkt_size); } diff --git a/src/route_ping.c b/src/route_ping.c index 717c13aa..9d2b5f06 100644 --- a/src/route_ping.c +++ b/src/route_ping.c @@ -117,7 +117,7 @@ int route_ping_send_req(struct ROUTE_BGP* bgp, struct ETCP_CONN* to_conn, uint64 pending->next = bgp->ping_pending; bgp->ping_pending = pending; - pending->timeout_timer = uasync_set_timeout(bgp->instance->ua, wait_timeout_ms * 10, pending, route_ping_pending_timeout); + pending->timeout_timer = uasync_set_timeout(bgp->instance->ua, wait_timeout_ms * 10, pending, route_ping_pending_timeout, "route_ping"); DEBUG_INFO(DEBUG_CATEGORY_BGP, "request_id=%016llx node=%016llx count=%u interval=%u timeout=%u wait=%u", (unsigned long long)pending->request_id, (unsigned long long)node_id, @@ -220,7 +220,7 @@ int route_ping_send_req_addr(struct ROUTE_BGP* bgp, struct ETCP_CONN* to_conn, u pending->next = bgp->ping_pending; bgp->ping_pending = pending; - pending->timeout_timer = uasync_set_timeout(bgp->instance->ua, wait_timeout_ms * 10, pending, route_ping_pending_timeout); + pending->timeout_timer = uasync_set_timeout(bgp->instance->ua, wait_timeout_ms * 10, pending, route_ping_pending_timeout, "route_ping"); DEBUG_INFO(DEBUG_CATEGORY_BGP, "request_id=%016llx node=%016llx ip=%s port=%u pubkey=%s", (unsigned long long)pending->request_id, (unsigned long long)node_id, diff --git a/src/utun.c b/src/utun.c index d7eb24ed..a6b8f980 100644 --- a/src/utun.c +++ b/src/utun.c @@ -258,7 +258,7 @@ static void signal_handler(int sig) { void test_tmr(void* arg) { struct UASYNC* ua = (struct UASYNC*)arg; - uasync_set_timeout(ua, 10000, ua, test_tmr); + uasync_set_timeout(ua, 10000, ua, test_tmr, "utun_test"); // DEBUG_INFO(DEBUG_CATEGORY_ETCP, "tick ..."); } diff --git a/tests/bench_uasync_timeouts.c b/tests/bench_uasync_timeouts.c index d67027aa..ec2b231d 100644 --- a/tests/bench_uasync_timeouts.c +++ b/tests/bench_uasync_timeouts.c @@ -58,7 +58,7 @@ static void benchmark_without_sockets(void) { // Set 100 zero timeouts clock_gettime(CLOCK_MONOTONIC, &start); for (i = 0; i < NUM_TIMEOUTS; i++) { - timeout_ids[i] = uasync_set_timeout(ua, 0, (void*)(uintptr_t)(i + 1), timeout_callback); + timeout_ids[i] = uasync_set_timeout(ua, 0, (void*)(uintptr_t)(i + 1), timeout_callback, "bench0"); if (!timeout_ids[i]) { fprintf(stderr, "Failed to set timeout at iteration %d\n", i); uasync_destroy(ua, 0); @@ -147,7 +147,7 @@ static void benchmark_with_sockets(void) { // Set 100 zero timeouts WITH sockets already open clock_gettime(CLOCK_MONOTONIC, &start); for (i = 0; i < NUM_TIMEOUTS; i++) { - timeout_ids[i] = uasync_set_timeout(ua, 0, (void*)(uintptr_t)(i + 1), timeout_callback); + timeout_ids[i] = uasync_set_timeout(ua, 0, (void*)(uintptr_t)(i + 1), timeout_callback, "bench0"); if (!timeout_ids[i]) { fprintf(stderr, "Failed to set timeout at iteration %d\n", i); for (int j = 0; j < NUM_SOCKETS; j++) { @@ -215,7 +215,7 @@ int main(void) { clock_gettime(CLOCK_MONOTONIC, &start); for (i = 0; i < NUM_TIMEOUTS; i++) { - timeout_ids[i] = uasync_set_timeout(ua, 0, (void*)(uintptr_t)(i + 1), timeout_callback); + timeout_ids[i] = uasync_set_timeout(ua, 0, (void*)(uintptr_t)(i + 1), timeout_callback, "bench0"); } clock_gettime(CLOCK_MONOTONIC, &end); set_time_no_sockets = measure_time_diff(&start, &end); @@ -266,7 +266,7 @@ int main(void) { // Set timeouts WITH sockets open clock_gettime(CLOCK_MONOTONIC, &start); for (i = 0; i < NUM_TIMEOUTS; i++) { - timeout_ids[i] = uasync_set_timeout(ua, 0, (void*)(uintptr_t)(i + 1), timeout_callback); + timeout_ids[i] = uasync_set_timeout(ua, 0, (void*)(uintptr_t)(i + 1), timeout_callback, "bench0"); } clock_gettime(CLOCK_MONOTONIC, &end); set_time_with_sockets = measure_time_diff(&start, &end); diff --git a/tests/debug_full_test.c b/tests/debug_full_test.c index 14090e8d..04227625 100644 --- a/tests/debug_full_test.c +++ b/tests/debug_full_test.c @@ -102,9 +102,9 @@ static void test_basic_timers(void) { ctx.timeout_ms = 10; // Non-zero to avoid immediate timeout counting /* Set multiple timers with different timeouts */ - void* timer1 = uasync_set_timeout(ua, 10, &ctx, test_timer_callback); /* 1ms */ - void* timer2 = uasync_set_timeout(ua, 20, &ctx, test_timer_callback); /* 2ms */ - void* timer3 = uasync_set_timeout(ua, 30, &ctx, test_timer_callback); /* 3ms */ + void* timer1 = uasync_set_timeout(ua, 10, &ctx, test_timer_callback, "test_t1"); /* 1ms */ + void* timer2 = uasync_set_timeout(ua, 20, &ctx, test_timer_callback, "test_t2"); /* 2ms */ + void* timer3 = uasync_set_timeout(ua, 30, &ctx, test_timer_callback, "test_t3"); /* 3ms */ ASSERT_NOT_NULL(timer1, "Failed to set timer 1"); ASSERT_NOT_NULL(timer2, "Failed to set timer 2"); @@ -136,9 +136,9 @@ static void test_timer_cancellation_races(void) { ctx.timeout_ms = 5; // Non-zero to avoid immediate timeout counting /* Create timers that will be cancelled at different stages */ - void* timer1 = uasync_set_timeout(ua, 5, &ctx, test_timer_callback); /* 0.5ms */ - void* timer2 = uasync_set_timeout(ua, 50, &ctx, test_timer_callback); /* 5ms */ - void* timer3 = uasync_set_timeout(ua, 100, &ctx, test_timer_callback); /* 10ms */ + void* timer1 = uasync_set_timeout(ua, 5, &ctx, test_timer_callback, "test_t1"); /* 0.5ms */ + void* timer2 = uasync_set_timeout(ua, 50, &ctx, test_timer_callback, "test_t2"); /* 5ms */ + void* timer3 = uasync_set_timeout(ua, 100, &ctx, test_timer_callback, "test_t3"); /* 10ms */ ASSERT_NOT_NULL(timer1, "Failed to set timer 1"); ASSERT_NOT_NULL(timer2, "Failed to set timer 2"); @@ -192,7 +192,7 @@ static void test_immediate_timeouts(void) { /* Set multiple immediate timeouts (0ms) */ for (int i = 0; i < 5; i++) { - void* timer = uasync_set_timeout(ua, 0, &ctx, test_timer_callback); + void* timer = uasync_set_timeout(ua, 0, &ctx, test_timer_callback, "test_imm"); ASSERT_NOT_NULL(timer, "Failed to set immediate timer"); } diff --git a/tests/detailed_test.c b/tests/detailed_test.c index f4835552..260a950e 100644 --- a/tests/detailed_test.c +++ b/tests/detailed_test.c @@ -36,7 +36,7 @@ int main() { test_context_t ctx1 = {.timeout_ms = 10}; for (int i = 0; i < 3; i++) { - uasync_set_timeout(ua1, 10 + i*10, &ctx1, test_timer_callback); + uasync_set_timeout(ua1, 10 + i*10, &ctx1, test_timer_callback, "test_d1"); } int polls = 0; @@ -55,7 +55,7 @@ int main() { test_context_t ctx2 = {.timeout_ms = 0}; for (int i = 0; i < 5; i++) { - uasync_set_timeout(ua2, 0, &ctx2, test_timer_callback); + uasync_set_timeout(ua2, 0, &ctx2, test_timer_callback, "test_d2"); } printf("Before poll: ctx2.callback_count = %d, immediate_timeouts = %d\n", ctx2.callback_count, test_stats.immediate_timeouts); @@ -73,7 +73,7 @@ int main() { test_context_t ctx3 = {.timeout_ms = 0}; for (int i = 0; i < 2; i++) { - uasync_set_timeout(ua3, 0, &ctx3, test_timer_callback); + uasync_set_timeout(ua3, 0, &ctx3, test_timer_callback, "test_d3"); } uasync_poll(ua3, 1); diff --git a/tests/test_bgp_route_exchange.c b/tests/test_bgp_route_exchange.c index a43aee6e..a4811df0 100644 --- a/tests/test_bgp_route_exchange.c +++ b/tests/test_bgp_route_exchange.c @@ -284,7 +284,7 @@ static void monitor_connections(void* arg) { DEBUG_INFO(DEBUG_CATEGORY_ETCP, "=== Connection established! Waiting for BGP exchange... ==="); test_phase = 1; // Schedule next check after BGP exchange time - monitor_timeout_id = uasync_set_timeout(ua, BGP_EXCHANGE_WAIT_MS, NULL, monitor_connections); + monitor_timeout_id = uasync_set_timeout(ua, BGP_EXCHANGE_WAIT_MS, NULL, monitor_connections, "test_monitor"); return; } break; @@ -317,7 +317,7 @@ static void monitor_connections(void* arg) { // Schedule next check if (test_phase < 3) { - monitor_timeout_id = uasync_set_timeout(ua, 100, NULL, monitor_connections); + monitor_timeout_id = uasync_set_timeout(ua, 100, NULL, monitor_connections, "test_monitor"); } } @@ -400,8 +400,8 @@ int main() { // Start monitoring DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Starting connection monitoring..."); - monitor_timeout_id = uasync_set_timeout(ua, 100, NULL, monitor_connections); - test_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, test_timeout); + monitor_timeout_id = uasync_set_timeout(ua, 100, NULL, monitor_connections, "test_monitor"); + test_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, test_timeout, "test_timeout"); // Main event loop - use uasync timers only, no artificial timing DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Running event loop..."); diff --git a/tests/test_dummynet.c b/tests/test_dummynet.c index 59109e6c..4b7b1713 100644 --- a/tests/test_dummynet.c +++ b/tests/test_dummynet.c @@ -114,7 +114,7 @@ static void send_timer_callback(void* arg) { st->next_seq++; /* Перезапускаем таймер на следующую отправку (10 timebase = 1ms) */ - st->send_timer = uasync_set_timeout(st->ua, 10, st, send_timer_callback); + st->send_timer = uasync_set_timeout(st->ua, 10, st, send_timer_callback, "test_dummynet"); } /* Burst отправка - все пакеты сразу */ @@ -259,7 +259,7 @@ static int run_scenario(const char* name, printf("Sending %d packets (fast)...\n", PKT_COUNT); /* Запускаем таймер отправки с интервалом 1 timebase (0.1ms) */ - st.send_timer = uasync_set_timeout(st.ua, 1, &st, send_timer_callback); + st.send_timer = uasync_set_timeout(st.ua, 1, &st, send_timer_callback, "test_dummynet"); /* Умное ожидание завершения: ранний выход при готовности + watchdog */ uint64_t start_time = get_time_us(); diff --git a/tests/test_etcp_100_packets.c b/tests/test_etcp_100_packets.c index c11d9ffa..b73080c2 100644 --- a/tests/test_etcp_100_packets.c +++ b/tests/test_etcp_100_packets.c @@ -361,7 +361,7 @@ static void monitor_and_send(void* arg) { } if (!test_completed) { - packet_timeout_id = uasync_set_timeout(ua, 10, NULL, monitor_and_send); + packet_timeout_id = uasync_set_timeout(ua, 10, NULL, monitor_and_send, "test_monitor"); } } @@ -419,8 +419,8 @@ int main() { printf("✅ Client ready\n\n"); printf("Sending %d packets in each direction (max queue size: %d)...\n", TOTAL_PACKETS, MAX_QUEUE_SIZE); - packet_timeout_id = uasync_set_timeout(ua, 500, NULL, monitor_and_send); - void* global_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, test_timeout); + packet_timeout_id = uasync_set_timeout(ua, 500, NULL, monitor_and_send, "test_monitor"); + void* global_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, test_timeout, "test_timeout"); while (!test_completed) { uasync_poll(ua, 100); diff --git a/tests/test_etcp_api.c b/tests/test_etcp_api.c index 309d2242..48c1fde6 100644 --- a/tests/test_etcp_api.c +++ b/tests/test_etcp_api.c @@ -437,7 +437,7 @@ static void monitor_and_send(void* arg) { connection_delay++; if (connection_delay < 50) { // Ждем 50 циклов (~500ms) if (!test_completed) { - packet_timeout_id = uasync_set_timeout(ua, 10, NULL, monitor_and_send); + packet_timeout_id = uasync_set_timeout(ua, 10, NULL, monitor_and_send, "test_monitor"); } return; } @@ -506,7 +506,7 @@ static void monitor_and_send(void* arg) { } if (!test_completed) { - packet_timeout_id = uasync_set_timeout(ua, 10, NULL, monitor_and_send); + packet_timeout_id = uasync_set_timeout(ua, 10, NULL, monitor_and_send, "test_monitor"); } } @@ -586,8 +586,8 @@ int main() { DATA_PACKET_ID, (void*)server_recv_callback, (void*)client_recv_callback); printf("Sending %d packets in each direction via etcp_send...\n", TOTAL_PACKETS); - packet_timeout_id = uasync_set_timeout(ua, 1000, NULL, monitor_and_send); - void* global_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS*10, NULL, test_timeout); + packet_timeout_id = uasync_set_timeout(ua, 1000, NULL, monitor_and_send, "test_monitor"); + void* global_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS*10, NULL, test_timeout, "test_timeout"); while (!test_completed) { uasync_poll(ua, 100); // 100ms timeout to allow timer processing diff --git a/tests/test_etcp_dummynet.c b/tests/test_etcp_dummynet.c index 23c5d1d5..ba5dd9b5 100644 --- a/tests/test_etcp_dummynet.c +++ b/tests/test_etcp_dummynet.c @@ -94,7 +94,7 @@ static void send_pkt(void* arg) { /* Schedule next packet with 5ms delay for rate limiting (~200 pkt/sec) * Note: uasync_set_timeout uses 0.1ms units, so 50 = 5ms */ - uasync_set_timeout(ua, 50, NULL, send_pkt); + uasync_set_timeout(ua, 50, NULL, send_pkt, "test_dnet"); } static struct UTUN_INSTANCE* create_instance(struct UASYNC* u, uint64_t node_id, diff --git a/tests/test_etcp_ping.c b/tests/test_etcp_ping.c index 980e8b4b..60b4dfdd 100644 --- a/tests/test_etcp_ping.c +++ b/tests/test_etcp_ping.c @@ -169,8 +169,8 @@ int main(void) { DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "Client init_connections failed with code %d", ret); goto cleanup; } - monitor_timeout_id = uasync_set_timeout(ua, 100, NULL, monitor_connections); - test_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, test_timeout); + monitor_timeout_id = uasync_set_timeout(ua, 100, NULL, monitor_connections, "test_monitor"); + test_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, test_timeout, "test_timeout"); while (!test_completed) { uasync_poll(ua, 10); } diff --git a/tests/test_etcp_simple_traffic.c b/tests/test_etcp_simple_traffic.c index 20f47fc9..64865af3 100644 --- a/tests/test_etcp_simple_traffic.c +++ b/tests/test_etcp_simple_traffic.c @@ -330,7 +330,7 @@ static void monitor_and_send(void* arg) { // Schedule next check if (!test_completed) { - void* new_timeout = 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, "test_monitor"); 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"); @@ -472,8 +472,8 @@ int main() { // Start monitoring and packet transmission printf("Starting packet transmission test...\n"); - packet_timeout_id = uasync_set_timeout(ua, 500, NULL, monitor_and_send); - void* global_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, test_timeout); + packet_timeout_id = uasync_set_timeout(ua, 500, NULL, monitor_and_send, "test_monitor"); + void* global_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, test_timeout, "test_timeout"); // Main event loop printf("Running event loop...\n\n"); diff --git a/tests/test_etcp_two_instances.c b/tests/test_etcp_two_instances.c index bbd0df34..27a1de59 100644 --- a/tests/test_etcp_two_instances.c +++ b/tests/test_etcp_two_instances.c @@ -231,7 +231,7 @@ static void monitor_connections(void* arg) { uasync_cancel_timeout(ua, monitor_timeout_id); monitor_timeout_id = NULL; } - monitor_timeout_id = uasync_set_timeout(ua, 200, NULL, monitor_connections); + monitor_timeout_id = uasync_set_timeout(ua, 200, NULL, monitor_connections, "test_monitor"); } } @@ -341,8 +341,8 @@ int main() { // Start monitoring DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Starting connection monitoring...\n"); - monitor_timeout_id = uasync_set_timeout(ua, 100, NULL, monitor_connections); - test_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, test_timeout); + monitor_timeout_id = uasync_set_timeout(ua, 100, NULL, monitor_connections, "test_monitor"); + test_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, test_timeout, "test_timeout"); // Main event loop DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Running event loop...\n\n"); diff --git a/tests/test_nat_detection.c b/tests/test_nat_detection.c index 4841a203..2c39b6ff 100644 --- a/tests/test_nat_detection.c +++ b/tests/test_nat_detection.c @@ -223,7 +223,7 @@ int main(void) { goto cleanup; } - test_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS * 10, NULL, test_timeout_cb); + test_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS * 10, NULL, test_timeout_cb, "test_nat"); // 1. Wait for links C1->S and C2->S to initialize DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Waiting for ETCP links to initialize..."); diff --git a/tests/test_pkt_normalizer_etcp.c b/tests/test_pkt_normalizer_etcp.c index adc4c7ed..7eca42d8 100644 --- a/tests/test_pkt_normalizer_etcp.c +++ b/tests/test_pkt_normalizer_etcp.c @@ -482,7 +482,7 @@ static void monitor_and_send(void* arg) { } if (!test_completed) { - packet_timeout_id = uasync_set_timeout(ua, 10, NULL, monitor_and_send); + packet_timeout_id = uasync_set_timeout(ua, 10, NULL, monitor_and_send, "test_monitor"); } } @@ -550,8 +550,8 @@ int main() { printf("Client created\n\n"); printf("Sending %d packets in each direction via normalizer...\n", TOTAL_PACKETS); - packet_timeout_id = uasync_set_timeout(ua, 500, NULL, monitor_and_send); - void* global_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS*10, NULL, test_timeout); + packet_timeout_id = uasync_set_timeout(ua, 500, NULL, monitor_and_send, "test_monitor"); + void* global_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS*10, NULL, test_timeout, "test_timeout"); while (!test_completed) { uasync_poll(ua, 100); // 100ms timeout to allow timer processing diff --git a/tests/test_pkt_normalizer_standalone.c b/tests/test_pkt_normalizer_standalone.c index a1e2e54f..6150f618 100644 --- a/tests/test_pkt_normalizer_standalone.c +++ b/tests/test_pkt_normalizer_standalone.c @@ -159,7 +159,7 @@ static void monitor(void* arg) { } // Schedule next check - uasync_set_timeout(mock_instance.ua, 10, NULL, monitor); + uasync_set_timeout(mock_instance.ua, 10, NULL, monitor, "test_monitor"); } // Timeout handler @@ -298,8 +298,8 @@ int main() { printf("Normalizer created (frag_size=%d)\n\n", pn->frag_size); // Set up monitoring and timeout FIRST (before sending) - uasync_set_timeout(mock_instance.ua, 10, NULL, monitor); - uasync_set_timeout(mock_instance.ua, TEST_TIMEOUT_MS, NULL, test_timeout); + uasync_set_timeout(mock_instance.ua, 10, NULL, monitor, "test_monitor"); + uasync_set_timeout(mock_instance.ua, TEST_TIMEOUT_MS, NULL, test_timeout, "test_timeout"); // Give uasync a chance to process any pending callbacks uasync_poll(mock_instance.ua, 1); diff --git a/tests/test_route_ping.c b/tests/test_route_ping.c index ef315f49..e726ba97 100644 --- a/tests/test_route_ping.c +++ b/tests/test_route_ping.c @@ -221,7 +221,7 @@ int main(void) { goto cleanup; } - test_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS * 10, NULL, test_timeout_cb); + test_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS * 10, NULL, test_timeout_cb, "test_route_ping"); // 1. Wait for links A->B and B->C to initialize DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Waiting for ETCP links to initialize..."); diff --git a/tests/test_routing_mesh.c b/tests/test_routing_mesh.c index 56feb9c9..34aeee70 100644 --- a/tests/test_routing_mesh.c +++ b/tests/test_routing_mesh.c @@ -105,7 +105,7 @@ static void check_mesh_state(void* arg) { return; } - timeout_id = uasync_set_timeout(ua, 500, NULL, check_mesh_state); + timeout_id = uasync_set_timeout(ua, 500, NULL, check_mesh_state, "test_mesh"); } static void timeout_handler(void* arg) { diff --git a/tests/test_u_async_comprehensive.c b/tests/test_u_async_comprehensive.c index 15b37ce7..92a8d0ce 100644 --- a/tests/test_u_async_comprehensive.c +++ b/tests/test_u_async_comprehensive.c @@ -147,9 +147,9 @@ static void test_basic_timers(void) { ctx.expected_count = 3; /* Set multiple timers with different timeouts */ - void* timer1 = uasync_set_timeout(ua, 10, &ctx, test_timer_callback); /* 1ms */ - void* timer2 = uasync_set_timeout(ua, 20, &ctx, test_timer_callback); /* 2ms */ - void* timer3 = uasync_set_timeout(ua, 30, &ctx, test_timer_callback); /* 3ms */ + void* timer1 = uasync_set_timeout(ua, 10, &ctx, test_timer_callback, "test_t1"); /* 1ms */ + void* timer2 = uasync_set_timeout(ua, 20, &ctx, test_timer_callback, "test_t2"); /* 2ms */ + void* timer3 = uasync_set_timeout(ua, 30, &ctx, test_timer_callback, "test_t3"); /* 3ms */ ASSERT_NOT_NULL(timer1, "Failed to set timer 1"); ASSERT_NOT_NULL(timer2, "Failed to set timer 2"); @@ -181,9 +181,9 @@ static void test_timer_cancellation_races(void) { ctx.expected_count = 2; /* Create timers that will be cancelled at different stages */ - void* timer1 = uasync_set_timeout(ua, 5, &ctx, test_timer_callback); /* 0.5ms */ - void* timer2 = uasync_set_timeout(ua, 50, &ctx, test_timer_callback); /* 5ms */ - void* timer3 = uasync_set_timeout(ua, 100, &ctx, test_timer_callback); /* 10ms */ + void* timer1 = uasync_set_timeout(ua, 5, &ctx, test_timer_callback, "test_t1"); /* 0.5ms */ + void* timer2 = uasync_set_timeout(ua, 50, &ctx, test_timer_callback, "test_t2"); /* 5ms */ + void* timer3 = uasync_set_timeout(ua, 100, &ctx, test_timer_callback, "test_t3"); /* 10ms */ ASSERT_NOT_NULL(timer1, "Failed to set timer 1"); ASSERT_NOT_NULL(timer2, "Failed to set timer 2"); @@ -238,7 +238,7 @@ static void test_immediate_timeouts(void) { /* Set multiple immediate timeouts (0ms) */ for (int i = 0; i < 5; i++) { - void* timer = uasync_set_timeout(ua, 0, &ctx, test_timer_callback); + void* timer = uasync_set_timeout(ua, 0, &ctx, test_timer_callback, "test_imm"); ASSERT_NOT_NULL(timer, "Failed to set immediate timer"); } @@ -272,7 +272,7 @@ static void test_memory_leak_detection(void) { for (int i = 0; i < 10; i++) { test_context_t timer_ctx = {0}; timer_ctx.timeout_ms = 100; // Set proper timeout to avoid immediate timeout - void* timer = uasync_set_timeout(ua, 100, &timer_ctx, test_timer_callback); + void* timer = uasync_set_timeout(ua, 100, &timer_ctx, test_timer_callback, "test_cancel"); ASSERT_NOT_NULL(timer, "Failed to set timer"); /* Cancel some, leave others to timeout */ @@ -350,7 +350,7 @@ static void test_error_handling(void) { ASSERT_NOT_NULL(ua, "Failed to create uasync instance"); /* Test invalid parameters */ - void* null_timer = uasync_set_timeout(NULL, 10, NULL, NULL); + void* null_timer = uasync_set_timeout(NULL, 10, NULL, NULL, "test_null"); ASSERT_NULL(null_timer, "Should fail with NULL uasync"); err_t cancel_result = uasync_cancel_timeout(NULL, NULL); @@ -364,7 +364,7 @@ static void test_error_handling(void) { test_context_t ctx = {0}; ctx.callback_arg = -1; /* Error injection flag */ - void* error_timer = uasync_set_timeout(ua, 5, &ctx, test_error_callback); + void* error_timer = uasync_set_timeout(ua, 5, &ctx, test_error_callback, "test_err"); ASSERT_NOT_NULL(error_timer, "Failed to set error timer"); uasync_poll(ua, 10); @@ -434,7 +434,7 @@ static void test_concurrent_operations(void) { individual_ctx->timeout_ms = (i + 1) * 5; // Different timeouts: 5, 10, 15, ..., 50ms individual_ctx->callback_arg = 0; - timers[i] = uasync_set_timeout(ua, (i + 1) * 5, individual_ctx, test_timer_callback); + timers[i] = uasync_set_timeout(ua, (i + 1) * 5, individual_ctx, test_timer_callback, "test_stress"); ASSERT_NOT_NULL(timers[i], "Failed to set timer"); } diff --git a/tests/test_u_async_timeouts.c b/tests/test_u_async_timeouts.c index 8847c013..d92c73f7 100644 --- a/tests/test_u_async_timeouts.c +++ b/tests/test_u_async_timeouts.c @@ -59,7 +59,7 @@ static void timer_callback(void* arg) { new_ctx->stop_flag = ctx->stop_flag; new_ctx->ua = ctx->ua; - void* new_timer = uasync_set_timeout(ctx->ua, random_delay, new_ctx, timer_callback); + void* new_timer = uasync_set_timeout(ctx->ua, random_delay, new_ctx, timer_callback, "test_timer"); if (new_timer) { ctx->timer_data[ctx->timer_number].timer_id = new_timer; } else { @@ -122,7 +122,7 @@ int main(void) { ctx->ua = ua; int random_delay = rand() % 101; /* 0-100 (0-10ms) */ - void* timer_id = uasync_set_timeout(ua, random_delay, ctx, timer_callback); + void* timer_id = uasync_set_timeout(ua, random_delay, ctx, timer_callback, "test_timer"); if (!timer_id) { DEBUG_ERROR(DEBUG_CATEGORY_TEST, "Failed to set timer %d", i); @@ -152,7 +152,7 @@ int main(void) { stop_ctx->stop_flag = &stop_flag; stop_ctx->ua = ua; - void* stop_timer = uasync_set_timeout(ua, STOP_TIMEOUT_TB, stop_ctx, stop_callback); + void* stop_timer = uasync_set_timeout(ua, STOP_TIMEOUT_TB, stop_ctx, stop_callback, "test_stop"); if (!stop_timer) { DEBUG_ERROR(DEBUG_CATEGORY_TEST, "Failed to set stop timer"); u_free(stop_ctx); diff --git a/tests/track_test.c b/tests/track_test.c index 212dce35..7ec812f1 100644 --- a/tests/track_test.c +++ b/tests/track_test.c @@ -89,9 +89,9 @@ static void test_basic_timers(void) { ctx.timeout_ms = 10; // Non-zero timeout /* Set multiple timers with different timeouts */ - void* timer1 = uasync_set_timeout(ua, 10, &ctx, test_timer_callback); /* 1ms */ - void* timer2 = uasync_set_timeout(ua, 20, &ctx, test_timer_callback); /* 2ms */ - void* timer3 = uasync_set_timeout(ua, 30, &ctx, test_timer_callback); /* 3ms */ + void* timer1 = uasync_set_timeout(ua, 10, &ctx, test_timer_callback, "test_t1"); /* 1ms */ + void* timer2 = uasync_set_timeout(ua, 20, &ctx, test_timer_callback, "test_t2"); /* 2ms */ + void* timer3 = uasync_set_timeout(ua, 30, &ctx, test_timer_callback, "test_t3"); /* 3ms */ ASSERT_NOT_NULL(timer1, "Failed to set timer 1"); ASSERT_NOT_NULL(timer2, "Failed to set timer 2"); @@ -124,7 +124,7 @@ static void test_immediate_timeouts(void) { /* Set multiple immediate timeouts (0ms) */ for (int i = 0; i < 5; i++) { - void* timer = uasync_set_timeout(ua, 0, &ctx, test_timer_callback); + void* timer = uasync_set_timeout(ua, 0, &ctx, test_timer_callback, "test_imm"); ASSERT_NOT_NULL(timer, "Failed to set immediate timer"); }