mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 13:43:47 +01:00
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>
This commit is contained in:
parent
7678022e85
commit
839bc4814e
@ -17,6 +17,16 @@
|
|||||||
|
|
||||||
#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 */
|
/* XXXX duplicated function from test_circuitlist.c */
|
||||||
static channel_t *
|
static channel_t *
|
||||||
new_fake_channel(void)
|
new_fake_channel(void)
|
||||||
@ -44,7 +54,7 @@ test_cmux_destroy_cell_queue(void *arg)
|
|||||||
packed_cell_t *pc = NULL;
|
packed_cell_t *pc = NULL;
|
||||||
destroy_cell_t *dc = NULL;
|
destroy_cell_t *dc = NULL;
|
||||||
|
|
||||||
scheduler_init();
|
MOCK(scheduler_release_channel, scheduler_release_channel_mock);
|
||||||
|
|
||||||
(void) arg;
|
(void) arg;
|
||||||
|
|
||||||
@ -82,6 +92,8 @@ test_cmux_destroy_cell_queue(void *arg)
|
|||||||
channel_free(ch);
|
channel_free(ch);
|
||||||
packed_cell_free(pc);
|
packed_cell_free(pc);
|
||||||
tor_free(dc);
|
tor_free(dc);
|
||||||
|
|
||||||
|
UNMOCK(scheduler_release_channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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[] = {
|
struct testcase_t circuitmux_tests[] = {
|
||||||
{ "destroy_cell_queue", test_cmux_destroy_cell_queue, TT_FORK, NULL, NULL },
|
TEST_CMUX(compute_ticks),
|
||||||
{ "compute_ticks", test_cmux_compute_ticks, TT_FORK, NULL, NULL },
|
TEST_CMUX(destroy_cell_queue),
|
||||||
|
|
||||||
END_OF_TESTCASES
|
END_OF_TESTCASES
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user