backup: Wire up qemu full pull backup commands over QMP
[libvirt/ericb.git] / tests / virnetdevopenvswitchtest.c
blobf01e77cbba9b7e7bbac5ec6042f2a65020f753cc
1 /*
2 * Copyright (C) 2019 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"
22 #include "virnetdevopenvswitch.h"
24 #define VIR_FROM_THIS VIR_FROM_NONE
26 typedef struct _InterfaceParseStatsData InterfaceParseStatsData;
27 struct _InterfaceParseStatsData {
28 const char *filename;
29 const virDomainInterfaceStatsStruct stats;
33 static int
34 testInterfaceParseStats(const void *opaque)
36 const InterfaceParseStatsData *data = opaque;
37 VIR_AUTOFREE(char *) filename = NULL;
38 VIR_AUTOFREE(char *) buf = NULL;
39 virDomainInterfaceStatsStruct actual;
41 if (virAsprintf(&filename, "%s/virnetdevopenvswitchdata/%s",
42 abs_srcdir, data->filename) < 0)
43 return -1;
45 if (virFileReadAll(filename, 1024, &buf) < 0)
46 return -1;
48 if (virNetDevOpenvswitchInterfaceParseStats(buf, &actual) < 0)
49 return -1;
51 if (memcmp(&actual, &data->stats, sizeof(actual)) != 0) {
52 fprintf(stderr,
53 "Expected stats: %lld %lld %lld %lld %lld %lld %lld %lld\n"
54 "Actual stats: %lld %lld %lld %lld %lld %lld %lld %lld",
55 data->stats.rx_bytes,
56 data->stats.rx_packets,
57 data->stats.rx_errs,
58 data->stats.rx_drop,
59 data->stats.tx_bytes,
60 data->stats.tx_packets,
61 data->stats.tx_errs,
62 data->stats.tx_drop,
63 actual.rx_bytes,
64 actual.rx_packets,
65 actual.rx_errs,
66 actual.rx_drop,
67 actual.tx_bytes,
68 actual.tx_packets,
69 actual.tx_errs,
70 actual.tx_drop);
72 return -1;
75 return 0;
79 static int
80 mymain(void)
82 int ret = 0;
84 #define TEST_INTERFACE_STATS(file, \
85 rxBytes, rxPackets, rxErrs, rxDrop, \
86 txBytes, txPackets, txErrs, txDrop) \
87 do { \
88 const InterfaceParseStatsData data = {.filename = file, .stats = { \
89 rxBytes, rxPackets, rxErrs, rxDrop, \
90 txBytes, txPackets, txErrs, txDrop}}; \
91 if (virTestRun("Interface stats " file, testInterfaceParseStats, &data) < 0) \
92 ret = -1; \
93 } while (0)
95 TEST_INTERFACE_STATS("stats1.json", 9, 12, 11, 10, 2, 8, 5, 4);
96 TEST_INTERFACE_STATS("stats2.json", 12406, 173, 0, 0, 0, 0, 0, 0);
98 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
101 VIR_TEST_MAIN(mymain);