mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
Remove redundant event2/event.h usage from test_scheduler.c
This module doesn't actually need to mock the libevent mainloop at all: it can just use the regular mainloop that the test environment sets up. Part of ticket 23750.
This commit is contained in:
parent
6a5f62f68f
commit
4225300648
@ -4,7 +4,6 @@
|
||||
#include "orconfig.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <event2/event.h>
|
||||
|
||||
#define SCHEDULER_KIST_PRIVATE
|
||||
#define TOR_CHANNEL_INTERNAL_
|
||||
@ -101,62 +100,6 @@ mock_kist_networkstatus_get_param(
|
||||
return 12;
|
||||
}
|
||||
|
||||
/* Event base for scheduelr tests */
|
||||
static struct event_base *mock_event_base = NULL;
|
||||
/* Setup for mock event stuff */
|
||||
static void mock_event_free_all(void);
|
||||
static void mock_event_init(void);
|
||||
static void
|
||||
mock_event_free_all(void)
|
||||
{
|
||||
tt_ptr_op(mock_event_base, OP_NE, NULL);
|
||||
|
||||
if (mock_event_base) {
|
||||
event_base_free(mock_event_base);
|
||||
mock_event_base = NULL;
|
||||
}
|
||||
|
||||
tt_ptr_op(mock_event_base, OP_EQ, NULL);
|
||||
|
||||
done:
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
mock_event_init(void)
|
||||
{
|
||||
struct event_config *cfg = NULL;
|
||||
|
||||
tt_ptr_op(mock_event_base, OP_EQ, NULL);
|
||||
|
||||
/*
|
||||
* Really cut down from tor_libevent_initialize of
|
||||
* src/common/compat_libevent.c to kill config dependencies
|
||||
*/
|
||||
|
||||
if (!mock_event_base) {
|
||||
cfg = event_config_new();
|
||||
#if LIBEVENT_VERSION_NUMBER >= V(2,0,9)
|
||||
/* We can enable changelist support with epoll, since we don't give
|
||||
* Libevent any dup'd fds. This lets us avoid some syscalls. */
|
||||
event_config_set_flag(cfg, EVENT_BASE_FLAG_EPOLL_USE_CHANGELIST);
|
||||
#endif
|
||||
mock_event_base = event_base_new_with_config(cfg);
|
||||
event_config_free(cfg);
|
||||
}
|
||||
|
||||
tt_ptr_op(mock_event_base, OP_NE, NULL);
|
||||
|
||||
done:
|
||||
return;
|
||||
}
|
||||
|
||||
static struct event_base *
|
||||
tor_libevent_get_base_mock(void)
|
||||
{
|
||||
return mock_event_base;
|
||||
}
|
||||
|
||||
static int
|
||||
scheduler_compare_channels_mock(const void *c1_v,
|
||||
const void *c2_v)
|
||||
@ -417,9 +360,7 @@ perform_channel_state_tests(int KISTSchedRunInterval, int sched_type)
|
||||
mocked_options.KISTSchedRunInterval = KISTSchedRunInterval;
|
||||
set_scheduler_options(sched_type);
|
||||
|
||||
/* Set up libevent and scheduler */
|
||||
mock_event_init();
|
||||
MOCK(tor_libevent_get_base, tor_libevent_get_base_mock);
|
||||
/* Set up scheduler */
|
||||
scheduler_init();
|
||||
/*
|
||||
* Install the compare channels mock so we can test
|
||||
@ -523,14 +464,12 @@ perform_channel_state_tests(int KISTSchedRunInterval, int sched_type)
|
||||
|
||||
channel_free_all();
|
||||
scheduler_free_all();
|
||||
mock_event_free_all();
|
||||
|
||||
done:
|
||||
tor_free(ch1);
|
||||
tor_free(ch2);
|
||||
|
||||
UNMOCK(scheduler_compare_channels);
|
||||
UNMOCK(tor_libevent_get_base);
|
||||
UNMOCK(get_options);
|
||||
cleanup_scheduler_options();
|
||||
|
||||
@ -635,10 +574,7 @@ test_scheduler_loop_vanilla(void *arg)
|
||||
set_scheduler_options(SCHEDULER_VANILLA);
|
||||
mocked_options.KISTSchedRunInterval = 0;
|
||||
|
||||
/* Set up libevent and scheduler */
|
||||
|
||||
mock_event_init();
|
||||
MOCK(tor_libevent_get_base, tor_libevent_get_base_mock);
|
||||
/* Set up scheduler */
|
||||
scheduler_init();
|
||||
/*
|
||||
* Install the compare channels mock so we can test
|
||||
@ -786,7 +722,6 @@ test_scheduler_loop_vanilla(void *arg)
|
||||
channel_flush_some_cells_mock_free_all();
|
||||
channel_free_all();
|
||||
scheduler_free_all();
|
||||
mock_event_free_all();
|
||||
|
||||
done:
|
||||
tor_free(ch1);
|
||||
@ -795,7 +730,6 @@ test_scheduler_loop_vanilla(void *arg)
|
||||
|
||||
UNMOCK(channel_flush_some_cells);
|
||||
UNMOCK(scheduler_compare_channels);
|
||||
UNMOCK(tor_libevent_get_base);
|
||||
UNMOCK(get_options);
|
||||
}
|
||||
|
||||
@ -917,8 +851,6 @@ test_scheduler_initfree(void *arg)
|
||||
tt_ptr_op(channels_pending, ==, NULL);
|
||||
tt_ptr_op(run_sched_ev, ==, NULL);
|
||||
|
||||
mock_event_init();
|
||||
MOCK(tor_libevent_get_base, tor_libevent_get_base_mock);
|
||||
MOCK(get_options, mock_get_options);
|
||||
set_scheduler_options(SCHEDULER_KIST);
|
||||
set_scheduler_options(SCHEDULER_KIST_LITE);
|
||||
@ -935,9 +867,6 @@ test_scheduler_initfree(void *arg)
|
||||
|
||||
scheduler_free_all();
|
||||
|
||||
UNMOCK(tor_libevent_get_base);
|
||||
mock_event_free_all();
|
||||
|
||||
tt_ptr_op(channels_pending, ==, NULL);
|
||||
tt_ptr_op(run_sched_ev, ==, NULL);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user