]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tests: use the test helpers in more places
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 20 Jan 2019 17:21:09 +0000 (18:21 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 4 Mar 2019 13:15:38 +0000 (14:15 +0100)
This is mostly cosmetic. It makes those test binaries support SYSTEMD_LOG_*
environment variables.

src/libsystemd-network/test-lldp.c
src/libsystemd/sd-bus/test-bus-address.c
src/libsystemd/sd-bus/test-bus-introspect.c
src/libsystemd/sd-bus/test-bus-queue-ref-cycle.c
src/libsystemd/sd-bus/test-bus-watch-bind.c
src/locale/test-keymap-util.c
src/resolve/test-resolved-etc-hosts.c
src/resolve/test-resolved-packet.c
src/test/test-nss.c

index b6c896f0a1a150c73a8912249cbcb20a5d32eab7..7406f94ce06ec492da7996f2bd3b36a49eb74e3f 100644 (file)
@@ -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);
index c58c52a778bf6b6843aa87d82cfdfa6863f7e5f6..70a6df10f96e2f34fd0050defbe39c0f2e56e7a7 100644 (file)
@@ -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);
 
index 940dbfe0e7e82a5ccb518876168fb51e0c3812bc..9c8e93e897a01322eef8c06f457fd7948b9c1922 100644 (file)
@@ -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);
 
index 70901c30b0e31b9416af977b4cc59b0e1fce03dd..f6506fb93f8887b5953edfbe08702e252a987eb5 100644 (file)
@@ -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);
index 4b3da30079764cf66ea5500b120a74530e0cf6b1..2723866e08472c837466dd8da108318e34247517 100644 (file)
@@ -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. */
index 2f82891d60c0b0d1251c8e3f2bdd97b20c764410..f96f5b07ec7faf8414793006e688e4c5acfa6bc4 100644 (file)
@@ -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();
index dbff889e3ead91edc16e82fc547090cce87925f2..ca3590066c83e7260de5849a27d67440e7452207 100644 (file)
@@ -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();
index 22ae26ce12ca6e6d3da456e024e26340ad596ac0..c9a511beba9ea6c8f9e2bb3c9b60b64f53c548fb 100644 (file)
@@ -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();
 
index 20aa6cf01ff9c15005c8ea2a6a6628a9d707eb6a..f1bba2a353fd0435833e315a847fdea9757b7c20 100644 (file)
 #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);