Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/tools/net/ynl/tests/ethtool.c
170958 views
1
// SPDX-License-Identifier: GPL-2.0
2
#include <stdio.h>
3
#include <string.h>
4
5
#include <ynl.h>
6
7
#include <net/if.h>
8
9
#include <kselftest_harness.h>
10
11
#include "ethtool-user.h"
12
13
FIXTURE(ethtool)
14
{
15
struct ynl_sock *ys;
16
};
17
18
FIXTURE_SETUP(ethtool)
19
{
20
self->ys = ynl_sock_create(&ynl_ethtool_family, NULL);
21
ASSERT_NE(NULL, self->ys)
22
TH_LOG("failed to create ethtool socket");
23
}
24
25
FIXTURE_TEARDOWN(ethtool)
26
{
27
ynl_sock_destroy(self->ys);
28
}
29
30
TEST_F(ethtool, channels)
31
{
32
struct ethtool_channels_get_req_dump creq = {};
33
struct ethtool_channels_get_list *channels;
34
35
creq._present.header = 1; /* ethtool needs an empty nest */
36
channels = ethtool_channels_get_dump(self->ys, &creq);
37
ASSERT_NE(NULL, channels) {
38
TH_LOG("channels dump failed: %s", self->ys->err.msg);
39
}
40
41
if (ynl_dump_empty(channels)) {
42
ethtool_channels_get_list_free(channels);
43
SKIP(return, "no entries in channels dump");
44
}
45
46
ynl_dump_foreach(channels, dev) {
47
EXPECT_TRUE((bool)dev->header._len.dev_name);
48
ksft_print_msg("%8s: ", dev->header.dev_name);
49
EXPECT_TRUE(dev->_present.rx_count ||
50
dev->_present.tx_count ||
51
dev->_present.combined_count);
52
if (dev->_present.rx_count)
53
printf("rx %d ", dev->rx_count);
54
if (dev->_present.tx_count)
55
printf("tx %d ", dev->tx_count);
56
if (dev->_present.combined_count)
57
printf("combined %d ", dev->combined_count);
58
printf("\n");
59
}
60
ethtool_channels_get_list_free(channels);
61
}
62
63
TEST_F(ethtool, rings)
64
{
65
struct ethtool_rings_get_req_dump rreq = {};
66
struct ethtool_rings_get_list *rings;
67
68
rreq._present.header = 1; /* ethtool needs an empty nest */
69
rings = ethtool_rings_get_dump(self->ys, &rreq);
70
ASSERT_NE(NULL, rings) {
71
TH_LOG("rings dump failed: %s", self->ys->err.msg);
72
}
73
74
if (ynl_dump_empty(rings)) {
75
ethtool_rings_get_list_free(rings);
76
SKIP(return, "no entries in rings dump");
77
}
78
79
ynl_dump_foreach(rings, dev) {
80
EXPECT_TRUE((bool)dev->header._len.dev_name);
81
ksft_print_msg("%8s: ", dev->header.dev_name);
82
EXPECT_TRUE(dev->_present.rx || dev->_present.tx);
83
if (dev->_present.rx)
84
printf("rx %d ", dev->rx);
85
if (dev->_present.tx)
86
printf("tx %d ", dev->tx);
87
printf("\n");
88
}
89
ethtool_rings_get_list_free(rings);
90
}
91
92
TEST_HARNESS_MAIN
93
94