From f684cd800577144a48e112951eaf4ddc602ad26a Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 16 Jan 2019 15:47:33 -0500 Subject: Fail any unit test that causes an unhandled LD_BUG or LOG_ERR Closes ticket 28668. --- src/test/testing_common.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/test') diff --git a/src/test/testing_common.c b/src/test/testing_common.c index 60015f3c24..62d40a42fa 100644 --- a/src/test/testing_common.c +++ b/src/test/testing_common.c @@ -239,6 +239,15 @@ tinytest_postfork(void) init_pregenerated_keys(); } +static void +log_callback_failure(int severity, uint32_t domain, const char *msg) +{ + (void)msg; + if (severity == LOG_ERR || (domain & LD_BUG)) { + tinytest_set_test_failed_(); + } +} + /** Main entry point for unit test code: parse the command line, and run * some unit tests. */ int @@ -287,6 +296,7 @@ main(int c, const char **v) c = i_out; { + /* setup logs to stdout */ log_severity_list_t s; memset(&s, 0, sizeof(s)); set_log_severity_config(loglevel, LOG_ERR, &s); @@ -294,6 +304,14 @@ main(int c, const char **v) s.masks[LOG_WARN-LOG_ERR] |= LD_BUG; add_stream_log(&s, "", fileno(stdout)); } + { + /* Setup logs that cause failure. */ + log_severity_list_t s; + memset(&s, 0, sizeof(s)); + set_log_severity_config(LOG_ERR, LOG_ERR, &s); + s.masks[LOG_WARN-LOG_ERR] |= LD_BUG; + add_callback_log(&s, log_callback_failure); + } init_protocol_warning_severity_level(); options->command = CMD_RUN_UNITTESTS; -- cgit v1.2.3-54-g00ecf From 54c9c8b04f6055dc4101b6a36cfb587af78dc9b4 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 23 Jan 2019 12:04:57 -0500 Subject: If address/get_if_addrs6 can't findipv6, log WARN, not ERR Fixes 29160, and allows 28668 (treating ERR logs as test failures) to procede. --- changes/ticket29160 | 4 ++++ src/test/test_address.c | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changes/ticket29160 (limited to 'src/test') diff --git a/changes/ticket29160 b/changes/ticket29160 new file mode 100644 index 0000000000..8e11183064 --- /dev/null +++ b/changes/ticket29160 @@ -0,0 +1,4 @@ + o Minor bugfixes (tests): + - Do not log an error-level message if we fail to find an IPv6 + network interface from the unit tests. Fixes bug 29160; bugfix on + 0.2.7.3-rc. diff --git a/src/test/test_address.c b/src/test/test_address.c index 43467aca13..cfb32b855f 100644 --- a/src/test/test_address.c +++ b/src/test/test_address.c @@ -1013,7 +1013,7 @@ test_address_get_if_addrs6(void *arg) (void)arg; - rv = get_interface_address6(LOG_ERR, AF_INET6, &tor_addr); + rv = get_interface_address6(LOG_WARN, AF_INET6, &tor_addr); /* Work even on systems without IPv6 interfaces */ if (rv == 0) { @@ -1204,4 +1204,3 @@ struct testcase_t address_tests[] = { ADDRESS_TEST(tor_addr_in_same_network_family, 0), END_OF_TESTCASES }; - -- cgit v1.2.3-54-g00ecf From 6144cf99adae5ffebbc549a4e0f3c6e05e51ad16 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 23 Jan 2019 12:37:12 -0500 Subject: Capture more BUG warnings in util/time test These are ones that happen on windows only. Fixes bug 29161. --- changes/bug29161 | 3 +++ src/lib/encoding/time_fmt.c | 4 ++++ src/test/test_util.c | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 changes/bug29161 (limited to 'src/test') diff --git a/changes/bug29161 b/changes/bug29161 new file mode 100644 index 0000000000..39a638acf6 --- /dev/null +++ b/changes/bug29161 @@ -0,0 +1,3 @@ + o Minor bugfixes (tests): + - Detect and suppress "bug" warnings from the util/time test on Windows. + Fixes bug 29161; bugfix on 0.2.9.3-alpha. diff --git a/src/lib/encoding/time_fmt.c b/src/lib/encoding/time_fmt.c index 5b2440d1ab..40543d41e0 100644 --- a/src/lib/encoding/time_fmt.c +++ b/src/lib/encoding/time_fmt.c @@ -39,6 +39,8 @@ * * Convert *timep to a struct tm in local time, and store the value in * *result. Return the result on success, or NULL on failure. + * + * Treat malformatted inputs localtime outputs as a BUG. */ struct tm * tor_localtime_r(const time_t *timep, struct tm *result) @@ -56,6 +58,8 @@ tor_localtime_r(const time_t *timep, struct tm *result) * * Convert *timep to a struct tm in UTC, and store the value in * *result. Return the result on success, or NULL on failure. + * + * Treat malformatted inputs or gmtime outputs as a BUG. */ struct tm * tor_gmtime_r(const time_t *timep, struct tm *result) diff --git a/src/test/test_util.c b/src/test/test_util.c index 089c1f1d7e..6a7b42b788 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -690,6 +690,12 @@ test_util_time(void *arg) expect_single_log_msg_containing(msg); \ teardown_capture_of_logs(); \ } while (0) +#define CHECK_POSSIBLE_EINVAL() do { \ + if (mock_saved_log_n_entries()) { \ + expect_single_log_msg_containing("Invalid argument"); \ + } \ + teardown_capture_of_logs(); \ + } while (0) #define CHECK_TIMEGM_ARG_OUT_OF_RANGE(msg) \ CHECK_TIMEGM_WARNING("Out-of-range argument to tor_timegm") @@ -885,12 +891,16 @@ test_util_time(void *arg) if (sizeof(time_t) == 4 || sizeof(time_t) == 8) { t_res = -1*(1 << 30); + CAPTURE(); tor_gmtime_r(&t_res, &b_time); + CHECK_POSSIBLE_EINVAL(); tt_assert(b_time.tm_year == (1970-1900) || b_time.tm_year == (1935-1900)); t_res = INT32_MIN; + CAPTURE(); tor_gmtime_r(&t_res, &b_time); + CHECK_POSSIBLE_EINVAL(); tt_assert(b_time.tm_year == (1970-1900) || b_time.tm_year == (1901-1900)); } @@ -900,7 +910,9 @@ test_util_time(void *arg) /* one of the smallest tm_year values my 64 bit system supports: * b_time.tm_year == (-292275055LL-1900LL) without clamping */ t_res = -9223372036854775LL; + CAPTURE(); tor_gmtime_r(&t_res, &b_time); + CHECK_POSSIBLE_EINVAL(); tt_assert(b_time.tm_year == (1970-1900) || b_time.tm_year == (1-1900)); @@ -926,7 +938,9 @@ test_util_time(void *arg) { /* As above, but with localtime. */ t_res = -9223372036854775LL; + CAPTURE(); tor_localtime_r(&t_res, &b_time); + CHECK_POSSIBLE_EINVAL(); tt_assert(b_time.tm_year == (1970-1900) || b_time.tm_year == (1-1900)); @@ -983,7 +997,9 @@ test_util_time(void *arg) /* one of the largest tm_year values my 64 bit system supports: * b_time.tm_year == (292278994L-1900L) without clamping */ t_res = 9223372036854775LL; + CAPTURE(); tor_gmtime_r(&t_res, &b_time); + CHECK_POSSIBLE_EINVAL(); tt_assert(b_time.tm_year == (2037-1900) || b_time.tm_year == (9999-1900)); @@ -1004,7 +1020,9 @@ test_util_time(void *arg) { /* As above but with localtime. */ t_res = 9223372036854775LL; + CAPTURE(); tor_localtime_r(&t_res, &b_time); + CHECK_POSSIBLE_EINVAL(); tt_assert(b_time.tm_year == (2037-1900) || b_time.tm_year == (9999-1900)); @@ -1216,7 +1234,9 @@ test_util_time(void *arg) /* This value is out of range with 32 bit time_t, but in range for 64 bit * time_t */ tv.tv_sec = (time_t)2150000000UL; + CAPTURE(); format_iso_time(timestr, (time_t)tv.tv_sec); + CHECK_POSSIBLE_EINVAL(); #if SIZEOF_TIME_T == 4 /* format_iso_time should indicate failure on overflow, but it doesn't yet. * Hopefully #18480 will improve the failure semantics in this case. @@ -1231,6 +1251,7 @@ test_util_time(void *arg) #undef CAPTURE #undef CHECK_TIMEGM_ARG_OUT_OF_RANGE +#undef CHECK_POSSIBLE_EINVAL done: teardown_capture_of_logs(); -- cgit v1.2.3-54-g00ecf From 2d74da3d0efd7a67f9bdb73145c38fe047faf1f8 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Thu, 29 Nov 2018 10:02:50 -0500 Subject: test: Fix a warning underflow in rend_cache/clean Because the test is adding entries to the "rend_cache" directly, the rend_cache_increment_allocation() was never called which made the rend_cache_clean() call trigger that underflow warning: rend_cache/clean: [forking] Nov 29 09:55:04.024 [warn] rend_cache_decrement_allocation(): Bug: Underflow in rend_cache_decrement_allocation (on Tor 0.4.0.0-alpha-dev 2240fe63feb9a8cf) The test is still good and valid. Fixes #28660 Signed-off-by: David Goulet --- src/test/test_rendcache.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/test') diff --git a/src/test/test_rendcache.c b/src/test/test_rendcache.c index 7ec4771b6e..4f544cf21c 100644 --- a/src/test/test_rendcache.c +++ b/src/test/test_rendcache.c @@ -788,7 +788,9 @@ test_rend_cache_clean(void *data) desc_two->pk = pk_generate(1); strmap_set_lc(rend_cache, "foo1", one); + rend_cache_increment_allocation(rend_cache_entry_allocation(one)); strmap_set_lc(rend_cache, "foo2", two); + rend_cache_increment_allocation(rend_cache_entry_allocation(two)); rend_cache_clean(time(NULL), REND_CACHE_TYPE_CLIENT); tt_int_op(strmap_size(rend_cache), OP_EQ, 0); @@ -806,7 +808,9 @@ test_rend_cache_clean(void *data) desc_one->pk = pk_generate(0); desc_two->pk = pk_generate(1); + rend_cache_increment_allocation(rend_cache_entry_allocation(one)); strmap_set_lc(rend_cache, "foo1", one); + rend_cache_increment_allocation(rend_cache_entry_allocation(two)); strmap_set_lc(rend_cache, "foo2", two); rend_cache_clean(time(NULL), REND_CACHE_TYPE_CLIENT); -- cgit v1.2.3-54-g00ecf From d71ca3968213ea2ed6e30e7a1a5478db759a61e5 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 23 Jan 2019 17:07:39 -0500 Subject: Another case of possible gmtime angst. --- src/test/test_util.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/test') diff --git a/src/test/test_util.c b/src/test/test_util.c index 6a7b42b788..4701fadf1a 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -1065,7 +1065,10 @@ test_util_time(void *arg) /* This value is out of range with 32 bit time_t, but in range for 64 bit * time_t */ + CAPTURE(); format_rfc1123_time(timestr, (time_t)2150000000UL); + CHECK_POSSIBLE_EINVAL(); + #if SIZEOF_TIME_T == 4 #if 0 /* Wrapping around will have made it this. */ -- cgit v1.2.3-54-g00ecf