aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_circuitmux.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2019-10-22 10:37:35 -0400
committerDavid Goulet <dgoulet@torproject.org>2019-10-28 13:17:11 -0400
commit839bc4814e8f99a15709994645bfa61f010d6dc0 (patch)
tree36f30128367aaa0552989e62bc0d1d7cd8cfeb2b /src/test/test_circuitmux.c
parent7678022e85736fc8a78b2a4252bf55db0043f1c5 (diff)
downloadtor-839bc4814e8f99a15709994645bfa61f010d6dc0.tar.gz
tor-839bc4814e8f99a15709994645bfa61f010d6dc0.zip
test: Add testcase setup object for test_cmux
Also remove a scheduler_init() from a test and MOCK the appropriate function so the test can pass. This is done in order to minimize initialization functions in the unit test and try to only go through the testcase setup object. Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/test/test_circuitmux.c')
-rw-r--r--src/test/test_circuitmux.c49
1 files changed, 46 insertions, 3 deletions
diff --git a/src/test/test_circuitmux.c b/src/test/test_circuitmux.c
index a2b3e62fe8..75bb4df5f6 100644
--- a/src/test/test_circuitmux.c
+++ b/src/test/test_circuitmux.c
@@ -17,6 +17,16 @@
#include <math.h>
+/**
+ * MOCKED functions.
+ */
+static void
+scheduler_release_channel_mock(channel_t *chan)
+{
+ (void) chan;
+ return;
+}
+
/* XXXX duplicated function from test_circuitlist.c */
static channel_t *
new_fake_channel(void)
@@ -44,7 +54,7 @@ test_cmux_destroy_cell_queue(void *arg)
packed_cell_t *pc = NULL;
destroy_cell_t *dc = NULL;
- scheduler_init();
+ MOCK(scheduler_release_channel, scheduler_release_channel_mock);
(void) arg;
@@ -82,6 +92,8 @@ test_cmux_destroy_cell_queue(void *arg)
channel_free(ch);
packed_cell_free(pc);
tor_free(dc);
+
+ UNMOCK(scheduler_release_channel);
}
static void
@@ -125,9 +137,40 @@ test_cmux_compute_ticks(void *arg)
;
}
+static void *
+cmux_setup_test(const struct testcase_t *tc)
+{
+ static int whatever;
+
+ (void) tc;
+
+ cell_ewma_initialize_ticks();
+ return &whatever;
+}
+
+static int
+cmux_cleanup_test(const struct testcase_t *tc, void *ptr)
+{
+ (void) tc;
+ (void) ptr;
+
+ circuitmux_ewma_free_all();
+
+ return 1;
+}
+
+static struct testcase_setup_t cmux_test_setup = {
+ .setup_fn = cmux_setup_test,
+ .cleanup_fn = cmux_cleanup_test,
+};
+
+#define TEST_CMUX(name) \
+ { #name, test_cmux_##name, TT_FORK, &cmux_test_setup, NULL }
+
struct testcase_t circuitmux_tests[] = {
- { "destroy_cell_queue", test_cmux_destroy_cell_queue, TT_FORK, NULL, NULL },
- { "compute_ticks", test_cmux_compute_ticks, TT_FORK, NULL, NULL },
+ TEST_CMUX(compute_ticks),
+ TEST_CMUX(destroy_cell_queue),
+
END_OF_TESTCASES
};