systemd/1242-test-time-util-do-not-fail-on-DST-change.patch
Jan Macku 2169d2c18c systemd-252-57
Resolves: RHEL-108555,RHEL-108568,RHEL-108576,RHEL-108584,RHEL-108596,RHEL-108598,RHEL-109096,RHEL-109488,RHEL-111065,RHEL-31756,RHEL-50103
2025-09-16 08:59:46 +02:00

73 lines
3.2 KiB
Diff

From c1e4badeadf75e75b6059a6d644d28414013c102 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Mon, 13 Mar 2023 03:47:45 +0900
Subject: [PATCH] test-time-util: do not fail on DST change
(cherry picked from commit cfacd245e798282fcb9b3231bd6e857abfe124fc)
Related: RHEL-109488
---
src/test/test-time-util.c | 37 ++++++++++++++++++++++++++++++-------
1 file changed, 30 insertions(+), 7 deletions(-)
diff --git a/src/test/test-time-util.c b/src/test/test-time-util.c
index eb8cc538c0..775e6bb84a 100644
--- a/src/test/test-time-util.c
+++ b/src/test/test-time-util.c
@@ -543,12 +543,30 @@ static void test_parse_timestamp_one(const char *str, usec_t max_diff, usec_t ex
int r;
r = parse_timestamp(str, &usec);
- log_debug("/* %s(%s): max_diff="USEC_FMT", expected="USEC_FMT", result="USEC_FMT"*/", __func__, str, max_diff, expected, usec);
+ log_debug("/* %s(%s): max_diff="USEC_FMT", expected="USEC_FMT", result="USEC_FMT" */", __func__, str, max_diff, expected, usec);
assert_se(r >= 0);
assert_se(usec >= expected);
assert_se(usec_sub_unsigned(usec, expected) <= max_diff);
}
+static bool time_is_zero(usec_t usec) {
+ const char *s;
+
+ s = FORMAT_TIMESTAMP(usec);
+ return strstr(s, " 00:00:00 ");
+}
+
+static bool timezone_equal(usec_t today, usec_t target) {
+ const char *s, *t, *sz, *tz;
+
+ s = FORMAT_TIMESTAMP(today);
+ t = FORMAT_TIMESTAMP(target);
+ assert_se(sz = strrchr(s, ' '));
+ assert_se(tz = strrchr(t, ' '));
+ log_debug("%s("USEC_FMT", "USEC_FMT") -> %s, %s", __func__, today, target, s, t);
+ return streq(sz, tz);
+}
+
static void test_parse_timestamp_impl(const char *tz) {
usec_t today, now_usec;
@@ -735,12 +753,17 @@ static void test_parse_timestamp_impl(const char *tz) {
/* without date */
assert_se(parse_timestamp("today", &today) == 0);
- test_parse_timestamp_one("00:01", 0, today + USEC_PER_MINUTE);
- test_parse_timestamp_one("00:00:01", 0, today + USEC_PER_SEC);
- test_parse_timestamp_one("00:00:01.001", 0, today + USEC_PER_SEC + 1000);
- test_parse_timestamp_one("00:00:01.0010", 0, today + USEC_PER_SEC + 1000);
- test_parse_timestamp_one("tomorrow", 0, today + USEC_PER_DAY);
- test_parse_timestamp_one("yesterday", 0, today - USEC_PER_DAY);
+ if (time_is_zero(today)) {
+ test_parse_timestamp_one("00:01", 0, today + USEC_PER_MINUTE);
+ test_parse_timestamp_one("00:00:01", 0, today + USEC_PER_SEC);
+ test_parse_timestamp_one("00:00:01.001", 0, today + USEC_PER_SEC + 1000);
+ test_parse_timestamp_one("00:00:01.0010", 0, today + USEC_PER_SEC + 1000);
+
+ if (timezone_equal(today, today + USEC_PER_DAY) && time_is_zero(today + USEC_PER_DAY))
+ test_parse_timestamp_one("tomorrow", 0, today + USEC_PER_DAY);
+ if (timezone_equal(today, today - USEC_PER_DAY) && time_is_zero(today - USEC_PER_DAY))
+ test_parse_timestamp_one("yesterday", 0, today - USEC_PER_DAY);
+ }
/* relative */
assert_se(parse_timestamp("now", &now_usec) == 0);