dirvote: Handling adding vote and signature if module is disabled
[tor.git] / src / test / test_circuitmux.c
blob75b7a0ea47d8548d02a2f1930baa7c265f17c2b5
1 /* Copyright (c) 2013-2017, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
4 #define TOR_CHANNEL_INTERNAL_
5 #define CIRCUITMUX_PRIVATE
6 #define RELAY_PRIVATE
7 #include "or.h"
8 #include "channel.h"
9 #include "circuitmux.h"
10 #include "circuitmux_ewma.h"
11 #include "relay.h"
12 #include "scheduler.h"
13 #include "test.h"
15 /* XXXX duplicated function from test_circuitlist.c */
16 static channel_t *
17 new_fake_channel(void)
19 channel_t *chan = tor_malloc_zero(sizeof(channel_t));
20 channel_init(chan);
21 return chan;
24 static int
25 has_queued_writes(channel_t *c)
27 (void) c;
28 return 1;
31 /** Test destroy cell queue with no interference from other queues. */
32 static void
33 test_cmux_destroy_cell_queue(void *arg)
35 circuitmux_t *cmux = NULL;
36 channel_t *ch = NULL;
37 circuit_t *circ = NULL;
38 destroy_cell_queue_t *cq = NULL;
39 packed_cell_t *pc = NULL;
40 destroy_cell_t *dc = NULL;
42 scheduler_init();
44 (void) arg;
46 cmux = circuitmux_alloc();
47 tt_assert(cmux);
48 ch = new_fake_channel();
49 circuitmux_set_policy(cmux, &ewma_policy);
50 ch->has_queued_writes = has_queued_writes;
51 ch->wide_circ_ids = 1;
53 circ = circuitmux_get_first_active_circuit(cmux, &cq);
54 tt_ptr_op(circ, OP_EQ, NULL);
55 tt_ptr_op(cq, OP_EQ, NULL);
57 circuitmux_append_destroy_cell(ch, cmux, 100, 10);
58 circuitmux_append_destroy_cell(ch, cmux, 190, 6);
59 circuitmux_append_destroy_cell(ch, cmux, 30, 1);
61 tt_int_op(circuitmux_num_cells(cmux), OP_EQ, 3);
63 circ = circuitmux_get_first_active_circuit(cmux, &cq);
64 tt_ptr_op(circ, OP_EQ, NULL);
65 tt_assert(cq);
67 tt_int_op(cq->n, OP_EQ, 3);
69 dc = destroy_cell_queue_pop(cq);
70 tt_assert(dc);
71 tt_uint_op(dc->circid, OP_EQ, 100);
73 tt_int_op(circuitmux_num_cells(cmux), OP_EQ, 2);
75 done:
76 circuitmux_free(cmux);
77 channel_free(ch);
78 packed_cell_free(pc);
79 tor_free(dc);
82 struct testcase_t circuitmux_tests[] = {
83 { "destroy_cell_queue", test_cmux_destroy_cell_queue, TT_FORK, NULL, NULL },
84 END_OF_TESTCASES