From: Yu Watanabe Date: Fri, 17 Nov 2023 16:54:01 +0000 (+0900) Subject: test: always call test_setup_logging() X-Git-Tag: v255-rc3~42^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=965040d811a44c39c4f524b949ab1b9d2ee7dd5c;p=thirdparty%2Fsystemd.git test: always call test_setup_logging() --- diff --git a/src/coredump/test-coredump-vacuum.c b/src/coredump/test-coredump-vacuum.c index 840884d9612..27f83309509 100644 --- a/src/coredump/test-coredump-vacuum.c +++ b/src/coredump/test-coredump-vacuum.c @@ -3,8 +3,10 @@ #include #include "coredump-vacuum.h" +#include "tests.h" int main(int argc, char *argv[]) { + test_setup_logging(LOG_DEBUG); if (coredump_vacuum(-1, UINT64_MAX, 70 * 1024) < 0) return EXIT_FAILURE; diff --git a/src/import/test-qcow2.c b/src/import/test-qcow2.c index ca31fd678d3..88932071bc4 100644 --- a/src/import/test-qcow2.c +++ b/src/import/test-qcow2.c @@ -7,11 +7,14 @@ #include "fd-util.h" #include "log.h" #include "qcow2-util.h" +#include "tests.h" int main(int argc, char *argv[]) { _cleanup_close_ int sfd = -EBADF, dfd = -EBADF; int r; + test_setup_logging(LOG_DEBUG); + if (argc != 3) { log_error("Needs two arguments."); return EXIT_FAILURE; diff --git a/src/journal/test-journald-tables.c b/src/journal/test-journald-tables.c index 958beb84173..d726c3f3e3c 100644 --- a/src/journal/test-journald-tables.c +++ b/src/journal/test-journald-tables.c @@ -2,8 +2,11 @@ #include "journald-server.h" #include "test-tables.h" +#include "tests.h" int main(int argc, char **argv) { + test_setup_logging(LOG_DEBUG); + test_table(split_mode, SPLIT); test_table(storage, STORAGE); diff --git a/src/libsystemd-network/test-dhcp-option.c b/src/libsystemd-network/test-dhcp-option.c index 47d799348f9..bcd46e4720f 100644 --- a/src/libsystemd-network/test-dhcp-option.c +++ b/src/libsystemd-network/test-dhcp-option.c @@ -12,6 +12,7 @@ #include "ether-addr-util.h" #include "macro.h" #include "memory-util.h" +#include "tests.h" struct option_desc { uint8_t sname[64]; @@ -362,6 +363,8 @@ static void test_option_set(void) { } int main(int argc, char *argv[]) { + test_setup_logging(LOG_DEBUG); + test_invalid_buffer_length(); test_message_init(); diff --git a/src/libsystemd/sd-bus/test-bus-benchmark.c b/src/libsystemd/sd-bus/test-bus-benchmark.c index 74fa0ed746c..d988588de04 100644 --- a/src/libsystemd/sd-bus/test-bus-benchmark.c +++ b/src/libsystemd/sd-bus/test-bus-benchmark.c @@ -12,6 +12,7 @@ #include "fd-util.h" #include "missing_resource.h" #include "string-util.h" +#include "tests.h" #include "time-util.h" #define MAX_SIZE (2*1024*1024) @@ -221,6 +222,8 @@ int main(int argc, char *argv[]) { pid_t pid; int r; + test_setup_logging(LOG_DEBUG); + for (i = 1; i < argc; i++) { if (streq(argv[i], "chart")) { mode = MODE_CHART; diff --git a/src/libsystemd/sd-bus/test-bus-objects.c b/src/libsystemd/sd-bus/test-bus-objects.c index 0d4a6db1e3b..ccdd0d50b7c 100644 --- a/src/libsystemd/sd-bus/test-bus-objects.c +++ b/src/libsystemd/sd-bus/test-bus-objects.c @@ -12,6 +12,7 @@ #include "log.h" #include "macro.h" #include "strv.h" +#include "tests.h" struct context { int fds[2]; @@ -646,6 +647,8 @@ int main(int argc, char *argv[]) { void *p; int r, q; + test_setup_logging(LOG_DEBUG); + c.automatic_integer_property = 4711; assert_se(c.automatic_string_property = strdup("dudeldu")); diff --git a/src/libsystemd/sd-bus/test-bus-server.c b/src/libsystemd/sd-bus/test-bus-server.c index e3cb8f705bb..8049e332949 100644 --- a/src/libsystemd/sd-bus/test-bus-server.c +++ b/src/libsystemd/sd-bus/test-bus-server.c @@ -10,6 +10,7 @@ #include "macro.h" #include "memory-util.h" #include "string-util.h" +#include "tests.h" struct context { int fds[2]; @@ -157,6 +158,8 @@ static int test_one(bool client_negotiate_unix_fds, bool server_negotiate_unix_f int main(int argc, char *argv[]) { int r; + test_setup_logging(LOG_DEBUG); + r = test_one(true, true, false, false); assert_se(r >= 0); diff --git a/src/libsystemd/sd-bus/test-bus-signature.c b/src/libsystemd/sd-bus/test-bus-signature.c index ba94804869c..5a4c8118643 100644 --- a/src/libsystemd/sd-bus/test-bus-signature.c +++ b/src/libsystemd/sd-bus/test-bus-signature.c @@ -4,11 +4,14 @@ #include "bus-signature.h" #include "log.h" #include "string-util.h" +#include "tests.h" int main(int argc, char *argv[]) { char prefix[256]; int r; + test_setup_logging(LOG_DEBUG); + assert_se(signature_is_single("y", false)); assert_se(signature_is_single("u", false)); assert_se(signature_is_single("v", false)); diff --git a/src/libsystemd/sd-journal/test-mmap-cache.c b/src/libsystemd/sd-journal/test-mmap-cache.c index 73c0b99978c..ce5ea123c68 100644 --- a/src/libsystemd/sd-journal/test-mmap-cache.c +++ b/src/libsystemd/sd-journal/test-mmap-cache.c @@ -8,6 +8,7 @@ #include "fd-util.h" #include "macro.h" #include "mmap-cache.h" +#include "tests.h" #include "tmpfile-util.h" int main(int argc, char *argv[]) { @@ -17,6 +18,8 @@ int main(int argc, char *argv[]) { MMapCache *m; void *p, *q; + test_setup_logging(LOG_DEBUG); + assert_se(m = mmap_cache_new()); x = mkostemp_safe(px); diff --git a/src/libsystemd/sd-resolve/test-resolve.c b/src/libsystemd/sd-resolve/test-resolve.c index 9c17a36610f..829e13ea69d 100644 --- a/src/libsystemd/sd-resolve/test-resolve.c +++ b/src/libsystemd/sd-resolve/test-resolve.c @@ -13,6 +13,7 @@ #include "macro.h" #include "socket-util.h" #include "string-util.h" +#include "tests.h" #include "time-util.h" #define TEST_TIMEOUT_USEC (20*USEC_PER_SEC) @@ -67,6 +68,8 @@ int main(int argc, char *argv[]) { .in.sin_port = htobe16(80), }; + test_setup_logging(LOG_DEBUG); + assert_se(sd_resolve_default(&resolve) >= 0); /* Test a floating resolver query */ diff --git a/src/login/test-inhibit.c b/src/login/test-inhibit.c index f59cca8fed7..abb80d953e4 100644 --- a/src/login/test-inhibit.c +++ b/src/login/test-inhibit.c @@ -9,6 +9,7 @@ #include "bus-util.h" #include "fd-util.h" #include "macro.h" +#include "tests.h" static int inhibit(sd_bus *bus, const char *what) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; @@ -57,6 +58,8 @@ int main(int argc, char *argv[]) { int fd1, fd2; int r; + test_setup_logging(LOG_DEBUG); + r = sd_bus_open_system(&bus); assert_se(r >= 0); diff --git a/src/login/test-login-tables.c b/src/login/test-login-tables.c index 9d16685082c..3c5ec04271f 100644 --- a/src/login/test-login-tables.c +++ b/src/login/test-login-tables.c @@ -3,8 +3,11 @@ #include "logind-action.h" #include "logind-session.h" #include "test-tables.h" +#include "tests.h" int main(int argc, char **argv) { + test_setup_logging(LOG_DEBUG); + test_table(handle_action, HANDLE_ACTION); test_table(inhibit_mode, INHIBIT_MODE); test_table(kill_who, KILL_WHO); diff --git a/src/machine/test-machine-tables.c b/src/machine/test-machine-tables.c index 0e51755087b..32c5e0e80d0 100644 --- a/src/machine/test-machine-tables.c +++ b/src/machine/test-machine-tables.c @@ -2,8 +2,11 @@ #include "machine.h" #include "test-tables.h" +#include "tests.h" int main(int argc, char **argv) { + test_setup_logging(LOG_DEBUG); + test_table(kill_who, KILL_WHO); test_table(machine_class, MACHINE_CLASS); test_table(machine_state, MACHINE_STATE); diff --git a/src/network/generator/test-network-generator.c b/src/network/generator/test-network-generator.c index 318b9e98c37..7850da99045 100644 --- a/src/network/generator/test-network-generator.c +++ b/src/network/generator/test-network-generator.c @@ -3,6 +3,7 @@ #include "macro.h" #include "network-generator.h" #include "string-util.h" +#include "tests.h" static void test_network_one(const char *ifname, const char *key, const char *value, const char *expected) { _cleanup_(context_clear) Context context = {}; @@ -63,6 +64,8 @@ static void test_link_one(const char *filename, const char *key, const char *val } int main(int argc, char *argv[]) { + test_setup_logging(LOG_DEBUG); + test_network_one("", "ip", "dhcp6", "[Match]\n" "Kind=!*\n" diff --git a/src/network/test-network-tables.c b/src/network/test-network-tables.c index e3e260754d6..564ca096099 100644 --- a/src/network/test-network-tables.c +++ b/src/network/test-network-tables.c @@ -12,9 +12,12 @@ #include "networkd-network.h" #include "networkd-util.h" #include "test-tables.h" +#include "tests.h" #include "tunnel.h" int main(int argc, char **argv) { + test_setup_logging(LOG_DEBUG); + test_table(bond_ad_select, NETDEV_BOND_AD_SELECT); test_table(bond_arp_all_targets, NETDEV_BOND_ARP_ALL_TARGETS); test_table(bond_arp_validate, NETDEV_BOND_ARP_VALIDATE); diff --git a/src/nspawn/test-nspawn-tables.c b/src/nspawn/test-nspawn-tables.c index 3baf5d301fa..daea4695e3c 100644 --- a/src/nspawn/test-nspawn-tables.c +++ b/src/nspawn/test-nspawn-tables.c @@ -2,8 +2,11 @@ #include "nspawn-settings.h" #include "test-tables.h" +#include "tests.h" int main(int argc, char **argv) { + test_setup_logging(LOG_DEBUG); + test_table(resolv_conf_mode, RESOLV_CONF_MODE); test_table(timezone_mode, TIMEZONE_MODE); diff --git a/src/resolve/test-dns-packet.c b/src/resolve/test-dns-packet.c index 01f15ca88a2..ca09b0840c5 100644 --- a/src/resolve/test-dns-packet.c +++ b/src/resolve/test-dns-packet.c @@ -128,7 +128,7 @@ int main(int argc, char **argv) { _cleanup_globfree_ glob_t g = {}; char **fnames; - log_parse_environment(); + test_setup_logging(LOG_DEBUG); if (argc >= 2) { N = argc - 1; diff --git a/src/resolve/test-dnssec-complex.c b/src/resolve/test-dnssec-complex.c index 976d197bb49..05a5f07aadc 100644 --- a/src/resolve/test-dnssec-complex.c +++ b/src/resolve/test-dnssec-complex.c @@ -12,6 +12,7 @@ #include "random-util.h" #include "resolved-def.h" #include "string-util.h" +#include "tests.h" #include "time-util.h" static void prefix_random(const char *name, char **ret) { @@ -105,6 +106,8 @@ int main(int argc, char* argv[]) { * That zones contacted are still set up as they were when I wrote this. */ + test_setup_logging(LOG_DEBUG); + assert_se(sd_bus_open_system(&bus) >= 0); /* Normally signed */ diff --git a/src/resolve/test-resolve-tables.c b/src/resolve/test-resolve-tables.c index e4f4e14cc30..6b8618103f9 100644 --- a/src/resolve/test-resolve-tables.c +++ b/src/resolve/test-resolve-tables.c @@ -4,10 +4,13 @@ #include "resolved-dns-dnssec.h" #include "resolved-dns-packet.h" #include "test-tables.h" +#include "tests.h" int main(int argc, char **argv) { uint16_t i; + test_setup_logging(LOG_DEBUG); + test_table(dns_protocol, DNS_PROTOCOL); test_table(dnssec_result, DNSSEC_RESULT); test_table(dnssec_verdict, DNSSEC_VERDICT); diff --git a/src/test/test-bitmap.c b/src/test/test-bitmap.c index 6a84508b12d..8acf8331291 100644 --- a/src/test/test-bitmap.c +++ b/src/test/test-bitmap.c @@ -1,11 +1,14 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include "bitmap.h" +#include "tests.h" int main(int argc, const char *argv[]) { _cleanup_bitmap_free_ Bitmap *b = NULL, *b2 = NULL; unsigned n = UINT_MAX, i = 0; + test_setup_logging(LOG_DEBUG); + b = bitmap_new(); assert_se(b); diff --git a/src/test/test-btrfs-physical-offset.c b/src/test/test-btrfs-physical-offset.c index 379ab311003..221c08e57e3 100644 --- a/src/test/test-btrfs-physical-offset.c +++ b/src/test/test-btrfs-physical-offset.c @@ -8,6 +8,7 @@ #include "format-util.h" #include "log.h" #include "memory-util.h" +#include "tests.h" int main(int argc, char *argv[]) { _cleanup_close_ int fd = -EBADF; @@ -17,6 +18,8 @@ int main(int argc, char *argv[]) { assert(argc == 2); assert(!isempty(argv[1])); + test_setup_logging(LOG_DEBUG); + fd = open(argv[1], O_RDONLY|O_CLOEXEC|O_NOCTTY); if (fd < 0) { log_error_errno(errno, "Failed to open '%s': %m", argv[1]); diff --git a/src/test/test-btrfs.c b/src/test/test-btrfs.c index 5980727c857..205142e9820 100644 --- a/src/test/test-btrfs.c +++ b/src/test/test-btrfs.c @@ -10,11 +10,14 @@ #include "format-util.h" #include "log.h" #include "string-util.h" +#include "tests.h" int main(int argc, char *argv[]) { BtrfsQuotaInfo quota; int r, fd; + test_setup_logging(LOG_DEBUG); + fd = open("/", O_RDONLY|O_CLOEXEC|O_DIRECTORY); if (fd < 0) log_error_errno(errno, "Failed to open root directory: %m"); diff --git a/src/test/test-chase-manual.c b/src/test/test-chase-manual.c index d65fbe1d744..475f089fa84 100644 --- a/src/test/test-chase-manual.c +++ b/src/test/test-chase-manual.c @@ -5,6 +5,7 @@ #include "fd-util.h" #include "log.h" #include "main-func.h" +#include "tests.h" static char *arg_root = NULL; static int arg_flags = 0; @@ -84,7 +85,7 @@ static int parse_argv(int argc, char *argv[]) { static int run(int argc, char **argv) { int r; - log_setup(); + test_setup_logging(LOG_DEBUG); r = parse_argv(argc, argv); if (r <= 0) diff --git a/src/test/test-daemon.c b/src/test/test-daemon.c index e5bc6c457b7..b880521025e 100644 --- a/src/test/test-daemon.c +++ b/src/test/test-daemon.c @@ -7,12 +7,15 @@ #include "parse-util.h" #include "strv.h" #include "time-util.h" +#include "tests.h" int main(int argc, char *argv[]) { _cleanup_strv_free_ char **l = NULL; int n, i; usec_t duration = USEC_PER_SEC / 10; + test_setup_logging(LOG_DEBUG); + if (argc >= 2) { unsigned x; diff --git a/src/test/test-dev-setup.c b/src/test/test-dev-setup.c index c9022ab9735..b75576ab4c5 100644 --- a/src/test/test-dev-setup.c +++ b/src/test/test-dev-setup.c @@ -14,6 +14,8 @@ int main(int argc, char *argv[]) { const char *f; struct stat st; + test_setup_logging(LOG_DEBUG); + if (have_effective_cap(CAP_DAC_OVERRIDE) <= 0) return log_tests_skipped("missing capability (CAP_DAC_OVERRIDE)"); diff --git a/src/test/test-hashmap-plain.c b/src/test/test-hashmap-plain.c index a821d412b7e..152b1c03e6d 100644 --- a/src/test/test-hashmap-plain.c +++ b/src/test/test-hashmap-plain.c @@ -7,8 +7,8 @@ #include "stdio-util.h" #include "string-util.h" #include "strv.h" -#include "time-util.h" #include "tests.h" +#include "time-util.h" TEST(hashmap_replace) { _cleanup_hashmap_free_ Hashmap *m = NULL; diff --git a/src/test/test-job-type.c b/src/test/test-job-type.c index 0a9b6dc2498..519fff71d57 100644 --- a/src/test/test-job-type.c +++ b/src/test/test-job-type.c @@ -3,11 +3,14 @@ #include #include "service.h" +#include "tests.h" #include "unit.h" int main(int argc, char *argv[]) { const ServiceState test_states[] = { SERVICE_DEAD, SERVICE_RUNNING }; + test_setup_logging(LOG_DEBUG); + for (size_t i = 0; i < ELEMENTSOF(test_states); i++) { /* fake a unit */ Service s = { diff --git a/src/test/test-list.c b/src/test/test-list.c index 4b20a9f956d..87f7c7b3d46 100644 --- a/src/test/test-list.c +++ b/src/test/test-list.c @@ -2,8 +2,11 @@ #include "alloc-util.h" #include "list.h" +#include "tests.h" int main(int argc, const char *argv[]) { + test_setup_logging(LOG_DEBUG); + size_t i; typedef struct list_item { LIST_FIELDS(struct list_item, item_list); diff --git a/src/test/test-log.c b/src/test/test-log.c index b0363c612ae..b5ba67b74b6 100644 --- a/src/test/test-log.c +++ b/src/test/test-log.c @@ -11,6 +11,7 @@ #include "process-util.h" #include "string-util.h" #include "strv.h" +#include "tests.h" assert_cc(IS_SYNTHETIC_ERRNO(SYNTHETIC_ERRNO(EINVAL))); assert_cc(!IS_SYNTHETIC_ERRNO(EINVAL)); @@ -204,6 +205,8 @@ static void test_log_prefix(void) { } int main(int argc, char* argv[]) { + test_setup_logging(LOG_DEBUG); + test_file(); assert_se(log_info_errno(SYNTHETIC_ERRNO(EUCLEAN), "foo") == -EUCLEAN); diff --git a/src/test/test-procfs-util.c b/src/test/test-procfs-util.c index 644de5831c1..2b19a9888b1 100644 --- a/src/test/test-procfs-util.c +++ b/src/test/test-procfs-util.c @@ -14,8 +14,7 @@ int main(int argc, char *argv[]) { uint64_t v, pid_max, threads_max, limit; int r; - log_parse_environment(); - log_open(); + test_setup_logging(LOG_DEBUG); assert_se(procfs_cpu_get_usage(&nsec) >= 0); log_info("Current system CPU time: %s", FORMAT_TIMESPAN(nsec/NSEC_PER_USEC, 1)); diff --git a/src/test/test-tables.c b/src/test/test-tables.c index 975f952a1f6..8abfba550cc 100644 --- a/src/test/test-tables.c +++ b/src/test/test-tables.c @@ -33,12 +33,15 @@ #include "swap.h" #include "target.h" #include "test-tables.h" +#include "tests.h" #include "timer.h" #include "unit-name.h" #include "unit.h" #include "virt.h" int main(int argc, char **argv) { + test_setup_logging(LOG_DEBUG); + test_table(architecture, ARCHITECTURE); test_table(assert_type, CONDITION_TYPE); test_table(automount_result, AUTOMOUNT_RESULT); diff --git a/src/test/test-varlink.c b/src/test/test-varlink.c index 05bdf9c3fab..2617ed0e1aa 100644 --- a/src/test/test-varlink.c +++ b/src/test/test-varlink.c @@ -11,6 +11,7 @@ #include "json.h" #include "rm-rf.h" #include "strv.h" +#include "tests.h" #include "tmpfile-util.h" #include "user-util.h" #include "varlink.h" @@ -330,8 +331,7 @@ int main(int argc, char *argv[]) { pthread_t t; const char *sp; - log_set_max_level(LOG_DEBUG); - log_open(); + test_setup_logging(LOG_DEBUG); assert_se(mkdtemp_malloc("/tmp/varlink-test-XXXXXX", &tmpdir) >= 0); sp = strjoina(tmpdir, "/socket"); diff --git a/src/test/test-xml.c b/src/test/test-xml.c index 5dee5c1beda..a8cb635aa31 100644 --- a/src/test/test-xml.c +++ b/src/test/test-xml.c @@ -4,6 +4,7 @@ #include "alloc-util.h" #include "string-util.h" +#include "tests.h" #include "xml.h" static void test_one(const char *data, ...) { @@ -36,6 +37,8 @@ static void test_one(const char *data, ...) { int main(int argc, char *argv[]) { + test_setup_logging(LOG_DEBUG); + test_one("", XML_END); test_one("", diff --git a/src/udev/net/test-link-config-tables.c b/src/udev/net/test-link-config-tables.c index 4fd004607f2..a4332320f68 100644 --- a/src/udev/net/test-link-config-tables.c +++ b/src/udev/net/test-link-config-tables.c @@ -2,8 +2,11 @@ #include "link-config.h" #include "test-tables.h" +#include "tests.h" int main(int argc, char **argv) { + test_setup_logging(LOG_DEBUG); + test_table(mac_address_policy, MAC_ADDRESS_POLICY); return EXIT_SUCCESS;