Browse Source

tests: use independent ports for radio and call topologies

master
evgeny 6 days ago
parent
commit
91909fbb1e
  1. 15
      tests/test_call.c
  2. 17
      tests/test_radio.c
  3. 24
      tests/test_radio_mesh.c

15
tests/test_call.c

@ -31,6 +31,7 @@
#include "../lib/mem.h"
#include "../lib/platform_compat.h"
#include "test_utils.h"
#include "test_net.h"
#include <sqlite3.h>
#define OPENSSL_API_COMPAT 0x10100000L
@ -114,7 +115,6 @@ struct call_shared {
uint8_t ch_x_pub[32], ch_ed_pub[32], ch_ed_priv[32], ch_sig[64];
uint64_t nid[2];
uint8_t x_pub[2][32], x_priv[2][32], ed_pub[2][32];
int port[2];
};
static struct call_shared g_sh;
@ -175,14 +175,13 @@ static int wf(const char* p, const char* f, ...) {
/* ── генерация данных сценария + конфигов ── */
static void fill_shared(int base_port) {
static void fill_shared(void) {
memset(&g_sh, 0, sizeof(g_sh));
for (int i = 0; i < 2; i++) {
gen_x25519(g_sh.x_pub[i], g_sh.x_priv[i]);
sc_derive_ed25519_pubkey(g_sh.x_priv[i], g_sh.ed_pub[i]);
g_sh.nid[i] = sc_derive_node_id_from_pubkey(g_sh.x_pub[i]);
g_sh.port[i] = base_port + i * 1000;
}
{ uint8_t ch_x_priv[32]; gen_x25519(g_sh.ch_x_pub, ch_x_priv); }
@ -213,18 +212,17 @@ static void write_configs(const char* dir) {
/* B → A (клиент к A) */
char apub[65]; to_hex(g_sh.x_pub[IDX_A], 32, apub);
snprintf(client, sizeof(client),
"[client: to_a]\npeer_public_key=%s\nlink=s1:127.0.0.1:%d\n",
apub, g_sh.port[IDX_A]);
"[client: to_a]\npeer_public_key=%s\nlink=s1:127.0.0.1:0\n", apub);
}
wf(path,
"[global]\ntun_ip=10.97.%d.1/24\ntun_ifname=tun%d0\ndb_path=%s/db%s\n"
"my_private_key=%s\nmy_public_key=%s\n"
"[server: s1]\naddr=127.0.0.1:%d\ntype=public\n"
"[server: s1]\naddr=127.0.0.1:0\ntype=public\n"
"%s"
"[chatserver]\nstorage_autoload=0\n[allowed_keys]\nallow_all=1\n",
i, i, dir, i == IDX_A ? "a" : "b",
priv, pub, g_sh.port[i], client);
priv, pub, client);
}
}
@ -514,7 +512,7 @@ int main(int argc, char** argv) {
if (test_mkdtemp(dir) != 0) { fprintf(stderr, "mkdtemp failed\n"); return 1; }
test_setenv("UTUN_TEST_DIR", dir, 1);
fill_shared(56000 + (getpid() % 2000));
fill_shared();
write_configs(dir);
printf("=== test_call ===\n"); fflush(stdout);
@ -542,6 +540,7 @@ int main(int argc, char** argv) {
uasync_destroy(ua, 0);
return 1;
}
test_etcp_set_peer(t.inst[IDX_B], "to_a", t.inst[IDX_A], "s1");
utun_instance_init(t.inst[IDX_A]);
utun_instance_init(t.inst[IDX_B]);

17
tests/test_radio.c

@ -30,6 +30,7 @@
#include "../lib/platform_compat.h"
#include "test_utils.h"
#include "test_clock.h"
#include "test_net.h"
#include <sqlite3.h>
#define OPENSSL_API_COMPAT 0x10100000L
@ -96,7 +97,6 @@ struct rad_shared {
uint8_t ch_x_pub[32], ch_ed_pub[32], ch_ed_priv[32], ch_sig[64];
uint64_t nid[3];
uint8_t x_pub[3][32], x_priv[3][32], ed_pub[3][32];
int port[3];
};
static struct rad_shared g_sh;
static struct rx_evt g_rx[3];
@ -216,13 +216,12 @@ static int wf(const char* p, const char* f, ...) {
/* ── данные сценария + конфиги (цепочка A←B←C) ── */
static void fill_shared(int base_port) {
static void fill_shared(void) {
memset(&g_sh, 0, sizeof(g_sh));
for (int i = 0; i < 3; i++) {
gen_x25519(g_sh.x_pub[i], g_sh.x_priv[i]);
sc_derive_ed25519_pubkey(g_sh.x_priv[i], g_sh.ed_pub[i]);
g_sh.nid[i] = sc_derive_node_id_from_pubkey(g_sh.x_pub[i]);
g_sh.port[i] = base_port + i * 1000;
}
{ uint8_t ch_x_priv[32]; gen_x25519(g_sh.ch_x_pub, ch_x_priv); }
gen_ed25519(g_sh.ch_ed_pub, g_sh.ch_ed_priv);
@ -249,20 +248,20 @@ static void write_configs(const char* dir) {
char client[512] = "";
if (i == IDX_B) { /* B → A */
char apub[65]; to_hex(g_sh.x_pub[IDX_A], 32, apub);
snprintf(client, sizeof(client), "[client: to_a]\npeer_public_key=%s\nlink=s1:127.0.0.1:%d\n", apub, g_sh.port[IDX_A]);
snprintf(client, sizeof(client), "[client: to_a]\npeer_public_key=%s\nlink=s1:127.0.0.1:0\n", apub);
} else if (i == IDX_C) { /* C → B */
char bpub[65]; to_hex(g_sh.x_pub[IDX_B], 32, bpub);
snprintf(client, sizeof(client), "[client: to_b]\npeer_public_key=%s\nlink=s1:127.0.0.1:%d\n", bpub, g_sh.port[IDX_B]);
snprintf(client, sizeof(client), "[client: to_b]\npeer_public_key=%s\nlink=s1:127.0.0.1:0\n", bpub);
}
wf(path,
"[global]\ntun_ip=10.98.%d.1/24\ntun_ifname=tun%d0\ndb_path=%s/db%s\n"
"my_private_key=%s\nmy_public_key=%s\n"
"[server: s1]\naddr=127.0.0.1:%d\ntype=public\n"
"[server: s1]\naddr=127.0.0.1:0\ntype=public\n"
"%s"
"[chatserver]\nstorage_autoload=0\n[allowed_keys]\nallow_all=1\n",
i, i, dir, i == IDX_A ? "a" : i == IDX_B ? "b" : "c",
priv, pub, g_sh.port[i], client);
priv, pub, client);
}
}
@ -581,7 +580,7 @@ int main(int argc, char** argv) {
if (test_mkdtemp(dir) != 0) { fprintf(stderr, "mkdtemp failed\n"); return 1; }
test_setenv("UTUN_TEST_DIR", dir, 1);
fill_shared(58000 + (getpid() % 2000));
fill_shared();
write_configs(dir);
printf("=== test_radio ===\n"); fflush(stdout);
@ -608,6 +607,8 @@ int main(int argc, char** argv) {
uasync_destroy(ua, 0);
return 1;
}
test_etcp_set_peer(t.inst[IDX_B], "to_a", t.inst[IDX_A], "s1");
test_etcp_set_peer(t.inst[IDX_C], "to_b", t.inst[IDX_B], "s1");
utun_instance_init(t.inst[IDX_A]);
utun_instance_init(t.inst[IDX_B]);
utun_instance_init(t.inst[IDX_C]);

24
tests/test_radio_mesh.c

@ -31,6 +31,7 @@
#include "../lib/mem.h"
#include "../lib/platform_compat.h"
#include "test_utils.h"
#include "test_net.h"
#include <sqlite3.h>
#define OPENSSL_API_COMPAT 0x10100000L
@ -86,7 +87,6 @@ struct mesh_shared {
uint8_t ch_x_pub[32], ch_ed_pub[32], ch_ed_priv[32], ch_sig[64];
uint64_t nid[4];
uint8_t x_pub[4][32], x_priv[4][32], ed_pub[4][32];
int port[4];
};
static struct mesh_shared g_sh;
static struct rx_evt g_rx[4];
@ -128,13 +128,12 @@ static int wf(const char* p, const char* f, ...) {
/* ── данные сценария + конфиги (diamond A↔B, A↔D, B↔C, D↔C) ── */
static void fill_shared(int base_port) {
static void fill_shared(void) {
memset(&g_sh, 0, sizeof(g_sh));
for (int i = 0; i < 4; i++) {
gen_x25519(g_sh.x_pub[i], g_sh.x_priv[i]);
sc_derive_ed25519_pubkey(g_sh.x_priv[i], g_sh.ed_pub[i]);
g_sh.nid[i] = sc_derive_node_id_from_pubkey(g_sh.x_pub[i]);
g_sh.port[i] = base_port + i * 1000;
}
{ uint8_t ch_x_priv[32]; gen_x25519(g_sh.ch_x_pub, ch_x_priv); }
gen_ed25519(g_sh.ch_ed_pub, g_sh.ch_ed_priv);
@ -163,28 +162,27 @@ static void write_configs(const char* dir) {
char client[1024] = "";
if (i == IDX_B) { /* B → A */
char apub[65]; to_hex(g_sh.x_pub[IDX_A], 32, apub);
snprintf(client, sizeof(client), "[client: to_a]\npeer_public_key=%s\nlink=s1:127.0.0.1:%d\n", apub, g_sh.port[IDX_A]);
snprintf(client, sizeof(client), "[client: to_a]\npeer_public_key=%s\nlink=s1:127.0.0.1:0\n", apub);
} else if (i == IDX_D) { /* D → A */
char apub[65]; to_hex(g_sh.x_pub[IDX_A], 32, apub);
snprintf(client, sizeof(client), "[client: to_a]\npeer_public_key=%s\nlink=s1:127.0.0.1:%d\n", apub, g_sh.port[IDX_A]);
snprintf(client, sizeof(client), "[client: to_a]\npeer_public_key=%s\nlink=s1:127.0.0.1:0\n", apub);
} else if (i == IDX_C) { /* C → B и C → D */
char bpub[65], dpub[65];
to_hex(g_sh.x_pub[IDX_B], 32, bpub);
to_hex(g_sh.x_pub[IDX_D], 32, dpub);
snprintf(client, sizeof(client),
"[client: to_b]\npeer_public_key=%s\nlink=s1:127.0.0.1:%d\n"
"[client: to_d]\npeer_public_key=%s\nlink=s1:127.0.0.1:%d\n",
bpub, g_sh.port[IDX_B], dpub, g_sh.port[IDX_D]);
"[client: to_b]\npeer_public_key=%s\nlink=s1:127.0.0.1:0\n"
"[client: to_d]\npeer_public_key=%s\nlink=s1:127.0.0.1:0\n", bpub, dpub);
}
wf(path,
"[global]\ntun_ip=10.98.%d.1/24\ntun_ifname=tun%d0\ndb_path=%s/db%s\n"
"my_private_key=%s\nmy_public_key=%s\n"
"[server: s1]\naddr=127.0.0.1:%d\ntype=public\n"
"[server: s1]\naddr=127.0.0.1:0\ntype=public\n"
"%s"
"[chatserver]\nstorage_autoload=0\n[allowed_keys]\nallow_all=1\n",
i, i, dir, i == IDX_A ? "a" : i == IDX_B ? "b" : i == IDX_D ? "d" : "c",
priv, pub, g_sh.port[i], client);
priv, pub, client);
}
}
@ -422,7 +420,7 @@ int main(int argc, char** argv) {
if (test_mkdtemp(dir) != 0) { fprintf(stderr, "mkdtemp failed\n"); return 1; }
test_setenv("UTUN_TEST_DIR", dir, 1);
fill_shared(59000 + (getpid() % 2000));
fill_shared();
write_configs(dir);
printf("=== test_radio_mesh ===\n"); fflush(stdout);
@ -444,6 +442,10 @@ int main(int argc, char** argv) {
t.inst[i] = utun_instance_create(ua, cfg[i]);
if (!t.inst[i]) { FAIL("instance create failed i=%d", i); uasync_destroy(ua, 0); return 1; }
}
test_etcp_set_peer(t.inst[IDX_B], "to_a", t.inst[IDX_A], "s1");
test_etcp_set_peer(t.inst[IDX_D], "to_a", t.inst[IDX_A], "s1");
test_etcp_set_peer(t.inst[IDX_C], "to_b", t.inst[IDX_B], "s1");
test_etcp_set_peer(t.inst[IDX_C], "to_d", t.inst[IDX_D], "s1");
for (int i = 0; i < 4; i++) utun_instance_init(t.inst[i]);
for (int i = 0; i < 4; i++) radio_set_frame_cb(t.inst[i], rx_frame_cb, &g_rx[i]);

Loading…
Cancel
Save