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.
This commit is contained in:
Thomas Haller 2016-03-01 08:56:14 +01:00
parent adb56d137e
commit 51e292885c
5 changed files with 106 additions and 0 deletions

1
.gitignore vendored
View 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

View 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
###########################################

View file

@ -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>

View 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

53
src/tests/test-systemd.c Normal file
View file

@ -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 ();
}