summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-09-13 14:31:13 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-09-14 09:29:57 +0200
commit6d7c403324091b0ac0797dbd26b9fe61d4aea9a3 (patch)
treec1e977d368f861961955db8624b61729d30943d2 /src/test
parent8b81c382c390d69e48d653c357b4d820bfc149a6 (diff)
downloadsystemd-6d7c403324091b0ac0797dbd26b9fe61d4aea9a3.tar.gz
systemd-6d7c403324091b0ac0797dbd26b9fe61d4aea9a3.tar.bz2
systemd-6d7c403324091b0ac0797dbd26b9fe61d4aea9a3.zip
tests: use a helper function to parse environment and open logging
The advantages are that we save a few lines, and that we can override logging using environment variables in more test executables.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-architecture.c2
-rw-r--r--src/test/test-barrier.c4
-rw-r--r--src/test/test-boot-timestamps.c3
-rw-r--r--src/test/test-bpf.c4
-rw-r--r--src/test/test-bus-util.c5
-rw-r--r--src/test/test-capability.c5
-rw-r--r--src/test/test-cgroup-mask.c3
-rw-r--r--src/test/test-cgroup-util.c5
-rw-r--r--src/test/test-condition.c5
-rw-r--r--src/test/test-conf-files.c5
-rw-r--r--src/test/test-copy.c3
-rw-r--r--src/test/test-date.c5
-rw-r--r--src/test/test-dissect-image.c3
-rw-r--r--src/test/test-dns-domain.c5
-rw-r--r--src/test/test-engine.c4
-rw-r--r--src/test/test-escape.c5
-rw-r--r--src/test/test-exec-util.c5
-rw-r--r--src/test/test-execute.c4
-rw-r--r--src/test/test-fd-util.c3
-rw-r--r--src/test/test-fileio.c5
-rw-r--r--src/test/test-firewall-util.c3
-rw-r--r--src/test/test-hash.c2
-rw-r--r--src/test/test-install-root.c3
-rw-r--r--src/test/test-install.c4
-rw-r--r--src/test/test-ipcrm.c2
-rw-r--r--src/test/test-journal-importer.c3
-rw-r--r--src/test/test-loopback.c5
-rw-r--r--src/test/test-mount-util.c3
-rw-r--r--src/test/test-namespace.c3
-rw-r--r--src/test/test-netlink-manual.c2
-rw-r--r--src/test/test-ns.c3
-rw-r--r--src/test/test-os-util.c5
-rw-r--r--src/test/test-path-lookup.c5
-rw-r--r--src/test/test-path-util.c5
-rw-r--r--src/test/test-path.c3
-rw-r--r--src/test/test-process-util.c5
-rw-r--r--src/test/test-random-util.c5
-rw-r--r--src/test/test-sched-prio.c2
-rw-r--r--src/test/test-seccomp.c3
-rw-r--r--src/test/test-selinux.c4
-rw-r--r--src/test/test-sigbus.c2
-rw-r--r--src/test/test-sleep.c3
-rw-r--r--src/test/test-socket-util.c3
-rw-r--r--src/test/test-specifier.c3
-rw-r--r--src/test/test-tmpfiles.c4
-rw-r--r--src/test/test-umount.c4
-rw-r--r--src/test/test-unit-file.c3
-rw-r--r--src/test/test-unit-name.c3
-rw-r--r--src/test/test-watch-pid.c4
-rw-r--r--src/test/test-watchdog.c4
-rw-r--r--src/test/test-xattr-util.c5
51 files changed, 86 insertions, 105 deletions
diff --git a/src/test/test-architecture.c b/src/test/test-architecture.c
index 6cd64b60b2..8c43bfc750 100644
--- a/src/test/test-architecture.c
+++ b/src/test/test-architecture.c
@@ -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);
diff --git a/src/test/test-barrier.c b/src/test/test-barrier.c
index 2a735695a1..6ae84cd6fc 100644
--- a/src/test/test-barrier.c
+++ b/src/test/test-barrier.c
@@ -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");
diff --git a/src/test/test-boot-timestamps.c b/src/test/test-boot-timestamps.c
index 578aa5b304..d45ca8c920 100644
--- a/src/test/test-boot-timestamps.c
+++ b/src/test/test-boot-timestamps.c
@@ -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);
diff --git a/src/test/test-bpf.c b/src/test/test-bpf.c
index a055fea802..2fb7968dfd 100644
--- a/src/test/test-bpf.c
+++ b/src/test/test-bpf.c
@@ -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)
diff --git a/src/test/test-bus-util.c b/src/test/test-bus-util.c
index 791b3928fe..789d19cf7f 100644
--- a/src/test/test-bus-util.c
+++ b/src/test/test-bus-util.c
@@ -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);
diff --git a/src/test/test-capability.c b/src/test/test-capability.c
index 79ddca9554..730dbf8cbd 100644
--- a/src/test/test-capability.c
+++ b/src/test/test-capability.c
@@ -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)
diff --git a/src/test/test-cgroup-mask.c b/src/test/test-cgroup-mask.c
index 0dd673e3e5..bab27edf54 100644
--- a/src/test/test-cgroup-mask.c
+++ b/src/test/test-cgroup-mask.c
@@ -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());
diff --git a/src/test/test-cgroup-util.c b/src/test/test-cgroup-util.c
index d49356315e..95ca41fba5 100644
--- a/src/test/test-cgroup-util.c
+++ b/src/test/test-cgroup-util.c
@@ -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();
diff --git a/src/test/test-condition.c b/src/test/test-condition.c
index 678fc426fe..5c2d00af88 100644
--- a/src/test/test-condition.c
+++ b/src/test/test-condition.c
@@ -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();
diff --git a/src/test/test-conf-files.c b/src/test/test-conf-files.c
index 2ec2dfc261..b69046c9c1 100644
--- a/src/test/test-conf-files.c
+++ b/src/test/test-conf-files.c
@@ -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);
diff --git a/src/test/test-copy.c b/src/test/test-copy.c
index 2e8d251ac1..4e265374ab 100644
--- a/src/test/test-copy.c
+++ b/src/test/test-copy.c
@@ -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();
diff --git a/src/test/test-date.c b/src/test/test-date.c
index 99b6f2eb9e..cba51e225c 100644
--- a/src/test/test-date.c
+++ b/src/test/test-date.c
@@ -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");
diff --git a/src/test/test-dissect-image.c b/src/test/test-dissect-image.c
index a0a909baf0..7b32e8373f 100644
--- a/src/test/test-dissect-image.c
+++ b/src/test/test-dissect-image.c
@@ -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.");
diff --git a/src/test/test-dns-domain.c b/src/test/test-dns-domain.c
index 7fa887e4d2..cbfe5ef390 100644
--- a/src/test/test-dns-domain.c
+++ b/src/test/test-dns-domain.c
@@ -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();
diff --git a/src/test/test-engine.c b/src/test/test-engine.c
index f7435bd4fb..0483c5b698 100644
--- a/src/test/test-engine.c
+++ b/src/test/test-engine.c
@@ -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)
diff --git a/src/test/test-escape.c b/src/test/test-escape.c
index 650a9a058d..4ee4aa974d 100644
--- a/src/test/test-escape.c
+++ b/src/test/test-escape.c
@@ -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();
diff --git a/src/test/test-exec-util.c b/src/test/test-exec-util.c
index cfc8b5f88e..d346a4d6f7 100644
--- a/src/test/test-exec-util.c
+++ b/src/test/test-exec-util.c
@@ -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);
diff --git a/src/test/test-execute.c b/src/test/test-execute.c
index 0d2f35734e..15967f76c2 100644
--- a/src/test/test-execute.c
+++ b/src/test/test-execute.c
@@ -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");
diff --git a/src/test/test-fd-util.c b/src/test/test-fd-util.c
index a04403d748..157dc88320 100644
--- a/src/test/test-fd-util.c
+++ b/src/test/test-fd-util.c
@@ -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();
diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c
index 14ba075144..aa38a7d29a 100644
--- a/src/test/test-fileio.c
+++ b/src/test/test-fileio.c
@@ -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();
diff --git a/src/test/test-firewall-util.c b/src/test/test-firewall-util.c
index 1b62590b49..1788e8d1ca 100644
--- a/src/test/test-firewall-util.c
+++ b/src/test/test-firewall-util.c
@@ -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)
diff --git a/src/test/test-hash.c b/src/test/test-hash.c
index ea56b74d0f..44d1044bf3 100644
--- a/src/test/test-hash.c
+++ b/src/test/test-hash.c
@@ -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);
diff --git a/src/test/test-install-root.c b/src/test/test-install-root.c
index fe1ca5b16f..c0956fa4bb 100644
--- a/src/test/test-install-root.c
+++ b/src/test/test-install-root.c
@@ -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);
diff --git a/src/test/test-install.c b/src/test/test-install.c
index 7dfc7e4272..62daaccd62 100644
--- a/src/test/test-install.c
+++ b/src/test/test-install.c
@@ -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);
diff --git a/src/test/test-ipcrm.c b/src/test/test-ipcrm.c
index 1f6d7b4351..4b658a0bdb 100644
--- a/src/test/test-ipcrm.c
+++ b/src/test/test-ipcrm.c
@@ -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");
diff --git a/src/test/test-journal-importer.c b/src/test/test-journal-importer.c
index 8f09d5ad2f..c1ceb0bbd8 100644
--- a/src/test/test-journal-importer.c
+++ b/src/test/test-journal-importer.c
@@ -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();
diff --git a/src/test/test-loopback.c b/src/test/test-loopback.c
index eaea9e4c76..89b760fae4 100644
--- a/src/test/test-loopback.c
+++ b/src/test/test-loopback.c
@@ -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)
diff --git a/src/test/test-mount-util.c b/src/test/test-mount-util.c
index c10e1681fb..56e385aa11 100644
--- a/src/test/test-mount-util.c
+++ b/src/test/test-mount-util.c
@@ -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);
diff --git a/src/test/test-namespace.c b/src/test/test-namespace.c
index 318bd5bad4..ab8f05076d 100644
--- a/src/test/test-namespace.c
+++ b/src/test/test-namespace.c
@@ -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);
diff --git a/src/test/test-netlink-manual.c b/src/test/test-netlink-manual.c
index 39826dfdb9..a471456e0c 100644
--- a/src/test/test-netlink-manual.c
+++ b/src/test/test-netlink-manual.c
@@ -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);
diff --git a/src/test/test-ns.c b/src/test/test-ns.c
index 4ab70f2306..d3dbb54ca1 100644
--- a/src/test/test-ns.c
+++ b/src/test/test-ns.c
@@ -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));
diff --git a/src/test/test-os-util.c b/src/test/test-os-util.c
index 8d8b52d7f6..c215a2e99e 100644
--- a/src/test/test-os-util.c
+++ b/src/test/test-os-util.c
@@ -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();
diff --git a/src/test/test-path-lookup.c b/src/test/test-path-lookup.c
index 892293cb10..029dc8e906 100644
--- a/src/test/test-path-lookup.c
+++ b/src/test/test-path-lookup.c
@@ -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);
diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c
index 35b27bcedd..9ec42aae7b 100644
--- a/src/test/test-path-util.c
+++ b/src/test/test-path-util.c
@@ -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();
diff --git a/src/test/test-path.c b/src/test/test-path.c
index 7e664ec849..025b3295a0 100644
--- a/src/test/test-path.c
+++ b/src/test/test-path.c
@@ -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);
diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c
index 1b3b357913..d396c29b06 100644
--- a/src/test/test-process-util.c
+++ b/src/test/test-process-util.c
@@ -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;
diff --git a/src/test/test-random-util.c b/src/test/test-random-util.c
index 70301a7782..9652a0af05 100644
--- a/src/test/test-random-util.c
+++ b/src/test/test-random-util.c
@@ -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);
diff --git a/src/test/test-sched-prio.c b/src/test/test-sched-prio.c
index c594336325..f6ca192f07 100644
--- a/src/test/test-sched-prio.c
+++ b/src/test/test-sched-prio.c
@@ -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");
diff --git a/src/test/test-seccomp.c b/src/test/test-seccomp.c
index d82cb5c1c5..e05710c00d 100644
--- a/src/test/test-seccomp.c
+++ b/src/test/test-seccomp.c
@@ -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();
diff --git a/src/test/test-selinux.c b/src/test/test-selinux.c
index 6caeb843f3..59b4f71946 100644
--- a/src/test/test-selinux.c
+++ b/src/test/test-selinux.c
@@ -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();
diff --git a/src/test/test-sigbus.c b/src/test/test-sigbus.c
index 518e48e1ec..33c9d42e9e 100644
--- a/src/test/test-sigbus.c
+++ b/src/test/test-sigbus.c
@@ -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
diff --git a/src/test/test-sleep.c b/src/test/test-sleep.c
index 0198d34f19..2ce79f8345 100644
--- a/src/test/test-sleep.c
+++ b/src/test/test-sleep.c
@@ -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");
diff --git a/src/test/test-socket-util.c b/src/test/test-socket-util.c
index 19c5395b92..df18a2a83c 100644
--- a/src/test/test-socket-util.c
+++ b/src/test/test-socket-util.c
@@ -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();
diff --git a/src/test/test-specifier.c b/src/test/test-specifier.c
index 9c7c352b51..a0ffdf6cb6 100644
--- a/src/test/test-specifier.c
+++ b/src/test/test-specifier.c
@@ -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();
diff --git a/src/test/test-tmpfiles.c b/src/test/test-tmpfiles.c
index 3817790233..7f288e54ce 100644
--- a/src/test/test-tmpfiles.c
+++ b/src/test/test-tmpfiles.c
@@ -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");
diff --git a/src/test/test-umount.c b/src/test/test-umount.c
index c068f7a0f0..1b243d03ef 100644
--- a/src/test/test-umount.c
+++ b/src/test/test-umount.c
@@ -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");
diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c
index 0b84d4c4ed..7132146827 100644
--- a/src/test/test-unit-file.c
+++ b/src/test/test-unit-file.c
@@ -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)
diff --git a/src/test/test-unit-name.c b/src/test/test-unit-name.c
index 7fd3f82d4d..b1600db534 100644
--- a/src/test/test-unit-name.c
+++ b/src/test/test-unit-name.c
@@ -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)
diff --git a/src/test/test-watch-pid.c b/src/test/test-watch-pid.c
index 615ded186b..03378ecf08 100644
--- a/src/test/test-watch-pid.c
+++ b/src/test/test-watch-pid.c
@@ -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");
diff --git a/src/test/test-watchdog.c b/src/test/test-watchdog.c
index d595ae27d5..ab66d5c49d 100644
--- a/src/test/test-watchdog.c
+++ b/src/test/test-watchdog.c
@@ -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();
diff --git a/src/test/test-xattr-util.c b/src/test/test-xattr-util.c
index 72720dccb8..2d93e65be2 100644
--- a/src/test/test-xattr-util.c
+++ b/src/test/test-xattr-util.c
@@ -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();