Skip to content

Commit

Permalink
test/tcp,udp: Add TOS/TCLASS tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilianfridrich committed Dec 12, 2024
1 parent f1d34a1 commit ab9206c
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 0 deletions.
60 changes: 60 additions & 0 deletions test/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,63 @@ int test_tcp(void)

return err;
}


static int tcp_tos(const char *addr)
{
struct tcp_test *tt;
struct sa srv;
int err;

tt = mem_zalloc(sizeof(*tt), destructor);
if (!tt)
return ENOMEM;

err = sa_set_str(&srv, addr, 0);
if (err)
goto out;

err = tcp_listen(&tt->ts, &srv, tcp_server_conn_handler, tt);
if (err)
goto out;

tcp_settos(tt->ts, 184);
tcp_settos(tt->ts, 120);

err = tcp_local_get(tt->ts, &srv);
if (err)
goto out;

err = tcp_connect(&tt->tc, &srv, tcp_client_estab_handler,
tcp_client_recv_handler, tcp_client_close_handler,
tt);
if (err)
goto out;

err = re_main_timeout(500);
if (err)
goto out;

if (tt->err)
err = tt->err;

out:
mem_deref(tt);

return err;
}


int test_tcp_tos(void)
{
int err;

err = tcp_tos("127.0.0.1");
TEST_ERR(err);

err = tcp_tos("::1");
TEST_ERR(err);

out:
return err;
}
2 changes: 2 additions & 0 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ static const struct test tests[] = {
TEST(test_sys_fs_fopen),
TEST(test_sys_getenv),
TEST(test_tcp),
TEST(test_tcp_tos),
TEST(test_telev),
TEST(test_text2pcap),
#ifdef USE_TLS
Expand All @@ -236,6 +237,7 @@ static const struct test tests[] = {
TEST(test_turn),
TEST(test_turn_tcp),
TEST(test_udp),
TEST(test_udp_tos),
TEST(test_unixsock),
TEST(test_uri),
TEST(test_uri_encode),
Expand Down
2 changes: 2 additions & 0 deletions test/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ int test_sys_fs_isfile(void);
int test_sys_fs_fopen(void);
int test_sys_getenv(void);
int test_tcp(void);
int test_tcp_tos(void);
int test_telev(void);
int test_text2pcap(void);
int test_thread(void);
Expand All @@ -343,6 +344,7 @@ int test_turn(void);
int test_turn_tcp(void);
int test_turn_thread(void);
int test_udp(void);
int test_udp_tos(void);
int test_unixsock(void);
int test_uri(void);
int test_uri_encode(void);
Expand Down
74 changes: 74 additions & 0 deletions test/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,77 @@ int test_udp(void)

return err;
}


static int udp_tos(const char *addr)
{
struct udp_test *ut;
int layer = 0;
int err;

ut = mem_zalloc(sizeof(*ut), destructor);
if (!ut)
return ENOMEM;

err = sa_set_str(&ut->cli, addr, 0);
err |= sa_set_str(&ut->srv, addr, 0);
if (err)
goto out;

err = udp_listen(&ut->usc, &ut->cli, udp_recv_client, ut);
err |= udp_listen(&ut->uss, &ut->srv, udp_recv_server, ut);
if (err)
goto out;

udp_settos(ut->usc, 184);
udp_settos(ut->uss, 120);

udp_rxbuf_presz_set(ut->uss, 16);

err = udp_local_get(ut->usc, &ut->cli);
err |= udp_local_get(ut->uss, &ut->srv);
if (err)
goto out;

err = udp_register_helper(&ut->uh, ut->usc, layer,
udp_helper_send, udp_helper_recv, ut);
if (err)
goto out;

/* Send from connected client UDP socket */
err = udp_connect(ut->usc, &ut->srv);
if (err)
goto out;

/* Start test */
err = send_data(ut->usc, &ut->srv, data0);
if (err)
goto out;

err = re_main_timeout(100);
if (err)
goto out;

if (ut->err)
err = ut->err;

out:
mem_deref(ut);

return err;
}


int test_udp_tos(void)
{
int err;

err = udp_tos("127.0.0.1");
TEST_ERR(err);

err = udp_tos("::1");
TEST_ERR(err);

out:
return err;
}

0 comments on commit ab9206c

Please sign in to comment.