commit ac8c5ec67a8b2f36f1c76777c640fc4299f42307 Author: Nick Mathewson nickm@torproject.org Date: Fri Oct 2 13:13:58 2015 +0200
Clean up compat_libevent tests --- changes/17075 | 3 ++ changes/17084 | 3 ++ src/common/compat_libevent.c | 1 + src/common/compat_libevent.h | 3 +- src/test/log_test_helpers.c | 5 ++- src/test/log_test_helpers.h | 1 + src/test/test.c | 1 + src/test/test_compat_libevent.c | 68 ++++++++++++++++++++++++++------------- 8 files changed, 60 insertions(+), 25 deletions(-)
diff --git a/changes/17075 b/changes/17075 new file mode 100644 index 0000000..a91ac67 --- /dev/null +++ b/changes/17075 @@ -0,0 +1,3 @@ + o Testing: + - More unit tests for compat_libevent.c. Closes ticket 17075. + Patch from Ola Bini. diff --git a/changes/17084 b/changes/17084 new file mode 100644 index 0000000..361e26f --- /dev/null +++ b/changes/17084 @@ -0,0 +1,3 @@ + o Testing: + - More unit tests for util_format.c. Closes ticket 17084. + Patch from Ola Bini. diff --git a/src/common/compat_libevent.c b/src/common/compat_libevent.c index 6cae41b..29e5c5f 100644 --- a/src/common/compat_libevent.c +++ b/src/common/compat_libevent.c @@ -626,3 +626,4 @@ tor_gettimeofday_cached_monotonic(struct timeval *tv) memcpy(&last_tv, tv, sizeof(struct timeval)); } } + diff --git a/src/common/compat_libevent.h b/src/common/compat_libevent.h index 9530ca9..8ee02c0 100644 --- a/src/common/compat_libevent.h +++ b/src/common/compat_libevent.h @@ -91,7 +91,6 @@ void tor_gettimeofday_cache_set(const struct timeval *tv); #endif void tor_gettimeofday_cached_monotonic(struct timeval *tv);
- #ifdef COMPAT_LIBEVENT_PRIVATE /** A number representing a version of Libevent.
@@ -121,7 +120,6 @@ typedef uint32_t le_version_t; * it is. */ #define LE_OTHER V(0,0,99)
- STATIC void libevent_logging_callback(int severity, const char *msg); STATIC le_version_t @@ -131,3 +129,4 @@ le_versions_compatibility(le_version_t v); #endif
#endif + diff --git a/src/test/log_test_helpers.c b/src/test/log_test_helpers.c index 925f0f1..51b5f9b 100644 --- a/src/test/log_test_helpers.c +++ b/src/test/log_test_helpers.c @@ -1,3 +1,5 @@ +/* Copyright (c) 2015, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ #define LOG_PRIVATE #include "torlog.h" #include "log_test_helpers.h" @@ -37,7 +39,7 @@ static mock_saved_log_entry_t * mock_get_log_entry(int ix) { int saved_log_count = mock_saved_log_number(); - if(ix < 0) { + if (ix < 0) { ix = saved_log_count + ix; }
@@ -106,3 +108,4 @@ mock_saving_logv(int severity, log_domain_mask_t domain, saved_logs = smartlist_new(); smartlist_add(saved_logs, e); } + diff --git a/src/test/log_test_helpers.h b/src/test/log_test_helpers.h index 4822ce5..af8e8a6 100644 --- a/src/test/log_test_helpers.h +++ b/src/test/log_test_helpers.h @@ -28,3 +28,4 @@ int mock_saved_severity_at(int ix); int mock_saved_log_number(void);
#endif + diff --git a/src/test/test.c b/src/test/test.c index 8427471..4cb33c9 100644 --- a/src/test/test.c +++ b/src/test/test.c @@ -1212,3 +1212,4 @@ struct testgroup_t testgroups[] = { { "dns/", dns_tests }, END_OF_GROUPS }; + diff --git a/src/test/test_compat_libevent.c b/src/test/test_compat_libevent.c index 7e5b7df..96502df 100644 --- a/src/test/test_compat_libevent.c +++ b/src/test/test_compat_libevent.c @@ -31,47 +31,67 @@ test_compat_libevent_logging_callback(void *ignored)
libevent_logging_callback(_EVENT_LOG_DEBUG, "hello world"); tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_str_op(mock_saved_log_at(0), OP_EQ, "Message from libevent: hello world\n"); + tt_str_op(mock_saved_log_at(0), OP_EQ, + "Message from libevent: hello world\n"); tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_DEBUG);
mock_clean_saved_logs(); libevent_logging_callback(_EVENT_LOG_MSG, "hello world another time"); tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_str_op(mock_saved_log_at(0), OP_EQ, "Message from libevent: hello world another time\n"); + tt_str_op(mock_saved_log_at(0), OP_EQ, + "Message from libevent: hello world another time\n"); tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_INFO);
mock_clean_saved_logs(); libevent_logging_callback(_EVENT_LOG_WARN, "hello world a third time"); tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_str_op(mock_saved_log_at(0), OP_EQ, "Warning from libevent: hello world a third time\n"); + tt_str_op(mock_saved_log_at(0), OP_EQ, + "Warning from libevent: hello world a third time\n"); tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_WARN);
mock_clean_saved_logs(); libevent_logging_callback(_EVENT_LOG_ERR, "hello world a fourth time"); tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_str_op(mock_saved_log_at(0), OP_EQ, "Error from libevent: hello world a fourth time\n"); + tt_str_op(mock_saved_log_at(0), OP_EQ, + "Error from libevent: hello world a fourth time\n"); tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_ERR);
mock_clean_saved_logs(); libevent_logging_callback(42, "hello world a fifth time"); tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_str_op(mock_saved_log_at(0), OP_EQ, "Message [42] from libevent: hello world a fifth time\n"); + tt_str_op(mock_saved_log_at(0), OP_EQ, + "Message [42] from libevent: hello world a fifth time\n"); tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_WARN);
mock_clean_saved_logs(); - libevent_logging_callback(_EVENT_LOG_DEBUG, "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" - "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" - "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" - "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" - "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" - "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" - "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" - "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" - "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" - "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" - "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"); + libevent_logging_callback(_EVENT_LOG_DEBUG, + "012345678901234567890123456789" + "012345678901234567890123456789" + "012345678901234567890123456789" + "012345678901234567890123456789" + "012345678901234567890123456789" + "012345678901234567890123456789" + "012345678901234567890123456789" + "012345678901234567890123456789" + "012345678901234567890123456789" + "012345678901234567890123456789" + "012345678901234567890123456789" + "012345678901234567890123456789" + ); tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_str_op(mock_saved_log_at(0), OP_EQ, "Message from libevent: 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901 2345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012\n"); + tt_str_op(mock_saved_log_at(0), OP_EQ, "Message from libevent: " + "012345678901234567890123456789" + "012345678901234567890123456789" + "012345678901234567890123456789" + "012345678901234567890123456789" + "012345678901234567890123456789" + "012345678901234567890123456789" + "012345678901234567890123456789" + "012345678901234567890123456789" + "012345678901234567890123456789" + "012345678901234567890123456789" + "012345678901234567890123456789" + "012345678901234567890123456789\n"); tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_DEBUG);
mock_clean_saved_logs(); @@ -84,7 +104,8 @@ test_compat_libevent_logging_callback(void *ignored) mock_clean_saved_logs(); libevent_logging_callback(_EVENT_LOG_MSG, "hello there"); tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_str_op(mock_saved_log_at(0), OP_EQ, "Message from libevent: hello there\n"); + tt_str_op(mock_saved_log_at(0), OP_EQ, + "Message from libevent: hello there\n"); tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_INFO);
mock_clean_saved_logs(); @@ -204,11 +225,14 @@ test_compat_libevent_header_version(void *ignored) (void)0; }
- struct testcase_t compat_libevent_tests[] = { - { "logging_callback", test_compat_libevent_logging_callback, TT_FORK, NULL, NULL }, - { "le_versions_compatibility", test_compat_libevent_le_versions_compatibility, 0, NULL, NULL }, - { "tor_decode_libevent_version", test_compat_libevent_tor_decode_libevent_version, 0, NULL, NULL }, + { "logging_callback", test_compat_libevent_logging_callback, + TT_FORK, NULL, NULL }, + { "le_versions_compatibility", + test_compat_libevent_le_versions_compatibility, 0, NULL, NULL }, + { "tor_decode_libevent_version", + test_compat_libevent_tor_decode_libevent_version, 0, NULL, NULL }, { "header_version", test_compat_libevent_header_version, 0, NULL, NULL }, END_OF_TESTCASES }; +