Make a pair of add_*_log() functions mockable.

This commit is contained in:
Nick Mathewson 2019-10-21 11:42:20 -04:00
parent ac3136a6fb
commit f4fc633937
2 changed files with 17 additions and 15 deletions

View File

@ -276,8 +276,8 @@ static int log_time_granularity = 1;
/** Define log time granularity for all logs to be <b>granularity_msec</b>
* milliseconds. */
void
set_log_time_granularity(int granularity_msec)
MOCK_IMPL(void,
set_log_time_granularity,(int granularity_msec))
{
log_time_granularity = granularity_msec;
tor_log_sigsafe_err_set_granularity(granularity_msec);
@ -937,9 +937,9 @@ set_log_severity_config(int loglevelMin, int loglevelMax,
/** Add a log handler named <b>name</b> to send all messages in <b>severity</b>
* to <b>fd</b>. Copies <b>severity</b>. Helper: does no locking. */
static void
add_stream_log_impl(const log_severity_list_t *severity,
const char *name, int fd)
MOCK_IMPL(STATIC void,
add_stream_log_impl,(const log_severity_list_t *severity,
const char *name, int fd))
{
logfile_t *lf;
lf = tor_malloc_zero(sizeof(logfile_t));
@ -1199,10 +1199,10 @@ mark_logs_temp(void)
* opening the logfile failed, -1 is returned and errno is set appropriately
* (by open(2)). Takes ownership of fd.
*/
int
add_file_log(const log_severity_list_t *severity,
const char *filename,
int fd)
MOCK_IMPL(int,
add_file_log,(const log_severity_list_t *severity,
const char *filename,
int fd))
{
logfile_t *lf;

View File

@ -163,11 +163,11 @@ int parse_log_severity_config(const char **cfg,
log_severity_list_t *severity_out);
void set_log_severity_config(int minSeverity, int maxSeverity,
log_severity_list_t *severity_out);
void add_stream_log(const log_severity_list_t *severity, const char *name,
int fd);
int add_file_log(const log_severity_list_t *severity,
const char *filename,
int fd);
void add_stream_log(const log_severity_list_t *severity,
const char *name, int fd);
MOCK_DECL(int, add_file_log,(const log_severity_list_t *severity,
const char *filename,
int fd));
#ifdef HAVE_SYSLOG_H
int add_syslog_log(const log_severity_list_t *severity,
@ -194,7 +194,7 @@ void change_callback_log_severity(int loglevelMin, int loglevelMax,
void flush_pending_log_callbacks(void);
void flush_log_messages_from_startup(void);
void log_set_application_name(const char *name);
void set_log_time_granularity(int granularity_msec);
MOCK_DECL(void, set_log_time_granularity,(int granularity_msec));
void truncate_logs(void);
void tor_log(int severity, log_domain_mask_t domain, const char *format, ...)
@ -306,6 +306,8 @@ extern const log_domain_mask_t LD_GENERAL_;
MOCK_DECL(STATIC void, logv, (int severity, log_domain_mask_t domain,
const char *funcname, const char *suffix, const char *format,
va_list ap) CHECK_PRINTF(5,0));
MOCK_DECL(STATIC void, add_stream_log_impl,(
const log_severity_list_t *severity, const char *name, int fd));
#endif
#if defined(LOG_PRIVATE) || defined(TOR_UNIT_TESTS)