From ff6db56a0131d039aab10ce27859f6972f06f447 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 2 Feb 2023 04:36:29 +0900 Subject: [PATCH] test-time-util: skip test for TIMESTAMP_DATE if the timestamp is too old Follow-up for 64f3419ec1f56a93b6dd48137ca40c945fc06c59. If the input timestamp is too old (say, 1min since 1970-01-01), then parse_timestamp() may fail on a timezone with positive shift e.g. JST (UTC+9). Moreover, even if parse_timestamp() succeeds, its result 'y' and 'usec_sub_unsigned(x, 2 * USEC_PER_DAY)' are both zero, and the assertion will be triggered. Fixes #26172. --- src/test/test-time-util.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/test/test-time-util.c b/src/test/test-time-util.c index 33d5b897290..0fb76391fd1 100644 --- a/src/test/test-time-util.c +++ b/src/test/test-time-util.c @@ -365,10 +365,12 @@ TEST(format_timestamp) { assert_se(parse_timestamp(buf, &y) >= 0); assert_se(x == y); - assert_se(format_timestamp_style(buf, sizeof(buf), x, TIMESTAMP_DATE)); - log_debug("%s", buf); - assert_se(parse_timestamp(buf, &y) >= 0); - assert_se(y > usec_sub_unsigned(x, 2 * USEC_PER_DAY) && y < usec_add(x, 2* USEC_PER_DAY)); + if (x > 2 * USEC_PER_DAY) { + assert_se(format_timestamp_style(buf, sizeof(buf), x, TIMESTAMP_DATE)); + log_debug("%s", buf); + assert_se(parse_timestamp(buf, &y) >= 0); + assert_se(y > usec_sub_unsigned(x, 2 * USEC_PER_DAY) && y < usec_add(x, 2 * USEC_PER_DAY)); + } assert_se(format_timestamp_relative(buf, sizeof(buf), x)); log_debug("%s", buf); -- 2.47.3