mirror of
https://github.com/Dasharo/systemd.git
synced 2026-03-06 15:02:31 -08:00
test-time-util: skip test for TIMESTAMP_DATE if the timestamp is too old
Follow-up for 64f3419ec1.
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:
committed by
Zbigniew Jędrzejewski-Szmek
parent
cf74e2e16f
commit
ff6db56a01
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user