aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_circuitmux.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2019-10-22 10:46:13 -0400
committerDavid Goulet <dgoulet@torproject.org>2019-10-28 13:17:11 -0400
commitd2e51aca7da8851e81d4ed0edb2a093652817385 (patch)
treecf6b258ad8823ed8095fd47a1f2714b38b183f25 /src/test/test_circuitmux.c
parent839bc4814e8f99a15709994645bfa61f010d6dc0 (diff)
downloadtor-d2e51aca7da8851e81d4ed0edb2a093652817385.tar.gz
tor-d2e51aca7da8851e81d4ed0edb2a093652817385.zip
test: Remove circuitmux/destroy_cell_queue code duplication
This also rename a function to improve code clarity. Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/test/test_circuitmux.c')
-rw-r--r--src/test/test_circuitmux.c36
1 files changed, 8 insertions, 28 deletions
diff --git a/src/test/test_circuitmux.c b/src/test/test_circuitmux.c
index 75bb4df5f6..cb57b1bd60 100644
--- a/src/test/test_circuitmux.c
+++ b/src/test/test_circuitmux.c
@@ -5,39 +5,22 @@
#define CIRCUITMUX_PRIVATE
#define CIRCUITMUX_EWMA_PRIVATE
#define RELAY_PRIVATE
+
#include "core/or/or.h"
#include "core/or/channel.h"
#include "core/or/circuitmux.h"
#include "core/or/circuitmux_ewma.h"
+#include "core/or/destroy_cell_queue_st.h"
#include "core/or/relay.h"
#include "core/or/scheduler.h"
-#include "test/test.h"
-#include "core/or/destroy_cell_queue_st.h"
+#include "test/fakechans.h"
+#include "test/test.h"
#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)
-{
- channel_t *chan = tor_malloc_zero(sizeof(channel_t));
- channel_init(chan);
- return chan;
-}
-
static int
-has_queued_writes(channel_t *c)
+mock_has_queued_writes_true(channel_t *c)
{
(void) c;
return 1;
@@ -58,12 +41,10 @@ test_cmux_destroy_cell_queue(void *arg)
(void) arg;
- cmux = circuitmux_alloc();
- tt_assert(cmux);
ch = new_fake_channel();
- circuitmux_set_policy(cmux, &ewma_policy);
- ch->has_queued_writes = has_queued_writes;
+ ch->has_queued_writes = mock_has_queued_writes_true;
ch->wide_circ_ids = 1;
+ cmux = ch->cmux;
circ = circuitmux_get_first_active_circuit(cmux, &cq);
tt_ptr_op(circ, OP_EQ, NULL);
@@ -88,8 +69,7 @@ test_cmux_destroy_cell_queue(void *arg)
tt_int_op(circuitmux_num_cells(cmux), OP_EQ, 2);
done:
- circuitmux_free(cmux);
- channel_free(ch);
+ free_fake_channel(ch);
packed_cell_free(pc);
tor_free(dc);