Files
NetworkManager/shared/nm-test-libnm-utils.h
Thomas Haller 9628aabc2f tests: use libnm via pygobject in tools/test-networkmanager-service.py
tools/test-networkmanager-service.py is our NetworkManager stub server.

NetworkManager uses libnm(-core) heavily, for example to decide whether
a connection verifies (nm_connection_verify()) and for normalizing
connections (nm_connection_normalize()).

If the stub server wants to mimic NetworkManager, it also must use these
function. Luckily, we already can do so, by loading libnm using python
GObject introspection.

We already correctly set GI_TYPELIB_PATH search path, so that the
correct libnm is loaded -- provided that we build with introspection
enabled.

We still need to gracefully fail, if starting the stub server fails.
That requries some extra effort. If the stub server notices that
something is missing, it shall exit with status 77. That will cause
the tests to g_test_skip().
2018-05-11 16:51:20 +02:00

110 lines
4.0 KiB
C

/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2014 - 2015 Red Hat, Inc.
*/
#include "NetworkManager.h"
#include "nm-utils/nm-test-utils.h"
#if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_GLIB
#include "nm-dbus-glib-types.h"
#endif
/*****************************************************************************/
typedef struct {
GDBusConnection *bus;
GDBusProxy *proxy;
GPid pid;
int keepalive_fd;
#if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_GLIB
struct {
DBusGConnection *bus;
} libdbus;
#endif
} NMTstcServiceInfo;
NMTstcServiceInfo *nmtstc_service_init (void);
void nmtstc_service_cleanup (NMTstcServiceInfo *info);
NMTstcServiceInfo *nmtstc_service_available (NMTstcServiceInfo *info);
static inline void _nmtstc_auto_service_cleanup (NMTstcServiceInfo **info)
{
nmtstc_service_cleanup (g_steal_pointer (info));
}
#define NMTSTC_SERVICE_INFO_SETUP(sinfo) \
NM_PRAGMA_WARNING_DISABLE ("-Wunused-variable") \
__attribute__ ((cleanup(_nmtstc_auto_service_cleanup))) NMTstcServiceInfo *sinfo = ({ \
NMTstcServiceInfo *_sinfo; \
\
_sinfo = nmtstc_service_init (); \
if (!nmtstc_service_available (_sinfo)) \
return; \
_sinfo; \
}); \
NM_PRAGMA_WARNING_REENABLE
/*****************************************************************************/
#if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_GLIB
#include "nm-client.h"
#include "nm-remote-settings.h"
NMClient *nmtstc_nm_client_new (void);
NMRemoteSettings *nmtstc_nm_remote_settings_new (void);
#else
NMDevice *nmtstc_service_add_device (NMTstcServiceInfo *info,
NMClient *client,
const char *method,
const char *ifname);
NMDevice * nmtstc_service_add_wired_device (NMTstcServiceInfo *sinfo,
NMClient *client,
const char *ifname,
const char *hwaddr,
const char **subchannels);
#endif
/*****************************************************************************/
void nmtstc_service_add_connection (NMTstcServiceInfo *sinfo,
NMConnection *connection,
gboolean verify_connection,
char **out_path);
void nmtstc_service_add_connection_variant (NMTstcServiceInfo *sinfo,
GVariant *connection,
gboolean verify_connection,
char **out_path);
void nmtstc_service_update_connection (NMTstcServiceInfo *sinfo,
const char *path,
NMConnection *connection,
gboolean verify_connection);
void nmtstc_service_update_connection_variant (NMTstcServiceInfo *sinfo,
const char *path,
GVariant *connection,
gboolean verify_connection);