1 /* Copyright (c) 2013-2017, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
4 #define TOR_CHANNEL_INTERNAL_
5 #define CIRCUITMUX_PRIVATE
9 #include "circuitmux.h"
10 #include "circuitmux_ewma.h"
12 #include "scheduler.h"
15 /* XXXX duplicated function from test_circuitlist.c */
17 new_fake_channel(void)
19 channel_t
*chan
= tor_malloc_zero(sizeof(channel_t
));
25 has_queued_writes(channel_t
*c
)
31 /** Test destroy cell queue with no interference from other queues. */
33 test_cmux_destroy_cell_queue(void *arg
)
35 circuitmux_t
*cmux
= 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
;
46 cmux
= circuitmux_alloc();
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
);
67 tt_int_op(cq
->n
, OP_EQ
, 3);
69 dc
= destroy_cell_queue_pop(cq
);
71 tt_uint_op(dc
->circid
, OP_EQ
, 100);
73 tt_int_op(circuitmux_num_cells(cmux
), OP_EQ
, 2);
76 circuitmux_free(cmux
);
82 struct testcase_t circuitmux_tests
[] = {
83 { "destroy_cell_queue", test_cmux_destroy_cell_queue
, TT_FORK
, NULL
, NULL
},