summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-01-20 18:21:09 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-03-04 14:15:38 +0100
commitf68a26221c3bb93be2841bfcaaaaae5bf0db64ee (patch)
treea915bed9be4b017ac01b9a7d45ce7d76277ade73
parentMerge pull request #11820 from dm0-/chase (diff)
downloadsystemd-f68a26221c3bb93be2841bfcaaaaae5bf0db64ee.tar.xz
systemd-f68a26221c3bb93be2841bfcaaaaae5bf0db64ee.zip
tests: use the test helpers in more places
This is mostly cosmetic. It makes those test binaries support SYSTEMD_LOG_* environment variables.
-rw-r--r--src/libsystemd-network/test-lldp.c3
-rw-r--r--src/libsystemd/sd-bus/test-bus-address.c5
-rw-r--r--src/libsystemd/sd-bus/test-bus-introspect.c3
-rw-r--r--src/libsystemd/sd-bus/test-bus-queue-ref-cycle.c16
-rw-r--r--src/libsystemd/sd-bus/test-bus-watch-bind.c3
-rw-r--r--src/locale/test-keymap-util.c4
-rw-r--r--src/resolve/test-resolved-etc-hosts.c5
-rw-r--r--src/resolve/test-resolved-packet.c6
-rw-r--r--src/test/test-nss.c15
9 files changed, 37 insertions, 23 deletions
diff --git a/src/libsystemd-network/test-lldp.c b/src/libsystemd-network/test-lldp.c
index b6c896f0a1..7406f94ce0 100644
--- a/src/libsystemd-network/test-lldp.c
+++ b/src/libsystemd-network/test-lldp.c
@@ -15,6 +15,7 @@
#include "lldp-network.h"
#include "macro.h"
#include "string-util.h"
+#include "tests.h"
#define TEST_LLDP_PORT "em1"
#define TEST_LLDP_TYPE_SYSTEM_NAME "systemd-lldp"
@@ -365,7 +366,7 @@ static void test_multiple_neighbors_sorted(sd_event *e) {
int main(int argc, char *argv[]) {
_cleanup_(sd_event_unrefp) sd_event *e = NULL;
- log_set_max_level(LOG_DEBUG);
+ test_setup_logging(LOG_DEBUG);
/* LLDP reception tests */
assert_se(sd_event_new(&e) == 0);
diff --git a/src/libsystemd/sd-bus/test-bus-address.c b/src/libsystemd/sd-bus/test-bus-address.c
index c58c52a778..70a6df10f9 100644
--- a/src/libsystemd/sd-bus/test-bus-address.c
+++ b/src/libsystemd/sd-bus/test-bus-address.c
@@ -4,6 +4,7 @@
#include "log.h"
#include "string-util.h"
#include "strv.h"
+#include "tests.h"
static void test_one_address(sd_bus *b,
const char *host,
@@ -59,9 +60,7 @@ static void test_bus_set_address_system_remote(char **args) {
}
int main(int argc, char *argv[]) {
- log_set_max_level(LOG_INFO);
- log_parse_environment();
- log_open();
+ test_setup_logging(LOG_INFO);
test_bus_set_address_system_remote(argv + 1);
diff --git a/src/libsystemd/sd-bus/test-bus-introspect.c b/src/libsystemd/sd-bus/test-bus-introspect.c
index 940dbfe0e7..9c8e93e897 100644
--- a/src/libsystemd/sd-bus/test-bus-introspect.c
+++ b/src/libsystemd/sd-bus/test-bus-introspect.c
@@ -2,6 +2,7 @@
#include "bus-introspect.h"
#include "log.h"
+#include "tests.h"
static int prop_get(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error) {
return -EINVAL;
@@ -29,7 +30,7 @@ static const sd_bus_vtable vtable[] = {
int main(int argc, char *argv[]) {
struct introspect intro;
- log_set_max_level(LOG_DEBUG);
+ test_setup_logging(LOG_DEBUG);
assert_se(introspect_begin(&intro, false) >= 0);
diff --git a/src/libsystemd/sd-bus/test-bus-queue-ref-cycle.c b/src/libsystemd/sd-bus/test-bus-queue-ref-cycle.c
index 70901c30b0..f6506fb93f 100644
--- a/src/libsystemd/sd-bus/test-bus-queue-ref-cycle.c
+++ b/src/libsystemd/sd-bus/test-bus-queue-ref-cycle.c
@@ -1,10 +1,10 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
+#include "sd-bus.h"
#include "main-func.h"
-#include "sd-bus.h"
#include "tests.h"
-static int run(int argc, char *argv[]) {
+static int test_ref_unref(void) {
sd_bus_message *m = NULL;
sd_bus *bus = NULL;
int r;
@@ -41,4 +41,16 @@ static int run(int argc, char *argv[]) {
return 0;
}
+static int run(int argc, char *argv[]) {
+ int r;
+
+ test_setup_logging(LOG_INFO);
+
+ r = test_ref_unref();
+ if (r < 0)
+ return r;
+
+ return 0;
+}
+
DEFINE_MAIN_FUNCTION(run);
diff --git a/src/libsystemd/sd-bus/test-bus-watch-bind.c b/src/libsystemd/sd-bus/test-bus-watch-bind.c
index 4b3da30079..2723866e08 100644
--- a/src/libsystemd/sd-bus/test-bus-watch-bind.c
+++ b/src/libsystemd/sd-bus/test-bus-watch-bind.c
@@ -16,6 +16,7 @@
#include "socket-util.h"
#include "string-util.h"
#include "tmpfile-util.h"
+#include "tests.h"
static int method_foobar(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
log_info("Got Foobar() call.");
@@ -198,7 +199,7 @@ int main(int argc, char *argv[]) {
pthread_t server, client1, client2;
char *path;
- log_set_max_level(LOG_DEBUG);
+ test_setup_logging(LOG_DEBUG);
/* We use /dev/shm here rather than /tmp, since some weird distros might set up /tmp as some weird fs that
* doesn't support inotify properly. */
diff --git a/src/locale/test-keymap-util.c b/src/locale/test-keymap-util.c
index 2f82891d60..f96f5b07ec 100644
--- a/src/locale/test-keymap-util.c
+++ b/src/locale/test-keymap-util.c
@@ -4,6 +4,7 @@
#include "keymap-util.h"
#include "log.h"
#include "string-util.h"
+#include "tests.h"
static void test_find_language_fallback(void) {
_cleanup_free_ char *ans = NULL, *ans2 = NULL;
@@ -189,8 +190,7 @@ static void test_x11_convert_to_vconsole(void) {
}
int main(int argc, char **argv) {
- log_set_max_level(LOG_DEBUG);
- log_parse_environment();
+ test_setup_logging(LOG_DEBUG);
test_find_language_fallback();
test_find_converted_keymap();
diff --git a/src/resolve/test-resolved-etc-hosts.c b/src/resolve/test-resolved-etc-hosts.c
index dbff889e3e..ca3590066c 100644
--- a/src/resolve/test-resolved-etc-hosts.c
+++ b/src/resolve/test-resolved-etc-hosts.c
@@ -10,6 +10,7 @@
#include "log.h"
#include "resolved-etc-hosts.h"
#include "strv.h"
+#include "tests.h"
#include "tmpfile-util.h"
static void test_parse_etc_hosts_system(void) {
@@ -137,9 +138,7 @@ static void test_parse_file(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);
if (argc == 1) {
test_parse_etc_hosts_system();
diff --git a/src/resolve/test-resolved-packet.c b/src/resolve/test-resolved-packet.c
index 22ae26ce12..c9a511beba 100644
--- a/src/resolve/test-resolved-packet.c
+++ b/src/resolve/test-resolved-packet.c
@@ -2,6 +2,7 @@
#include "log.h"
#include "resolved-dns-packet.h"
+#include "tests.h"
static void test_dns_packet_new(void) {
size_t i;
@@ -23,10 +24,7 @@ static void test_dns_packet_new(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_packet_new();
diff --git a/src/test/test-nss.c b/src/test/test-nss.c
index 20aa6cf01f..f1bba2a353 100644
--- a/src/test/test-nss.c
+++ b/src/test/test-nss.c
@@ -12,11 +12,13 @@
#include "in-addr-util.h"
#include "local-addresses.h"
#include "log.h"
+#include "main-func.h"
#include "nss-util.h"
#include "path-util.h"
#include "stdio-util.h"
#include "string-util.h"
#include "strv.h"
+#include "tests.h"
static const char* nss_status_to_string(enum nss_status status, char *buf, size_t buf_len) {
switch (status) {
@@ -485,7 +487,7 @@ static int parse_argv(int argc, char **argv,
return 0;
}
-int main(int argc, char **argv) {
+static int run(int argc, char **argv) {
_cleanup_free_ char *dir = NULL;
_cleanup_strv_free_ char **modules = NULL, **names = NULL;
_cleanup_free_ struct local_address *addresses = NULL;
@@ -493,8 +495,7 @@ int main(int argc, char **argv) {
char **module;
int r;
- log_set_max_level(LOG_INFO);
- log_parse_environment();
+ test_setup_logging(LOG_INFO);
r = parse_argv(argc, argv, &modules, &names, &addresses, &n_addresses);
if (r < 0) {
@@ -504,13 +505,15 @@ int main(int argc, char **argv) {
dir = dirname_malloc(argv[0]);
if (!dir)
- return EXIT_FAILURE;
+ return log_oom();
STRV_FOREACH(module, modules) {
r = test_one_module(dir, *module, names, addresses, n_addresses);
if (r < 0)
- return EXIT_FAILURE;
+ return r;
}
- return EXIT_SUCCESS;
+ return 0;
}
+
+DEFINE_MAIN_FUNCTION(run);