systemd/tests: add test util for systemd
authorThomas Haller <thaller@redhat.com>
Tue, 1 Mar 2016 07:56:14 +0000 (08:56 +0100)
committerThomas Haller <thaller@redhat.com>
Tue, 1 Mar 2016 11:42:42 +0000 (12:42 +0100)
Most interestingly is also, whether we can link libsystemd.a without
having undefined references (which might be wrongly satisfied by an
externally loaded libsystem shared library.

.gitignore
src/Makefile.am
src/nm-logging.c
src/tests/Makefile.am
src/tests/test-systemd.c [new file with mode: 0644]

index 8b98bf0..0cd4e28 100644 (file)
@@ -264,6 +264,7 @@ test-*.trs
 /src/tests/test-resolvconf-capture
 /src/tests/test-route-manager-fake
 /src/tests/test-route-manager-linux
+/src/tests/test-systemd
 /src/tests/test-utils
 /src/tests/test-wired-defname
 
index 8fd8bba..eea646a 100644 (file)
@@ -184,6 +184,37 @@ libsystemd_nm_la_CPPFLAGS = \
 libsystemd_nm_la_LIBADD = \
        $(GLIB_LIBS)
 
+######################
+# libsystemd-nm-base
+######################
+
+if ENABLE_TESTS
+noinst_LTLIBRARIES += \
+       libNetworkManager-base.la
+
+libNetworkManager_base_la_SOURCES = \
+       nm-core-utils.c \
+       nm-core-utils.h \
+       nm-logging.c \
+       nm-logging.h
+
+libNetworkManager_base_la_CPPFLAGS = \
+       -I$(top_srcdir)/shared \
+       -I$(top_builddir)/shared \
+       -I$(top_srcdir)/libnm-core \
+       -I$(top_builddir)/libnm-core \
+       -I$(top_srcdir)/src/platform \
+       -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
+       -DNO_SYSTEMD_JOURNAL \
+       -DPREFIX=\"$(prefix)\" \
+       -DNMSTATEDIR=\"$(nmstatedir)\" \
+       $(GLIB_CFLAGS)
+
+libNetworkManager_base_la_LIBADD = \
+       $(top_builddir)/libnm-core/libnm-core.la \
+       $(GLIB_LIBS)
+endif
+
 ###########################################
 # NetworkManager
 ###########################################
index 7f0621b..5bb3660 100644 (file)
 #include <strings.h>
 #include <string.h>
 
+#if defined (NO_SYSTEMD_JOURNAL) && defined (SYSTEMD_JOURNAL)
+#undef SYSTEMD_JOURNAL
+#define SYSTEMD_JOURNAL 0
+#endif
+
 #if SYSTEMD_JOURNAL
 #define SD_JOURNAL_SUPPRESS_LOCATION
 #include <systemd/sd-journal.h>
index 26c2ed7..a3447fb 100644 (file)
@@ -23,6 +23,7 @@ noinst_PROGRAMS = \
        test-route-manager-linux \
        test-route-manager-fake \
        test-dcb \
+       test-systemd \
        test-resolvconf-capture \
        test-wired-defname \
        test-utils
@@ -111,6 +112,20 @@ test_wired_defname_SOURCES = \
 test_wired_defname_LDADD = \
        $(top_builddir)/src/libNetworkManager.la
 
+####### systemd test #######
+
+test_systemd_CFLAGS = \
+       "-I$(srcdir)/../" \
+       "-I$(srcdir)/../platform" \
+       "-I$(srcdir)/../systemd/src/systemd"
+
+test_systemd_SOURCES = \
+       test-systemd.c
+
+test_systemd_LDADD = \
+       $(top_builddir)/src/libNetworkManager-base.la \
+       $(top_builddir)/src/libsystemd-nm.la
+
 ####### utils test #######
 
 test_utils_SOURCES = \
@@ -143,6 +158,7 @@ TESTS = \
        test-resolvconf-capture \
        test-general \
        test-general-with-expect \
+       test-systemd \
        test-wired-defname \
        test-utils
 
diff --git a/src/tests/test-systemd.c b/src/tests/test-systemd.c
new file mode 100644 (file)
index 0000000..84ad95b
--- /dev/null
@@ -0,0 +1,53 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2016 Red Hat, Inc.
+ */
+
+#include "nm-default.h"
+
+#include "sd-dhcp-client.h"
+
+#include "nm-test-utils.h"
+
+/*****************************************************************************/
+
+static void
+test_dhcp_create (void)
+{
+       sd_dhcp_client *client4 = NULL;
+       int r;
+
+       r = sd_dhcp_client_new (&client4);
+       g_assert (r == 0);
+       g_assert (client4);
+
+       sd_dhcp_client_unref (client4);
+}
+
+/*****************************************************************************/
+
+NMTST_DEFINE ();
+
+int
+main (int argc, char **argv)
+{
+       nmtst_init_assert_logging (&argc, &argv, "INFO", "ALL");
+
+       g_test_add_func ("/systemd/dhcp/create", test_dhcp_create);
+
+       return g_test_run ();
+}