summaryrefslogtreecommitdiff
path: root/shared/nm-test-utils.h
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-05-31 14:31:29 +0200
committerThomas Haller <thaller@redhat.com>2016-06-01 13:30:00 +0200
commit19ea8f44b7a3931ccd038cb0afd48a09fd403413 (patch)
treeb0cf018ca749ffef9b0e6ec0ae4c2c2be8311dfd /shared/nm-test-utils.h
parent70d194c159c80266140157db535700f8e44dbe0b (diff)
parentec53ed2cbaab754ddf1283658b5adfba8134e757 (diff)
downloadNetworkManager-19ea8f44b7a3931ccd038cb0afd48a09fd403413.tar.gz
all: merge branch 'master' into nm-1-2th/nm-1-2-merge
Since releasing 1.2.0, we maintain a stable branch 'nm-1-2' and implement new features on 'master'. Occasionally, we backport patches by cherry-picking from 'master'. While developing RHEL-7.3, we want essentially all those features and fixes from 'master' also show up in final RHEL-7.3, because that largely determines our priorities. One way to get 'master' stuff into RHEL-7.3, would be to release 1.4.0, and bring that to RHEL-7.3. The downside is, that we already have downstreams as a user of 'nm-1-2' branch (Ubuntu 16.04 LTS). Obviously, there are many useful and important fixes on 'master' that also should reach downstream. Would downstream also rebase with us to 1.4.0? Do we want to invest the effort to heavily maintain both a 'nm-1-4' and 'nm-1-2' branch upstream? After releasing 1.4.0, upstream has less motivation for the additional work to maintain an old-stable 'nm-1-2' branch. So I think this either means more work for upstream, or less upstream help with old-stable branch. The latter possibly also means a worse expirience for 'nm-1-2' users. The alternative is to bring 'nm-1-2' to RHEL-7.3, but that means we backport essentially everything from 'master'. Of course, that temporarily destabilizes our 'nm-1-2' somewhat (our 'master' is in a decent shape, so it shouldn't be that bad). It also means, that 'nm-1-2' will see large development/backporting efforts and thus our upstream stable branch isn't what one would traditionally consider a bugfix-only, stable branch. This is also exactly what we did for 'nm-1-0' branch at the RHEL-7.2 time and although it has downsides, I think it is preferable to above option. Upstream is not going to maintain a bugfix-only 'nm-1-2' branch. If somebody wants that, he must be prepared to do the work and maintain such a "stable" branch based on 1.2.2 himself. Do note, that 'master' is supposed to be backward compatible, and all the gazillion of changes that happend there are considered to be an improvement. Thus, we bring all those improvements to 'nm-1-2', not only bugfixes. Also note, that after this large merge we are going to take the time to test and fix possible regressions before releasing 1.2.4. You can also think of 1.2.4 as a new backward compatible version of NetworkManager and 'master' was the development branch towards that. Now, instead of cherry-picking basically everything, re-merge 'master' into 'nm-1-2'. The outcome is pretty similar, the difference is: + doing it in one rush is considerabily less work, and you can easily verify that the backports are correct via `git diff master`. + we anyway backport everything. Thus a real merge in our git history better represents what is happening. + with a real merge, git has a new merge-parent and future backports will less conflict. - we don't have a fine-grained history of cherry-picked patches on 'nm-1-2'. Instead, there is only this one merge-commit. Of course, the real history is all here and comes from 'master', on HEAD^2. - it also means, if downstream wants to patch 1.2.2 release, it must find the appropriate patch on HEAD^2. - the large merge plays less nice with git-annotate and git-bisect, but still acceptable. I think the time to do this is good, because - 'master' is in a relatively good shape - there are many useful fixes to backport - 1.2.4 is still a bit out, and we can find regressions that this merge may cause. - RHEL-7.3 is even farther away and thus all the testing effort immediately benefits 'nm-1-2'. Yet another alternative to a real merge or extensive cherry-picking would be to do a `git merge --squash master`. However, I think that a real merge better expresses what actually happened. Conflicts: clients/cli/settings.c clients/common/nm-vpn-helpers.c configure.ac libnm-core/Makefile.am libnm-core/nm-vpn-editor-plugin.c man/common.ent.in po/pt_BR.po po/sv.po shared/nm-macros-internal.h shared/nm-test-utils.h shared/nm-version-macros.h.in src/devices/bluetooth/nm-bluez-device.c src/devices/nm-device-ethernet.c src/devices/nm-device.c src/devices/nm-device.h src/devices/wwan/nm-modem-broadband.c src/dhcp-manager/nm-dhcp-systemd.c src/dns-manager/nm-dns-dnsmasq.c src/dns-manager/nm-dns-manager.c src/dnsmasq-manager/tests/test-dnsmasq-utils.c src/nm-auth-subject.c src/nm-connection-provider.c src/nm-connection-provider.h src/nm-core-utils.c src/nm-ip4-config.c src/nm-ip6-config.c src/nm-manager.c src/platform/nm-fake-platform.c src/platform/nm-linux-platform.c src/platform/nm-platform-utils.c src/platform/nm-platform-utils.h src/platform/nm-platform.c src/platform/nm-platform.h src/ppp-manager/nm-ppp-manager.c src/settings/nm-settings.c src/tests/test-ip4-config.c src/vpn-manager/nm-vpn-connection.c
Diffstat (limited to 'shared/nm-test-utils.h')
-rw-r--r--shared/nm-test-utils.h286
1 files changed, 8 insertions, 278 deletions
diff --git a/shared/nm-test-utils.h b/shared/nm-test-utils.h
index b792a69c85..ad3cad650f 100644
--- a/shared/nm-test-utils.h
+++ b/shared/nm-test-utils.h
@@ -101,13 +101,6 @@
#include "nm-utils.h"
-#ifdef __NETWORKMANAGER_LOGGING_H__
-/* We are running tests under src/. Let's include some files by default.
- * They are useful, and affect how nm-test-utils.h itself behaves. */
-#include "NetworkManagerUtils.h"
-#include "nm-keyfile-internal.h"
-#endif
-
/*******************************************************************************/
/* general purpose functions that have no dependency on other nmtst functions */
@@ -153,13 +146,11 @@
g_assert_not_reached (); \
} G_STMT_END
-inline static void
-_nmtst_assert_success (gboolean success, GError *error, const char *file, int line)
-{
- if (!success || error)
- g_error ("(%s:%d) FAILURE success=%d, error=%s", file, line, success, error ? error->message : "(no error)");
-}
-#define nmtst_assert_success(success, error) _nmtst_assert_success ((success), (error), __FILE__, __LINE__)
+#define nmtst_assert_success(success, error) \
+ G_STMT_START { \
+ g_assert_no_error (error); \
+ g_assert ((success)); \
+ } G_STMT_END
#define nmtst_assert_no_success(success, error) \
G_STMT_START { \
@@ -512,7 +503,7 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_
if (!__nmtst_internal.assert_logging) {
gboolean success = TRUE;
-#ifdef __NETWORKMANAGER_LOGGING_H__
+#ifdef _NMTST_INSIDE_CORE
success = nm_logging_setup (log_level, log_domains, NULL, NULL);
*out_set_logging = TRUE;
#endif
@@ -529,7 +520,7 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_
* This transforms g_test_expect_message() into a NOP, but we also have to relax
* g_log_set_always_fatal(), which was set by g_test_init(). */
g_log_set_always_fatal (G_LOG_FATAL_MASK);
-#ifdef __NETWORKMANAGER_LOGGING_H__
+#ifdef _NMTST_INSIDE_CORE
if (c_log_domains || c_log_level) {
/* Normally, tests with assert_logging do not overwrite the logging level/domains because
* the logging statements are part of the assertions. But if the test is run with
@@ -590,27 +581,7 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_
#endif
}
-#ifdef __NETWORKMANAGER_LOGGING_H__
-inline static void
-nmtst_init_with_logging (int *argc, char ***argv, const char *log_level, const char *log_domains)
-{
- __nmtst_init (argc, argv, FALSE, log_level, log_domains, NULL);
-}
-inline static void
-nmtst_init_assert_logging (int *argc, char ***argv, const char *log_level, const char *log_domains)
-{
- gboolean set_logging;
-
- __nmtst_init (argc, argv, TRUE, NULL, NULL, &set_logging);
-
- if (!set_logging) {
- gboolean success;
-
- success = nm_logging_setup (log_level, log_domains, NULL, NULL);
- g_assert (success);
- }
-}
-#else
+#ifndef _NMTST_INSIDE_CORE
inline static void
nmtst_init (int *argc, char ***argv, gboolean assert_logging)
{
@@ -1177,247 +1148,6 @@ _nmtst_assert_resolve_relative_path_equals (const char *f1, const char *f2, cons
/*******************************************************************************/
-#ifdef __NETWORKMANAGER_PLATFORM_H__
-
-inline static NMPlatformIP4Address *
-nmtst_platform_ip4_address (const char *address, const char *peer_address, guint plen)
-{
- static NMPlatformIP4Address addr;
-
- g_assert (plen <= 32);
-
- memset (&addr, 0, sizeof (addr));
- addr.address = nmtst_inet4_from_string (address);
- if (peer_address)
- addr.peer_address = nmtst_inet4_from_string (peer_address);
- else
- addr.peer_address = addr.address;
- addr.plen = plen;
-
- return &addr;
-}
-
-inline static NMPlatformIP4Address *
-nmtst_platform_ip4_address_full (const char *address, const char *peer_address, guint plen,
- int ifindex, NMIPConfigSource source, guint32 timestamp,
- guint32 lifetime, guint32 preferred, guint32 flags,
- const char *label)
-{
- NMPlatformIP4Address *addr = nmtst_platform_ip4_address (address, peer_address, plen);
-
- G_STATIC_ASSERT (IFNAMSIZ == sizeof (addr->label));
- g_assert (!label || strlen (label) < IFNAMSIZ);
-
- addr->ifindex = ifindex;
- addr->source = source;
- addr->timestamp = timestamp;
- addr->lifetime = lifetime;
- addr->preferred = preferred;
- addr->n_ifa_flags = flags;
- if (label)
- g_strlcpy (addr->label, label, sizeof (addr->label));
-
- return addr;
-}
-
-inline static NMPlatformIP6Address *
-nmtst_platform_ip6_address (const char *address, const char *peer_address, guint plen)
-{
- static NMPlatformIP6Address addr;
-
- g_assert (plen <= 128);
-
- memset (&addr, 0, sizeof (addr));
- addr.address = *nmtst_inet6_from_string (address);
- addr.peer_address = *nmtst_inet6_from_string (peer_address);
- addr.plen = plen;
-
- return &addr;
-}
-
-inline static NMPlatformIP6Address *
-nmtst_platform_ip6_address_full (const char *address, const char *peer_address, guint plen,
- int ifindex, NMIPConfigSource source, guint32 timestamp,
- guint32 lifetime, guint32 preferred, guint32 flags)
-{
- NMPlatformIP6Address *addr = nmtst_platform_ip6_address (address, peer_address, plen);
-
- addr->ifindex = ifindex;
- addr->source = source;
- addr->timestamp = timestamp;
- addr->lifetime = lifetime;
- addr->preferred = preferred;
- addr->n_ifa_flags = flags;
-
- return addr;
-}
-
-inline static NMPlatformIP4Route *
-nmtst_platform_ip4_route (const char *network, guint plen, const char *gateway)
-{
- static NMPlatformIP4Route route;
-
- g_assert (plen <= 32);
-
- memset (&route, 0, sizeof (route));
- route.network = nmtst_inet4_from_string (network);
- route.plen = plen;
- route.gateway = nmtst_inet4_from_string (gateway);
-
- return &route;
-}
-
-inline static NMPlatformIP4Route *
-nmtst_platform_ip4_route_full (const char *network, guint plen, const char *gateway,
- int ifindex, NMIPConfigSource source,
- guint metric, guint mss,
- guint8 scope,
- const char *pref_src)
-{
- NMPlatformIP4Route *route = nmtst_platform_ip4_route (network, plen, gateway);
-
- route->ifindex = ifindex;
- route->source = source;
- route->metric = metric;
- route->mss = mss;
- route->scope_inv = nm_platform_route_scope_inv (scope);
- route->pref_src = nmtst_inet4_from_string (pref_src);
-
- return route;
-}
-
-inline static NMPlatformIP6Route *
-nmtst_platform_ip6_route (const char *network, guint plen, const char *gateway)
-{
- static NMPlatformIP6Route route;
-
- nm_assert (plen <= 128);
-
- memset (&route, 0, sizeof (route));
- route.network = *nmtst_inet6_from_string (network);
- route.plen = plen;
- route.gateway = *nmtst_inet6_from_string (gateway);
-
- return &route;
-}
-
-inline static NMPlatformIP6Route *
-nmtst_platform_ip6_route_full (const char *network, guint plen, const char *gateway,
- int ifindex, NMIPConfigSource source,
- guint metric, guint mss)
-{
- NMPlatformIP6Route *route = nmtst_platform_ip6_route (network, plen, gateway);
-
- route->ifindex = ifindex;
- route->source = source;
- route->metric = metric;
- route->mss = mss;
-
- return route;
-}
-
-inline static int
-_nmtst_platform_ip4_routes_equal_sort (gconstpointer a, gconstpointer b, gpointer user_data)
-{
- return nm_platform_ip4_route_cmp ((const NMPlatformIP4Route *) a, (const NMPlatformIP4Route *) b);
-}
-
-inline static void
-nmtst_platform_ip4_routes_equal (const NMPlatformIP4Route *a, const NMPlatformIP4Route *b, gsize len, gboolean ignore_order)
-{
- gsize i;
- gs_free const NMPlatformIP4Route *c_a = NULL, *c_b = NULL;
-
- g_assert (a);
- g_assert (b);
-
- if (ignore_order) {
- a = c_a = g_memdup (a, sizeof (NMPlatformIP4Route) * len);
- b = c_b = g_memdup (b, sizeof (NMPlatformIP4Route) * len);
- g_qsort_with_data (c_a, len, sizeof (NMPlatformIP4Route), _nmtst_platform_ip4_routes_equal_sort, NULL);
- g_qsort_with_data (c_b, len, sizeof (NMPlatformIP4Route), _nmtst_platform_ip4_routes_equal_sort, NULL);
- }
-
- for (i = 0; i < len; i++) {
- if (nm_platform_ip4_route_cmp (&a[i], &b[i]) != 0) {
- char buf[sizeof (_nm_utils_to_string_buffer)];
-
- g_error ("Error comparing IPv4 route[%lu]: %s vs %s", (long unsigned) i,
- nm_platform_ip4_route_to_string (&a[i], NULL, 0),
- nm_platform_ip4_route_to_string (&b[i], buf, sizeof (buf)));
- g_assert_not_reached ();
- }
- }
-}
-
-inline static int
-_nmtst_platform_ip6_routes_equal_sort (gconstpointer a, gconstpointer b, gpointer user_data)
-{
- return nm_platform_ip6_route_cmp ((const NMPlatformIP6Route *) a, (const NMPlatformIP6Route *) b);
-}
-
-inline static void
-nmtst_platform_ip6_routes_equal (const NMPlatformIP6Route *a, const NMPlatformIP6Route *b, gsize len, gboolean ignore_order)
-{
- gsize i;
- gs_free const NMPlatformIP6Route *c_a = NULL, *c_b = NULL;
-
- g_assert (a);
- g_assert (b);
-
- if (ignore_order) {
- a = c_a = g_memdup (a, sizeof (NMPlatformIP6Route) * len);
- b = c_b = g_memdup (b, sizeof (NMPlatformIP6Route) * len);
- g_qsort_with_data (c_a, len, sizeof (NMPlatformIP6Route), _nmtst_platform_ip6_routes_equal_sort, NULL);
- g_qsort_with_data (c_b, len, sizeof (NMPlatformIP6Route), _nmtst_platform_ip6_routes_equal_sort, NULL);
- }
-
- for (i = 0; i < len; i++) {
- if (nm_platform_ip6_route_cmp (&a[i], &b[i]) != 0) {
- char buf[sizeof (_nm_utils_to_string_buffer)];
-
- g_error ("Error comparing IPv6 route[%lu]: %s vs %s", (long unsigned) i,
- nm_platform_ip6_route_to_string (&a[i], NULL, 0),
- nm_platform_ip6_route_to_string (&b[i], buf, sizeof (buf)));
- g_assert_not_reached ();
- }
- }
-}
-
-#endif
-
-
-#ifdef __NETWORKMANAGER_IP4_CONFIG_H__
-
-inline static NMIP4Config *
-nmtst_ip4_config_clone (NMIP4Config *config)
-{
- NMIP4Config *copy = nm_ip4_config_new (-1);
-
- g_assert (copy);
- g_assert (config);
- nm_ip4_config_replace (copy, config, NULL);
- return copy;
-}
-
-#endif
-
-
-#ifdef __NETWORKMANAGER_IP6_CONFIG_H__
-
-inline static NMIP6Config *
-nmtst_ip6_config_clone (NMIP6Config *config)
-{
- NMIP6Config *copy = nm_ip6_config_new (-1);
-
- g_assert (copy);
- g_assert (config);
- nm_ip6_config_replace (copy, config, NULL);
- return copy;
-}
-
-#endif
-
#ifdef NM_SETTING_IP_CONFIG_H
inline static void
nmtst_setting_ip_config_add_address (NMSettingIPConfig *s_ip,