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>
This commit is contained in:
David Goulet 2019-10-22 10:46:13 -04:00
parent 839bc4814e
commit d2e51aca7d

View File

@ -5,39 +5,22 @@
#define CIRCUITMUX_PRIVATE #define CIRCUITMUX_PRIVATE
#define CIRCUITMUX_EWMA_PRIVATE #define CIRCUITMUX_EWMA_PRIVATE
#define RELAY_PRIVATE #define RELAY_PRIVATE
#include "core/or/or.h" #include "core/or/or.h"
#include "core/or/channel.h" #include "core/or/channel.h"
#include "core/or/circuitmux.h" #include "core/or/circuitmux.h"
#include "core/or/circuitmux_ewma.h" #include "core/or/circuitmux_ewma.h"
#include "core/or/destroy_cell_queue_st.h"
#include "core/or/relay.h" #include "core/or/relay.h"
#include "core/or/scheduler.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> #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 static int
has_queued_writes(channel_t *c) mock_has_queued_writes_true(channel_t *c)
{ {
(void) c; (void) c;
return 1; return 1;
@ -58,12 +41,10 @@ test_cmux_destroy_cell_queue(void *arg)
(void) arg; (void) arg;
cmux = circuitmux_alloc();
tt_assert(cmux);
ch = new_fake_channel(); ch = new_fake_channel();
circuitmux_set_policy(cmux, &ewma_policy); ch->has_queued_writes = mock_has_queued_writes_true;
ch->has_queued_writes = has_queued_writes;
ch->wide_circ_ids = 1; ch->wide_circ_ids = 1;
cmux = ch->cmux;
circ = circuitmux_get_first_active_circuit(cmux, &cq); circ = circuitmux_get_first_active_circuit(cmux, &cq);
tt_ptr_op(circ, OP_EQ, NULL); 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); tt_int_op(circuitmux_num_cells(cmux), OP_EQ, 2);
done: done:
circuitmux_free(cmux); free_fake_channel(ch);
channel_free(ch);
packed_cell_free(pc); packed_cell_free(pc);
tor_free(dc); tor_free(dc);