tests: assign independent CM and chat sync listener ports
This commit is contained in:
1 parent
a4dfc3fa77
commit
0670d30837
3 files changed
+21
-18
No files matched your search
@@ -6,6 +6,7 @@
|
||||
#include <time.h>
|
||||
#include "../lib/platform_compat.h"
|
||||
#include "test_utils.h"
|
||||
#include "test_net.h"
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <direct.h>
|
||||
@@ -46,7 +47,6 @@ static char log_path[320];
|
||||
static unsigned int g_seed;
|
||||
static char temp_dir[] = "/tmp/utun_chatsync_XXXXXX";
|
||||
static char config_a[256], config_b[256];
|
||||
static int port_a_srv, port_b_srv;
|
||||
|
||||
static int write_file(const char* path, const char* fmt, ...) {
|
||||
va_list ap; FILE* f = fopen(path, "w"); if (!f) return -1;
|
||||
@@ -58,8 +58,6 @@ static char* get_pubkey(const char* path) {
|
||||
}
|
||||
static int create_temp_configs(void) {
|
||||
if (test_mkdtemp(temp_dir) != 0) { return -1; }
|
||||
int base = 42000 + (getpid() % 15000);
|
||||
port_a_srv = base; port_b_srv = base + 1;
|
||||
snprintf(config_a, sizeof(config_a), "%s/a.conf", temp_dir);
|
||||
snprintf(config_b, sizeof(config_b), "%s/b.conf", temp_dir);
|
||||
char db_path[320];
|
||||
@@ -69,17 +67,17 @@ static int create_temp_configs(void) {
|
||||
if (write_file(config_a,
|
||||
"[global]\nmy_node_id=0xAAAAAAAAAAAAAAAA\ntun_ip=10.200.0.1/24\ntun_ifname=tun200\n"
|
||||
"db_path=%s/db_a\ndb_sync_enabled=1\n\n"
|
||||
"[server: srv_a]\naddr=127.0.0.1:%d\ntype=public\n\n[allowed_keys]\nallow_all=1\n",
|
||||
temp_dir, port_a_srv) != 0) return -1;
|
||||
"[server: srv_a]\naddr=127.0.0.1:0\ntype=public\n\n[allowed_keys]\nallow_all=1\n",
|
||||
temp_dir) != 0) return -1;
|
||||
if (config_ensure_keys_and_node_id(config_a) != 0) return -1;
|
||||
char* pub_a = get_pubkey(config_a); if (!pub_a) return -1;
|
||||
if (write_file(config_b,
|
||||
"[global]\nmy_node_id=0xBBBBBBBBBBBBBBBB\ntun_ip=10.200.0.2/24\ntun_ifname=tun201\n"
|
||||
"db_path=%s/db_b\ndb_sync_enabled=1\n\n"
|
||||
"[server: srv_b]\naddr=127.0.0.1:%d\ntype=public\n\n"
|
||||
"[client: to_a]\nkeepalive=1\npeer_public_key=%s\nlink=srv_b:127.0.0.1:%d\n\n"
|
||||
"[server: srv_b]\naddr=127.0.0.1:0\ntype=public\n\n"
|
||||
"[client: to_a]\nkeepalive=1\npeer_public_key=%s\nlink=srv_b:127.0.0.1:0\n\n"
|
||||
"[allowed_keys]\nallow_all=1\n",
|
||||
temp_dir, port_b_srv, pub_a, port_a_srv) != 0) { free(pub_a); return -1; }
|
||||
temp_dir, pub_a) != 0) { free(pub_a); return -1; }
|
||||
free(pub_a);
|
||||
if (config_ensure_keys_and_node_id(config_b) != 0) return -1;
|
||||
return 0;
|
||||
@@ -162,6 +160,7 @@ int main(void) {
|
||||
inst_a = utun_instance_create(ua, config_a);
|
||||
inst_b = utun_instance_create(ua, config_b);
|
||||
if (!inst_a || !inst_b) { DEBUG_ERROR(DEBUG_CATEGORY_DEBUG, "instance_create"); cleanup_temp_configs(); return 1; }
|
||||
test_etcp_set_peer(inst_b, "to_a", inst_a, "srv_a");
|
||||
if (utun_instance_init(inst_a) != 0 || utun_instance_init(inst_b) != 0) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_DEBUG, "instance_init"); cleanup_temp_configs(); return 1;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <stdarg.h>
|
||||
#include "../lib/platform_compat.h"
|
||||
#include "test_utils.h"
|
||||
#include "test_net.h"
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
@@ -33,7 +34,6 @@ static struct UASYNC *ua = NULL;
|
||||
static volatile int result = 0, cb_fired = 0, cb_ok = 0;
|
||||
static char tdir[] = "/tmp/utun_cm2_XXXXXX";
|
||||
static char ca[256], cb[256];
|
||||
static int pa = 0, pb = 0;
|
||||
|
||||
static int wf(const char* p, const char* f, ...) {
|
||||
va_list ap; FILE* fp = fopen(p, "w"); if (!fp) return -1;
|
||||
@@ -91,20 +91,22 @@ int main(void) {
|
||||
utun_instance_set_tun_init_enabled(0);
|
||||
|
||||
test_mkdtemp(tdir);
|
||||
int base = 49000 + (getpid() % 10000); pa = base; pb = base + 1;
|
||||
snprintf(ca, sizeof(ca), "%s/a.conf", tdir); snprintf(cb, sizeof(cb), "%s/b.conf", tdir);
|
||||
wf(ca, "[global]\ntun_ip=10.97.0.1/24\ntun_ifname=tun95\n[server: s1]\naddr=127.0.0.1:%d\ntype=public\n[allowed_keys]\nallow_all=1\n", pa);
|
||||
wf(cb, "[global]\ntun_ip=10.97.0.2/24\ntun_ifname=tun94\n[server: s1]\naddr=127.0.0.1:%d\ntype=public\n[allowed_keys]\nallow_all=1\n", pb);
|
||||
wf(ca, "[global]\ntun_ip=10.97.0.1/24\ntun_ifname=tun95\n[server: s1]\naddr=127.0.0.1:0\ntype=public\n[allowed_keys]\nallow_all=1\n");
|
||||
wf(cb, "[global]\ntun_ip=10.97.0.2/24\ntun_ifname=tun94\n[server: s1]\naddr=127.0.0.1:0\ntype=public\n[allowed_keys]\nallow_all=1\n");
|
||||
config_ensure_keys_and_node_id(ca); config_ensure_keys_and_node_id(cb);
|
||||
{ struct utun_config* cfa = parse_config(ca); struct utun_config* cfb = parse_config(cb);
|
||||
free_config(cfa); free_config(cfb); }
|
||||
char *r0 = gv(ca,"priv"), *p0 = gv(ca,"pub"), *p1 = gv(cb,"pub");
|
||||
wf(ca, "[global]\nmy_private_key=%s\nmy_public_key=%s\ntun_ip=10.97.0.1/24\ntun_ifname=tun95\n[server: s1]\naddr=127.0.0.1:%d\ntype=public\n[client: to_b]\nkeepalive=1\npeer_public_key=%s\nlink=s1:127.0.0.1:%d\n[allowed_keys]\nallow_all=1\n", r0, p0, pa, p1, pb);
|
||||
wf(ca, "[global]\nmy_private_key=%s\nmy_public_key=%s\ntun_ip=10.97.0.1/24\ntun_ifname=tun95\n"
|
||||
"[server: s1]\naddr=127.0.0.1:0\ntype=public\n[client: to_b]\nkeepalive=1\npeer_public_key=%s\n"
|
||||
"link=s1:127.0.0.1:0\n[allowed_keys]\nallow_all=1\n", r0, p0, p1);
|
||||
u_free(r0); u_free(p0); u_free(p1);
|
||||
|
||||
ua = uasync_create();
|
||||
g_a = utun_instance_create(ua, ca); g_b = utun_instance_create(ua, cb);
|
||||
if (!g_a || !g_b) { fprintf(stderr,"create failed\n"); result=2; goto done; }
|
||||
test_etcp_set_peer(g_a, "to_b", g_b, "s1");
|
||||
utun_instance_init(g_a); utun_instance_init(g_b);
|
||||
|
||||
uasync_call_soon(ua, NULL, test_find_conn);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <stdarg.h>
|
||||
#include "../lib/platform_compat.h"
|
||||
#include "test_utils.h"
|
||||
#include "test_net.h"
|
||||
|
||||
#include "etcp.h"
|
||||
#include "etcp_connections.h"
|
||||
@@ -33,7 +34,6 @@ static volatile int result = 0;
|
||||
static void* ttimer = NULL;
|
||||
static char tdir[] = "/tmp/utun_cmh_XXXXXX";
|
||||
static char ca[256], cb[256];
|
||||
static int pa = 0, pb = 0;
|
||||
static uint64_t g_nid_a = 0, g_nid_b = 0;
|
||||
|
||||
static volatile int cb1_ok = 0, cb2_ok = 0;
|
||||
@@ -159,21 +159,23 @@ int main(void) {
|
||||
utun_instance_set_tun_init_enabled(0);
|
||||
|
||||
test_mkdtemp(tdir);
|
||||
int base = 50000 + (getpid() % 10000); pa = base; pb = base + 1;
|
||||
snprintf(ca, sizeof(ca), "%s/a.conf", tdir); snprintf(cb, sizeof(cb), "%s/b.conf", tdir);
|
||||
wf(ca, "[global]\ntun_ip=10.96.0.1/24\ntun_ifname=tun93\n[server: s1]\naddr=127.0.0.1:%d\ntype=public\n[allowed_keys]\nallow_all=1\n", pa);
|
||||
wf(cb, "[global]\ntun_ip=10.96.0.2/24\ntun_ifname=tun92\n[server: s1]\naddr=127.0.0.1:%d\ntype=public\n[allowed_keys]\nallow_all=1\n", pb);
|
||||
wf(ca, "[global]\ntun_ip=10.96.0.1/24\ntun_ifname=tun93\n[server: s1]\naddr=127.0.0.1:0\ntype=public\n[allowed_keys]\nallow_all=1\n");
|
||||
wf(cb, "[global]\ntun_ip=10.96.0.2/24\ntun_ifname=tun92\n[server: s1]\naddr=127.0.0.1:0\ntype=public\n[allowed_keys]\nallow_all=1\n");
|
||||
config_ensure_keys_and_node_id(ca); config_ensure_keys_and_node_id(cb);
|
||||
{ struct utun_config* cfa = parse_config(ca); struct utun_config* cfb = parse_config(cb);
|
||||
g_nid_a = cfa->global.my_node_id; g_nid_b = cfb->global.my_node_id;
|
||||
free_config(cfa); free_config(cfb); }
|
||||
char *p0 = gv(ca,"pub"), *r0 = gv(ca,"priv"), *p1 = gv(cb,"pub");
|
||||
wf(ca, "[global]\nmy_private_key=%s\nmy_public_key=%s\ntun_ip=10.96.0.1/24\ntun_ifname=tun93\n[server: s1]\naddr=127.0.0.1:%d\ntype=public\n[client: to_b]\nkeepalive=1\npeer_public_key=%s\nlink=s1:127.0.0.1:%d\n[allowed_keys]\nallow_all=1\n", r0, p0, pa, p1, pb);
|
||||
wf(ca, "[global]\nmy_private_key=%s\nmy_public_key=%s\ntun_ip=10.96.0.1/24\ntun_ifname=tun93\n"
|
||||
"[server: s1]\naddr=127.0.0.1:0\ntype=public\n[client: to_b]\nkeepalive=1\npeer_public_key=%s\n"
|
||||
"link=s1:127.0.0.1:0\n[allowed_keys]\nallow_all=1\n", r0, p0, p1);
|
||||
u_free(p0); u_free(r0); u_free(p1);
|
||||
|
||||
ua = uasync_create();
|
||||
g_a = utun_instance_create(ua, ca); g_b = utun_instance_create(ua, cb);
|
||||
if (!g_a || !g_b) { fprintf(stderr,"create failed\n"); result=2; goto done; }
|
||||
test_etcp_set_peer(g_a, "to_b", g_b, "s1");
|
||||
utun_instance_init(g_a); utun_instance_init(g_b);
|
||||
uasync_call_soon(ua, NULL, test1);
|
||||
ttimer = uasync_set_timeout(ua, TIMEOUT_TB, NULL, to_cb, "to");
|
||||
|
||||
Reference in new issue
Block a user