tests: allocate STCP traffic and link listener ports automatically

This commit is contained in:
evgeny committed 2026-10-10 15:32:47 +02:00
1 parent 0dcecdd7b2
commit 98529b3268
4 files changed
+10 -18

No files matched your search

+2 -6
View File
@@ -17,8 +17,6 @@
#include <stdlib.h>
#include <time.h>
#define TEST_PORT 25678
static int test_failed = 0;
static struct SC_MYKEYS s_keys, c_keys;
static struct UTUN_INSTANCE *srv_inst, *cli_inst;
@@ -92,13 +90,11 @@ int main(void) {
struct UASYNC *ua = uasync_create(); TASSERT(ua);
utun_instance_set_tun_init_enabled(0);
int port = TEST_PORT + rand() % 1000;
srv_inst = utun_instance_create_from_str(ua, build_server_config(port));
srv_inst = utun_instance_create_from_str(ua, build_server_config(0));
TASSERT(srv_inst);
TASSERT(utun_instance_init(srv_inst) >= 0);
cli_inst = utun_instance_create_from_str(ua, build_client_config(port + 1));
cli_inst = utun_instance_create_from_str(ua, build_client_config(0));
TASSERT(cli_inst);
TASSERT(utun_instance_init(cli_inst) >= 0);
+4 -5
View File
@@ -14,7 +14,6 @@ static int tests_passed = 0, tests_total = 0;
static struct SC_MYKEYS s_keys, c_keys;
static int test_failed = 0;
#define BASE_PORT 24567
#define TASSERT(cond) do { \
if (!(cond)) { DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, " FAIL: %s", #cond); test_failed = 1; return test_failed; } \
} while(0)
@@ -45,11 +44,11 @@ static int test1_basic(void) {
struct stcp_link_config cfg = {.inst = inst, .listen_family = AF_INET};
g_on_srv_link = NULL;
struct stcp_server *ss = stcp_server_listen(&cfg, BASE_PORT + 1, on_srv_link, NULL);
struct stcp_server *ss = stcp_server_listen(&cfg, 0, on_srv_link, NULL);
TASSERT(ss);
int cli_ready = 0;
struct stcp_client *sc = stcp_client_connect(ua, "127.0.0.1", BASE_PORT + 1, &c_keys,
struct stcp_client *sc = stcp_client_connect(ua, "127.0.0.1", stcp_link_server_get_port(ss), &c_keys,
s_keys.public_key, NULL,
0, NULL,
0, 200, 0, on_cli_ready, &cli_ready, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL);
@@ -73,12 +72,12 @@ static int test2_wrong_key(void) {
struct stcp_link_config cfg = {.inst = inst, .listen_family = AF_INET};
g_on_srv_link = NULL;
struct stcp_server *ss = stcp_server_listen(&cfg, BASE_PORT + 2, on_srv_link, NULL);
struct stcp_server *ss = stcp_server_listen(&cfg, 0, on_srv_link, NULL);
TASSERT(ss);
struct SC_MYKEYS rogue; TASSERT(sc_generate_keypair(&rogue) == SC_OK);
int cli_ready = 0;
struct stcp_client *sc = stcp_client_connect(ua, "127.0.0.1", BASE_PORT + 2, &c_keys,
struct stcp_client *sc = stcp_client_connect(ua, "127.0.0.1", stcp_link_server_get_port(ss), &c_keys,
rogue.public_key, NULL,
0, NULL,
0, 200, 0, on_cli_ready, &cli_ready, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL);
+2 -5
View File
@@ -16,7 +16,6 @@
#include <stdlib.h>
#include <time.h>
#define TEST_PORT 25680
#define TRAFFIC_MB (1024*1024)
#define PKT_MIN 10
#define PKT_MAX 1800
@@ -143,13 +142,11 @@ int main(void) {
struct UASYNC *ua = uasync_create(); TASSERT(ua);
utun_instance_set_tun_init_enabled(0);
int port = TEST_PORT + rand() % 1000;
srv_inst = utun_instance_create_from_str(ua, build_server_config(port));
srv_inst = utun_instance_create_from_str(ua, build_server_config(0));
TASSERT(srv_inst);
TASSERT(utun_instance_init(srv_inst) >= 0);
cli_inst = utun_instance_create_from_str(ua, build_client_config(port + 1));
cli_inst = utun_instance_create_from_str(ua, build_client_config(0));
TASSERT(cli_inst);
TASSERT(utun_instance_init(cli_inst) >= 0);