summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-03-01 08:56:14 +0100
committerThomas Haller <thaller@redhat.com>2016-03-01 12:42:42 +0100
commit51e292885cbe3d49e2f9aa1a93008bf4db70918d (patch)
tree11ab43705903973031ac17632bf5ff1db810cdec
parentadb56d137e36f5ab1143c8ecc090504564599c2a (diff)
downloadNetworkManager-51e292885cbe3d49e2f9aa1a93008bf4db70918d.tar.gz
systemd/tests: add test util for systemd
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.
-rw-r--r--.gitignore1
-rw-r--r--src/Makefile.am31
-rw-r--r--src/nm-logging.c5
-rw-r--r--src/tests/Makefile.am16
-rw-r--r--src/tests/test-systemd.c53
5 files changed, 106 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 8b98bf0ad5..0cd4e28d6e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
diff --git a/src/Makefile.am b/src/Makefile.am
index 8fd8bbaded..eea646a487 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -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
###########################################
diff --git a/src/nm-logging.c b/src/nm-logging.c
index 7f0621b371..5bb3660fa2 100644
--- a/src/nm-logging.c
+++ b/src/nm-logging.c
@@ -32,6 +32,11 @@
#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>
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
index 26c2ed7f55..a3447fbf38 100644
--- a/src/tests/Makefile.am
+++ b/src/tests/Makefile.am
@@ -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
index 0000000000..84ad95ba86
--- /dev/null
+++ b/src/tests/test-systemd.c
@@ -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 ();
+}