aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_util.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2019-01-23 14:50:22 -0500
committerNick Mathewson <nickm@torproject.org>2019-01-23 14:50:22 -0500
commitd23704bf26ae6c00e97fb0c3ceb4a362c49eaf07 (patch)
treec0b2fe52c2ace1790000b8b63a213d3bc13690f7 /src/test/test_util.c
parent3da3aca08f022f6c1e33a06afe4e30804754d005 (diff)
parent2d74da3d0efd7a67f9bdb73145c38fe047faf1f8 (diff)
downloadtor-d23704bf26ae6c00e97fb0c3ceb4a362c49eaf07.tar.gz
tor-d23704bf26ae6c00e97fb0c3ceb4a362c49eaf07.zip
Merge branch 'ticket28668_035' into ticket28668_040
Diffstat (limited to 'src/test/test_util.c')
-rw-r--r--src/test/test_util.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 4e95303f2e..1069c05700 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -712,6 +712,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")
@@ -907,12 +913,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));
}
@@ -922,7 +932,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));
@@ -948,7 +960,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));
@@ -1005,7 +1019,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));
@@ -1026,7 +1042,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));
@@ -1238,7 +1256,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.
@@ -1253,6 +1273,7 @@ test_util_time(void *arg)
#undef CAPTURE
#undef CHECK_TIMEGM_ARG_OUT_OF_RANGE
+#undef CHECK_POSSIBLE_EINVAL
done:
teardown_capture_of_logs();