Browse Source

Add name parameter to uasync_set_timeout for timer identification in dumps

congestion
Evgeny 5 months ago
parent
commit
d74ab1c1c6
  1. 10
      lib/u_async.c
  2. 2
      lib/u_async.h
  3. 2
      net_emulator/net_emulator.c
  4. 6
      src/dummynet.c
  5. 6
      src/etcp.c
  6. 13
      src/etcp_connections.c
  7. 2
      src/etcp_loadbalancer.c
  8. 4
      src/route_ping.c
  9. 2
      src/utun.c
  10. 8
      tests/bench_uasync_timeouts.c
  11. 14
      tests/debug_full_test.c
  12. 6
      tests/detailed_test.c
  13. 8
      tests/test_bgp_route_exchange.c
  14. 4
      tests/test_dummynet.c
  15. 6
      tests/test_etcp_100_packets.c
  16. 8
      tests/test_etcp_api.c
  17. 2
      tests/test_etcp_dummynet.c
  18. 4
      tests/test_etcp_ping.c
  19. 6
      tests/test_etcp_simple_traffic.c
  20. 6
      tests/test_etcp_two_instances.c
  21. 2
      tests/test_nat_detection.c
  22. 6
      tests/test_pkt_normalizer_etcp.c
  23. 6
      tests/test_pkt_normalizer_standalone.c
  24. 2
      tests/test_route_ping.c
  25. 2
      tests/test_routing_mesh.c
  26. 22
      tests/test_u_async_comprehensive.c
  27. 6
      tests/test_u_async_timeouts.c
  28. 8
      tests/track_test.c

10
lib/u_async.c

@ -32,6 +32,7 @@
// Timeout node with safe cancellation // Timeout node with safe cancellation
struct timeout_node { struct timeout_node {
char name[16];
void* arg; void* arg;
timeout_callback_t callback; timeout_callback_t callback;
uint64_t expiration_ms; // absolute expiration time in milliseconds uint64_t expiration_ms; // absolute expiration time in milliseconds
@ -492,7 +493,7 @@ static void get_next_timeout(struct UASYNC* ua, struct timeval* tv) {
// Instance version // Instance version
void* uasync_set_timeout(struct UASYNC* ua, int timeout_tb, void* arg, timeout_callback_t callback) { 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_tb < 0 || !callback) return NULL;
if (!ua->timeout_heap) return NULL; if (!ua->timeout_heap) return NULL;
@ -505,6 +506,12 @@ void* uasync_set_timeout(struct UASYNC* ua, int timeout_tb, void* arg, timeout_c
} }
ua->timer_alloc_count++; 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->arg = arg;
node->callback = callback; node->callback = callback;
node->ua = ua; node->ua = ua;
@ -538,6 +545,7 @@ void* uasync_call_soon(struct UASYNC* ua, void* user_arg, timeout_callback_t cal
} }
ua->timer_alloc_count++; ua->timer_alloc_count++;
node->name[0] = '\0';
node->arg = user_arg; node->arg = user_arg;
node->callback = callback; node->callback = callback;
node->ua = ua; node->ua = ua;

2
lib/u_async.h

@ -82,7 +82,7 @@ void uasync_destroy(struct UASYNC* ua, int close_fds);
uint64_t get_time_tb(void); uint64_t get_time_tb(void);
// Timeouts, timebase = 0.1 mS // 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); err_t uasync_cancel_timeout(struct UASYNC* ua, void* t_id);
// Immediate execution in next mainloop (FIFO order) // Immediate execution in next mainloop (FIFO order)

2
net_emulator/net_emulator.c

@ -376,7 +376,7 @@ static void socket_callback(int fd, void *user_arg) {
u_free(packet); u_free(packet);
return; 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 // Callback for sending delayed packet

6
src/dummynet.c

@ -158,7 +158,7 @@ static void dummynet_process_queue(struct dummynet* dn, int dir_idx) {
if (sarg) { if (sarg) {
sarg->dn = dn; sarg->dn = dn;
sarg->dir_idx = dir_idx; 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) { if (dir->shaper_timer) {
dir->shaper_timer_set++; dir->shaper_timer_set++;
} else { } else {
@ -270,7 +270,7 @@ static void dummynet_read_callback(socket_t sock, void* user_arg) {
targ->dn = dn; targ->dn = dn;
targ->entry = entry; 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) { if (!timer) {
DEBUG_ERROR(DEBUG_CATEGORY_DUMMYNET, "Failed to set delay timer"); DEBUG_ERROR(DEBUG_CATEGORY_DUMMYNET, "Failed to set delay timer");
dir->stats.dropped++; dir->stats.dropped++;
@ -326,7 +326,7 @@ static void dummynet_delay_callback(void* user_arg) {
if (sarg) { if (sarg) {
sarg->dn = dn; sarg->dn = dn;
sarg->dir_idx = dir_idx; 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 { } else {
dir->shaper_pending = 0; dir->shaper_pending = 0;
} }

6
src/etcp.c

@ -606,7 +606,7 @@ static void ack_timeout_check(struct ETCP_CONN* etcp) {
// shedule timer // shedule timer
int64_t next_timeout=timeout - elapsed; int64_t next_timeout=timeout - elapsed;
if (next_timeout<0) next_timeout=0; 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); DEBUG_TRACE(DEBUG_CATEGORY_ETCP, "[%s] retransmission timer set for %llu units", etcp->log_name, next_timeout);
return; return;
} }
@ -670,7 +670,7 @@ static void ack_response_timer_cb(void* arg) {// проверяем неотпр
if (etcp->ack_q->count==0) return;// нечего отправлять if (etcp->ack_q->count==0) return;// нечего отправлять
etcp_conn_process_send_queue(etcp);// проталкиваем (она же должна отправлять только ack если больше ничего нет) etcp_conn_process_send_queue(etcp);// проталкиваем (она же должна отправлять только ack если больше ничего нет)
// если 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; // 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); queue_data_put_with_index(etcp->ack_q, (struct ll_entry*)p, 0, 4);
if (etcp->ack_resp_timer == NULL) { 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); 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 if (((int32_t)(etcp->last_delivered_id-seq)<0) && (queue_find_data_by_index(etcp->recv_q, &seq, 4)==NULL)) {// проверяем есть ли пакет с этим seq

13
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; link->init_timeout += link->init_timeout/4 +1;
if (link->init_timeout > INIT_TIMEOUT_MAX) link->init_timeout = INIT_TIMEOUT_MAX; 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) 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) 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, ""); DEBUG_TRACE(DEBUG_CATEGORY_CONNECTION, "");
if (link->init_timer) uasync_cancel_timeout(link->etcp->instance->ua, link->init_timer); if (link->init_timer) uasync_cancel_timeout(link->etcp->instance->ua, link->init_timer);
link->init_timeout = INIT_TIMEOUT_INITIAL; 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) {// 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) { 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); 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; link->pkt_sent_since_keepalive = 0;
restart_timer: 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) { 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, link->etcp->instance->ua,
tb, tb,
link, 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; while (last->next) last = last->next;
last->next = ctx; 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", DEBUG_INFO(DEBUG_CATEGORY_BGP, "ping sent nonce=%016llx timeout=%d ulen=%zu",
(unsigned long long)ctx->nonce, timeout_ms, user_data_len); (unsigned long long)ctx->nonce, timeout_ms, user_data_len);
return 0; return 0;

2
src/etcp_loadbalancer.c

@ -136,7 +136,7 @@ void etcp_loadbalancer_send(struct ETCP_DGRAM* dgram) {
uint64_t now_tb=get_time_tb(); uint64_t now_tb=get_time_tb();
if (link->shaper_load_time_tb >= now_tb + SHAPER_BURST_DELAY_TB) { if (link->shaper_load_time_tb >= now_tb + SHAPER_BURST_DELAY_TB) {
uint64_t wait_tb = link->shaper_load_time_tb - now_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"); 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); 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);
} }

4
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; pending->next = bgp->ping_pending;
bgp->ping_pending = 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", 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, (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; pending->next = bgp->ping_pending;
bgp->ping_pending = 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", 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, (unsigned long long)pending->request_id, (unsigned long long)node_id,

2
src/utun.c

@ -258,7 +258,7 @@ static void signal_handler(int sig) {
void test_tmr(void* arg) { void test_tmr(void* arg) {
struct UASYNC* ua = (struct UASYNC*)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 ..."); // DEBUG_INFO(DEBUG_CATEGORY_ETCP, "tick ...");
} }

8
tests/bench_uasync_timeouts.c

@ -58,7 +58,7 @@ static void benchmark_without_sockets(void) {
// Set 100 zero timeouts // Set 100 zero timeouts
clock_gettime(CLOCK_MONOTONIC, &start); clock_gettime(CLOCK_MONOTONIC, &start);
for (i = 0; i < NUM_TIMEOUTS; i++) { 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]) { if (!timeout_ids[i]) {
fprintf(stderr, "Failed to set timeout at iteration %d\n", i); fprintf(stderr, "Failed to set timeout at iteration %d\n", i);
uasync_destroy(ua, 0); uasync_destroy(ua, 0);
@ -147,7 +147,7 @@ static void benchmark_with_sockets(void) {
// Set 100 zero timeouts WITH sockets already open // Set 100 zero timeouts WITH sockets already open
clock_gettime(CLOCK_MONOTONIC, &start); clock_gettime(CLOCK_MONOTONIC, &start);
for (i = 0; i < NUM_TIMEOUTS; i++) { 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]) { if (!timeout_ids[i]) {
fprintf(stderr, "Failed to set timeout at iteration %d\n", i); fprintf(stderr, "Failed to set timeout at iteration %d\n", i);
for (int j = 0; j < NUM_SOCKETS; j++) { for (int j = 0; j < NUM_SOCKETS; j++) {
@ -215,7 +215,7 @@ int main(void) {
clock_gettime(CLOCK_MONOTONIC, &start); clock_gettime(CLOCK_MONOTONIC, &start);
for (i = 0; i < NUM_TIMEOUTS; i++) { 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); clock_gettime(CLOCK_MONOTONIC, &end);
set_time_no_sockets = measure_time_diff(&start, &end); set_time_no_sockets = measure_time_diff(&start, &end);
@ -266,7 +266,7 @@ int main(void) {
// Set timeouts WITH sockets open // Set timeouts WITH sockets open
clock_gettime(CLOCK_MONOTONIC, &start); clock_gettime(CLOCK_MONOTONIC, &start);
for (i = 0; i < NUM_TIMEOUTS; i++) { 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); clock_gettime(CLOCK_MONOTONIC, &end);
set_time_with_sockets = measure_time_diff(&start, &end); set_time_with_sockets = measure_time_diff(&start, &end);

14
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 ctx.timeout_ms = 10; // Non-zero to avoid immediate timeout counting
/* Set multiple timers with different timeouts */ /* Set multiple timers with different timeouts */
void* timer1 = uasync_set_timeout(ua, 10, &ctx, test_timer_callback); /* 1ms */ 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); /* 2ms */ 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); /* 3ms */ 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(timer1, "Failed to set timer 1");
ASSERT_NOT_NULL(timer2, "Failed to set timer 2"); 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 ctx.timeout_ms = 5; // Non-zero to avoid immediate timeout counting
/* Create timers that will be cancelled at different stages */ /* Create timers that will be cancelled at different stages */
void* timer1 = uasync_set_timeout(ua, 5, &ctx, test_timer_callback); /* 0.5ms */ 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); /* 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); /* 10ms */ 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(timer1, "Failed to set timer 1");
ASSERT_NOT_NULL(timer2, "Failed to set timer 2"); ASSERT_NOT_NULL(timer2, "Failed to set timer 2");
@ -192,7 +192,7 @@ static void test_immediate_timeouts(void) {
/* Set multiple immediate timeouts (0ms) */ /* Set multiple immediate timeouts (0ms) */
for (int i = 0; i < 5; i++) { 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"); ASSERT_NOT_NULL(timer, "Failed to set immediate timer");
} }

6
tests/detailed_test.c

@ -36,7 +36,7 @@ int main() {
test_context_t ctx1 = {.timeout_ms = 10}; test_context_t ctx1 = {.timeout_ms = 10};
for (int i = 0; i < 3; i++) { 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; int polls = 0;
@ -55,7 +55,7 @@ int main() {
test_context_t ctx2 = {.timeout_ms = 0}; test_context_t ctx2 = {.timeout_ms = 0};
for (int i = 0; i < 5; i++) { 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); 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}; test_context_t ctx3 = {.timeout_ms = 0};
for (int i = 0; i < 2; i++) { 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); uasync_poll(ua3, 1);

8
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... ==="); DEBUG_INFO(DEBUG_CATEGORY_ETCP, "=== Connection established! Waiting for BGP exchange... ===");
test_phase = 1; test_phase = 1;
// Schedule next check after BGP exchange time // 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; return;
} }
break; break;
@ -317,7 +317,7 @@ static void monitor_connections(void* arg) {
// Schedule next check // Schedule next check
if (test_phase < 3) { 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 // Start monitoring
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Starting connection monitoring..."); DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Starting connection monitoring...");
monitor_timeout_id = uasync_set_timeout(ua, 100, NULL, monitor_connections); 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_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, test_timeout, "test_timeout");
// Main event loop - use uasync timers only, no artificial timing // Main event loop - use uasync timers only, no artificial timing
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Running event loop..."); DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Running event loop...");

4
tests/test_dummynet.c

@ -114,7 +114,7 @@ static void send_timer_callback(void* arg) {
st->next_seq++; st->next_seq++;
/* Перезапускаем таймер на следующую отправку (10 timebase = 1ms) */ /* Перезапускаем таймер на следующую отправку (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 отправка - все пакеты сразу */ /* Burst отправка - все пакеты сразу */
@ -259,7 +259,7 @@ static int run_scenario(const char* name,
printf("Sending %d packets (fast)...\n", PKT_COUNT); printf("Sending %d packets (fast)...\n", PKT_COUNT);
/* Запускаем таймер отправки с интервалом 1 timebase (0.1ms) */ /* Запускаем таймер отправки с интервалом 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 */ /* Умное ожидание завершения: ранний выход при готовности + watchdog */
uint64_t start_time = get_time_us(); uint64_t start_time = get_time_us();

6
tests/test_etcp_100_packets.c

@ -361,7 +361,7 @@ static void monitor_and_send(void* arg) {
} }
if (!test_completed) { 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("✅ Client ready\n\n");
printf("Sending %d packets in each direction (max queue size: %d)...\n", TOTAL_PACKETS, MAX_QUEUE_SIZE); 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); 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); void* global_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, test_timeout, "test_timeout");
while (!test_completed) { while (!test_completed) {
uasync_poll(ua, 100); uasync_poll(ua, 100);

8
tests/test_etcp_api.c

@ -437,7 +437,7 @@ static void monitor_and_send(void* arg) {
connection_delay++; connection_delay++;
if (connection_delay < 50) { // Ждем 50 циклов (~500ms) if (connection_delay < 50) { // Ждем 50 циклов (~500ms)
if (!test_completed) { 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; return;
} }
@ -506,7 +506,7 @@ static void monitor_and_send(void* arg) {
} }
if (!test_completed) { 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); DATA_PACKET_ID, (void*)server_recv_callback, (void*)client_recv_callback);
printf("Sending %d packets in each direction via etcp_send...\n", TOTAL_PACKETS); 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); 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); void* global_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS*10, NULL, test_timeout, "test_timeout");
while (!test_completed) { while (!test_completed) {
uasync_poll(ua, 100); // 100ms timeout to allow timer processing uasync_poll(ua, 100); // 100ms timeout to allow timer processing

2
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) /* Schedule next packet with 5ms delay for rate limiting (~200 pkt/sec)
* Note: uasync_set_timeout uses 0.1ms units, so 50 = 5ms */ * 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, static struct UTUN_INSTANCE* create_instance(struct UASYNC* u, uint64_t node_id,

4
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); DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "Client init_connections failed with code %d", ret);
goto cleanup; goto cleanup;
} }
monitor_timeout_id = uasync_set_timeout(ua, 100, NULL, monitor_connections); 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_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, test_timeout, "test_timeout");
while (!test_completed) { while (!test_completed) {
uasync_poll(ua, 10); uasync_poll(ua, 10);
} }

6
tests/test_etcp_simple_traffic.c

@ -330,7 +330,7 @@ static void monitor_and_send(void* arg) {
// Schedule next check // Schedule next check
if (!test_completed) { 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) { if (!new_timeout) {
DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "monitor_and_send: Failed to set timeout - uasync_set_timeout returned NULL"); 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"); printf("[ERROR] Failed to set timeout in monitor_and_send\n");
@ -472,8 +472,8 @@ int main() {
// Start monitoring and packet transmission // Start monitoring and packet transmission
printf("Starting packet transmission test...\n"); printf("Starting packet transmission test...\n");
packet_timeout_id = uasync_set_timeout(ua, 500, NULL, monitor_and_send); 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); void* global_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, test_timeout, "test_timeout");
// Main event loop // Main event loop
printf("Running event loop...\n\n"); printf("Running event loop...\n\n");

6
tests/test_etcp_two_instances.c

@ -231,7 +231,7 @@ static void monitor_connections(void* arg) {
uasync_cancel_timeout(ua, monitor_timeout_id); uasync_cancel_timeout(ua, monitor_timeout_id);
monitor_timeout_id = NULL; 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 // Start monitoring
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Starting connection monitoring...\n"); DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Starting connection monitoring...\n");
monitor_timeout_id = uasync_set_timeout(ua, 100, NULL, monitor_connections); 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_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, test_timeout, "test_timeout");
// Main event loop // Main event loop
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Running event loop...\n\n"); DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Running event loop...\n\n");

2
tests/test_nat_detection.c

@ -223,7 +223,7 @@ int main(void) {
goto cleanup; 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 // 1. Wait for links C1->S and C2->S to initialize
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Waiting for ETCP links to initialize..."); DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Waiting for ETCP links to initialize...");

6
tests/test_pkt_normalizer_etcp.c

@ -482,7 +482,7 @@ static void monitor_and_send(void* arg) {
} }
if (!test_completed) { 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("Client created\n\n");
printf("Sending %d packets in each direction via normalizer...\n", TOTAL_PACKETS); printf("Sending %d packets in each direction via normalizer...\n", TOTAL_PACKETS);
packet_timeout_id = uasync_set_timeout(ua, 500, NULL, monitor_and_send); 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); void* global_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS*10, NULL, test_timeout, "test_timeout");
while (!test_completed) { while (!test_completed) {
uasync_poll(ua, 100); // 100ms timeout to allow timer processing uasync_poll(ua, 100); // 100ms timeout to allow timer processing

6
tests/test_pkt_normalizer_standalone.c

@ -159,7 +159,7 @@ static void monitor(void* arg) {
} }
// Schedule next check // 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 // Timeout handler
@ -298,8 +298,8 @@ int main() {
printf("Normalizer created (frag_size=%d)\n\n", pn->frag_size); printf("Normalizer created (frag_size=%d)\n\n", pn->frag_size);
// Set up monitoring and timeout FIRST (before sending) // Set up monitoring and timeout FIRST (before sending)
uasync_set_timeout(mock_instance.ua, 10, NULL, monitor); uasync_set_timeout(mock_instance.ua, 10, NULL, monitor, "test_monitor");
uasync_set_timeout(mock_instance.ua, TEST_TIMEOUT_MS, NULL, test_timeout); uasync_set_timeout(mock_instance.ua, TEST_TIMEOUT_MS, NULL, test_timeout, "test_timeout");
// Give uasync a chance to process any pending callbacks // Give uasync a chance to process any pending callbacks
uasync_poll(mock_instance.ua, 1); uasync_poll(mock_instance.ua, 1);

2
tests/test_route_ping.c

@ -221,7 +221,7 @@ int main(void) {
goto cleanup; 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 // 1. Wait for links A->B and B->C to initialize
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Waiting for ETCP links to initialize..."); DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Waiting for ETCP links to initialize...");

2
tests/test_routing_mesh.c

@ -105,7 +105,7 @@ static void check_mesh_state(void* arg) {
return; 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) { static void timeout_handler(void* arg) {

22
tests/test_u_async_comprehensive.c

@ -147,9 +147,9 @@ static void test_basic_timers(void) {
ctx.expected_count = 3; ctx.expected_count = 3;
/* Set multiple timers with different timeouts */ /* Set multiple timers with different timeouts */
void* timer1 = uasync_set_timeout(ua, 10, &ctx, test_timer_callback); /* 1ms */ 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); /* 2ms */ 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); /* 3ms */ 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(timer1, "Failed to set timer 1");
ASSERT_NOT_NULL(timer2, "Failed to set timer 2"); ASSERT_NOT_NULL(timer2, "Failed to set timer 2");
@ -181,9 +181,9 @@ static void test_timer_cancellation_races(void) {
ctx.expected_count = 2; ctx.expected_count = 2;
/* Create timers that will be cancelled at different stages */ /* Create timers that will be cancelled at different stages */
void* timer1 = uasync_set_timeout(ua, 5, &ctx, test_timer_callback); /* 0.5ms */ 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); /* 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); /* 10ms */ 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(timer1, "Failed to set timer 1");
ASSERT_NOT_NULL(timer2, "Failed to set timer 2"); ASSERT_NOT_NULL(timer2, "Failed to set timer 2");
@ -238,7 +238,7 @@ static void test_immediate_timeouts(void) {
/* Set multiple immediate timeouts (0ms) */ /* Set multiple immediate timeouts (0ms) */
for (int i = 0; i < 5; i++) { 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"); 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++) { for (int i = 0; i < 10; i++) {
test_context_t timer_ctx = {0}; test_context_t timer_ctx = {0};
timer_ctx.timeout_ms = 100; // Set proper timeout to avoid immediate timeout 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"); ASSERT_NOT_NULL(timer, "Failed to set timer");
/* Cancel some, leave others to timeout */ /* 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"); ASSERT_NOT_NULL(ua, "Failed to create uasync instance");
/* Test invalid parameters */ /* 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"); ASSERT_NULL(null_timer, "Should fail with NULL uasync");
err_t cancel_result = uasync_cancel_timeout(NULL, NULL); err_t cancel_result = uasync_cancel_timeout(NULL, NULL);
@ -364,7 +364,7 @@ static void test_error_handling(void) {
test_context_t ctx = {0}; test_context_t ctx = {0};
ctx.callback_arg = -1; /* Error injection flag */ 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"); ASSERT_NOT_NULL(error_timer, "Failed to set error timer");
uasync_poll(ua, 10); 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->timeout_ms = (i + 1) * 5; // Different timeouts: 5, 10, 15, ..., 50ms
individual_ctx->callback_arg = 0; 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"); ASSERT_NOT_NULL(timers[i], "Failed to set timer");
} }

6
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->stop_flag = ctx->stop_flag;
new_ctx->ua = ctx->ua; 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) { if (new_timer) {
ctx->timer_data[ctx->timer_number].timer_id = new_timer; ctx->timer_data[ctx->timer_number].timer_id = new_timer;
} else { } else {
@ -122,7 +122,7 @@ int main(void) {
ctx->ua = ua; ctx->ua = ua;
int random_delay = rand() % 101; /* 0-100 (0-10ms) */ 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) { if (!timer_id) {
DEBUG_ERROR(DEBUG_CATEGORY_TEST, "Failed to set timer %d", i); 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->stop_flag = &stop_flag;
stop_ctx->ua = ua; 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) { if (!stop_timer) {
DEBUG_ERROR(DEBUG_CATEGORY_TEST, "Failed to set stop timer"); DEBUG_ERROR(DEBUG_CATEGORY_TEST, "Failed to set stop timer");
u_free(stop_ctx); u_free(stop_ctx);

8
tests/track_test.c

@ -89,9 +89,9 @@ static void test_basic_timers(void) {
ctx.timeout_ms = 10; // Non-zero timeout ctx.timeout_ms = 10; // Non-zero timeout
/* Set multiple timers with different timeouts */ /* Set multiple timers with different timeouts */
void* timer1 = uasync_set_timeout(ua, 10, &ctx, test_timer_callback); /* 1ms */ 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); /* 2ms */ 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); /* 3ms */ 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(timer1, "Failed to set timer 1");
ASSERT_NOT_NULL(timer2, "Failed to set timer 2"); ASSERT_NOT_NULL(timer2, "Failed to set timer 2");
@ -124,7 +124,7 @@ static void test_immediate_timeouts(void) {
/* Set multiple immediate timeouts (0ms) */ /* Set multiple immediate timeouts (0ms) */
for (int i = 0; i < 5; i++) { 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"); ASSERT_NOT_NULL(timer, "Failed to set immediate timer");
} }

Loading…
Cancel
Save