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/>.
21 #include "testutils.h"
22 #include "virnetdevopenvswitch.h"
24 #define VIR_FROM_THIS VIR_FROM_NONE
26 typedef struct _InterfaceParseStatsData InterfaceParseStatsData
;
27 struct _InterfaceParseStatsData
{
29 const virDomainInterfaceStatsStruct stats
;
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)
45 if (virFileReadAll(filename
, 1024, &buf
) < 0)
48 if (virNetDevOpenvswitchInterfaceParseStats(buf
, &actual
) < 0)
51 if (memcmp(&actual
, &data
->stats
, sizeof(actual
)) != 0) {
53 "Expected stats: %lld %lld %lld %lld %lld %lld %lld %lld\n"
54 "Actual stats: %lld %lld %lld %lld %lld %lld %lld %lld",
56 data
->stats
.rx_packets
,
60 data
->stats
.tx_packets
,
84 #define TEST_INTERFACE_STATS(file, \
85 rxBytes, rxPackets, rxErrs, rxDrop, \
86 txBytes, txPackets, txErrs, txDrop) \
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) \
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
);