diff --git a/tests/Makefile.am b/tests/Makefile.am index 8f80dbb3..97a66d63 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -27,6 +27,7 @@ check_PROGRAMS = \ test_reality_record \ test_stream_sign \ test_reality_config \ + test_socks_client \ test_dm \ test_nat_engine \ test_opus_codec \ @@ -36,6 +37,7 @@ check_PROGRAMS = \ test_etcp_lifecycle \ test_reality_bgp \ test_tcp_proxy_client \ + test_etcp_session \ test_proxy_packets \ test_media_delivery_download \ test_transport \ @@ -73,6 +75,7 @@ check_PROGRAMS = \ test_radix \ test_daemon_worker \ test_attachment_send \ + test_group_recovery \ test_conn_mgr_handles \ test_tcp_io_flush @@ -140,7 +143,6 @@ endif # Проверки до 3с. check_PROGRAMS += \ - test_socks_client \ test_u_async_timeouts \ test_async_dns \ test_chat_poll_network \ @@ -148,8 +150,6 @@ check_PROGRAMS += \ test_dm_e2e \ test_media_async \ test_bgp_triangle \ - test_group_recovery \ - test_etcp_session \ test_chat_join_e2e \ test_media_delivery_chat \ test_member_files_network \ @@ -312,9 +312,10 @@ test_stcp_SOURCES = test_stcp.c test_stcp_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib test_stcp_LDADD = $(LIBUTUN) $(CRYPTO_LIBS) $(COMMON_LIBS) -test_socks_client_SOURCES = test_socks_client.c +test_socks_client_SOURCES = test_socks_client.c $(test_clock_sources) test_socks_client_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/transport_layer -I$(top_srcdir)/lib test_socks_client_LDADD = $(LIBUTUN) $(CRYPTO_LIBS) $(COMMON_LIBS) +test_socks_client_LDFLAGS = $(test_clock_ldflags) test_etcp_two_instances_SOURCES = test_etcp_two_instances.c test_etcp_two_instances_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib @@ -542,9 +543,10 @@ test_bgp_paths_SOURCES = test_bgp_paths.c test_bgp_paths_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib test_bgp_paths_LDADD = $(LIBUTUN) $(CRYPTO_LIBS) $(COMMON_LIBS) -test_group_recovery_SOURCES = test_group_recovery.c +test_group_recovery_SOURCES = test_group_recovery.c $(test_clock_sources) test_group_recovery_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib test_group_recovery_LDADD = $(LIBUTUN) $(CRYPTO_LIBS) $(COMMON_LIBS) +test_group_recovery_LDFLAGS = $(test_clock_ldflags) test_group_connect_SOURCES = test_group_connect.c $(test_clock_sources) test_group_connect_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib @@ -807,8 +809,9 @@ test_etcp_lifecycle_LDADD = $(LIBUTUN) $(CRYPTO_LIBS) $(COMMON_LIBS) test_topo_recovery_SOURCES = test_topo_recovery.c test_topo_recovery_LDADD = $(LIBUTUN) $(CRYPTO_LIBS) $(COMMON_LIBS) -test_etcp_session_SOURCES = test_etcp_session.c +test_etcp_session_SOURCES = test_etcp_session.c $(test_clock_sources) test_etcp_session_LDADD = $(LIBUTUN) $(COMMON_LIBS) +test_etcp_session_LDFLAGS = $(test_clock_ldflags) test_etcp_router_tcp_SOURCES = test_etcp_router_tcp.c test_etcp_router_tcp_LDADD = $(LIBUTUN) $(COMMON_LIBS) diff --git a/tests/test_etcp_session.c b/tests/test_etcp_session.c index dd08a806..3511eea8 100644 --- a/tests/test_etcp_session.c +++ b/tests/test_etcp_session.c @@ -10,6 +10,7 @@ #include "config_parser.h" #include "../lib/debug_config.h" #include "../lib/mem.h" +#include "test_clock.h" #define CHECK(x) do { if (!(x)) { fprintf(stderr,"FAIL %s:%d: %s\n",__func__,__LINE__,#x); exit(1); } } while (0) struct endpoint { struct UTUN_INSTANCE inst; struct utun_config cfg; struct ETCP_CONN* c; struct ETCP_SOCKET sock; struct ETCP_LINK links[2]; }; @@ -120,7 +121,7 @@ static void deliver(const struct frame* f, int allow_drop) { CHECK(etcp_packet_decrypted(&ep[to].sock,p,&ep[to].links[0],len) == 0); } static void pump(void) { - uasync_poll(ua,1); + test_clock_poll(ua,1); unsigned end = tail; // callbacks can append replies while (head < end) { struct frame f = frames[head++ % 4096]; deliver(&f,1); } } @@ -250,6 +251,7 @@ static void receive_window_case(int wrap) { } int main(void) { debug_config_init(); debug_set_level(DEBUG_LEVEL_WARN); + test_clock_init(10); size_t baseline=u_get_allocated_count(); debug_sequence_boundaries(); CHECK(u_get_allocated_count() == baseline); const char* log=getenv("SESSION_TEST_LOG"); @@ -301,5 +303,5 @@ int main(void) { } CHECK(u_get_allocated_count()==baseline); printf("PASS session scenario %d\n",scenario+1); } - puts("All ETCP session scenarios passed"); return 0; + puts("All ETCP session scenarios passed"); test_clock_finish(); return 0; } diff --git a/tests/test_group_recovery.c b/tests/test_group_recovery.c index b3b4a740..ebe40e27 100644 --- a/tests/test_group_recovery.c +++ b/tests/test_group_recovery.c @@ -11,6 +11,7 @@ #include "../lib/mem.h" #include "../lib/debug_config.h" #include "../lib/platform_compat.h" +#include "test_clock.h" struct fixture { struct UASYNC* ua; @@ -210,7 +211,7 @@ static void connect_deadline(void) { topo_recovery_start(f.group); poll_events(&f); assert(peer(&f, 0)); uint64_t deadline = get_time_tb() + (TOPO_RECOVERY_CONNECT_TIMEOUT_MS + 1000) * 10ULL; - while (f.group->recovery && get_time_tb() < deadline) uasync_poll(f.ua, 100); + while (f.group->recovery && get_time_tb() < deadline) test_clock_poll(f.ua, 100); assert(!f.group->recovery && !peer(&f, 0)); destroy(&f); } @@ -306,6 +307,7 @@ static void manual_planner_cancel(void) { int main(void) { debug_config_init(); debug_set_level(DEBUG_LEVEL_INFO); + test_clock_init(1000); utun_instance_set_tun_init_enabled(0); persistent_request(); manual_planner_cancel(); @@ -316,5 +318,6 @@ int main(void) { restored_during_connect(); connect_deadline(); DEBUG_INFO(DEBUG_CATEGORY_BGP, "recovery tests: partial routes, readiness, progress, exhaustion and shared cancellation passed"); + test_clock_finish(); return 0; } diff --git a/tests/test_socks_client.c b/tests/test_socks_client.c index 796fbfd2..6a6f0a0c 100644 --- a/tests/test_socks_client.c +++ b/tests/test_socks_client.c @@ -5,6 +5,7 @@ #include "../lib/mem.h" #include "../lib/socket_compat.h" #include "../lib/platform_compat.h" +#include "test_clock.h" #include #include #include @@ -315,7 +316,7 @@ static int run_dial(struct UASYNC *ua, struct socks_cfg *cfg, const char *target void *h = socks_dial(ua, cfg, target, tport, dial_cb, NULL, 0); if (!h) return -1; int ticks = 0; - while (!g_done && ticks < 20000) { uasync_poll(ua, 10); ticks++; } + while (!g_done && ticks < 20000) { test_clock_poll(ua, 10); ticks++; } if (!g_done) return -1; return g_err; } @@ -337,7 +338,7 @@ static int test1_noauth_v4(void) { uint8_t x = 'A'; send(g_sock, &x, 1, 0); int ticks = 0; - while (got == 0 && ticks < 5000) { uasync_poll(ua, 10); ticks++; } + while (got == 0 && ticks < 5000) { test_clock_poll(ua, 10); ticks++; } TASSERT(got == 'A'); uasync_remove_socket_t(ua, g_sock); @@ -401,7 +402,7 @@ static int test4_udp_associate(void) { TASSERT(su != NULL); int ticks = 0; - while (g_su_ready == 0 && ticks < 20000) { uasync_poll(ua, 10); ticks++; } + while (g_su_ready == 0 && ticks < 20000) { test_clock_poll(ua, 10); ticks++; } TASSERT(g_su_ready == 1); TASSERT(g_su_err == 0); TASSERT(m.got_associate == 1); @@ -420,7 +421,7 @@ static int test4_udp_associate(void) { while (ticks < 5000) { got = recvfrom(lfd, raw, sizeof(raw), 0, (struct sockaddr *)&from, &fl); if (got > 0) break; - uasync_poll(ua, 10); ticks++; + test_clock_poll(ua, 10); ticks++; } TASSERT(got > 0); @@ -459,7 +460,7 @@ static int test5_udp_reassociate(void) { TASSERT(su != NULL); int ticks = 0; - while (g_su_ready == 0 && ticks < 20000) { uasync_poll(ua, 10); ticks++; } + while (g_su_ready == 0 && ticks < 20000) { test_clock_poll(ua, 10); ticks++; } TASSERT(g_su_ready == 1); TASSERT(m.got_associate == 1); @@ -469,7 +470,7 @@ static int test5_udp_reassociate(void) { int ready_before = g_su_ready; ticks = 0; - while (g_su_ready == ready_before && ticks < 50000) { uasync_poll(ua, 10); ticks++; } // backoff ~1с + while (g_su_ready == ready_before && ticks < 50000) { test_clock_poll(ua, 10); ticks++; } // backoff ~1с TASSERT(g_su_ready > ready_before); TASSERT(m.got_associate >= 2); @@ -486,7 +487,7 @@ static int test5_udp_reassociate(void) { while (ticks < 5000) { got = recvfrom(lfd, raw, sizeof(raw), 0, (struct sockaddr *)&from, &fl); if (got > 0) break; - uasync_poll(ua, 10); ticks++; + test_clock_poll(ua, 10); ticks++; } TASSERT(got > 0); uint8_t payload[256]; @@ -503,7 +504,9 @@ static int test5_udp_reassociate(void) { } int main(void) { + debug_config_init(); debug_set_level(DEBUG_LEVEL_ERROR); + test_clock_init(1000); socket_platform_init(); struct { const char *name; int (*fn)(void); } tests[] = { @@ -523,5 +526,6 @@ int main(void) { } socket_platform_cleanup(); DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "Results: %d/%d passed", passed, n); + test_clock_finish(); return passed == n ? 0 : 1; }