Browse Source

tests: accelerate autosocket waits and payload verification

master
evgeny 2 days ago
parent
commit
91081fc5c7
  1. 3
      tests/Makefile.am
  2. 14
      tests/test_auto_socket_dynamic.c

3
tests/Makefile.am

@ -695,9 +695,10 @@ test_etcp_link_stress_SOURCES = test_etcp_link_stress.c
test_etcp_link_stress_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib test_etcp_link_stress_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib
test_etcp_link_stress_LDADD = $(LIBUTUN) $(CRYPTO_LIBS) $(COMMON_LIBS) test_etcp_link_stress_LDADD = $(LIBUTUN) $(CRYPTO_LIBS) $(COMMON_LIBS)
test_auto_socket_dynamic_SOURCES = test_auto_socket_dynamic.c test_auto_socket_dynamic_SOURCES = test_auto_socket_dynamic.c $(test_clock_sources)
test_auto_socket_dynamic_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/transport_layer -I$(top_srcdir)/src/routing_layer -I$(top_srcdir)/lib test_auto_socket_dynamic_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/transport_layer -I$(top_srcdir)/src/routing_layer -I$(top_srcdir)/lib
test_auto_socket_dynamic_LDADD = $(LIBUTUN) $(CRYPTO_LIBS) $(COMMON_LIBS) test_auto_socket_dynamic_LDADD = $(LIBUTUN) $(CRYPTO_LIBS) $(COMMON_LIBS)
test_auto_socket_dynamic_LDFLAGS = $(test_clock_ldflags)
test_media_delivery_full_SOURCES = test_media_delivery_full.c test_media_delivery_full_SOURCES = test_media_delivery_full.c
test_media_delivery_full_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/media_delivery -I$(top_srcdir)/src/media_async -I$(top_srcdir)/lib -I$(top_srcdir)/src/transport_layer -I$(top_srcdir)/src/routing_layer -I$(top_srcdir)/src/chat test_media_delivery_full_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/media_delivery -I$(top_srcdir)/src/media_async -I$(top_srcdir)/lib -I$(top_srcdir)/src/transport_layer -I$(top_srcdir)/src/routing_layer -I$(top_srcdir)/src/chat

14
tests/test_auto_socket_dynamic.c

@ -6,6 +6,7 @@
#include <ftw.h> #include <ftw.h>
#include "../lib/platform_compat.h" #include "../lib/platform_compat.h"
#include "test_utils.h" #include "test_utils.h"
#include "test_clock.h"
#ifndef _WIN32 #ifndef _WIN32
#include <net/if.h> #include <net/if.h>
#include <sched.h> #include <sched.h>
@ -70,6 +71,7 @@ static struct test_ctx {
uint32_t total_recv; uint32_t total_recv;
uint32_t pre_delete_total_recv; uint32_t pre_delete_total_recv;
int draining; int draining;
uint8_t probe_payload[256][PROBE_SIZE - 9]; // Периодический эталон для каждого младшего байта seq+direction.
} ctx; } ctx;
static char tdir[] = "/tmp/utun_as_XXXXXX"; static char tdir[] = "/tmp/utun_as_XXXXXX";
@ -257,7 +259,7 @@ static void send_ready(struct ll_queue* q, void* arg) {
uint32_t seq = ++p->sent, direction = p - pending; uint32_t seq = ++p->sent, direction = p - pending;
entry->len = PROBE_SIZE; entry->dgram[0] = ETCP_RT_ID_TEST; entry->len = PROBE_SIZE; entry->dgram[0] = ETCP_RT_ID_TEST;
memcpy(entry->dgram + 1, &seq, 4); memcpy(entry->dgram + 5, &direction, 4); memcpy(entry->dgram + 1, &seq, 4); memcpy(entry->dgram + 5, &direction, 4);
for (int i = 9; i < PROBE_SIZE; i++) entry->dgram[i] = (uint8_t)(seq + direction + i * 17); memcpy(entry->dgram + 9, ctx.probe_payload[(seq + direction) & 255u], PROBE_SIZE - 9);
p->budget--; p->budget--;
if (etcp_send(p->conn, entry) != 0) { if (etcp_send(p->conn, entry) != 0) {
queue_dgram_free(entry); queue_entry_free(entry); queue_dgram_free(entry); queue_entry_free(entry);
@ -280,8 +282,8 @@ static void receive_probe(struct ll_entry* entry, int direction) {
fprintf(stderr, "sequence dir=%d wire_dir=%u received=%u seq=%u sent=%u\n", direction, wire_direction, p->received, seq, p->sent); fprintf(stderr, "sequence dir=%d wire_dir=%u received=%u seq=%u sent=%u\n", direction, wire_direction, p->received, seq, p->sent);
fail("missing, duplicate or out-of-order packet"); goto done; fail("missing, duplicate or out-of-order packet"); goto done;
} }
for (int i = 9; i < PROBE_SIZE; i++) { if (memcmp(entry->dgram + 9, ctx.probe_payload[(seq + direction) & 255u], PROBE_SIZE - 9)) {
if (entry->dgram[i] != (uint8_t)(seq + direction + i * 17)) { fail("corrupt probe payload"); goto done; } fail("corrupt probe payload"); goto done;
} }
p->received++; p->received++;
ctx.total_recv++; ctx.total_recv++;
@ -776,11 +778,14 @@ static void cleanup(void) {
int main(void) { int main(void) {
debug_config_init(); debug_config_init();
debug_set_level(DEBUG_LEVEL_WARN); debug_set_level(DEBUG_LEVEL_WARN);
test_clock_init(TRAF_SEND_TB); // Шаг не крупнее периода отправки; объём трафика и фазы остаются прежними.
if (getenv("UTUN_TEST_DEBUG")) { if (getenv("UTUN_TEST_DEBUG")) {
debug_set_category_level(DEBUG_CATEGORY_SOCKET, DEBUG_LEVEL_INFO); debug_set_category_level(DEBUG_CATEGORY_SOCKET, DEBUG_LEVEL_INFO);
debug_set_category_level(DEBUG_CATEGORY_CONNECTION, DEBUG_LEVEL_INFO); debug_set_category_level(DEBUG_CATEGORY_CONNECTION, DEBUG_LEVEL_INFO);
} }
utun_instance_set_tun_init_enabled(0); utun_instance_set_tun_init_enabled(0);
for (unsigned base = 0; base < 256; base++) for (int i = 9; i < PROBE_SIZE; i++)
ctx.probe_payload[base][i - 9] = (uint8_t)(base + i * 17);
ctx.allocations_before = u_get_allocated_count(); ctx.allocations_before = u_get_allocated_count();
setup(); setup();
if (ctx.result) return 1; if (ctx.result) return 1;
@ -807,7 +812,7 @@ int main(void) {
{ uint64_t start = get_time_tb(); { uint64_t start = get_time_tb();
while (!ctx.result && (int)(get_time_tb() - start) < TIMEOUT_TB + 50000) while (!ctx.result && (int)(get_time_tb() - start) < TIMEOUT_TB + 50000)
uasync_poll(ctx.ua, POLL_MS); } test_clock_poll(ctx.ua, POLL_MS); }
fprintf(stderr, "final result=%d\n", ctx.result); fflush(stderr); fprintf(stderr, "final result=%d\n", ctx.result); fflush(stderr);
@ -825,6 +830,7 @@ done:
uasync_destroy(ctx.ua, 0); ctx.ua = NULL; uasync_destroy(ctx.ua, 0); ctx.ua = NULL;
} }
cleanup(); cleanup();
test_clock_finish();
if (u_get_allocated_count() != ctx.allocations_before) { if (u_get_allocated_count() != ctx.allocations_before) {
u_report_unfreed_blocks(); fail("allocations leaked after fixture cleanup"); u_report_unfreed_blocks(); fail("allocations leaked after fixture cleanup");
} }

Loading…
Cancel
Save