2018-06-20 14:13:28 +02:00
|
|
|
/* Copyright (c) 2014-2018, The Tor Project, Inc. */
|
2015-09-15 17:20:44 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
2018-07-05 22:34:59 +02:00
|
|
|
#include "core/or/or.h"
|
2015-09-15 17:20:44 +02:00
|
|
|
|
|
|
|
#ifndef TOR_LOG_TEST_HELPERS_H
|
|
|
|
#define TOR_LOG_TEST_HELPERS_H
|
|
|
|
|
2016-08-31 19:03:59 +02:00
|
|
|
/** An element of mock_saved_logs(); records the log element that we
|
|
|
|
* received. */
|
2015-09-15 17:20:44 +02:00
|
|
|
typedef struct mock_saved_log_entry_t {
|
|
|
|
int severity;
|
|
|
|
const char *funcname;
|
|
|
|
const char *suffix;
|
|
|
|
const char *format;
|
|
|
|
char *generated_msg;
|
|
|
|
} mock_saved_log_entry_t;
|
|
|
|
|
|
|
|
void mock_clean_saved_logs(void);
|
|
|
|
const smartlist_t *mock_saved_logs(void);
|
2016-09-08 21:01:32 +02:00
|
|
|
void setup_capture_of_logs(int new_level);
|
|
|
|
void setup_full_capture_of_logs(int new_level);
|
|
|
|
void teardown_capture_of_logs(void);
|
2016-02-11 18:45:51 +01:00
|
|
|
|
2016-01-29 17:38:54 +01:00
|
|
|
int mock_saved_log_has_message(const char *msg);
|
2016-08-31 17:35:12 +02:00
|
|
|
int mock_saved_log_has_message_containing(const char *msg);
|
2016-02-01 00:02:04 +01:00
|
|
|
int mock_saved_log_has_severity(int severity);
|
|
|
|
int mock_saved_log_has_entry(void);
|
2016-09-08 20:39:20 +02:00
|
|
|
int mock_saved_log_n_entries(void);
|
2016-09-08 16:33:01 +02:00
|
|
|
void mock_dump_saved_logs(void);
|
2016-02-01 00:02:04 +01:00
|
|
|
|
2016-09-08 16:33:01 +02:00
|
|
|
#define assert_log_predicate(predicate, failure_msg) \
|
|
|
|
do { \
|
|
|
|
if (!(predicate)) { \
|
|
|
|
tt_fail_msg((failure_msg)); \
|
|
|
|
mock_dump_saved_logs(); \
|
|
|
|
TT_EXIT_TEST_FUNCTION; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define expect_log_msg(str) \
|
|
|
|
assert_log_predicate(mock_saved_log_has_message(str), \
|
2016-02-01 00:02:04 +01:00
|
|
|
"expected log to contain " # str);
|
|
|
|
|
2016-08-31 18:51:22 +02:00
|
|
|
#define expect_log_msg_containing(str) \
|
2016-09-08 16:33:01 +02:00
|
|
|
assert_log_predicate(mock_saved_log_has_message_containing(str), \
|
2016-08-31 18:51:22 +02:00
|
|
|
"expected log to contain " # str);
|
|
|
|
|
2016-09-08 17:47:16 +02:00
|
|
|
#define expect_log_msg_containing_either(str1, str2) \
|
|
|
|
assert_log_predicate(mock_saved_log_has_message_containing(str1) || \
|
|
|
|
mock_saved_log_has_message_containing(str2), \
|
2016-11-16 03:03:20 +01:00
|
|
|
"expected log to contain " # str1 " or " # str2);
|
2016-11-16 02:33:31 +01:00
|
|
|
|
2016-11-16 03:03:20 +01:00
|
|
|
#define expect_log_msg_containing_either3(str1, str2, str3) \
|
|
|
|
assert_log_predicate(mock_saved_log_has_message_containing(str1) || \
|
|
|
|
mock_saved_log_has_message_containing(str2) || \
|
|
|
|
mock_saved_log_has_message_containing(str3), \
|
|
|
|
"expected log to contain " # str1 " or " # str2 \
|
|
|
|
" or " # str3);
|
2016-11-16 02:33:31 +01:00
|
|
|
|
2016-11-16 03:03:20 +01:00
|
|
|
#define expect_log_msg_containing_either4(str1, str2, str3, str4) \
|
|
|
|
assert_log_predicate(mock_saved_log_has_message_containing(str1) || \
|
|
|
|
mock_saved_log_has_message_containing(str2) || \
|
|
|
|
mock_saved_log_has_message_containing(str3) || \
|
|
|
|
mock_saved_log_has_message_containing(str4), \
|
|
|
|
"expected log to contain " # str1 " or " # str2 \
|
|
|
|
" or " # str3 " or " # str4);
|
2016-11-16 02:33:31 +01:00
|
|
|
|
2016-09-08 20:39:20 +02:00
|
|
|
#define expect_single_log_msg(str) \
|
|
|
|
do { \
|
|
|
|
\
|
|
|
|
assert_log_predicate(mock_saved_log_has_message_containing(str) && \
|
|
|
|
mock_saved_log_n_entries() == 1, \
|
2017-02-19 13:09:50 +01:00
|
|
|
"expected log to contain exactly 1 message " # str); \
|
2016-09-08 20:39:20 +02:00
|
|
|
} while (0);
|
|
|
|
|
2016-08-31 20:30:34 +02:00
|
|
|
#define expect_single_log_msg_containing(str) \
|
2016-09-08 20:39:20 +02:00
|
|
|
do { \
|
|
|
|
assert_log_predicate(mock_saved_log_has_message_containing(str)&& \
|
|
|
|
mock_saved_log_n_entries() == 1 , \
|
2017-02-19 13:09:50 +01:00
|
|
|
"expected log to contain 1 message, containing " # str); \
|
2016-08-31 20:30:34 +02:00
|
|
|
} while (0);
|
|
|
|
|
2016-02-01 00:02:04 +01:00
|
|
|
#define expect_no_log_msg(str) \
|
2016-09-08 16:33:01 +02:00
|
|
|
assert_log_predicate(!mock_saved_log_has_message(str), \
|
2016-02-01 00:02:04 +01:00
|
|
|
"expected log to not contain " # str);
|
|
|
|
|
2018-05-04 04:49:19 +02:00
|
|
|
#define expect_no_log_msg_containing(str) \
|
|
|
|
assert_log_predicate(!mock_saved_log_has_message_containing(str), \
|
|
|
|
"expected log to not contain " # str);
|
|
|
|
|
2016-02-01 00:02:04 +01:00
|
|
|
#define expect_log_severity(severity) \
|
2016-09-08 16:33:01 +02:00
|
|
|
assert_log_predicate(mock_saved_log_has_severity(severity), \
|
2016-02-01 00:02:04 +01:00
|
|
|
"expected log to contain severity " # severity);
|
|
|
|
|
|
|
|
#define expect_no_log_severity(severity) \
|
2016-09-08 16:33:01 +02:00
|
|
|
assert_log_predicate(!mock_saved_log_has_severity(severity), \
|
2016-02-01 00:02:04 +01:00
|
|
|
"expected log to not contain severity " # severity);
|
|
|
|
|
|
|
|
#define expect_log_entry() \
|
2016-09-08 16:33:01 +02:00
|
|
|
assert_log_predicate(mock_saved_log_has_entry(), \
|
2016-02-01 00:02:04 +01:00
|
|
|
"expected log to contain entries");
|
|
|
|
|
|
|
|
#define expect_no_log_entry() \
|
2016-09-08 16:33:01 +02:00
|
|
|
assert_log_predicate(!mock_saved_log_has_entry(), \
|
2016-02-01 00:02:04 +01:00
|
|
|
"expected log to not contain entries");
|
2015-09-15 17:20:44 +02:00
|
|
|
|
2017-09-15 22:24:44 +02:00
|
|
|
#endif /* !defined(TOR_LOG_TEST_HELPERS_H) */
|
2016-01-15 16:57:03 +01:00
|
|
|
|