]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tests: use a helper function to parse environment and open logging
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 13 Sep 2018 12:31:13 +0000 (14:31 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 14 Sep 2018 07:29:57 +0000 (09:29 +0200)
The advantages are that we save a few lines, and that we can override
logging using environment variables in more test executables.

85 files changed:
src/fuzz/fuzz-main.c
src/journal/test-catalog.c
src/journal/test-compress-benchmark.c
src/journal/test-compress.c
src/journal/test-journal-enum.c
src/journal/test-journal-init.c
src/journal/test-journal-interleaving.c
src/journal/test-journal-match.c
src/journal/test-journal-stream.c
src/journal/test-journal-verify.c
src/journal/test-journal.c
src/libsystemd-network/test-acd.c
src/libsystemd-network/test-dhcp-client.c
src/libsystemd-network/test-dhcp-server.c
src/libsystemd-network/test-dhcp6-client.c
src/libsystemd-network/test-ipv4ll-manual.c
src/libsystemd-network/test-ipv4ll.c
src/libsystemd-network/test-ndisc-ra.c
src/libsystemd-network/test-ndisc-rs.c
src/libsystemd/sd-bus/test-bus-chat.c
src/libsystemd/sd-bus/test-bus-cleanup.c
src/libsystemd/sd-bus/test-bus-creds.c
src/libsystemd/sd-bus/test-bus-gvariant.c
src/libsystemd/sd-bus/test-bus-marshal.c
src/libsystemd/sd-bus/test-bus-match.c
src/libsystemd/sd-bus/test-bus-track.c
src/libsystemd/sd-event/test-event.c
src/libsystemd/sd-netlink/test-local-addresses.c
src/network/test-network.c
src/network/test-routing-policy-rule.c
src/nspawn/test-patch-uid.c
src/shared/tests.c
src/shared/tests.h
src/test/test-architecture.c
src/test/test-barrier.c
src/test/test-boot-timestamps.c
src/test/test-bpf.c
src/test/test-bus-util.c
src/test/test-capability.c
src/test/test-cgroup-mask.c
src/test/test-cgroup-util.c
src/test/test-condition.c
src/test/test-conf-files.c
src/test/test-copy.c
src/test/test-date.c
src/test/test-dissect-image.c
src/test/test-dns-domain.c
src/test/test-engine.c
src/test/test-escape.c
src/test/test-exec-util.c
src/test/test-execute.c
src/test/test-fd-util.c
src/test/test-fileio.c
src/test/test-firewall-util.c
src/test/test-hash.c
src/test/test-install-root.c
src/test/test-install.c
src/test/test-ipcrm.c
src/test/test-journal-importer.c
src/test/test-loopback.c
src/test/test-mount-util.c
src/test/test-namespace.c
src/test/test-netlink-manual.c
src/test/test-ns.c
src/test/test-os-util.c
src/test/test-path-lookup.c
src/test/test-path-util.c
src/test/test-path.c
src/test/test-process-util.c
src/test/test-random-util.c
src/test/test-sched-prio.c
src/test/test-seccomp.c
src/test/test-selinux.c
src/test/test-sigbus.c
src/test/test-sleep.c
src/test/test-socket-util.c
src/test/test-specifier.c
src/test/test-tmpfiles.c
src/test/test-umount.c
src/test/test-unit-file.c
src/test/test-unit-name.c
src/test/test-watch-pid.c
src/test/test-watchdog.c
src/test/test-xattr-util.c
src/timesync/test-timesync.c

index d549dc95ffe5608ffc1d5f28dfb6e55891d6f3f3..caf7a27ef135af547345697ea67235e54cc6156f 100644 (file)
@@ -4,6 +4,7 @@
 #include "log.h"
 #include "fileio.h"
 #include "fuzz.h"
+#include "tests.h"
 
 /* This is a test driver for the systemd fuzzers that provides main function
  * for regression testing outside of oss-fuzz (https://github.com/google/oss-fuzz)
@@ -16,9 +17,7 @@ int main(int argc, char **argv) {
         size_t size;
         char *name;
 
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         for (i = 1; i < argc; i++) {
                 _cleanup_free_ char *buf = NULL;
index d9ee557b9c4a036b8f13190605d4cd06871d5e1d..368ac749d0ac15f87df50d23a3b22fff8a77d9c2 100644 (file)
@@ -206,9 +206,7 @@ int main(int argc, char *argv[]) {
 
         setlocale(LC_ALL, "de_DE.UTF-8");
 
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         /* If test-catalog is located at the build directory, then use catalogs in that.
          * If it is not, e.g. installed by systemd-tests package, then use installed catalogs. */
index 0633fe6ea44804597f0236eeb00bcdd5fab68a0d..7f13b611e6ad5d41b0a8a7984c67bc7cab327657 100644 (file)
@@ -143,11 +143,7 @@ static void test_compress_decompress(const char* label, const char* type,
 
 int main(int argc, char *argv[]) {
 #if HAVE_XZ || HAVE_LZ4
-        const char *i;
-
-        log_set_max_level(LOG_INFO);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_INFO);
 
         if (argc >= 2) {
                 unsigned x;
@@ -163,6 +159,7 @@ int main(int argc, char *argv[]) {
         else
                 arg_start = getpid_cached();
 
+        const char *i;
         NULSTR_FOREACH(i, "zeros\0simple\0random\0") {
 #if HAVE_XZ
                 test_compress_decompress("XZ", i, compress_blob_xz, decompress_blob_xz);
index d59a613b399d80d4f105cc2d88c5a485bf43cda2..7addf318d69544fe84a207868ebfa762ae3d25b2 100644 (file)
@@ -12,6 +12,7 @@
 #include "macro.h"
 #include "path-util.h"
 #include "random-util.h"
+#include "tests.h"
 #include "util.h"
 
 #if HAVE_XZ
@@ -253,7 +254,7 @@ int main(int argc, char *argv[]) {
         memcpy(huge, "HUGE=", 5);
         char_array_0(huge);
 
-        log_set_max_level(LOG_DEBUG);
+        test_setup_logging(LOG_DEBUG);
 
         random_bytes(data + 7, sizeof(data) - 7);
 
index b25a983498cd0b07ea5ca5fb8b2f0656a8bca13d..f74b49d5010cde0e94c444246215e5d27ec83841 100644 (file)
@@ -7,12 +7,13 @@
 #include "journal-internal.h"
 #include "log.h"
 #include "macro.h"
+#include "tests.h"
 
 int main(int argc, char *argv[]) {
         unsigned n = 0;
         _cleanup_(sd_journal_closep) sd_journal*j = NULL;
 
-        log_set_max_level(LOG_DEBUG);
+        test_setup_logging(LOG_DEBUG);
 
         assert_se(sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY) >= 0);
 
index a43672b6e1e2cc3ca7217612caa5e688623a3379..860baca38388e0b0e50cda82b3e2b63d62331dcd 100644 (file)
@@ -5,6 +5,7 @@
 #include "log.h"
 #include "parse-util.h"
 #include "rm-rf.h"
+#include "tests.h"
 #include "util.h"
 
 int main(int argc, char *argv[]) {
@@ -12,7 +13,7 @@ int main(int argc, char *argv[]) {
         int r, i, I = 100;
         char t[] = "/tmp/journal-stream-XXXXXX";
 
-        log_set_max_level(LOG_DEBUG);
+        test_setup_logging(LOG_DEBUG);
 
         if (argc >= 2) {
                 r = safe_atoi(argv[1], &I);
index 82da68e0eabfad884bf6ea2080fff98eaeaaa428..7b098b4ba260885ad078581e45ba9f9c94563949 100644 (file)
@@ -274,7 +274,7 @@ static void test_sequence_numbers(void) {
 }
 
 int main(int argc, char *argv[]) {
-        log_set_max_level(LOG_DEBUG);
+        test_setup_logging(LOG_DEBUG);
 
         /* journal_file_open requires a valid machine id */
         if (access("/etc/machine-id", F_OK) != 0)
index 4e5ad1791a8e21f70aa9532fcdc0686d85cbc079..ba415fcc38375bff949eeaa4121af234fadec83b 100644 (file)
@@ -8,13 +8,14 @@
 #include "journal-internal.h"
 #include "log.h"
 #include "string-util.h"
+#include "tests.h"
 #include "util.h"
 
 int main(int argc, char *argv[]) {
         _cleanup_(sd_journal_closep) sd_journal*j = NULL;
         _cleanup_free_ char *t;
 
-        log_set_max_level(LOG_DEBUG);
+        test_setup_logging(LOG_DEBUG);
 
         assert_se(sd_journal_open(&j, 0) >= 0);
 
index d7fdf907c8cf47bada2699fdf87d4c0e52995a58..226c30f80a3914677918e9e71589da1f794bce6a 100644 (file)
@@ -71,7 +71,7 @@ int main(int argc, char *argv[]) {
         if (access("/etc/machine-id", F_OK) != 0)
                 return log_tests_skipped("/etc/machine-id not found");
 
-        log_set_max_level(LOG_DEBUG);
+        test_setup_logging(LOG_DEBUG);
 
         assert_se(mkdtemp(t));
         assert_se(chdir(t) >= 0);
index c2a21cef9cad19e42d2b942f88ef997fcf1da5af..8d6b4412134402fec1a111462f07c87bd655f7f6 100644 (file)
@@ -65,7 +65,7 @@ int main(int argc, char *argv[]) {
         if (access("/etc/machine-id", F_OK) != 0)
                 return log_tests_skipped("/etc/machine-id not found");
 
-        log_set_max_level(LOG_DEBUG);
+        test_setup_logging(LOG_DEBUG);
 
         assert_se(mkdtemp(t));
         assert_se(chdir(t) >= 0);
index 7e188420db0cc54b21dab2d3bbe87da9f591a725..34f202c81da244382eb6d644504b68c516831522 100644 (file)
@@ -22,7 +22,7 @@ static void test_non_empty(void) {
         sd_id128_t fake_boot_id;
         char t[] = "/tmp/journal-XXXXXX";
 
-        log_set_max_level(LOG_DEBUG);
+        test_setup_logging(LOG_DEBUG);
 
         assert_se(mkdtemp(t));
         assert_se(chdir(t) >= 0);
@@ -113,7 +113,7 @@ static void test_empty(void) {
         JournalFile *f1, *f2, *f3, *f4;
         char t[] = "/tmp/journal-XXXXXX";
 
-        log_set_max_level(LOG_DEBUG);
+        test_setup_logging(LOG_DEBUG);
 
         assert_se(mkdtemp(t));
         assert_se(chdir(t) >= 0);
@@ -165,7 +165,7 @@ static bool check_compressed(uint64_t compress_threshold, uint64_t data_size) {
 
         assert_se(data_size <= sizeof(data));
 
-        log_set_max_level(LOG_DEBUG);
+        test_setup_logging(LOG_DEBUG);
 
         assert_se(mkdtemp(t));
         assert_se(chdir(t) >= 0);
@@ -239,6 +239,8 @@ static void test_min_compress_size(void) {
 int main(int argc, char *argv[]) {
         arg_keep = argc > 1;
 
+        test_setup_logging(LOG_INFO);
+
         /* journal_file_open requires a valid machine id */
         if (access("/etc/machine-id", F_OK) != 0)
                 return log_tests_skipped("/etc/machine-id not found");
index 079e760996f63c3ff28682c6cbedf19ebb7023a8..302eea2c30fa7fb09e5516d2174a73618f3f4ed6 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "in-addr-util.h"
 #include "netlink-util.h"
+#include "tests.h"
 #include "util.h"
 
 static void acd_handler(sd_ipv4acd *acd, int event, void *userdata) {
@@ -83,9 +84,7 @@ static int test_acd(const char *ifname, const char *address) {
 }
 
 int main(int argc, char *argv[]) {
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         if (argc == 3)
                 return test_acd(argv[1], argv[2]);
index 0e257633b85dd86d7f35e0013d4668126aaf7db1..30dc36140f6abdc0da605f5e936e8d679b61082b 100644 (file)
@@ -16,6 +16,7 @@
 #include "dhcp-internal.h"
 #include "dhcp-protocol.h"
 #include "fd-util.h"
+#include "tests.h"
 #include "util.h"
 
 static uint8_t mac_addr[] = {'A', 'B', 'C', '1', '2', '3'};
@@ -524,9 +525,7 @@ static void test_addr_acq(sd_event *e) {
 int main(int argc, char *argv[]) {
         _cleanup_(sd_event_unrefp) sd_event *e;
 
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         assert_se(sd_event_new(&e) >= 0);
 
index 2854e04abc2e235543bf131c8bb4f0f050aa8d49..ea998939bc48729adf2c7e5dfa07220142e05b64 100644 (file)
@@ -229,9 +229,7 @@ int main(int argc, char *argv[]) {
         _cleanup_(sd_event_unrefp) sd_event *e;
         int r;
 
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         assert_se(sd_event_new(&e) >= 0);
 
index 27c0002fe2853132905aac2d1078e96238f89ff8..5e20580783e8b9e09c86333decc7f6cd5128a004 100644 (file)
@@ -19,6 +19,7 @@
 #include "fd-util.h"
 #include "macro.h"
 #include "socket-util.h"
+#include "tests.h"
 #include "virt.h"
 
 static struct ether_addr mac_addr = {
@@ -910,9 +911,7 @@ int main(int argc, char *argv[]) {
 
         assert_se(sd_event_new(&e) >= 0);
 
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         test_client_basic(e);
         test_option(e);
index 125133f0393502ea1a3cae1c722aeafeb3871dd0..fd827ff40144e37cadef649df6fd22cddc03eeb4 100644 (file)
@@ -15,6 +15,7 @@
 #include "netlink-util.h"
 #include "parse-util.h"
 #include "string-util.h"
+#include "tests.h"
 #include "util.h"
 
 static void ll_handler(sd_ipv4ll *ll, int event, void *userdata) {
@@ -95,9 +96,7 @@ static int test_ll(const char *ifname, const char *seed) {
 }
 
 int main(int argc, char *argv[]) {
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         if (argc == 2)
                 return test_ll(argv[1], NULL);
index ee9cce02a895cafed743ebacda07ea79f272e421..d9c803f899dc00efc46a5ffadb178017fe3a3b42 100644 (file)
@@ -15,6 +15,7 @@
 #include "arp-util.h"
 #include "fd-util.h"
 #include "socket-util.h"
+#include "tests.h"
 #include "util.h"
 
 static bool verbose = false;
@@ -193,9 +194,7 @@ static void test_basic_request(sd_event *e) {
 int main(int argc, char *argv[]) {
         _cleanup_(sd_event_unrefp) sd_event *e = NULL;
 
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         assert_se(sd_event_new(&e) >= 0);
 
index d5a023766382b47fa2dd4da750762415239350b7..c8870fad0d56723adb239127f0ad368aa556987e 100644 (file)
@@ -13,6 +13,7 @@
 #include "icmp6-util.h"
 #include "socket-util.h"
 #include "strv.h"
+#include "tests.h"
 
 static struct ether_addr mac_addr = {
         .ether_addr_octet = { 0x78, 0x2b, 0xcb, 0xb3, 0x6d, 0x53 }
@@ -357,9 +358,7 @@ static void test_ra(void) {
 
 int main(int argc, char *argv[]) {
 
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         test_radv_prefix();
         test_radv();
index b9d0e7dc90e3648e358079c671e0c4cc24e2c1f7..70f289bcb560f2d5f397c67b63131d269d346c75 100644 (file)
@@ -14,6 +14,7 @@
 #include "socket-util.h"
 #include "strv.h"
 #include "ndisc-internal.h"
+#include "tests.h"
 
 static struct ether_addr mac_addr = {
         .ether_addr_octet = {'A', 'B', 'C', '1', '2', '3'}
@@ -407,9 +408,7 @@ static void test_timeout(void) {
 
 int main(int argc, char *argv[]) {
 
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         test_rs();
         test_timeout();
index 28922e6a699eb7ebc3fe387ef1bc27c4d2d372c7..2ba6eaee7d17871deccad944dfb95a13289fabdf 100644 (file)
@@ -510,6 +510,8 @@ int main(int argc, char *argv[]) {
         void *p;
         int q, r;
 
+        test_setup_logging(LOG_INFO);
+
         r = server_init(&bus);
         if (r < 0)
                 return log_tests_skipped("Failed to connect to bus");
index a70f4823db4db95eea8de8e89601cbe83b27f51f..975d3f97dd9d03bf9956cadb48b26c27b6e70123 100644 (file)
@@ -60,8 +60,7 @@ static void test_bus_new_signal(void) {
 }
 
 int main(int argc, char **argv) {
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_INFO);
 
         test_bus_new();
 
index a99fbc3bc5dbf615d2507693886e16bc5736685f..c02c459663b883f68c7c652704f274df9859b0b6 100644 (file)
@@ -11,9 +11,7 @@ int main(int argc, char *argv[]) {
         _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
         int r;
 
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         if (cg_unified_flush() == -ENOMEDIUM)
                 return log_tests_skipped("/sys/fs/cgroup/ not available");
index ae3e71e3650c08403bacee7367e8d4ef6bbba3f3..648fea76e0219e87f61f49a7c637b012539c2b5e 100644 (file)
@@ -13,6 +13,7 @@
 #include "bus-message.h"
 #include "bus-util.h"
 #include "macro.h"
+#include "tests.h"
 #include "util.h"
 
 static void test_bus_gvariant_is_fixed_size(void) {
@@ -199,6 +200,7 @@ static void test_marshal(void) {
 }
 
 int main(int argc, char *argv[]) {
+        test_setup_logging(LOG_INFO);
 
         test_bus_gvariant_is_fixed_size();
         test_bus_gvariant_get_size();
index 22c48e38dcb876c217166302844491e578b71697..7e113b179e0e06e274731cca9f99ab4dd3bd41ca 100644 (file)
@@ -121,6 +121,8 @@ int main(int argc, char *argv[]) {
         double dbl;
         uint64_t u64;
 
+        test_setup_logging(LOG_INFO);
+
         r = sd_bus_default_user(&bus);
         if (r < 0)
                 return log_tests_skipped("Failed to connect to bus");
index 527911c5af8bb0b638762c56d1228d27efaf7a53..c56b39437bccf89352bcb86763c95a373ea169fc 100644 (file)
@@ -78,6 +78,8 @@ int main(int argc, char *argv[]) {
         sd_bus_slot slots[19];
         int r;
 
+        test_setup_logging(LOG_INFO);
+
         r = sd_bus_open_user(&bus);
         if (r < 0)
                 return log_tests_skipped("Failed to connect to bus");
index 8a3dcf1654abfc0dac9bef16c30754e37e7fd805..a2782cd1d50a330c29eb403de8bf955aef21fb1d 100644 (file)
@@ -48,6 +48,8 @@ int main(int argc, char *argv[]) {
         const char *unique;
         int r;
 
+        test_setup_logging(LOG_INFO);
+
         r = sd_event_default(&event);
         assert_se(r >= 0);
 
index 1f08b4d4b8cd4308638ef991040b64af65f79dbf..50074a56be81fa9f974eb6c8312252691e9135e0 100644 (file)
@@ -16,6 +16,7 @@
 #include "signal-util.h"
 #include "stdio-util.h"
 #include "string-util.h"
+#include "tests.h"
 #include "util.h"
 
 static int prepare_handler(sd_event_source *s, void *userdata) {
@@ -481,9 +482,7 @@ static void test_inotify(unsigned n_create_events) {
 }
 
 int main(int argc, char *argv[]) {
-
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
+        test_setup_logging(LOG_DEBUG);
 
         test_basic();
         test_sd_event_now();
index cb05d05a896c7d3216ff5f28c9e9be100132f7d3..17114265d7be965f86cb2126553cd183e1b809d3 100644 (file)
@@ -4,6 +4,7 @@
 #include "alloc-util.h"
 #include "in-addr-util.h"
 #include "local-addresses.h"
+#include "tests.h"
 
 static void print_local_addresses(struct local_address *a, unsigned n) {
         unsigned i;
@@ -20,9 +21,7 @@ int main(int argc, char *argv[]) {
         struct local_address *a;
         int n;
 
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         a = NULL;
         n = local_addresses(NULL, 0, AF_UNSPEC, &a);
index e8c10bc15cde5a2a5ddd39031273eebc56e6892a..6e169e0fca00c0d82f9ce56f6d37990c036f0db6 100644 (file)
@@ -224,6 +224,8 @@ int main(void) {
         _cleanup_(sd_device_unrefp) sd_device *loopback = NULL;
         int ifindex, r;
 
+        test_setup_logging(LOG_INFO);
+
         test_deserialize_in_addr();
         test_deserialize_dhcp_routes();
         test_address_equality();
index 9920f516b7a895fdb71ff0b3d2a6e54b937cf72b..d112471587752eb5966f86186292904d804de581 100644 (file)
@@ -9,6 +9,7 @@
 #include "network-internal.h"
 #include "networkd-manager.h"
 #include "string-util.h"
+#include "tests.h"
 
 static void test_rule_serialization(const char *title, const char *ruleset, const char *expected) {
         char pattern[] = "/tmp/systemd-test-routing-policy-rule.XXXXXX",
@@ -57,9 +58,7 @@ static void test_rule_serialization(const char *title, const char *ruleset, cons
 int main(int argc, char **argv) {
         _cleanup_free_ char *p = NULL;
 
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         test_rule_serialization("basic parsing",
                                 "RULE=from=1.2.3.4/32 to=2.3.4.5/32 tos=5 fwmark=1/2 table=10", NULL);
index 8e29d3e806990095ea267a2cb25a4c933a5aead7..b50f0990d842d5044e0baf3c734ea0a8c17107d1 100644 (file)
@@ -5,15 +5,14 @@
 #include "log.h"
 #include "nspawn-patch-uid.h"
 #include "user-util.h"
+#include "tests.h"
 #include "util.h"
 
 int main(int argc, char *argv[]) {
         uid_t shift, range;
         int r;
 
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         if (argc != 4) {
                 log_error("Expected PATH SHIFT RANGE parameters.");
index 884f34bc72e9c165fdda179a2369b583b905bd3e..8d70c02802dba9d483ae72e3f7b10575196e042a 100644 (file)
@@ -91,6 +91,12 @@ bool slow_tests_enabled(void) {
         return SYSTEMD_SLOW_TESTS_DEFAULT;
 }
 
+void test_setup_logging(int level) {
+        log_set_max_level(level);
+        log_parse_environment();
+        log_open();
+}
+
 int log_tests_skipped(const char *message) {
         log_notice("%s: %s, skipping tests.",
                    program_invocation_short_name, message);
index 67d5e1ce4a08dcc88f9081acaec47b6240c932fd..f35a526737a7ccc48759b3127c7ad513faa9bdb7 100644 (file)
@@ -5,4 +5,5 @@ char* setup_fake_runtime_dir(void);
 const char* get_testdata_dir(void);
 const char* get_catalog_dir(void);
 bool slow_tests_enabled(void);
+void test_setup_logging(int level);
 int log_tests_skipped(const char *message);
index 6cd64b60b2bcc1f8d8cbafd7bd36429d477cb88f..8c43bfc750ec265e9a58d63ada0836e453732daf 100644 (file)
@@ -10,6 +10,8 @@ int main(int argc, char *argv[]) {
         int a, v;
         const char *p;
 
+        test_setup_logging(LOG_INFO);
+
         assert_se(architecture_from_string("") < 0);
         assert_se(architecture_from_string(NULL) < 0);
         assert_se(architecture_from_string("hoge") < 0);
index 2a735695a1ba95ecfd4a4379359105ea05186e85..6ae84cd6fcfcf38daebba54fe8f9517fb46b3975 100644 (file)
@@ -420,9 +420,7 @@ TEST_BARRIER(test_barrier_pending_exit,
         TEST_BARRIER_WAIT_SUCCESS(pid2));
 
 int main(int argc, char *argv[]) {
-        log_set_max_level(LOG_INFO);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_INFO);
 
         if (!slow_tests_enabled())
                 return log_tests_skipped("slow tests are disabled");
index 578aa5b30480aede1f04c392c80e5108c079e3ac..d45ca8c9204fc7e29bec69ca09d3048aba5fd930 100644 (file)
@@ -82,8 +82,7 @@ static int test_boot_timestamps(void) {
 int main(int argc, char* argv[]) {
         int p, q, r;
 
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
+        test_setup_logging(LOG_DEBUG);
 
         p = test_acpi_fpdt();
         assert(p >= 0);
index a055fea8024b211098b3804190a2e9cc8b3c834d..2fb7968dfd074b8cccc92846be4cff5153ac886d 100644 (file)
@@ -28,9 +28,7 @@ int main(int argc, char *argv[]) {
         char log_buf[65535];
         int r;
 
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         r = enter_cgroup_subroot();
         if (r == -ENOMEDIUM)
index 791b3928fe7600e7119696dbb8bb2e324ef570ee..789d19cf7f79d886b990332d823957ccc06f3078 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "bus-util.h"
 #include "log.h"
+#include "tests.h"
 
 static void test_name_async(unsigned n_messages) {
         _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
@@ -78,9 +79,7 @@ static void test_destroy_callback(void) {
 }
 
 int main(int argc, char **argv) {
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         test_name_async(0);
         test_name_async(20);
index 79ddca955419c5618739e49dde7e15795e3511fd..730dbf8cbdaaca84d5c748991c30ce3f45efa232 100644 (file)
@@ -220,12 +220,11 @@ static void test_set_ambient_caps(void) {
 int main(int argc, char *argv[]) {
         bool run_ambient;
 
+        test_setup_logging(LOG_INFO);
+
         test_last_cap_file();
         test_last_cap_probe();
 
-        log_parse_environment();
-        log_open();
-
         log_info("have ambient caps: %s", yes_no(ambient_capabilities_supported()));
 
         if (getuid() != 0)
index 0dd673e3e57fc826a71dfc3d0ca51213657aaf59..bab27edf5453806b7e35ac3de659e4e0458f74ce 100644 (file)
@@ -118,8 +118,7 @@ static void test_cg_mask_to_string(void) {
 int main(int argc, char* argv[]) {
         int rc = EXIT_SUCCESS;
 
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         test_cg_mask_to_string();
         TEST_REQ_RUNNING_SYSTEMD(rc = test_cgroup_mask());
index d49356315edbdbdd49702d424a75e243de7f350e..95ca41fba5d9695a3af8c537ea3b7c9807b3fc98 100644 (file)
@@ -14,6 +14,7 @@
 #include "string-util.h"
 #include "strv.h"
 #include "test-helper.h"
+#include "tests.h"
 #include "user-util.h"
 #include "util.h"
 
@@ -447,9 +448,7 @@ static void test_cg_get_keyed_attribute(void) {
 }
 
 int main(void) {
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         test_path_decode_unit();
         test_path_get_unit();
index 678fc426fe38eb78618ec0f923c07befaf5e8be1..5c2d00af886a5ca7ff3035e55e382f3fb1c24f44 100644 (file)
@@ -26,6 +26,7 @@
 #include "strv.h"
 #include "tomoyo-util.h"
 #include "user-util.h"
+#include "tests.h"
 #include "util.h"
 #include "virt.h"
 
@@ -673,9 +674,7 @@ static void test_condition_test_group(void) {
 }
 
 int main(int argc, char *argv[]) {
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         test_condition_test_path();
         test_condition_test_ac_power();
index 2ec2dfc26154c72d4815fe50f2e6394a586c5281..b69046c9c19b253c02fa090173bbc5b0fdc3d84e 100644 (file)
@@ -16,6 +16,7 @@
 #include "rm-rf.h"
 #include "string-util.h"
 #include "strv.h"
+#include "tests.h"
 #include "user-util.h"
 #include "util.h"
 
@@ -93,9 +94,7 @@ static void test_conf_files_list(bool use_root) {
 }
 
 int main(int argc, char **argv) {
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         test_conf_files_list(false);
         test_conf_files_list(true);
index 2e8d251ac145c4ff1dbffdcc0adb6e399ce93be3..4e265374ab116548305e565cba9e2b7365f2c95e 100644 (file)
@@ -14,6 +14,7 @@
 #include "rm-rf.h"
 #include "string-util.h"
 #include "strv.h"
+#include "tests.h"
 #include "user-util.h"
 #include "util.h"
 
@@ -254,7 +255,7 @@ static void test_copy_atomic(void) {
 }
 
 int main(int argc, char *argv[]) {
-        log_set_max_level(LOG_DEBUG);
+        test_setup_logging(LOG_DEBUG);
 
         test_copy_file();
         test_copy_file_fd();
index 99b6f2eb9ea3a3a6d232bf431b675a4d80e60985..cba51e225c68c3264657081939310b8111171165 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "alloc-util.h"
 #include "string-util.h"
+#include "tests.h"
 #include "util.h"
 
 static void test_should_pass(const char *p) {
@@ -66,9 +67,7 @@ static void test_one_noutc(const char *p) {
 }
 
 int main(int argc, char *argv[]) {
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         test_one("17:41");
         test_one("18:42:44");
index a0a909baf0a65d0290025c805f96d4fa2ad01e50..7b32e8373f920a01ca44e3b67958c3375cbca783 100644 (file)
@@ -7,13 +7,14 @@
 #include "log.h"
 #include "loop-util.h"
 #include "string-util.h"
+#include "tests.h"
 
 int main(int argc, char *argv[]) {
         _cleanup_(loop_device_unrefp) LoopDevice *d = NULL;
         _cleanup_(dissected_image_unrefp) DissectedImage *m = NULL;
         int r, i;
 
-        log_set_max_level(LOG_DEBUG);
+        test_setup_logging(LOG_DEBUG);
 
         if (argc < 2) {
                 log_error("Requires one command line argument.");
index 7fa887e4d2109b7c0202772545163f4b4903e268..cbfe5ef390388623028d6dbe2ba1ebb8895e072e 100644 (file)
@@ -4,6 +4,7 @@
 #include "dns-domain.h"
 #include "macro.h"
 #include "string-util.h"
+#include "tests.h"
 
 static void test_dns_label_unescape_one(const char *what, const char *expect, size_t buffer_sz, int ret) {
         char buffer[buffer_sz];
@@ -687,9 +688,7 @@ static void test_dns_name_is_valid_or_address(void) {
 }
 
 int main(int argc, char *argv[]) {
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         test_dns_label_unescape();
         test_dns_label_unescape_suffix();
index f7435bd4fbc247d514a97b33216fa6320b3f1005..0483c5b698e71cbcd63a453685ad44c25fbd376a 100644 (file)
@@ -18,9 +18,7 @@ int main(int argc, char *argv[]) {
         Job *j;
         int r;
 
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         r = enter_cgroup_subroot();
         if (r == -ENOMEDIUM)
index 650a9a058dd74149b82f71fd8e914591f279e9a4..4ee4aa974d73272dcc845ccd62b7e7ae54cf6ad2 100644 (file)
@@ -3,6 +3,7 @@
 #include "alloc-util.h"
 #include "escape.h"
 #include "macro.h"
+#include "tests.h"
 
 static void test_cescape(void) {
         _cleanup_free_ char *escaped;
@@ -119,9 +120,7 @@ static void test_shell_maybe_quote(void) {
 }
 
 int main(int argc, char *argv[]) {
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         test_cescape();
         test_cunescape();
index cfc8b5f88ee29abff38e7102d7fa4cacca6cf638..d346a4d6f7d11af8bc1c7f2ede18b918c0b8339f 100644 (file)
@@ -19,6 +19,7 @@
 #include "rm-rf.h"
 #include "string-util.h"
 #include "strv.h"
+#include "tests.h"
 
 static int here = 0, here2 = 0, here3 = 0;
 void *ignore_stdout_args[] = {&here, &here2, &here3};
@@ -334,9 +335,7 @@ static void test_environment_gathering(void) {
 }
 
 int main(int argc, char *argv[]) {
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         test_execute_directory(true);
         test_execute_directory(false);
index 0d2f35734e31e0ed7c17201e60e6519cb835066e..15967f76c27e534a76904513e5f93cc438b633ec 100644 (file)
@@ -724,9 +724,7 @@ int main(int argc, char *argv[]) {
         };
         int r;
 
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         (void) unsetenv("USER");
         (void) unsetenv("LOGNAME");
index a04403d7485938626284a3a4cd9e6e4ea9211011..157dc88320789b43c9f4838b191924da3c3d0e9b 100644 (file)
@@ -12,6 +12,7 @@
 #include "random-util.h"
 #include "string-util.h"
 #include "util.h"
+#include "tests.h"
 
 static void test_close_many(void) {
         int fds[3];
@@ -316,7 +317,7 @@ static void test_read_nr_open(void) {
 
 int main(int argc, char *argv[]) {
 
-        log_set_max_level(LOG_DEBUG);
+        test_setup_logging(LOG_DEBUG);
 
         test_close_many();
         test_close_nointr();
index 14ba075144b10652b7fff8c5b00fb0c911448591..aa38a7d29a4e623588463f910c36adf1c2e64198 100644 (file)
@@ -16,6 +16,7 @@
 #include "process-util.h"
 #include "string-util.h"
 #include "strv.h"
+#include "tests.h"
 #include "util.h"
 
 static void test_parse_env_file(void) {
@@ -710,9 +711,7 @@ static void test_read_line3(void) {
 }
 
 int main(int argc, char *argv[]) {
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         test_parse_env_file();
         test_parse_multiline_env_file();
index 1b62590b49bf304e2c531ebf19cd8d11d4148897..1788e8d1ca8c262a5d50c894037ab8abc6e26c2d 100644 (file)
@@ -2,12 +2,13 @@
 
 #include "firewall-util.h"
 #include "log.h"
+#include "tests.h"
 
 #define MAKE_IN_ADDR_UNION(a,b,c,d) (union in_addr_union) { .in.s_addr = htobe32((uint32_t) (a) << 24 | (uint32_t) (b) << 16 | (uint32_t) (c) << 8 | (uint32_t) (d))}
 
 int main(int argc, char *argv[]) {
         int r;
-        log_set_max_level(LOG_DEBUG);
+        test_setup_logging(LOG_DEBUG);
 
         r = fw_add_masquerade(true, AF_INET, 0, NULL, 0, "foobar", NULL, 0);
         if (r < 0)
index ea56b74d0f77226f6090c31d14b2029242dccb5b..44d1044bf37fe96eb6054853f6a1d51634f4ac18 100644 (file)
@@ -14,7 +14,7 @@ int main(int argc, char *argv[]) {
         _cleanup_free_ char *s = NULL;
         int r;
 
-        log_set_max_level(LOG_DEBUG);
+        test_setup_logging(LOG_DEBUG);
 
         assert_se(khash_new(&h, NULL) == -EINVAL);
         assert_se(khash_new(&h, "") == -EINVAL);
index fe1ca5b16f47425cb396a5be601c903bfdd68281..c0956fa4bb35d6a88f10bba9484ea4a2199920e3 100644 (file)
@@ -7,6 +7,7 @@
 #include "rm-rf.h"
 #include "special.h"
 #include "string-util.h"
+#include "tests.h"
 
 static void test_basic_mask_and_enable(const char *root) {
         const char *p;
@@ -14,7 +15,7 @@ static void test_basic_mask_and_enable(const char *root) {
         UnitFileChange *changes = NULL;
         size_t n_changes = 0;
 
-        log_set_max_level(LOG_DEBUG);
+        test_setup_logging(LOG_DEBUG);
 
         assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "a.service", NULL) == -ENOENT);
         assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "b.service", NULL) == -ENOENT);
index 7dfc7e42724665f1033078ca3875226487ef91ed..62daaccd6229c3bdead762013b68a5c0e4a1055c 100644 (file)
@@ -4,6 +4,7 @@
 #include <string.h>
 
 #include "install.h"
+#include "tests.h"
 
 static void dump_changes(UnitFileChange *c, unsigned n) {
         unsigned i;
@@ -29,8 +30,7 @@ int main(int argc, char* argv[]) {
         size_t n_changes = 0;
         UnitFileState state = 0;
 
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
+        test_setup_logging(LOG_DEBUG);
 
         h = hashmap_new(&string_hash_ops);
         r = unit_file_get_list(UNIT_FILE_SYSTEM, NULL, h, NULL, NULL);
index 1f6d7b4351dc93a691ec8cecc3fb60fc9aefcedd..4b658a0bdbbc70787ad154a5f6c0ba0ba2e06776 100644 (file)
@@ -10,6 +10,8 @@ int main(int argc, char *argv[]) {
         int r;
         const char* name = argv[1] ?: NOBODY_USER_NAME;
 
+        test_setup_logging(LOG_INFO);
+
         r = get_user_creds(&name, &uid, NULL, NULL, NULL, 0);
         if (r == -ESRCH)
                 return log_tests_skipped("Failed to resolve user");
index 8f09d5ad2f3d8c7ffab7c756aca00cd807f8018d..c1ceb0bbd8b47e645a0c3112127dd6a07c0c0b39 100644 (file)
@@ -69,8 +69,7 @@ static void test_bad_input(void) {
 }
 
 int main(int argc, char **argv) {
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
+        test_setup_logging(LOG_DEBUG);
 
         test_basic_parsing();
         test_bad_input();
index eaea9e4c7670997c6a528c6fd4363e66f3919961..89b760fae436d2ed53b5951b34cf96f4d7c87618 100644 (file)
@@ -5,13 +5,12 @@
 
 #include "log.h"
 #include "loopback-setup.h"
+#include "tests.h"
 
 int main(int argc, char* argv[]) {
         int r;
 
-        log_open();
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
+        test_setup_logging(LOG_DEBUG);
 
         r = loopback_setup();
         if (r < 0)
index c10e1681fb971f839c88e46ce1fe62c3831ed19b..56e385aa11703bb886bd3fb63c26ba1683edbc84 100644 (file)
@@ -13,6 +13,7 @@
 #include "path-util.h"
 #include "rm-rf.h"
 #include "string-util.h"
+#include "tests.h"
 
 static void test_mount_propagation_flags(const char *name, int ret, unsigned long expected) {
         long unsigned flags;
@@ -295,7 +296,7 @@ static void test_mount_option_mangle(void) {
 
 int main(int argc, char *argv[]) {
 
-        log_set_max_level(LOG_DEBUG);
+        test_setup_logging(LOG_DEBUG);
 
         test_mount_propagation_flags("shared", 0, MS_SHARED);
         test_mount_propagation_flags("slave", 0, MS_SLAVE);
index 318bd5bad4deb2a7dc8e317800fd6d3f989221ab..ab8f05076df7b4e069cb159435c52844731aea2c 100644 (file)
@@ -109,8 +109,7 @@ int main(int argc, char *argv[]) {
         char boot_id[SD_ID128_STRING_MAX];
         _cleanup_free_ char *x = NULL, *y = NULL, *z = NULL, *zz = NULL;
 
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_INFO);
 
         assert_se(sd_id128_get_boot(&bid) >= 0);
         sd_id128_to_string(bid, boot_id);
index 39826dfdb9942b1f638e0692cd75e4066fcc0f6b..a471456e0cf01c52dee7ac79f442b237cd790b86 100644 (file)
@@ -118,6 +118,8 @@ int main(int argc, char *argv[]) {
         sd_netlink *rtnl;
         int r;
 
+        test_setup_logging(LOG_INFO);
+
         assert_se(sd_netlink_open(&rtnl) >= 0);
         assert_se(rtnl);
 
index 4ab70f2306d3075a004e2bcd74d60630f3acf3b7..d3dbb54ca175a7ce1073527211866df5ad1fbc60 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "log.h"
 #include "namespace.h"
+#include "tests.h"
 
 int main(int argc, char *argv[]) {
         const char * const writable[] = {
@@ -43,7 +44,7 @@ int main(int argc, char *argv[]) {
         char tmp_dir[] = "/tmp/systemd-private-XXXXXX",
              var_tmp_dir[] = "/var/tmp/systemd-private-XXXXXX";
 
-        log_set_max_level(LOG_DEBUG);
+        test_setup_logging(LOG_DEBUG);
 
         assert_se(mkdtemp(tmp_dir));
         assert_se(mkdtemp(var_tmp_dir));
index 8d8b52d7f6aa5aff4799070d67183180c6615891..c215a2e99e945787d730d83c6cd19e5f9d2b1bff 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "log.h"
 #include "os-util.h"
+#include "tests.h"
 
 static void test_path_is_os_tree(void) {
         assert_se(path_is_os_tree("/") > 0);
@@ -12,9 +13,7 @@ static void test_path_is_os_tree(void) {
 }
 
 int main(int argc, char *argv[]) {
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         test_path_is_os_tree();
 
index 892293cb10e91d52ab94d1e5fae1ae8fedc65f1a..029dc8e906ccb79c6f6c3d69d48f225b3d8a3cca 100644 (file)
@@ -8,6 +8,7 @@
 #include "rm-rf.h"
 #include "string-util.h"
 #include "strv.h"
+#include "tests.h"
 
 static void test_paths(UnitFileScope scope) {
         char template[] = "/tmp/test-path-lookup.XXXXXXX";
@@ -76,9 +77,7 @@ static void print_generator_binary_paths(UnitFileScope scope) {
 }
 
 int main(int argc, char **argv) {
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         test_paths(UNIT_FILE_SYSTEM);
         test_paths(UNIT_FILE_USER);
index 35b27bcedd5b1e87ab9297053c3f11361c4fcd11..9ec42aae7b06bc2d41a99b7c4af4fe548eea7b11 100644 (file)
@@ -12,6 +12,7 @@
 #include "stat-util.h"
 #include "string-util.h"
 #include "strv.h"
+#include "tests.h"
 #include "util.h"
 
 #define test_path_compare(a, b, result) {                 \
@@ -506,9 +507,7 @@ static void test_empty_or_root(void) {
 }
 
 int main(int argc, char **argv) {
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         test_path();
         test_path_equal_root();
index 7e664ec849fa82200a042f81d8ae6e9a372426d7..025b3295a0b4ae4ed38655916a3fff4ed70d801f 100644 (file)
@@ -252,8 +252,7 @@ int main(int argc, char *argv[]) {
 
         umask(022);
 
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_INFO);
 
         test_path = path_join(NULL, get_testdata_dir(), "test-path");
         assert_se(set_unit_path(test_path) >= 0);
index 1b3b357913d9125cdea2f35c41b7cce21211b5b1..d396c29b06b46aee556f1b3546a67afed5555372 100644 (file)
@@ -24,6 +24,7 @@
 #include "string-util.h"
 #include "terminal-util.h"
 #include "test-helper.h"
+#include "tests.h"
 #include "util.h"
 #include "virt.h"
 
@@ -587,9 +588,7 @@ static void test_ioprio_class_from_to_string(void) {
 }
 
 int main(int argc, char *argv[]) {
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         saved_argc = argc;
         saved_argv = argv;
index 70301a7782132da2db57a8c3e160d562e1f434e2..9652a0af05b2c3e1387a4bc7b306b01dcd50ab95 100644 (file)
@@ -3,6 +3,7 @@
 #include "hexdecoct.h"
 #include "random-util.h"
 #include "log.h"
+#include "tests.h"
 
 static void test_acquire_random_bytes(bool high_quality_required) {
         uint8_t buf[16] = {};
@@ -51,9 +52,7 @@ static void test_rdrand64(void) {
 }
 
 int main(int argc, char **argv) {
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         test_acquire_random_bytes(false);
         test_acquire_random_bytes(true);
index c5943363259286b858b29bc5ac4b4c25d9fe7df7..f6ca192f07596e07fabc5ceee8a9ba7c4fa3a429 100644 (file)
@@ -19,6 +19,8 @@ int main(int argc, char *argv[]) {
         Service *ser;
         int r;
 
+        test_setup_logging(LOG_INFO);
+
         r = enter_cgroup_subroot();
         if (r == -ENOMEDIUM)
                 return log_tests_skipped("cgroupfs not available");
index d82cb5c1c56e6d59593dc9b6cab0c969d7eb9daf..e05710c00d95e0b106277eb56bc3b35da23c2ea8 100644 (file)
@@ -20,6 +20,7 @@
 #include "seccomp-util.h"
 #include "set.h"
 #include "string-util.h"
+#include "tests.h"
 #include "util.h"
 #include "virt.h"
 
@@ -668,7 +669,7 @@ static void test_filter_sets_ordered(void) {
 
 int main(int argc, char *argv[]) {
 
-        log_set_max_level(LOG_DEBUG);
+        test_setup_logging(LOG_DEBUG);
 
         test_seccomp_arch_to_string();
         test_architecture_table();
index 6caeb843f3ecf5fcb870da7dec7be4844f0f1637..59b4f719466ec4b02cd5b0bbc43699387f38a65c 100644 (file)
@@ -7,6 +7,7 @@
 #include "log.h"
 #include "selinux-util.h"
 #include "string-util.h"
+#include "tests.h"
 #include "time-util.h"
 #include "util.h"
 
@@ -92,8 +93,7 @@ int main(int argc, char **argv) {
         if (argc >= 2)
                 path = argv[1];
 
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
+        test_setup_logging(LOG_DEBUG);
 
         test_testing();
         test_loading();
index 518e48e1ec1c1465e9ad874281bf9968b2809ad3..33c9d42e9e3711a3c7c1353dcca862a3d39eb8ce 100644 (file)
@@ -17,6 +17,8 @@ int main(int argc, char *argv[]) {
         void *addr = NULL;
         uint8_t *p;
 
+        test_setup_logging(LOG_INFO);
+
 #ifdef __SANITIZE_ADDRESS__
         return log_tests_skipped("address-sanitizer is enabled");
 #endif
index 0198d34f194bcd475922fa2e36133c0598351951..2ce79f8345c460012bfdb0de0c91ebdda1ea63a1 100644 (file)
@@ -80,8 +80,7 @@ static void test_sleep(void) {
 int main(int argc, char* argv[]) {
         int i, r = 0, k;
 
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_INFO);
 
         if (getuid() != 0)
                 log_warning("This program is unlikely to work for unprivileged users");
index 19c5395b924b9e8019d943e867c3f0989ae0c292..df18a2a83c48b5a2c3a8818d4d548c4627f9405b 100644 (file)
@@ -17,6 +17,7 @@
 #include "socket-util.h"
 #include "string-util.h"
 #include "util.h"
+#include "tests.h"
 
 static void test_ifname_valid(void) {
         assert(ifname_valid("foo"));
@@ -698,7 +699,7 @@ static void test_send_emptydata(void) {
 
 int main(int argc, char *argv[]) {
 
-        log_set_max_level(LOG_DEBUG);
+        test_setup_logging(LOG_DEBUG);
 
         test_ifname_valid();
 
index 9c7c352b5155fd295b623c7f3a9b4e6b92003467..a0ffdf6cb6aa54c340cdbbe854d7a852d56c628b 100644 (file)
@@ -5,6 +5,7 @@
 #include "specifier.h"
 #include "string-util.h"
 #include "strv.h"
+#include "tests.h"
 
 static void test_specifier_escape_one(const char *a, const char *b) {
         _cleanup_free_ char *x = NULL;
@@ -39,7 +40,7 @@ static void test_specifier_escape_strv(void) {
 }
 
 int main(int argc, char *argv[]) {
-        log_set_max_level(LOG_DEBUG);
+        test_setup_logging(LOG_DEBUG);
 
         test_specifier_escape();
         test_specifier_escape_strv();
index 3817790233b205083c4519f18e570d46e2df2254..7f288e54ceff72d86e3fa0d6e8e6370d399dd3cc 100644 (file)
@@ -13,6 +13,7 @@
 #include "log.h"
 #include "process-util.h"
 #include "string-util.h"
+#include "tests.h"
 #include "util.h"
 
 int main(int argc, char** argv) {
@@ -21,8 +22,7 @@ int main(int argc, char** argv) {
         const char *p = argv[1] ?: "/tmp";
         char *pattern;
 
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
+        test_setup_logging(LOG_DEBUG);
 
         pattern = strjoina(p, "/systemd-test-XXXXXX");
 
index c068f7a0f0db7fac84b58eb1d08bb5d78f6bd730..1b243d03efb3858f728b98da0aeb98081c3df34c 100644 (file)
@@ -53,9 +53,7 @@ static void test_swap_list(const char *fname) {
 }
 
 int main(int argc, char **argv) {
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         test_mount_points_list(NULL);
         test_mount_points_list("/test-umount/empty.mountinfo");
index 0b84d4c4ed227939f5436f1213bb6e2a4b03c4a1..71321468279b16c71943105c7b8a5a48c6ed298f 100644 (file)
@@ -896,8 +896,7 @@ int main(int argc, char *argv[]) {
         _cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
         int r;
 
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_INFO);
 
         r = enter_cgroup_subroot();
         if (r == -ENOMEDIUM)
index 7fd3f82d4db2f467a32ca2d2fd7cfa2ab0110244..b1600db5342ea209817e10fa90351b017341da53 100644 (file)
@@ -811,8 +811,7 @@ int main(int argc, char* argv[]) {
         _cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
         int r, rc = 0;
 
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_INFO);
 
         r = enter_cgroup_subroot();
         if (r == -ENOMEDIUM)
index 615ded186bf286d08810c224781b3b443f33f935..03378ecf089c1aa0f17b32edb78913c2c36f002b 100644 (file)
@@ -13,9 +13,7 @@ int main(int argc, char *argv[]) {
         Unit *a, *b, *c, *u;
         int r;
 
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         if (getuid() != 0)
                 return log_tests_skipped("not root");
index d595ae27d5214351297e44d54ddd6bf6a8ddaab6..ab66d5c49d83f5757df32961ac86401b3960b819 100644 (file)
@@ -13,9 +13,7 @@ int main(int argc, char *argv[]) {
         int r;
         bool slow;
 
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         slow = slow_tests_enabled();
 
index 72720dccb8c8f71f07a1fedbe579f175cdb90b17..2d93e65be21aea37ac69e7e9ca13ae321f8c08b3 100644 (file)
@@ -12,6 +12,7 @@
 #include "fs-util.h"
 #include "macro.h"
 #include "string-util.h"
+#include "tests.h"
 #include "xattr-util.h"
 
 static void test_fgetxattrat_fake(void) {
@@ -78,9 +79,7 @@ static void test_getcrtime(void) {
 }
 
 int main(void) {
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         test_fgetxattrat_fake();
         test_getcrtime();
index a045eeeec11b65ae378e4352725be91ec3455186..bd03a1dd90aca6b37fa7494c56ec395c2d39e577 100644 (file)
@@ -5,6 +5,7 @@
 #include "log.h"
 #include "macro.h"
 #include "timesyncd-conf.h"
+#include "tests.h"
 
 static void test_manager_parse_string(void) {
         /* Make sure that NTP_SERVERS is configured to something
@@ -25,8 +26,7 @@ static void test_manager_parse_string(void) {
 }
 
 int main(int argc, char **argv) {
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
+        test_setup_logging(LOG_DEBUG);
 
         test_manager_parse_string();