tests/network: Copy files from network manager for network panel testing

This copies a number of files from network manager in preparation of
adding network panel tests.
This commit is contained in:
Benjamin Berg 2018-04-04 11:58:54 +02:00 committed by Georges Basile Stavracas Neto
parent aec8c911bb
commit 2ebdb532cf
12 changed files with 4027 additions and 0 deletions

View file

@ -0,0 +1,17 @@
These files are either copied from NetworkManager or just empty files. The
files live in the nn-utils subdirectory as that makes the relative
includes that they contain work fine.
The test-networkmanager-service.py is also from NetworkManager. It is
however extended for our use here.
gsystem-local-alloc.h: shared/nm-utils/gsystem-local-alloc.h
nm-glib.h: shared/nm-utils/nm-glib.h
nm-macros-internal.h: shared/nm-utils/nm-macros-internal.h
nm-default.h: shared/nm-default.h
nm-dbus-compat.h: shared/nm-dbus-compat.h
nm-default.h: shared/nm-default.h
nm-test-utils-impl.c: shared/nm-test-utils-impl.c
nm-shared-utils.h: empty
nm-test-libnm-utils.h: empty
nm-hash-utils.h: empty

View file

@ -0,0 +1,208 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2012 Colin Walters <walters@verbum.org>.
*
* 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., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GSYSTEM_LOCAL_ALLOC_H__
#define __GSYSTEM_LOCAL_ALLOC_H__
#include <gio/gio.h>
G_BEGIN_DECLS
#define GS_DEFINE_CLEANUP_FUNCTION(Type, name, func) \
static inline void name (void *v) \
{ \
func (*(Type*)v); \
}
#define GS_DEFINE_CLEANUP_FUNCTION0(Type, name, func) \
static inline void name (void *v) \
{ \
if (*(Type*)v) \
func (*(Type*)v); \
}
/* These functions shouldn't be invoked directly;
* they are stubs that:
* 1) Take a pointer to the location (typically itself a pointer).
* 2) Provide %NULL-safety where it doesn't exist already (e.g. g_object_unref)
*/
/**
* gs_free:
*
* Call g_free() on a variable location when it goes out of scope.
*/
#define gs_free __attribute__ ((cleanup(gs_local_free)))
GS_DEFINE_CLEANUP_FUNCTION(void*, gs_local_free, g_free)
/**
* gs_unref_object:
*
* Call g_object_unref() on a variable location when it goes out of
* scope. Note that unlike g_object_unref(), the variable may be
* %NULL.
*/
#define gs_unref_object __attribute__ ((cleanup(gs_local_obj_unref)))
GS_DEFINE_CLEANUP_FUNCTION0(GObject*, gs_local_obj_unref, g_object_unref)
/**
* gs_unref_variant:
*
* Call g_variant_unref() on a variable location when it goes out of
* scope. Note that unlike g_variant_unref(), the variable may be
* %NULL.
*/
#define gs_unref_variant __attribute__ ((cleanup(gs_local_variant_unref)))
GS_DEFINE_CLEANUP_FUNCTION0(GVariant*, gs_local_variant_unref, g_variant_unref)
/**
* gs_free_variant_iter:
*
* Call g_variant_iter_free() on a variable location when it goes out of
* scope.
*/
#define gs_free_variant_iter __attribute__ ((cleanup(gs_local_variant_iter_free)))
GS_DEFINE_CLEANUP_FUNCTION0(GVariantIter*, gs_local_variant_iter_free, g_variant_iter_free)
/**
* gs_free_variant_builder:
*
* Call g_variant_builder_unref() on a variable location when it goes out of
* scope.
*/
#define gs_unref_variant_builder __attribute__ ((cleanup(gs_local_variant_builder_unref)))
GS_DEFINE_CLEANUP_FUNCTION0(GVariantBuilder*, gs_local_variant_builder_unref, g_variant_builder_unref)
/**
* gs_unref_array:
*
* Call g_array_unref() on a variable location when it goes out of
* scope. Note that unlike g_array_unref(), the variable may be
* %NULL.
*/
#define gs_unref_array __attribute__ ((cleanup(gs_local_array_unref)))
GS_DEFINE_CLEANUP_FUNCTION0(GArray*, gs_local_array_unref, g_array_unref)
/**
* gs_unref_ptrarray:
*
* Call g_ptr_array_unref() on a variable location when it goes out of
* scope. Note that unlike g_ptr_array_unref(), the variable may be
* %NULL.
*/
#define gs_unref_ptrarray __attribute__ ((cleanup(gs_local_ptrarray_unref)))
GS_DEFINE_CLEANUP_FUNCTION0(GPtrArray*, gs_local_ptrarray_unref, g_ptr_array_unref)
/**
* gs_unref_hashtable:
*
* Call g_hash_table_unref() on a variable location when it goes out
* of scope. Note that unlike g_hash_table_unref(), the variable may
* be %NULL.
*/
#define gs_unref_hashtable __attribute__ ((cleanup(gs_local_hashtable_unref)))
GS_DEFINE_CLEANUP_FUNCTION0(GHashTable*, gs_local_hashtable_unref, g_hash_table_unref)
/**
* gs_free_list:
*
* Call g_list_free() on a variable location when it goes out
* of scope.
*/
#define gs_free_list __attribute__ ((cleanup(gs_local_free_list)))
GS_DEFINE_CLEANUP_FUNCTION(GList*, gs_local_free_list, g_list_free)
/**
* gs_free_slist:
*
* Call g_slist_free() on a variable location when it goes out
* of scope.
*/
#define gs_free_slist __attribute__ ((cleanup(gs_local_free_slist)))
GS_DEFINE_CLEANUP_FUNCTION(GSList*, gs_local_free_slist, g_slist_free)
/**
* gs_free_checksum:
*
* Call g_checksum_free() on a variable location when it goes out
* of scope. Note that unlike g_checksum_free(), the variable may
* be %NULL.
*/
#define gs_free_checksum __attribute__ ((cleanup(gs_local_checksum_free)))
GS_DEFINE_CLEANUP_FUNCTION0(GChecksum*, gs_local_checksum_free, g_checksum_free)
/**
* gs_unref_bytes:
*
* Call g_bytes_unref() on a variable location when it goes out
* of scope. Note that unlike g_bytes_unref(), the variable may
* be %NULL.
*/
#define gs_unref_bytes __attribute__ ((cleanup(gs_local_bytes_unref)))
GS_DEFINE_CLEANUP_FUNCTION0(GBytes*, gs_local_bytes_unref, g_bytes_unref)
/**
* gs_strfreev:
*
* Call g_strfreev() on a variable location when it goes out of scope.
*/
#define gs_strfreev __attribute__ ((cleanup(gs_local_strfreev)))
GS_DEFINE_CLEANUP_FUNCTION(char**, gs_local_strfreev, g_strfreev)
/**
* gs_free_error:
*
* Call g_error_free() on a variable location when it goes out of scope.
*/
#define gs_free_error __attribute__ ((cleanup(gs_local_free_error)))
GS_DEFINE_CLEANUP_FUNCTION0(GError*, gs_local_free_error, g_error_free)
/**
* gs_unref_keyfile:
*
* Call g_key_file_unref() on a variable location when it goes out of scope.
*/
#define gs_unref_keyfile __attribute__ ((cleanup(gs_local_keyfile_unref)))
GS_DEFINE_CLEANUP_FUNCTION0(GKeyFile*, gs_local_keyfile_unref, g_key_file_unref)
static inline void
gs_cleanup_close_fdp (int *fdp)
{
int fd;
g_assert (fdp);
fd = *fdp;
if (fd != -1)
(void) close (fd);
}
/**
* gs_fd_close:
*
* Call close() on a variable location when it goes out of scope.
*/
#define gs_fd_close __attribute__((cleanup(gs_cleanup_close_fdp)))
G_END_DECLS
#endif

View file

@ -0,0 +1,74 @@
/* -*- 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 of the License, 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 2015 Red Hat, Inc.
*/
#ifndef __NM_DBUS_COMPAT_H__
#define __NM_DBUS_COMPAT_H__
/* Copied from <dbus/dbus-shared.h> */
/* Bus names */
/** The bus name used to talk to the bus itself. */
#define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
/* Paths */
/** The object path used to talk to the bus itself. */
#define DBUS_PATH_DBUS "/org/freedesktop/DBus"
/** The object path used in local/in-process-generated messages. */
#define DBUS_PATH_LOCAL "/org/freedesktop/DBus/Local"
/* Interfaces, these #define don't do much other than
* catch typos at compile time
*/
/** The interface exported by the object with #DBUS_SERVICE_DBUS and #DBUS_PATH_DBUS */
#define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
/** The interface supported by introspectable objects */
#define DBUS_INTERFACE_INTROSPECTABLE "org.freedesktop.DBus.Introspectable"
/** The interface supported by objects with properties */
#define DBUS_INTERFACE_PROPERTIES "org.freedesktop.DBus.Properties"
/** The interface supported by most dbus peers */
#define DBUS_INTERFACE_PEER "org.freedesktop.DBus.Peer"
/** This is a special interface whose methods can only be invoked
* by the local implementation (messages from remote apps aren't
* allowed to specify this interface).
*/
#define DBUS_INTERFACE_LOCAL "org.freedesktop.DBus.Local"
/* Owner flags */
#define DBUS_NAME_FLAG_ALLOW_REPLACEMENT 0x1 /**< Allow another service to become the primary owner if requested */
#define DBUS_NAME_FLAG_REPLACE_EXISTING 0x2 /**< Request to replace the current primary owner */
#define DBUS_NAME_FLAG_DO_NOT_QUEUE 0x4 /**< If we can not become the primary owner do not place us in the queue */
/* Replies to request for a name */
#define DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER 1 /**< Service has become the primary owner of the requested name */
#define DBUS_REQUEST_NAME_REPLY_IN_QUEUE 2 /**< Service could not become the primary owner and has been placed in the queue */
#define DBUS_REQUEST_NAME_REPLY_EXISTS 3 /**< Service is already in the queue */
#define DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER 4 /**< Service is already the primary owner */
/* Replies to releasing a name */
#define DBUS_RELEASE_NAME_REPLY_RELEASED 1 /**< Service was released from the given name */
#define DBUS_RELEASE_NAME_REPLY_NON_EXISTENT 2 /**< The given name does not exist on the bus */
#define DBUS_RELEASE_NAME_REPLY_NOT_OWNER 3 /**< Service is not an owner of the given name */
/* Replies to service starts */
#define DBUS_START_REPLY_SUCCESS 1 /**< Service was auto started */
#define DBUS_START_REPLY_ALREADY_RUNNING 2 /**< Service was already running */
#endif /* __NM_DBUS_COMPAT_H__ */

View file

@ -0,0 +1,316 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* 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.
*
* (C) Copyright 2015 Red Hat, Inc.
*/
#ifndef __NM_DEFAULT_H__
#define __NM_DEFAULT_H__
#define NM_NETWORKMANAGER_COMPILATION_WITH_GLIB (1 << 0)
#define NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_LIB (1 << 1)
#define NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_PROG (1 << 2)
#define NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM (1 << 3)
#define NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_PRIVATE (1 << 4)
#define NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE (1 << 5)
#define NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_INTERNAL (1 << 6)
#define NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_PRIVATE (1 << 7)
#define NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_UTIL (1 << 8)
#define NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_GLIB (1 << 9)
#define NM_NETWORKMANAGER_COMPILATION_WITH_DAEMON (1 << 10)
#define NM_NETWORKMANAGER_COMPILATION_WITH_SYSTEMD (1 << 11)
#define NM_NETWORKMANAGER_COMPILATION_LIBNM_CORE ( 0 \
| NM_NETWORKMANAGER_COMPILATION_WITH_GLIB \
| NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_LIB \
| NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE \
| NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_PRIVATE \
| NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_INTERNAL \
)
#define NM_NETWORKMANAGER_COMPILATION_LIBNM ( 0 \
| NM_NETWORKMANAGER_COMPILATION_WITH_GLIB \
| NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_LIB \
| NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM \
| NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_PRIVATE \
| NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE \
| NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_INTERNAL \
)
#define NM_NETWORKMANAGER_COMPILATION_LIBNM_UTIL ( 0 \
| NM_NETWORKMANAGER_COMPILATION_WITH_GLIB \
| NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_LIB \
| NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_UTIL \
)
#define NM_NETWORKMANAGER_COMPILATION_LIBNM_GLIB ( 0 \
| NM_NETWORKMANAGER_COMPILATION_LIBNM_UTIL \
| NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_GLIB \
)
#define NM_NETWORKMANAGER_COMPILATION_CLIENT ( 0 \
| NM_NETWORKMANAGER_COMPILATION_WITH_GLIB \
| NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_PROG \
| NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM \
| NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE \
)
#define NM_NETWORKMANAGER_COMPILATION_DAEMON ( 0 \
| NM_NETWORKMANAGER_COMPILATION_WITH_GLIB \
| NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_PROG \
| NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE \
| NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_INTERNAL \
| NM_NETWORKMANAGER_COMPILATION_WITH_DAEMON \
)
#define NM_NETWORKMANAGER_COMPILATION_SYSTEMD ( 0 \
| NM_NETWORKMANAGER_COMPILATION_DAEMON \
| NM_NETWORKMANAGER_COMPILATION_WITH_SYSTEMD \
)
#define NM_NETWORKMANAGER_COMPILATION_GLIB ( 0 \
| NM_NETWORKMANAGER_COMPILATION_WITH_GLIB \
)
#ifndef NETWORKMANAGER_COMPILATION
#error Define NETWORKMANAGER_COMPILATION accordingly
#endif
#ifndef G_LOG_DOMAIN
#if defined(NETWORKMANAGER_COMPILATION_TEST)
#define G_LOG_DOMAIN "test"
#elif NETWORKMANAGER_COMPILATION & NM_NETWORKMANAGER_COMPILATION_WITH_DAEMON
#define G_LOG_DOMAIN "NetworkManager"
#else
#error Need to define G_LOG_DOMAIN
#endif
#elif defined (NETWORKMANAGER_COMPILATION_TEST) || (NETWORKMANAGER_COMPILATION & NM_NETWORKMANAGER_COMPILATION_WITH_DAEMON)
#error Do not define G_LOG_DOMAIN with NM_NETWORKMANAGER_COMPILATION_WITH_DAEMON
#endif
/*****************************************************************************/
/* always include these headers for our internal source files. */
#ifndef ___CONFIG_H__
#define ___CONFIG_H__
#include <config.h>
#endif
/* for internal compilation we don't want the deprecation macros
* to be in effect. Define the widest range of versions to effectively
* disable deprecation checks */
#define NM_VERSION_MIN_REQUIRED NM_VERSION_0_9_8
#ifndef NM_MORE_ASSERTS
#define NM_MORE_ASSERTS 0
#endif
#if NM_MORE_ASSERTS == 0
/* The cast macros like NM_TYPE() are implemented via G_TYPE_CHECK_INSTANCE_CAST()
* and _G_TYPE_CIC(). The latter, by default performs runtime checks of the type
* by calling g_type_check_instance_cast().
* This check has a certain overhead without being helpful.
*
* Example 1:
* static void foo (NMType *obj)
* {
* access_obj_without_check (obj);
* }
* foo ((NMType *) obj);
* // There is no runtime check and passing an invalid pointer
* // leads to a crash.
*
* Example 2:
* static void foo (NMType *obj)
* {
* access_obj_without_check (obj);
* }
* foo (NM_TYPE (obj));
* // There is a runtime check which prints a g_warning(), but that doesn't
* // avoid the crash as NM_TYPE() cannot do anything then passing on the
* // invalid pointer.
*
* Example 3:
* static void foo (NMType *obj)
* {
* g_return_if_fail (NM_IS_TYPE (obj));
* access_obj_without_check (obj);
* }
* foo ((NMType *) obj);
* // There is a runtime check which prints a g_critical() which also avoids
* // the crash. That is actually helpful to catch bugs and avoid crashes.
*
* Example 4:
* static void foo (NMType *obj)
* {
* g_return_if_fail (NM_IS_TYPE (obj));
* access_obj_without_check (obj);
* }
* foo (NM_TYPE (obj));
* // The runtime check is performed twice, with printing a g_warning() and
* // a g_critical() and avoiding the crash.
*
* Example 3 is how it should be done. Type checks in NM_TYPE() are pointless.
* Disable them for our production builds.
*/
#ifndef G_DISABLE_CAST_CHECKS
#define G_DISABLE_CAST_CHECKS
#endif
#endif
#if NM_MORE_ASSERTS == 0
#ifndef G_DISABLE_CAST_CHECKS
/* Unless compiling with G_DISABLE_CAST_CHECKS, glib performs type checking
* during G_VARIANT_TYPE() via g_variant_type_checked_(). This is not necesary
* because commonly this cast is needed during something like
*
* g_variant_builder_init (&props, G_VARIANT_TYPE ("a{sv}"));
*
* Note that in if the variant type would be invalid, the check still
* wouldn't make the buggy code magically work. Instead of passing a
* bogus type string (bad), it would pass %NULL to g_variant_builder_init()
* (also bad).
*
* Also, a function like g_variant_builder_init() already validates
* the input type via something like
*
* g_return_if_fail (g_variant_type_is_container (type));
*
* So, by having G_VARIANT_TYPE() also validate the type, we validate
* twice, whereas the first validation is rather pointless because it
* doesn't prevent the function to be called with invalid arguments.
*
* Just patch G_VARIANT_TYPE() to perform no check.
*/
#undef G_VARIANT_TYPE
#define G_VARIANT_TYPE(type_string) ((const GVariantType *) (type_string))
#endif
#endif
#include <stdlib.h>
/*****************************************************************************/
#if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_GLIB
#include <glib.h>
#if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_PROG
#if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_LIB
#error Cannot define NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_PROG and NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_LIB
#endif
#include <glib/gi18n.h>
#elif (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_LIB
#include <glib/gi18n-lib.h>
#endif
/*****************************************************************************/
#if NM_MORE_ASSERTS == 0
/* glib assertions (g_return_*(), g_assert*()) contain a textual representation
* of the checked statement. This part of the assertion blows up the size of the
* binary. Unless we compile a debug-build with NM_MORE_ASSERTS, drop these
* parts. Note that the failed assertion still prints the file and line where the
* assertion fails. That shall suffice. */
static inline void
_nm_g_return_if_fail_warning (const char *log_domain,
const char *file,
int line)
{
char file_buf[256 + 15];
g_snprintf (file_buf, sizeof (file_buf), "((%s:%d))", file, line);
g_return_if_fail_warning (log_domain, file_buf, "<dropped>");
}
#define g_return_if_fail_warning(log_domain, pretty_function, expression) \
_nm_g_return_if_fail_warning (log_domain, __FILE__, __LINE__)
#define g_assertion_message_expr(domain, file, line, func, expr) \
g_assertion_message_expr(domain, file, line, "<unknown-fcn>", (expr) ? "<dropped>" : NULL)
#undef g_return_val_if_reached
#define g_return_val_if_reached(val) \
G_STMT_START { \
g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_CRITICAL, \
"file %s: line %d (%s): should not be reached", \
__FILE__, \
__LINE__, \
"<dropped>"); \
return (val); \
} G_STMT_END
#undef g_return_if_reached
#define g_return_if_reached() \
G_STMT_START { \
g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_CRITICAL, \
"file %s: line %d (%s): should not be reached", \
__FILE__, \
__LINE__, \
"<dropped>"); \
return; \
} G_STMT_END
#define NM_ASSERT_G_RETURN_EXPR(expr) "<dropped>"
#define NM_ASSERT_NO_MSG 1
#else
#define NM_ASSERT_G_RETURN_EXPR(expr) ""expr""
#define NM_ASSERT_NO_MSG 0
#endif
/*****************************************************************************/
#include "nm-utils/nm-macros-internal.h"
#include "nm-utils/nm-shared-utils.h"
#if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_UTIL
/* no hash-utils in legacy code. */
#else
#include "nm-utils/nm-hash-utils.h"
#endif
/*****************************************************************************/
#if (NETWORKMANAGER_COMPILATION) & (NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE | NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_UTIL)
#include "nm-version.h"
#endif
/*****************************************************************************/
#if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_DAEMON
#include "nm-types.h"
#include "nm-logging.h"
#endif
#if ((NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM) && !((NETWORKMANAGER_COMPILATION) & (NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_PRIVATE | NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_INTERNAL))
#include "NetworkManager.h"
#endif
#endif /* NM_NETWORKMANAGER_COMPILATION_WITH_GLIB */
/*****************************************************************************/
#endif /* __NM_DEFAULT_H__ */

View file

@ -0,0 +1,125 @@
/* -*- 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 of the License, 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 2008 - 2018 Red Hat, Inc.
*/
#ifndef __NM_GLIB_H__
#define __NM_GLIB_H__
#include <gio/gio.h>
#include <string.h>
#include "gsystem-local-alloc.h"
#ifdef __clang__
#undef G_GNUC_BEGIN_IGNORE_DEPRECATIONS
#undef G_GNUC_END_IGNORE_DEPRECATIONS
#define G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
#define G_GNUC_END_IGNORE_DEPRECATIONS \
_Pragma("clang diagnostic pop")
#endif
/* g_assert_cmpmem() is only available since glib 2.46. */
#if !GLIB_CHECK_VERSION (2, 45, 7)
#define g_assert_cmpmem(m1, l1, m2, l2) G_STMT_START {\
gconstpointer __m1 = m1, __m2 = m2; \
int __l1 = l1, __l2 = l2; \
if (__l1 != __l2) \
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
#l1 " (len(" #m1 ")) == " #l2 " (len(" #m2 "))", __l1, "==", __l2, 'i'); \
else if (memcmp (__m1, __m2, __l1) != 0) \
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
"assertion failed (" #m1 " == " #m2 ")"); \
} G_STMT_END
#endif
/* Rumtime check for glib version. First do a compile time check which
* (if satisfied) shortcuts the runtime check. */
static inline gboolean
nm_glib_check_version (guint major, guint minor, guint micro)
{
return GLIB_CHECK_VERSION (major, minor, micro)
|| ( ( glib_major_version > major)
|| ( glib_major_version == major
&& glib_minor_version > minor)
|| ( glib_major_version == major
&& glib_minor_version == minor
&& glib_micro_version < micro));
}
#if !GLIB_CHECK_VERSION(2, 44, 0)
static inline gpointer
g_steal_pointer (gpointer pp)
{
gpointer *ptr = (gpointer *) pp;
gpointer ref;
ref = *ptr;
*ptr = NULL;
return ref;
}
/* type safety */
#define g_steal_pointer(pp) \
(0 ? (*(pp)) : (g_steal_pointer) (pp))
#endif
static inline gboolean
_nm_g_strv_contains (const gchar * const *strv,
const gchar *str)
{
#if !GLIB_CHECK_VERSION(2, 44, 0)
g_return_val_if_fail (strv != NULL, FALSE);
g_return_val_if_fail (str != NULL, FALSE);
for (; *strv != NULL; strv++) {
if (g_str_equal (str, *strv))
return TRUE;
}
return FALSE;
#else
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
return g_strv_contains (strv, str);
G_GNUC_END_IGNORE_DEPRECATIONS
#endif
}
#define g_strv_contains _nm_g_strv_contains
#if !GLIB_CHECK_VERSION (2, 56, 0)
#define g_object_ref(Obj) ((typeof(Obj)) g_object_ref (Obj))
#define g_object_ref_sink(Obj) ((typeof(Obj)) g_object_ref_sink (Obj))
#endif
#ifndef g_autofree
/* we still don't rely on recent glib to provide g_autofree. Hence, we continue
* to use our gs_* free macros that we took from libgsystem.
*
* To ease migration towards g_auto*, add a compat define for g_autofree. */
#define g_autofree gs_free
#endif
#endif /* __NM_GLIB_H__ */

View file

File diff suppressed because it is too large Load diff

View file

View file

@ -0,0 +1,105 @@
/* -*- 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-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);
static inline void _nmtstc_auto_service_cleanup (NMTstcServiceInfo **info)
{
if (info && *info) {
nmtstc_service_cleanup (*info);
*info = NULL;
}
}
#define NMTSTC_SERVICE_INFO_SETUP(sinfo) \
NM_PRAGMA_WARNING_DISABLE ("-Wunused-variable") \
__attribute__ ((cleanup(_nmtstc_auto_service_cleanup))) NMTstcServiceInfo *sinfo = nmtstc_service_init (); \
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);

View file

@ -0,0 +1,457 @@
/* -*- 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 2010 - 2015 Red Hat, Inc.
*
*/
#include "nm-default.h"
#include <string.h>
#include "NetworkManager.h"
#include "nm-dbus-compat.h"
#include "nm-test-libnm-utils.h"
/*****************************************************************************/
static gboolean
name_exists (GDBusConnection *c, const char *name)
{
GVariant *reply;
gboolean exists = FALSE;
reply = g_dbus_connection_call_sync (c,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"GetNameOwner",
g_variant_new ("(s)", name),
NULL,
G_DBUS_CALL_FLAGS_NO_AUTO_START,
-1,
NULL,
NULL);
if (reply != NULL) {
exists = TRUE;
g_variant_unref (reply);
}
return exists;
}
#if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_GLIB
static DBusGProxy *
_libdbus_create_proxy_test (DBusGConnection *bus)
{
DBusGProxy *proxy;
proxy = dbus_g_proxy_new_for_name (bus,
NM_DBUS_SERVICE,
NM_DBUS_PATH,
"org.freedesktop.NetworkManager.LibnmGlibTest");
g_assert (proxy);
dbus_g_proxy_set_default_timeout (proxy, G_MAXINT);
return proxy;
}
#endif
NMTstcServiceInfo *
nmtstc_service_init (void)
{
NMTstcServiceInfo *info;
const char *args[] = { TEST_NM_PYTHON, TEST_NM_SERVICE, NULL };
GError *error = NULL;
int i;
info = g_malloc0 (sizeof (*info));
info->bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
g_assert_no_error (error);
/* Spawn the test service. info->keepalive_fd will be a pipe to the service's
* stdin; if it closes, the service will exit immediately. We use this to
* make sure the service exits if the test program crashes.
*/
g_spawn_async_with_pipes (NULL, (char **) args, NULL,
G_SPAWN_SEARCH_PATH,
NULL, NULL,
&info->pid, &info->keepalive_fd, NULL, NULL, &error);
g_assert_no_error (error);
/* Wait until the service is registered on the bus */
for (i = 1000; i > 0; i--) {
if (name_exists (info->bus, "org.freedesktop.NetworkManager"))
break;
g_usleep (G_USEC_PER_SEC / 50);
}
g_assert (i > 0);
/* Grab a proxy to our fake NM service to trigger tests */
info->proxy = g_dbus_proxy_new_sync (info->bus,
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS |
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
NULL,
NM_DBUS_SERVICE,
NM_DBUS_PATH,
"org.freedesktop.NetworkManager.LibnmGlibTest",
NULL, &error);
g_assert_no_error (error);
#if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_GLIB
info->libdbus.bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
g_assert_no_error (error);
g_assert (info->libdbus.bus);
#endif
return info;
}
void
nmtstc_service_cleanup (NMTstcServiceInfo *info)
{
int i;
g_object_unref (info->proxy);
kill (info->pid, SIGTERM);
/* Wait until the bus notices the service is gone */
for (i = 100; i > 0; i--) {
if (!name_exists (info->bus, "org.freedesktop.NetworkManager"))
break;
g_usleep (G_USEC_PER_SEC / 50);
}
g_assert (i > 0);
g_object_unref (info->bus);
nm_close (info->keepalive_fd);
#if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_GLIB
g_clear_pointer (&info->libdbus.bus, dbus_g_connection_unref);
#endif
memset (info, 0, sizeof (*info));
g_free (info);
}
#if !((NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_GLIB)
typedef struct {
GMainLoop *loop;
const char *ifname;
char *path;
NMDevice *device;
} AddDeviceInfo;
static void
device_added_cb (NMClient *client,
NMDevice *device,
gpointer user_data)
{
AddDeviceInfo *info = user_data;
g_assert (device);
g_assert_cmpstr (nm_object_get_path (NM_OBJECT (device)), ==, info->path);
g_assert_cmpstr (nm_device_get_iface (device), ==, info->ifname);
info->device = device;
g_main_loop_quit (info->loop);
}
static gboolean
timeout (gpointer user_data)
{
g_assert_not_reached ();
return G_SOURCE_REMOVE;
}
static GVariant *
call_add_wired_device (GDBusProxy *proxy, const char *ifname, const char *hwaddr,
const char **subchannels, GError **error)
{
const char *empty[] = { NULL };
if (!hwaddr)
hwaddr = "/";
if (!subchannels)
subchannels = empty;
return g_dbus_proxy_call_sync (proxy,
"AddWiredDevice",
g_variant_new ("(ss^as)", ifname, hwaddr, subchannels),
G_DBUS_CALL_FLAGS_NO_AUTO_START,
3000,
NULL,
error);
}
static GVariant *
call_add_device (GDBusProxy *proxy, const char *method, const char *ifname, GError **error)
{
return g_dbus_proxy_call_sync (proxy,
method,
g_variant_new ("(s)", ifname),
G_DBUS_CALL_FLAGS_NO_AUTO_START,
3000,
NULL,
error);
}
static NMDevice *
add_device_common (NMTstcServiceInfo *sinfo, NMClient *client,
const char *method, const char *ifname,
const char *hwaddr, const char **subchannels)
{
AddDeviceInfo info;
GError *error = NULL;
GVariant *ret;
guint timeout_id;
if (g_strcmp0 (method, "AddWiredDevice") == 0)
ret = call_add_wired_device (sinfo->proxy, ifname, hwaddr, subchannels, &error);
else
ret = call_add_device (sinfo->proxy, method, ifname, &error);
g_assert_no_error (error);
g_assert (ret);
g_assert_cmpstr (g_variant_get_type_string (ret), ==, "(o)");
g_variant_get (ret, "(o)", &info.path);
g_variant_unref (ret);
/* Wait for libnm to find the device */
info.ifname = ifname;
info.loop = g_main_loop_new (NULL, FALSE);
g_signal_connect (client, "device-added",
G_CALLBACK (device_added_cb), &info);
timeout_id = g_timeout_add_seconds (5, timeout, NULL);
g_main_loop_run (info.loop);
g_source_remove (timeout_id);
g_signal_handlers_disconnect_by_func (client, device_added_cb, &info);
g_free (info.path);
g_main_loop_unref (info.loop);
return info.device;
}
NMDevice *
nmtstc_service_add_device (NMTstcServiceInfo *sinfo, NMClient *client,
const char *method, const char *ifname)
{
return add_device_common (sinfo, client, method, ifname, NULL, NULL);
}
NMDevice *
nmtstc_service_add_wired_device (NMTstcServiceInfo *sinfo, NMClient *client,
const char *ifname, const char *hwaddr,
const char **subchannels)
{
return add_device_common (sinfo, client, "AddWiredDevice", ifname, hwaddr, subchannels);
}
#endif
void
nmtstc_service_add_connection (NMTstcServiceInfo *sinfo,
NMConnection *connection,
gboolean verify_connection,
char **out_path)
{
#if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_GLIB
gs_unref_hashtable GHashTable *new_settings = NULL;
gboolean success;
gs_free_error GError *error = NULL;
gs_free char *path = NULL;
gs_unref_object DBusGProxy *proxy = NULL;
g_assert (sinfo);
g_assert (NM_IS_CONNECTION (connection));
new_settings = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL);
proxy = _libdbus_create_proxy_test (sinfo->libdbus.bus);
success = dbus_g_proxy_call (proxy,
"AddConnection",
&error,
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, new_settings,
G_TYPE_BOOLEAN, verify_connection,
G_TYPE_INVALID,
DBUS_TYPE_G_OBJECT_PATH, &path,
G_TYPE_INVALID);
g_assert_no_error (error);
g_assert (success);
g_assert (path && *path);
if (out_path)
*out_path = g_strdup (path);
#else
nmtstc_service_add_connection_variant (sinfo,
nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL),
verify_connection,
out_path);
#endif
}
void
nmtstc_service_add_connection_variant (NMTstcServiceInfo *sinfo,
GVariant *connection,
gboolean verify_connection,
char **out_path)
{
GVariant *result;
GError *error = NULL;
g_assert (sinfo);
g_assert (G_IS_DBUS_PROXY (sinfo->proxy));
g_assert (g_variant_is_of_type (connection, G_VARIANT_TYPE ("a{sa{sv}}")));
result = g_dbus_proxy_call_sync (sinfo->proxy,
"AddConnection",
g_variant_new ("(vb)", connection, verify_connection),
G_DBUS_CALL_FLAGS_NO_AUTO_START,
3000,
NULL,
&error);
g_assert_no_error (error);
g_assert (g_variant_is_of_type (result, G_VARIANT_TYPE ("(o)")));
if (out_path)
g_variant_get (result, "(o)", out_path);
g_variant_unref (result);
}
void
nmtstc_service_update_connection (NMTstcServiceInfo *sinfo,
const char *path,
NMConnection *connection,
gboolean verify_connection)
{
if (!path)
path = nm_connection_get_path (connection);
g_assert (path);
#if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_GLIB
{
gs_unref_hashtable GHashTable *new_settings = NULL;
gboolean success;
gs_free_error GError *error = NULL;
gs_unref_object DBusGProxy *proxy = NULL;
g_assert (sinfo);
g_assert (NM_IS_CONNECTION (connection));
new_settings = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL);
proxy = _libdbus_create_proxy_test (sinfo->libdbus.bus);
success = dbus_g_proxy_call (proxy,
"UpdateConnection",
&error,
DBUS_TYPE_G_OBJECT_PATH, path,
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, new_settings,
G_TYPE_BOOLEAN, verify_connection,
G_TYPE_INVALID,
G_TYPE_INVALID);
g_assert_no_error (error);
g_assert (success);
}
#else
nmtstc_service_update_connection_variant (sinfo,
path,
nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL),
verify_connection);
#endif
}
void
nmtstc_service_update_connection_variant (NMTstcServiceInfo *sinfo,
const char *path,
GVariant *connection,
gboolean verify_connection)
{
GVariant *result;
GError *error = NULL;
g_assert (sinfo);
g_assert (G_IS_DBUS_PROXY (sinfo->proxy));
g_assert (g_variant_is_of_type (connection, G_VARIANT_TYPE ("a{sa{sv}}")));
g_assert (path && path[0] == '/');
result = g_dbus_proxy_call_sync (sinfo->proxy,
"UpdateConnection",
g_variant_new ("(ovb)", path, connection, verify_connection),
G_DBUS_CALL_FLAGS_NO_AUTO_START,
3000,
NULL,
&error);
g_assert_no_error (error);
g_assert (g_variant_is_of_type (result, G_VARIANT_TYPE ("()")));
g_variant_unref (result);
}
/*****************************************************************************/
#if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_GLIB
NMClient *
nmtstc_nm_client_new (void)
{
NMClient *client;
DBusGConnection *bus;
GError *error = NULL;
gboolean success;
bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
g_assert_no_error (error);
g_assert (bus);
client = g_object_new (NM_TYPE_CLIENT,
NM_OBJECT_DBUS_CONNECTION, bus,
NM_OBJECT_DBUS_PATH, NM_DBUS_PATH,
NULL);
g_assert (client != NULL);
dbus_g_connection_unref (bus);
success = g_initable_init (G_INITABLE (client), NULL, &error);
g_assert_no_error (error);
g_assert (success == TRUE);
return client;
}
NMRemoteSettings *
nmtstc_nm_remote_settings_new (void)
{
NMRemoteSettings *settings;
DBusGConnection *bus;
GError *error = NULL;
bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
g_assert_no_error (error);
g_assert (bus);
settings = nm_remote_settings_new (bus);
g_assert (settings);
dbus_g_connection_unref (bus);
return settings;
}
#endif
/*****************************************************************************/

View file

File diff suppressed because it is too large Load diff