backup: Wire up qemu full pull backup commands over QMP
[libvirt/ericb.git] / tests / virnetdevtest.c
blob24fb4d35e035309073d4f0463b4aa38b1636d7fc
1 /*
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/>.
19 #include <config.h>
21 #include "testutils.h"
23 #ifdef __linux__
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 */
35 static int
36 testVirNetDevGetLinkInfo(const void *opaque)
38 int ret = -1;
39 const struct testVirNetDevGetLinkInfoData *data = opaque;
40 virNetDevIfLink lnk;
42 if (virNetDevGetLinkInfo(data->ifname, &lnk) < 0)
43 goto cleanup;
45 if (lnk.state != data->state) {
46 fprintf(stderr,
47 "Fetched link state (%s) doesn't match the expected one (%s)",
48 virNetDevIfStateTypeToString(lnk.state),
49 virNetDevIfStateTypeToString(data->state));
50 goto cleanup;
53 if (lnk.speed != data->speed) {
54 fprintf(stderr,
55 "Fetched link speed (%u) doesn't match the expected one (%u)",
56 lnk.speed, data->speed);
57 goto cleanup;
60 ret = 0;
61 cleanup:
62 return ret;
65 static int
66 mymain(void)
68 int ret = 0;
70 # define DO_TEST_LINK(ifname, state, speed) \
71 do { \
72 struct testVirNetDevGetLinkInfoData data = {ifname, state, speed}; \
73 if (virTestRun("Link info: " # ifname, \
74 testVirNetDevGetLinkInfo, &data) < 0) \
75 ret = -1; \
76 } while (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")
86 #else
87 int
88 main(void)
90 return EXIT_AM_SKIP;
92 #endif