summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-03-03 19:40:40 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-03-03 19:45:32 +0900
commit0b20d70d1c7c190fb943dd4d1f28e6f456d2193e (patch)
tree7376f3f32ca7fa8da1b4a05c6cbaeed34dcb1e4c /src
parent11875a98e4f1c31e247d99e00c7774ea3653bafd (diff)
downloadsystemd-0b20d70d1c7c190fb943dd4d1f28e6f456d2193e.tar.gz
test: use get_timezones() to iterate all known timezones
Diffstat (limited to 'src')
-rw-r--r--src/test/test-time-util.c50
1 files changed, 11 insertions, 39 deletions
diff --git a/src/test/test-time-util.c b/src/test/test-time-util.c
index d6fbb8582f..cd4d635dfa 100644
--- a/src/test/test-time-util.c
+++ b/src/test/test-time-util.c
@@ -1,6 +1,5 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
-#include "dirent-util.h"
#include "env-util.h"
#include "fd-util.h"
#include "fileio.h"
@@ -421,23 +420,18 @@ TEST(FORMAT_TIMESTAMP) {
test_format_timestamp_loop();
}
-static void test_format_timestamp_with_tz_one(const char *name1, const char *name2) {
- _cleanup_free_ char *buf = NULL, *tz = NULL;
- const char *name, *saved_tz;
+static void test_format_timestamp_with_tz_one(const char *tz) {
+ const char *saved_tz, *colon_tz;
- if (name2)
- assert_se(buf = path_join(name1, name2));
- name = buf ?: name1;
-
- if (!timezone_is_valid(name, LOG_DEBUG))
+ if (!timezone_is_valid(tz, LOG_DEBUG))
return;
- log_info("/* %s(%s) */", __func__, name);
+ log_info("/* %s(%s) */", __func__, tz);
saved_tz = getenv("TZ");
- assert_se(tz = strjoin(":", name));
- assert_se(setenv("TZ", tz, 1) >= 0);
+ assert_se(colon_tz = strjoina(":", tz));
+ assert_se(setenv("TZ", colon_tz, 1) >= 0);
tzset();
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) {
- if (!slow_tests_enabled())
- return (void) log_tests_skipped("slow tests are disabled");
-
- _cleanup_closedir_ DIR *dir = opendir("/usr/share/zoneinfo");
- if (!dir)
- return (void) log_tests_skipped_errno(errno, "Failed to open /usr/share/zoneinfo");
-
- 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);
- }
- }
+ _cleanup_strv_free_ char **timezones = NULL;
+
+ assert_se(get_timezones(&timezones) >= 0);
+ STRV_FOREACH(tz, timezones)
+ test_format_timestamp_with_tz_one(*tz);
}
TEST(format_timestamp_relative_full) {