[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor] 04/20: Prop#329 Tests: Add tests for conflux cells.



This is an automated email from the git hooks/post-receive script.

ahf pushed a commit to branch main
in repository tor.

commit 0d14d6b44a7b42d860dabc643bb702fee530622c
Author: David Goulet <dgoulet@xxxxxxxxxxxxxx>
AuthorDate: Wed Feb 1 22:32:33 2023 +0000

    Prop#329 Tests: Add tests for conflux cells.
    
    Signed-off-by: David Goulet <dgoulet@xxxxxxxxxxxxxx>
---
 src/test/include.am          |  1 +
 src/test/test.c              |  1 +
 src/test/test.h              |  1 +
 src/test/test_conflux_cell.c | 60 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 63 insertions(+)

diff --git a/src/test/include.am b/src/test/include.am
index 2765cf27d0..1c2929c3ca 100644
--- a/src/test/include.am
+++ b/src/test/include.am
@@ -147,6 +147,7 @@ src_test_test_SOURCES += \
 	src/test/test_circuitstats.c \
 	src/test/test_compat_libevent.c \
 	src/test/test_config.c \
+	src/test/test_conflux_cell.c \
 	src/test/test_confmgr.c \
 	src/test/test_confparse.c \
 	src/test/test_connection.c \
diff --git a/src/test/test.c b/src/test/test.c
index 6b7e0b6442..e1252eda66 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -778,6 +778,7 @@ struct testgroup_t testgroups[] = {
   { "config/", config_tests },
   { "config/mgr/", confmgr_tests },
   { "config/parse/", confparse_tests },
+  { "conflux/cell/", conflux_cell_tests },
   { "connection/", connection_tests },
   { "conscache/", conscache_tests },
   { "consdiff/", consdiff_tests },
diff --git a/src/test/test.h b/src/test/test.h
index e17bce427c..fb0ea98f93 100644
--- a/src/test/test.h
+++ b/src/test/test.h
@@ -107,6 +107,7 @@ extern struct testcase_t circuitstats_tests[];
 extern struct testcase_t circuituse_tests[];
 extern struct testcase_t compat_libevent_tests[];
 extern struct testcase_t config_tests[];
+extern struct testcase_t conflux_cell_tests[];
 extern struct testcase_t confmgr_tests[];
 extern struct testcase_t confparse_tests[];
 extern struct testcase_t connection_tests[];
diff --git a/src/test/test_conflux_cell.c b/src/test/test_conflux_cell.c
new file mode 100644
index 0000000000..bb440d0d0a
--- /dev/null
+++ b/src/test/test_conflux_cell.c
@@ -0,0 +1,60 @@
+/* Copyright (c) 2023, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file test_conflux_cell.
+ * \brief Test conflux cells.
+ */
+
+#include "test/test.h"
+#include "test/test_helpers.h"
+#include "test/log_test_helpers.h"
+
+#include "core/or/conflux_cell.h"
+#include "core/or/conflux_st.h"
+#include "trunnel/conflux.h"
+
+#include "lib/crypt_ops/crypto_rand.h"
+
+static void
+test_link(void *arg)
+{
+  cell_t cell;
+  conflux_cell_link_t link;
+  conflux_cell_link_t *decoded_link = NULL;
+
+  (void) arg;
+
+  memset(&link, 0, sizeof(link));
+
+  link.desired_ux = CONFLUX_UX_HIGH_THROUGHPUT;
+  link.last_seqno_recv = 0;
+  link.last_seqno_sent = 0;
+  link.version = 0x01;
+
+  crypto_rand((char *) link.nonce, sizeof(link.nonce));
+
+  ssize_t cell_len = build_link_cell(&link, cell.payload+RELAY_HEADER_SIZE);
+  tt_int_op(cell_len, OP_GT, 0);
+
+  decoded_link = conflux_cell_parse_link(&cell, cell_len);
+  tt_assert(decoded_link);
+
+  uint8_t buf[RELAY_PAYLOAD_SIZE];
+  ssize_t enc_cell_len = build_link_cell(decoded_link, buf);
+  tt_int_op(cell_len, OP_EQ, enc_cell_len);
+
+  /* Validate the original link object with the decoded one. */
+  tt_mem_op(&link, OP_EQ, decoded_link, sizeof(link));
+  tor_free(decoded_link);
+
+ done:
+  tor_free(decoded_link);
+}
+
+struct testcase_t conflux_cell_tests[] = {
+  { "link", test_link, TT_FORK, NULL, NULL },
+
+  END_OF_TESTCASES
+};
+

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits