]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-time-util: skip test for TIMESTAMP_DATE if the timestamp is too old
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 1 Feb 2023 19:36:29 +0000 (04:36 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 2 Feb 2023 09:59:59 +0000 (10:59 +0100)
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

index 33d5b89729041f84bdf6618fd2e226cd63c1a23c..0fb76391fd1f4dab870a0db2ca4b102d1489384c 100644 (file)
@@ -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);