|
Packit Service |
87a54e |
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
Packit |
5756e2 |
/*
|
|
Packit |
5756e2 |
* Copyright (C) 2019 Red Hat, Inc.
|
|
Packit |
5756e2 |
*/
|
|
Packit |
5756e2 |
|
|
Packit Service |
2bceb2 |
#include "libnm/nm-default-client.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nm-libnm-core-aux/nm-libnm-core-aux.h"
|
|
Packit |
5756e2 |
#include "nm-libnm-core-intern/nm-libnm-core-utils.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nm-utils/nm-test-utils.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static NMTeamLinkWatcher *
|
|
Packit Service |
a1bd4f |
_team_link_watcher_from_string_impl(const char *str, gsize nextra, const char *const *vextra)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMTeamLinkWatcher *watcher;
|
|
Packit Service |
a1bd4f |
gs_free char * str1_free = NULL;
|
|
Packit Service |
a1bd4f |
gs_free_error GError *error = NULL;
|
|
Packit Service |
a1bd4f |
gsize i;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_assert(str);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
watcher = nm_utils_team_link_watcher_from_string(str, &error);
|
|
Packit Service |
a1bd4f |
nmtst_assert_success(watcher, error);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
for (i = 0; i < 1 + nextra; i++) {
|
|
Packit Service |
a1bd4f |
nm_auto_unref_team_link_watcher NMTeamLinkWatcher *watcher1 = NULL;
|
|
Packit Service |
a1bd4f |
const char * str1;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (i == 0) {
|
|
Packit Service |
a1bd4f |
str1_free = nm_utils_team_link_watcher_to_string(watcher);
|
|
Packit Service |
a1bd4f |
g_assert(str1_free);
|
|
Packit Service |
a1bd4f |
str1 = str1_free;
|
|
Packit Service |
a1bd4f |
g_assert_cmpstr(str, ==, str1);
|
|
Packit Service |
a1bd4f |
} else
|
|
Packit Service |
a1bd4f |
str1 = vextra[i - 1];
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
watcher1 = nm_utils_team_link_watcher_from_string(str1, &error);
|
|
Packit Service |
a1bd4f |
nmtst_assert_success(watcher1, error);
|
|
Packit Service |
a1bd4f |
if (!nm_team_link_watcher_equal(watcher, watcher1)) {
|
|
Packit Service |
a1bd4f |
gs_free char *ss1 = NULL;
|
|
Packit Service |
a1bd4f |
gs_free char *ss2 = NULL;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_print(">>> watcher differs: \"%s\" vs. \"%s\"",
|
|
Packit Service |
a1bd4f |
(ss1 = nm_utils_team_link_watcher_to_string(watcher)),
|
|
Packit Service |
a1bd4f |
(ss2 = nm_utils_team_link_watcher_to_string(watcher1)));
|
|
Packit Service |
a1bd4f |
g_print(">>> ORIG: \"%s\" vs. \"%s\"", str, str1);
|
|
Packit Service |
a1bd4f |
g_assert_not_reached();
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
g_assert(nm_team_link_watcher_equal(watcher1, watcher));
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
return watcher;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
#define _team_link_watcher_from_string(str, ...) \
|
|
Packit Service |
a1bd4f |
_team_link_watcher_from_string_impl((str), NM_NARG(__VA_ARGS__), NM_MAKE_STRV(__VA_ARGS__))
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
test_team_link_watcher_tofro_string(void)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nm_auto_unref_team_link_watcher NMTeamLinkWatcher *w = NULL;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
#define _team_link_watcher_cmp(watcher, \
|
|
Packit Service |
a1bd4f |
name, \
|
|
Packit Service |
a1bd4f |
delay_down, \
|
|
Packit Service |
a1bd4f |
delay_up, \
|
|
Packit Service |
a1bd4f |
init_wait, \
|
|
Packit Service |
a1bd4f |
interval, \
|
|
Packit Service |
a1bd4f |
missed_max, \
|
|
Packit Service |
a1bd4f |
target_host, \
|
|
Packit Service |
a1bd4f |
source_host, \
|
|
Packit Service |
a1bd4f |
vlanid, \
|
|
Packit Service |
a1bd4f |
arping_flags) \
|
|
Packit Service |
a1bd4f |
G_STMT_START \
|
|
Packit Service |
a1bd4f |
{ \
|
|
Packit Service |
a1bd4f |
nm_auto_unref_team_link_watcher NMTeamLinkWatcher *_w = g_steal_pointer(watcher); \
|
|
Packit Service |
a1bd4f |
\
|
|
Packit Service |
a1bd4f |
g_assert_cmpstr((name), ==, nm_team_link_watcher_get_name(_w)); \
|
|
Packit Service |
a1bd4f |
g_assert_cmpint((delay_down), ==, nm_team_link_watcher_get_delay_down(_w)); \
|
|
Packit Service |
a1bd4f |
g_assert_cmpint((delay_up), ==, nm_team_link_watcher_get_delay_up(_w)); \
|
|
Packit Service |
a1bd4f |
g_assert_cmpint((init_wait), ==, nm_team_link_watcher_get_init_wait(_w)); \
|
|
Packit Service |
a1bd4f |
g_assert_cmpint((interval), ==, nm_team_link_watcher_get_interval(_w)); \
|
|
Packit Service |
a1bd4f |
g_assert_cmpint((missed_max), ==, nm_team_link_watcher_get_missed_max(_w)); \
|
|
Packit Service |
a1bd4f |
g_assert_cmpstr((target_host), ==, nm_team_link_watcher_get_target_host(_w)); \
|
|
Packit Service |
a1bd4f |
g_assert_cmpstr((source_host), ==, nm_team_link_watcher_get_source_host(_w)); \
|
|
Packit Service |
a1bd4f |
g_assert_cmpint((vlanid), ==, nm_team_link_watcher_get_vlanid(_w)); \
|
|
Packit Service |
a1bd4f |
g_assert_cmpint((arping_flags), ==, nm_team_link_watcher_get_flags(_w)); \
|
|
Packit Service |
a1bd4f |
} \
|
|
Packit Service |
a1bd4f |
G_STMT_END
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
w = _team_link_watcher_from_string("name=ethtool",
|
|
Packit Service |
a1bd4f |
"delay-up=0 name=ethtool",
|
|
Packit Service |
a1bd4f |
" delay-down=0 name=ethtool ");
|
|
Packit Service |
a1bd4f |
_team_link_watcher_cmp(&w,
|
|
Packit Service |
a1bd4f |
"ethtool",
|
|
Packit Service |
a1bd4f |
0,
|
|
Packit Service |
a1bd4f |
0,
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
NULL,
|
|
Packit Service |
a1bd4f |
NULL,
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
w = _team_link_watcher_from_string("name=ethtool delay-up=10",
|
|
Packit Service |
a1bd4f |
" delay-down=0 delay-up=10 name=ethtool");
|
|
Packit Service |
a1bd4f |
_team_link_watcher_cmp(&w,
|
|
Packit Service |
a1bd4f |
"ethtool",
|
|
Packit Service |
a1bd4f |
0,
|
|
Packit Service |
a1bd4f |
10,
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
NULL,
|
|
Packit Service |
a1bd4f |
NULL,
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
w = _team_link_watcher_from_string("name=ethtool delay-up=10 delay-down=11",
|
|
Packit Service |
a1bd4f |
" delay-down=11 delay-up=10 name=ethtool");
|
|
Packit Service |
a1bd4f |
_team_link_watcher_cmp(&w,
|
|
Packit Service |
a1bd4f |
"ethtool",
|
|
Packit Service |
a1bd4f |
11,
|
|
Packit Service |
a1bd4f |
10,
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
NULL,
|
|
Packit Service |
a1bd4f |
NULL,
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
w = _team_link_watcher_from_string(
|
|
Packit Service |
a1bd4f |
"name=nsna_ping target-host=xxx",
|
|
Packit Service |
a1bd4f |
"name=nsna_ping target-host=xxx",
|
|
Packit Service |
a1bd4f |
" missed-max=3 target-host=xxx name=nsna_ping ");
|
|
Packit Service |
a1bd4f |
_team_link_watcher_cmp(&w,
|
|
Packit Service |
a1bd4f |
"nsna_ping",
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
0,
|
|
Packit Service |
a1bd4f |
0,
|
|
Packit Service |
a1bd4f |
3,
|
|
Packit Service |
a1bd4f |
"xxx",
|
|
Packit Service |
a1bd4f |
NULL,
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
w = _team_link_watcher_from_string("name=arp_ping target-host=xxx source-host=yzd",
|
|
Packit Service |
a1bd4f |
" source-host=yzd target-host=xxx name=arp_ping ");
|
|
Packit Service |
a1bd4f |
_team_link_watcher_cmp(&w,
|
|
Packit Service |
a1bd4f |
"arp_ping",
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
0,
|
|
Packit Service |
a1bd4f |
0,
|
|
Packit Service |
a1bd4f |
3,
|
|
Packit Service |
a1bd4f |
"xxx",
|
|
Packit Service |
a1bd4f |
"yzd",
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
w = _team_link_watcher_from_string(
|
|
Packit Service |
a1bd4f |
"name=arp_ping missed-max=0 target-host=xxx vlanid=0 source-host=yzd");
|
|
Packit Service |
a1bd4f |
_team_link_watcher_cmp(&w,
|
|
Packit Service |
a1bd4f |
"arp_ping",
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
0,
|
|
Packit Service |
a1bd4f |
0,
|
|
Packit Service |
a1bd4f |
0,
|
|
Packit Service |
a1bd4f |
"xxx",
|
|
Packit Service |
a1bd4f |
"yzd",
|
|
Packit Service |
a1bd4f |
0,
|
|
Packit Service |
a1bd4f |
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
w = _team_link_watcher_from_string(
|
|
Packit Service |
a1bd4f |
"name=arp_ping target-host=xxx source-host=yzd validate-active=true",
|
|
Packit Service |
a1bd4f |
"source-host=yzd send-always=false name=arp_ping validate-active=true "
|
|
Packit Service |
a1bd4f |
"validate-inactive=false target-host=xxx",
|
|
Packit Service |
a1bd4f |
" source-host=yzd target-host=xxx validate-active=true name=arp_ping ");
|
|
Packit Service |
a1bd4f |
_team_link_watcher_cmp(&w,
|
|
Packit Service |
a1bd4f |
"arp_ping",
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
0,
|
|
Packit Service |
a1bd4f |
0,
|
|
Packit Service |
a1bd4f |
3,
|
|
Packit Service |
a1bd4f |
"xxx",
|
|
Packit Service |
a1bd4f |
"yzd",
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_VALIDATE_ACTIVE);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
w = _team_link_watcher_from_string(
|
|
Packit Service |
a1bd4f |
"name=arp_ping target-host=xxx source-host=yzd validate-active=true validate-inactive=true "
|
|
Packit Service |
a1bd4f |
"send-always=true",
|
|
Packit Service |
a1bd4f |
"source-host=yzd send-always=true name=arp_ping validate-active=true "
|
|
Packit Service |
a1bd4f |
"validate-inactive=true target-host=xxx",
|
|
Packit Service |
a1bd4f |
"source-host=yzd send-always=true name=arp_ping validate-active=1 validate-inactive=yes "
|
|
Packit Service |
a1bd4f |
"target-host=xxx",
|
|
Packit Service |
a1bd4f |
" source-host=yzd target-host=xxx validate-inactive=true send-always=true "
|
|
Packit Service |
a1bd4f |
"validate-active=true name=arp_ping ");
|
|
Packit Service |
a1bd4f |
_team_link_watcher_cmp(&w,
|
|
Packit Service |
a1bd4f |
"arp_ping",
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
0,
|
|
Packit Service |
a1bd4f |
0,
|
|
Packit Service |
a1bd4f |
3,
|
|
Packit Service |
a1bd4f |
"xxx",
|
|
Packit Service |
a1bd4f |
"yzd",
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_VALIDATE_ACTIVE
|
|
Packit Service |
a1bd4f |
| NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_VALIDATE_INACTIVE
|
|
Packit Service |
a1bd4f |
| NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_SEND_ALWAYS);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
w = _team_link_watcher_from_string(
|
|
Packit Service |
a1bd4f |
"name=arp_ping missed-max=0 target-host=xxx vlanid=0 source-host=yzd");
|
|
Packit Service |
a1bd4f |
_team_link_watcher_cmp(&w,
|
|
Packit Service |
a1bd4f |
"arp_ping",
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
0,
|
|
Packit Service |
a1bd4f |
0,
|
|
Packit Service |
a1bd4f |
0,
|
|
Packit Service |
a1bd4f |
"xxx",
|
|
Packit Service |
a1bd4f |
"yzd",
|
|
Packit Service |
a1bd4f |
0,
|
|
Packit Service |
a1bd4f |
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
NMTST_DEFINE();
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
int
|
|
Packit Service |
a1bd4f |
main(int argc, char **argv)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nmtst_init(&argc, &argv, TRUE);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_test_add_func("/libnm-core-aux/test_team_link_watcher_tofro_string",
|
|
Packit Service |
a1bd4f |
test_team_link_watcher_tofro_string);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return g_test_run();
|
|
Packit |
5756e2 |
}
|