2 * Copyright (C) 2015 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see
16 * <http://www.gnu.org/licenses/>.
21 #include "testutils.h"
25 # include "virnetdev.h"
27 # define VIR_FROM_THIS VIR_FROM_NONE
29 struct testVirNetDevGetLinkInfoData
{
30 const char *ifname
; /* ifname to get info on */
31 virNetDevIfState state
; /* expected state */
32 unsigned int speed
; /* expected speed */
36 testVirNetDevGetLinkInfo(const void *opaque
)
39 const struct testVirNetDevGetLinkInfoData
*data
= opaque
;
42 if (virNetDevGetLinkInfo(data
->ifname
, &lnk
) < 0)
45 if (lnk
.state
!= data
->state
) {
47 "Fetched link state (%s) doesn't match the expected one (%s)",
48 virNetDevIfStateTypeToString(lnk
.state
),
49 virNetDevIfStateTypeToString(data
->state
));
53 if (lnk
.speed
!= data
->speed
) {
55 "Fetched link speed (%u) doesn't match the expected one (%u)",
56 lnk
.speed
, data
->speed
);
70 # define DO_TEST_LINK(ifname, state, speed) \
72 struct testVirNetDevGetLinkInfoData data = {ifname, state, speed}; \
73 if (virTestRun("Link info: " # ifname, \
74 testVirNetDevGetLinkInfo, &data) < 0) \
78 DO_TEST_LINK("eth0", VIR_NETDEV_IF_STATE_UP
, 1000);
79 DO_TEST_LINK("lo", VIR_NETDEV_IF_STATE_UNKNOWN
, 0);
80 DO_TEST_LINK("eth0-broken", VIR_NETDEV_IF_STATE_DOWN
, 0);
82 return ret
== 0 ? EXIT_SUCCESS
: EXIT_FAILURE
;
85 VIR_TEST_MAIN_PRELOAD(mymain
, abs_builddir
"/.libs/virnetdevmock.so")