1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-29 21:55:36 +03:00

test: use get_timezones() to iterate all known timezones

This commit is contained in:
Yu Watanabe 2023-03-03 19:40:40 +09:00
parent 11875a98e4
commit 0b20d70d1c

View File

@ -1,6 +1,5 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "dirent-util.h"
#include "env-util.h" #include "env-util.h"
#include "fd-util.h" #include "fd-util.h"
#include "fileio.h" #include "fileio.h"
@ -421,23 +420,18 @@ TEST(FORMAT_TIMESTAMP) {
test_format_timestamp_loop(); test_format_timestamp_loop();
} }
static void test_format_timestamp_with_tz_one(const char *name1, const char *name2) { static void test_format_timestamp_with_tz_one(const char *tz) {
_cleanup_free_ char *buf = NULL, *tz = NULL; const char *saved_tz, *colon_tz;
const char *name, *saved_tz;
if (name2) if (!timezone_is_valid(tz, LOG_DEBUG))
assert_se(buf = path_join(name1, name2));
name = buf ?: name1;
if (!timezone_is_valid(name, LOG_DEBUG))
return; return;
log_info("/* %s(%s) */", __func__, name); log_info("/* %s(%s) */", __func__, tz);
saved_tz = getenv("TZ"); saved_tz = getenv("TZ");
assert_se(tz = strjoin(":", name)); assert_se(colon_tz = strjoina(":", tz));
assert_se(setenv("TZ", tz, 1) >= 0); assert_se(setenv("TZ", colon_tz, 1) >= 0);
tzset(); tzset();
log_debug("%s: tzname[0]=%s, tzname[1]=%s", tz, strempty(tzname[0]), strempty(tzname[1])); log_debug("%s: tzname[0]=%s, tzname[1]=%s", tz, strempty(tzname[0]), strempty(tzname[1]));
@ -448,33 +442,11 @@ static void test_format_timestamp_with_tz_one(const char *name1, const char *nam
} }
TEST(FORMAT_TIMESTAMP_with_tz) { TEST(FORMAT_TIMESTAMP_with_tz) {
if (!slow_tests_enabled()) _cleanup_strv_free_ char **timezones = NULL;
return (void) log_tests_skipped("slow tests are disabled");
_cleanup_closedir_ DIR *dir = opendir("/usr/share/zoneinfo"); assert_se(get_timezones(&timezones) >= 0);
if (!dir) STRV_FOREACH(tz, timezones)
return (void) log_tests_skipped_errno(errno, "Failed to open /usr/share/zoneinfo"); test_format_timestamp_with_tz_one(*tz);
FOREACH_DIRENT(de, dir, break) {
if (de->d_type == DT_REG)
test_format_timestamp_with_tz_one(de->d_name, NULL);
else if (de->d_type == DT_DIR) {
if (streq(de->d_name, "right"))
/* The test does not support timezone with leap second info. */
continue;
_cleanup_closedir_ DIR *subdir = xopendirat(dirfd(dir), de->d_name, 0);
if (!subdir) {
log_notice_errno(errno, "Failed to open /usr/share/zoneinfo/%s, ignoring: %m", de->d_name);
continue;
}
FOREACH_DIRENT(subde, subdir, break)
if (subde->d_type == DT_REG)
test_format_timestamp_with_tz_one(de->d_name, subde->d_name);
}
}
} }
TEST(format_timestamp_relative_full) { TEST(format_timestamp_relative_full) {