| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "networkd-address.h" |
| 4 |
#include "tests.h" |
| 5 |
#include "time-util.h" |
| 6 |
|
| 7 |
static void test_FORMAT_LIFETIME_one(usec_t lifetime, const char *expected) { |
| 8 |
const char *t = FORMAT_LIFETIME(lifetime); |
| 9 |
|
| 10 |
log_debug(USEC_FMT " → \"%s\" (expected \"%s\")", lifetime, t, strna(expected)); |
| 11 |
if (expected) |
| 12 |
ASSERT_STREQ(t, expected); |
| 13 |
} |
| 14 |
|
| 15 |
TEST(FORMAT_LIFETIME) { |
| 16 |
usec_t now_usec; |
| 17 |
|
| 18 |
now_usec = now(CLOCK_BOOTTIME); |
| 19 |
|
| 20 |
test_FORMAT_LIFETIME_one(now_usec, "for 0"); |
| 21 |
test_FORMAT_LIFETIME_one(USEC_INFINITY, "forever"); |
| 22 |
|
| 23 |
/* These two are necessarily racy, especially for slow test environment. */ |
| 24 |
test_FORMAT_LIFETIME_one(usec_add(now_usec, 2 * USEC_PER_SEC - 1), NULL); |
| 25 |
test_FORMAT_LIFETIME_one(usec_add(now_usec, 3 * USEC_PER_WEEK + USEC_PER_SEC - 1), NULL); |
| 26 |
} |
| 27 |
|
| 28 |
DEFINE_TEST_MAIN(LOG_DEBUG); |