mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 12:23:32 +01:00
Add testing-only functions to get the subsystem config/state indices
This commit is contained in:
parent
52c0ab4af3
commit
b06e9d8ad5
@ -335,6 +335,54 @@ subsystems_register_state_formats(config_mgr_t *mgr)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TOR_UNIT_TESTS
|
||||||
|
/**
|
||||||
|
* Helper: look up the index for <b>sys</b>. Return -1 if the subsystem
|
||||||
|
* is not recognized.
|
||||||
|
**/
|
||||||
|
static int
|
||||||
|
subsys_get_idx(const subsys_fns_t *sys)
|
||||||
|
{
|
||||||
|
for (unsigned i = 0; i < n_tor_subsystems; ++i) {
|
||||||
|
if (sys == tor_subsystems[i])
|
||||||
|
return (int)i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the current state-manager's index for any state held by the
|
||||||
|
* subsystem <b>sys</b>. If <b>sys</b> has no options, return -1.
|
||||||
|
*
|
||||||
|
* Using raw indices can be error-prone: only do this from the unit
|
||||||
|
* tests. If you need a way to access another subsystem's configuration,
|
||||||
|
* that subsystem should provide access functions.
|
||||||
|
**/
|
||||||
|
int
|
||||||
|
subsystems_get_options_idx(const subsys_fns_t *sys)
|
||||||
|
{
|
||||||
|
int i = subsys_get_idx(sys);
|
||||||
|
tor_assert(i >= 0);
|
||||||
|
return sys_status[i].options_idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the current state-manager's index for any state held by the
|
||||||
|
* subsystem <b>sys</b>. If <b>sys</b> has no state, return -1.
|
||||||
|
*
|
||||||
|
* Using raw indices can be error-prone: only do this from the unit
|
||||||
|
* tests. If you need a way to access another subsystem's state
|
||||||
|
* that subsystem should provide access functions.
|
||||||
|
**/
|
||||||
|
int
|
||||||
|
subsystems_get_state_idx(const subsys_fns_t *sys)
|
||||||
|
{
|
||||||
|
int i = subsys_get_idx(sys);
|
||||||
|
tor_assert(i >= 0);
|
||||||
|
return sys_status[i].state_idx;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call all appropriate set_options() methods to tell the various subsystems
|
* Call all appropriate set_options() methods to tell the various subsystems
|
||||||
* about a new set of torrc options. Return 0 on success, -1 on
|
* about a new set of torrc options. Return 0 on success, -1 on
|
||||||
|
@ -43,4 +43,9 @@ int subsystems_set_state(const struct config_mgr_t *mgr,
|
|||||||
int subsystems_flush_state(const struct config_mgr_t *mgr,
|
int subsystems_flush_state(const struct config_mgr_t *mgr,
|
||||||
struct or_state_t *state);
|
struct or_state_t *state);
|
||||||
|
|
||||||
|
#ifdef TOR_UNIT_TESTS
|
||||||
|
int subsystems_get_options_idx(const subsys_fns_t *sys);
|
||||||
|
int subsystems_get_state_idx(const subsys_fns_t *sys);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* !defined(TOR_SUBSYSMGR_T) */
|
#endif /* !defined(TOR_SUBSYSMGR_T) */
|
||||||
|
Loading…
Reference in New Issue
Block a user