1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-21 18:03:41 +03:00

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.
This commit is contained in:
Yu Watanabe 2023-02-02 04:36:29 +09:00 committed by Zbigniew Jędrzejewski-Szmek
parent cf74e2e16f
commit ff6db56a01

View 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);