From: Yu Watanabe Date: Wed, 1 Feb 2023 19:36:29 +0000 (+0900) Subject: test-time-util: skip test for TIMESTAMP_DATE if the timestamp is too old X-Git-Tag: v253-rc2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff6db56a0131d039aab10ce27859f6972f06f447;p=thirdparty%2Fsystemd.git 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. --- 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);