From 6d50a8bff1938a8d7f398275a886aca37d6f6a7c Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Tue, 14 May 2024 23:09:36 +0200 Subject: tests improved logging; add dir client test --- ecp/test/Makefile | 7 ++++-- ecp/test/basic.c | 27 ++++++++++----------- ecp/test/client.c | 16 ++++++------- ecp/test/dir.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++ ecp/test/init.h | 2 ++ ecp/test/init_vconn.h | 2 ++ ecp/test/server.c | 12 +++++----- ecp/test/vc_client.c | 20 ++++++++-------- ecp/test/vc_common.c | 4 ++-- ecp/test/vc_server.c | 22 ++++++++--------- ecp/test/vcs.c | 20 ++++++++-------- 11 files changed, 135 insertions(+), 62 deletions(-) create mode 100644 ecp/test/dir.c (limited to 'ecp/test') diff --git a/ecp/test/Makefile b/ecp/test/Makefile index 3e5effe..3fc85d1 100644 --- a/ecp/test/Makefile +++ b/ecp/test/Makefile @@ -3,9 +3,9 @@ include $(src_dir)/ecp/common.mk CFLAGS += -I../util dep = ../build-posix/*.a ../util/libecputil.a -target = basic client server +target = basic client server dir ifeq ($(with_htable),yes) -target += vc_inb vc_outb vcs vc_server vc_client +target += vcs vc_server vc_client vc_inb vc_outb endif @@ -23,6 +23,9 @@ client: client.o init.o $(dep) server: server.o init.o $(dep) $(CC) -o $@ $< init.o $(dep) $(LDFLAGS) +dir: dir.o $(dep) + $(CC) -o $@ $< init.o $(dep) $(LDFLAGS) + vc_inb: vc_inb.o vc_common.o init_vconn.o $(dep) $(CC) -o $@ $< vc_common.o init_vconn.o $(dep) $(LDFLAGS) diff --git a/ecp/test/basic.c b/ecp/test/basic.c index 2e6bfd0..68cc604 100644 --- a/ecp/test/basic.c +++ b/ecp/test/basic.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -53,52 +54,52 @@ int main(int argc, char *argv[]) { /* server */ rv = ecp_init(&ctx_s); - printf("ecp_init RV:%d\n", rv); + LOG("ecp_init", rv); ecp_conn_handler_init(&handler_s, NULL, NULL, handle_msg_s, NULL); ecp_ctx_set_handler(&ctx_s, CTYPE_TEST, &handler_s); rv = ecp_dhkey_gen(&key_perma_s); - printf("ecp_dhkey_gen RV:%d\n", rv); + LOG("ecp_dhkey_gen", rv); rv = ecp_sock_create(&sock_s, &ctx_s, &key_perma_s); - printf("ecp_sock_create RV:%d\n", rv); + LOG("ecp_sock_create", rv); rv = ecp_addr_init(&addr, "0.0.0.0:3000"); - printf("ecp_addr_init RV:%d\n", rv); + LOG("ecp_addr_init", rv); rv = ecp_sock_open(&sock_s, &addr); - printf("ecp_sock_open RV:%d\n", rv); + LOG("ecp_sock_open", rv); rv = ecp_start_receiver(&sock_s); - printf("ecp_start_receiver RV:%d\n", rv); + LOG("ecp_start_receiver", rv); /* client */ rv = ecp_init(&ctx_c); - printf("ecp_init RV:%d\n", rv); + LOG("ecp_init", rv); ecp_conn_handler_init(&handler_c, handle_open_c, NULL, handle_msg_c, NULL); ecp_ctx_set_handler(&ctx_c, CTYPE_TEST, &handler_c); rv = ecp_dhkey_gen(&key_perma_c); - printf("ecp_dhkey_gen RV:%d\n", rv); + LOG("ecp_dhkey_gen", rv); rv = ecp_sock_create(&sock_c, &ctx_c, &key_perma_c); - printf("ecp_sock_create RV:%d\n", rv); + LOG("ecp_sock_create", rv); rv = ecp_sock_open(&sock_c, NULL); - printf("ecp_sock_open RV:%d\n", rv); + LOG("ecp_sock_open", rv); rv = ecp_start_receiver(&sock_c); - printf("ecp_start_receiver RV:%d\n", rv); + LOG("ecp_start_receiver", rv); ecp_node_init(&node, &key_perma_s.public, NULL); rv = ecp_node_set_addr(&node, "127.0.0.1:3000"); - printf("ecp_node_set_addr RV:%d\n", rv); + LOG("ecp_node_set_addr", rv); ecp_conn_init(&conn, &sock_c, CTYPE_TEST); rv = ecp_conn_open(&conn, &node); - printf("ecp_conn_open RV:%d\n", rv); + LOG("ecp_conn_open", rv); while (1) sleep(1); } diff --git a/ecp/test/client.c b/ecp/test/client.c index 0236f97..eb39c92 100644 --- a/ecp/test/client.c +++ b/ecp/test/client.c @@ -47,33 +47,33 @@ int main(int argc, char *argv[]) { if (argc != 3) usage(argv[0]); rv = ecp_init(&ctx); - printf("ecp_init RV:%d\n", rv); + LOG("ecp_init", rv); ecp_conn_handler_init(&handler, handle_open, NULL, handle_msg, NULL); ecp_ctx_set_handler(&ctx, CTYPE_TEST, &handler); rv = ecp_dhkey_gen(&key_perma); - printf("ecp_dhkey_gen RV:%d\n", rv); + LOG("ecp_dhkey_gen", rv); rv = ecp_sock_create(&sock, &ctx, &key_perma); - printf("ecp_sock_create RV:%d\n", rv); + LOG("ecp_sock_create", rv); rv = ecp_sock_open(&sock, NULL); - printf("ecp_sock_open RV:%d\n", rv); + LOG("ecp_sock_open", rv); rv = ecp_start_receiver(&sock); - printf("ecp_start_receiver RV:%d\n", rv); + LOG("ecp_start_receiver", rv); rv = ecp_util_load_key(argv[2], &node_pub, NULL); - printf("ecp_util_load_key RV:%d\n", rv); + LOG("ecp_util_load_key", rv); ecp_node_init(&node, &node_pub, NULL); rv = ecp_node_set_addr(&node, argv[1]); - printf("ecp_node_set_addr RV:%d\n", rv); + LOG("ecp_node_set_addr", rv); ecp_conn_init(&conn, &sock, CTYPE_TEST); rv = ecp_conn_open(&conn, &node); - printf("ecp_conn_open RV:%d\n", rv); + LOG("ecp_conn_open", rv); while (1) sleep(1); } diff --git a/ecp/test/dir.c b/ecp/test/dir.c new file mode 100644 index 0000000..099ecbb --- /dev/null +++ b/ecp/test/dir.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include + +#include +#include +#include + +#include + +ECPContext ctx; +ECPSocket sock; +ECPConnection conn; +ECPConnHandler dir_handler; + +#define LOG(fmt, rv) { printf(fmt " RV:%d\n", rv); if (rv) exit(1); } + +static void handle_err(ECPConnection *conn, unsigned char mtype, int err) { + printf("ERROR: CTYPE:0x%x MTYPE:0x%x ERR:%d\n", conn->type, mtype, err); +} + +static void print_list(ECPDirList *dir_list, int err) { + ecp_dir_list_destroy(dir_list); +} + +static void usage(char *arg) { + fprintf(stderr, "Usage: %s
\n", arg); + exit(1); +} + +int main(int argc, char *argv[]) { + ECPNode node; + ecp_ecdh_public_t node_pub; + int rv; + + if (argc != 3) usage(argv[0]); + + rv = ecp_ctx_init(&ctx, NULL, NULL, NULL, handle_err); + LOG("ecp_ctx_init", rv); + + rv = ecp_dir_set_handler(&ctx, &dir_handler, print_list); + LOG("ecp_dir_ctx_init", rv); + + rv = ecp_sock_create(&sock, &ctx, NULL); + LOG("ecp_sock_create", rv); + + rv = ecp_sock_open(&sock, NULL); + LOG("ecp_sock_open", rv); + + rv = ecp_start_receiver(&sock); + LOG("ecp_start_receiver", rv); + + rv = ecp_util_load_key(argv[2], &node_pub, NULL); + LOG("ecp_util_load_key", rv); + + ecp_node_init(&node, &node_pub, NULL); + rv = ecp_node_set_addr(&node, argv[1]); + LOG("ecp_node_set_addr", rv); + + rv = ecp_dir_get(&conn, &sock, &node, 0); + LOG("ecp_dir_get", rv); + + while(1) pause(); +} diff --git a/ecp/test/init.h b/ecp/test/init.h index a1a21d1..7edba6e 100644 --- a/ecp/test/init.h +++ b/ecp/test/init.h @@ -1 +1,3 @@ +#define LOG(fmt, rv) { printf(fmt " RV:%d\n", rv); if (rv) exit(1); } + int ecp_init(ECPContext *ctx); \ No newline at end of file diff --git a/ecp/test/init_vconn.h b/ecp/test/init_vconn.h index 64e3269..06f10e2 100644 --- a/ecp/test/init_vconn.h +++ b/ecp/test/init_vconn.h @@ -1 +1,3 @@ +#define LOG(fmt, rv) { printf(fmt " RV:%d\n", rv); if (rv) exit(1); } + int ecp_init(ECPContext *ctx, ECPConnHandler *vconn_handler, ECPConnHandler *vlink_handler); \ No newline at end of file diff --git a/ecp/test/server.c b/ecp/test/server.c index 0af41c6..9943adb 100644 --- a/ecp/test/server.c +++ b/ecp/test/server.c @@ -41,26 +41,26 @@ int main(int argc, char *argv[]) { if (argc != 3) usage(argv[0]); rv = ecp_init(&ctx); - printf("ecp_init RV:%d\n", rv); + LOG("ecp_init", rv); ecp_conn_handler_init(&handler, NULL, NULL, handle_msg, NULL); ecp_ctx_set_handler(&ctx, CTYPE_TEST, &handler); rv = ecp_util_load_key(argv[2], &key_perma.public, &key_perma.private); - printf("ecp_util_load_key RV:%d\n", rv); + LOG("ecp_util_load_key", rv); key_perma.valid = 1; rv = ecp_sock_create(&sock, &ctx, &key_perma); - printf("ecp_sock_create RV:%d\n", rv); + LOG("ecp_sock_create", rv); rv = ecp_addr_init(&addr, argv[1]); - printf("ecp_addr_init RV:%d\n", rv); + LOG("ecp_addr_init", rv); rv = ecp_sock_open(&sock, &addr); - printf("ecp_sock_open RV:%d\n", rv); + LOG("ecp_sock_open", rv); rv = ecp_start_receiver(&sock); - printf("ecp_start_receiver RV:%d\n", rv); + LOG("ecp_start_receiver", rv); while (1) sleep(1); } diff --git a/ecp/test/vc_client.c b/ecp/test/vc_client.c index d157081..f46824b 100644 --- a/ecp/test/vc_client.c +++ b/ecp/test/vc_client.c @@ -52,42 +52,42 @@ int main(int argc, char *argv[]) { if ((argc < 4) || (argc > 6)) usage(argv[0]); rv = ecp_init(&ctx, &vconn_handler, &vlink_handler); - printf("ecp_init RV:%d\n", rv); + LOG("ecp_init", rv); ecp_conn_handler_init(&handler, handle_open, NULL, handle_msg, NULL); ecp_ctx_set_handler(&ctx, CTYPE_TEST, &handler); rv = ecp_dhkey_gen(&key_perma); - printf("ecp_dhkey_gen RV:%d\n", rv); + LOG("ecp_dhkey_gen", rv); rv = ecp_sock_create(&sock, &ctx, &key_perma); - printf("ecp_sock_create RV:%d\n", rv); + LOG("ecp_sock_create", rv); rv = ecp_vconn_sock_create(&sock); - printf("ecp_vconn_htable_init RV:%d\n", rv); + LOG("ecp_vconn_htable_init", rv); rv = ecp_sock_open(&sock, NULL); - printf("ecp_sock_open RV:%d\n", rv); + LOG("ecp_sock_open", rv); rv = ecp_start_receiver(&sock); - printf("ecp_start_receiver RV:%d\n", rv); + LOG("ecp_start_receiver", rv); rv = ecp_util_load_key(argv[1], &node_pub, NULL); - printf("ecp_util_load_key RV:%d\n", rv); + LOG("ecp_util_load_key", rv); ecp_node_init(&node, &node_pub, NULL); rv = ecp_node_set_addr(&node, argv[2]); - printf("ecp_node_set_addr RV:%d\n", rv); + LOG("ecp_node_set_addr", rv); for (i=3; i 7)) usage(argv[0]); rv = ecp_init(&ctx, &vconn_handler, &vlink_handler); - printf("ecp_init RV:%d\n", rv); + LOG("ecp_init", rv); ecp_conn_handler_init(&handler, handle_open, NULL, handle_msg, NULL); ecp_ctx_set_handler(&ctx, CTYPE_TEST, &handler); rv = ecp_util_load_key(argv[1], &key_perma.public, &key_perma.private); - printf("ecp_util_load_key RV:%d\n", rv); + LOG("ecp_util_load_key", rv); key_perma.valid = 1; rv = ecp_sock_create(&sock, &ctx, &key_perma); - printf("ecp_sock_create RV:%d\n", rv); + LOG("ecp_sock_create", rv); rv = ecp_vconn_sock_create(&sock); - printf("ecp_vconn_htable_init RV:%d\n", rv); + LOG("ecp_vconn_htable_init", rv); rv = ecp_sock_open(&sock, NULL); - printf("ecp_sock_open RV:%d\n", rv); + LOG("ecp_sock_open", rv); rv = ecp_start_receiver(&sock); - printf("ecp_start_receiver RV:%d\n", rv); + LOG("ecp_start_receiver", rv); rv = ecp_util_load_key(argv[argc-1], &node_pub, NULL); - printf("ecp_util_load_key RV:%d\n", rv); + LOG("ecp_util_load_key", rv); ecp_node_init(&node, &node_pub, NULL); rv = ecp_node_set_addr(&node, argv[2]); - printf("ecp_node_set_addr RV:%d\n", rv); + LOG("ecp_node_set_addr", rv); ecp_vlink_init(&conn, &sock); if (argc > 4) { @@ -85,15 +85,15 @@ int main(int argc, char *argv[]) { for (i=3; i 5)) usage(argv[0]); rv = ecp_init(&ctx, &vconn_handler, &vlink_handler); - printf("ecp_init RV:%d\n", rv); + LOG("ecp_init", rv); vlink_handler.handle_open = vlink_handle_open; rv = ecp_util_load_key(argv[2], &key_perma.public, &key_perma.private); - printf("ecp_util_load_key RV:%d\n", rv); + LOG("ecp_util_load_key", rv); key_perma.valid = 1; rv = ecp_sock_create(&sock, &ctx, &key_perma); - printf("ecp_sock_create RV:%d\n", rv); + LOG("ecp_sock_create", rv); rv = ecp_vconn_sock_create(&sock); - printf("ecp_vconn_htable_init RV:%d\n", rv); + LOG("ecp_vconn_htable_init", rv); rv = ecp_addr_init(&addr, argv[1]); - printf("ecp_addr_init RV:%d\n", rv); + LOG("ecp_addr_init", rv); rv = ecp_sock_open(&sock, &addr); - printf("ecp_sock_open RV:%d\n", rv); + LOG("ecp_sock_open", rv); rv = ecp_start_receiver(&sock); - printf("ecp_start_receiver RV:%d\n", rv); + LOG("ecp_start_receiver", rv); if (argc == 5) { ECPNode node; ecp_ecdh_public_t node_pub; rv = ecp_util_load_key(argv[4], &node_pub, NULL); - printf("ecp_util_load_key RV:%d\n", rv); + LOG("ecp_util_load_key", rv); ecp_node_init(&node, &node_pub, NULL); rv = ecp_node_set_addr(&node, argv[3]); - printf("ecp_node_set_addr RV:%d\n", rv); + LOG("ecp_node_set_addr", rv); ecp_vlink_init(&conn, &sock); rv = ecp_conn_open(&conn, &node); - printf("ecp_conn_open RV:%d\n", rv); + LOG("ecp_conn_open", rv); } else { memset(&conn, 0, sizeof(conn)); } -- cgit v1.2.3