|
|
|
|
@ -6,6 +6,7 @@
|
|
|
|
|
#include <ftw.h> |
|
|
|
|
#include "../lib/platform_compat.h" |
|
|
|
|
#include "test_utils.h" |
|
|
|
|
#include "test_clock.h" |
|
|
|
|
#ifndef _WIN32 |
|
|
|
|
#include <net/if.h> |
|
|
|
|
#include <sched.h> |
|
|
|
|
@ -70,6 +71,7 @@ static struct test_ctx {
|
|
|
|
|
uint32_t total_recv; |
|
|
|
|
uint32_t pre_delete_total_recv; |
|
|
|
|
int draining; |
|
|
|
|
uint8_t probe_payload[256][PROBE_SIZE - 9]; // Периодический эталон для каждого младшего байта seq+direction.
|
|
|
|
|
} ctx; |
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
entry->len = PROBE_SIZE; entry->dgram[0] = ETCP_RT_ID_TEST; |
|
|
|
|
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--; |
|
|
|
|
if (etcp_send(p->conn, entry) != 0) { |
|
|
|
|
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); |
|
|
|
|
fail("missing, duplicate or out-of-order packet"); goto done; |
|
|
|
|
} |
|
|
|
|
for (int i = 9; i < PROBE_SIZE; i++) { |
|
|
|
|
if (entry->dgram[i] != (uint8_t)(seq + direction + i * 17)) { fail("corrupt probe payload"); goto done; } |
|
|
|
|
if (memcmp(entry->dgram + 9, ctx.probe_payload[(seq + direction) & 255u], PROBE_SIZE - 9)) { |
|
|
|
|
fail("corrupt probe payload"); goto done; |
|
|
|
|
} |
|
|
|
|
p->received++; |
|
|
|
|
ctx.total_recv++; |
|
|
|
|
@ -776,11 +778,14 @@ static void cleanup(void) {
|
|
|
|
|
int main(void) { |
|
|
|
|
debug_config_init(); |
|
|
|
|
debug_set_level(DEBUG_LEVEL_WARN); |
|
|
|
|
test_clock_init(TRAF_SEND_TB); // Шаг не крупнее периода отправки; объём трафика и фазы остаются прежними.
|
|
|
|
|
if (getenv("UTUN_TEST_DEBUG")) { |
|
|
|
|
debug_set_category_level(DEBUG_CATEGORY_SOCKET, DEBUG_LEVEL_INFO); |
|
|
|
|
debug_set_category_level(DEBUG_CATEGORY_CONNECTION, DEBUG_LEVEL_INFO); |
|
|
|
|
} |
|
|
|
|
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(); |
|
|
|
|
setup(); |
|
|
|
|
if (ctx.result) return 1; |
|
|
|
|
@ -807,7 +812,7 @@ int main(void) {
|
|
|
|
|
|
|
|
|
|
{ uint64_t start = get_time_tb(); |
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
@ -825,6 +830,7 @@ done:
|
|
|
|
|
uasync_destroy(ctx.ua, 0); ctx.ua = NULL; |
|
|
|
|
} |
|
|
|
|
cleanup(); |
|
|
|
|
test_clock_finish(); |
|
|
|
|
if (u_get_allocated_count() != ctx.allocations_before) { |
|
|
|
|
u_report_unfreed_blocks(); fail("allocations leaked after fixture cleanup"); |
|
|
|
|
} |
|
|
|
|
|