mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-03 01:17:45 +03:00
test-time-util: fix truncation of usec to sec
Also
- use ASSERT_XYZ() macros,
- log tzname[] on failure.
(cherry picked from commit 3f1d499964abb6a4c0141d7ea8f852829880adff)
(cherry picked from commit 11d70500171ca6dbbad8ecf9b1cf0d29e1d6d1ed)
(cherry picked from commit 1d4bde5a40a9a1d4dcb89b240a1b80c226866ade)
(cherry picked from commit b07b4cee88
)
This commit is contained in:
parent
33b0102ab3
commit
af8cb09f43
@ -393,7 +393,7 @@ TEST(format_timestamp) {
|
||||
static void test_format_timestamp_impl(usec_t x) {
|
||||
bool success, override;
|
||||
const char *xx, *yy;
|
||||
usec_t y;
|
||||
usec_t y, x_sec, y_sec;
|
||||
|
||||
xx = FORMAT_TIMESTAMP(x);
|
||||
assert_se(xx);
|
||||
@ -401,19 +401,23 @@ static void test_format_timestamp_impl(usec_t x) {
|
||||
yy = FORMAT_TIMESTAMP(y);
|
||||
assert_se(yy);
|
||||
|
||||
success = (x / USEC_PER_SEC == y / USEC_PER_SEC) && streq(xx, yy);
|
||||
x_sec = x / USEC_PER_SEC;
|
||||
y_sec = y / USEC_PER_SEC;
|
||||
success = (x_sec == y_sec) && streq(xx, yy);
|
||||
/* Workaround for https://github.com/systemd/systemd/issues/28472
|
||||
* and https://github.com/systemd/systemd/pull/35471. */
|
||||
override = !success &&
|
||||
(STRPTR_IN_SET(tzname[0], "CAT", "EAT", "WET") ||
|
||||
STRPTR_IN_SET(tzname[1], "CAT", "EAT", "WET")) &&
|
||||
DIV_ROUND_UP(x > y ? x - y : y - x, USEC_PER_SEC) == 3600; /* 1 hour, ignore fractional second */
|
||||
(x_sec > y_sec ? x_sec - y_sec : y_sec - x_sec) == 3600; /* 1 hour, ignore fractional second */
|
||||
log_full(success ? LOG_DEBUG : override ? LOG_WARNING : LOG_ERR,
|
||||
"@" USEC_FMT " → %s → @" USEC_FMT " → %s%s",
|
||||
x, xx, y, yy,
|
||||
override ? ", ignoring." : "");
|
||||
if (!override) {
|
||||
assert_se(x / USEC_PER_SEC == y / USEC_PER_SEC);
|
||||
if (!success)
|
||||
log_warning("tzname[0]=\"%s\", tzname[1]=\"%s\"", tzname[0], tzname[1]);
|
||||
assert_se(x_sec == y_sec);
|
||||
assert_se(streq(xx, yy));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user