|
6 | 6 | """
|
7 | 7 |
|
8 | 8 | import glob
|
9 |
| -from lib.py import ksft_run, ksft_exit, ksft_eq, ksft_is, ksft_ne |
| 9 | +from lib.py import ksft_run, ksft_exit, ksft_eq, ksft_is, ksft_ne, ksft_raises |
10 | 10 | from lib.py import KsftSkipEx, KsftFailEx
|
11 |
| -from lib.py import defer, ethtool |
12 |
| -from lib.py import EthtoolFamily |
| 11 | +from lib.py import defer, ethtool, CmdExitFailure |
| 12 | +from lib.py import EthtoolFamily, NlError |
13 | 13 | from lib.py import NetDrvEnv
|
14 | 14 |
|
15 | 15 |
|
@@ -59,6 +59,95 @@ def _ethtool_get_cfg(cfg, fl_type, to_nl=False):
|
59 | 59 | return ret
|
60 | 60 |
|
61 | 61 |
|
| 62 | +def test_rxfh_nl_set_fail(cfg): |
| 63 | + """ |
| 64 | + Test error path of Netlink SET. |
| 65 | + """ |
| 66 | + _require_2qs(cfg) |
| 67 | + |
| 68 | + ethnl = EthtoolFamily() |
| 69 | + ethnl.ntf_subscribe("monitor") |
| 70 | + |
| 71 | + with ksft_raises(NlError): |
| 72 | + ethnl.rss_set({"header": {"dev-name": "lo"}, |
| 73 | + "indir": None}) |
| 74 | + |
| 75 | + with ksft_raises(NlError): |
| 76 | + ethnl.rss_set({"header": {"dev-index": cfg.ifindex}, |
| 77 | + "indir": [100000]}) |
| 78 | + ntf = next(ethnl.poll_ntf(duration=0.2), None) |
| 79 | + ksft_is(ntf, None) |
| 80 | + |
| 81 | + |
| 82 | +def test_rxfh_nl_set_indir(cfg): |
| 83 | + """ |
| 84 | + Test setting indirection table via Netlink. |
| 85 | + """ |
| 86 | + qcnt = _require_2qs(cfg) |
| 87 | + |
| 88 | + # Test some SETs with a value |
| 89 | + reset = defer(cfg.ethnl.rss_set, |
| 90 | + {"header": {"dev-index": cfg.ifindex}, "indir": None}) |
| 91 | + cfg.ethnl.rss_set({"header": {"dev-index": cfg.ifindex}, |
| 92 | + "indir": [1]}) |
| 93 | + rss = cfg.ethnl.rss_get({"header": {"dev-index": cfg.ifindex}}) |
| 94 | + ksft_eq(set(rss.get("indir", [-1])), {1}) |
| 95 | + |
| 96 | + cfg.ethnl.rss_set({"header": {"dev-index": cfg.ifindex}, |
| 97 | + "indir": [0, 1]}) |
| 98 | + rss = cfg.ethnl.rss_get({"header": {"dev-index": cfg.ifindex}}) |
| 99 | + ksft_eq(set(rss.get("indir", [-1])), {0, 1}) |
| 100 | + |
| 101 | + # Make sure we can't set the queue count below max queue used |
| 102 | + with ksft_raises(CmdExitFailure): |
| 103 | + ethtool(f"-L {cfg.ifname} combined 0 rx 1") |
| 104 | + with ksft_raises(CmdExitFailure): |
| 105 | + ethtool(f"-L {cfg.ifname} combined 1 rx 0") |
| 106 | + |
| 107 | + # Test reset back to default |
| 108 | + reset.exec() |
| 109 | + rss = cfg.ethnl.rss_get({"header": {"dev-index": cfg.ifindex}}) |
| 110 | + ksft_eq(set(rss.get("indir", [-1])), set(range(qcnt))) |
| 111 | + |
| 112 | + |
| 113 | +def test_rxfh_nl_set_indir_ctx(cfg): |
| 114 | + """ |
| 115 | + Test setting indirection table for a custom context via Netlink. |
| 116 | + """ |
| 117 | + _require_2qs(cfg) |
| 118 | + |
| 119 | + # Get setting for ctx 0, we'll make sure they don't get clobbered |
| 120 | + dflt = cfg.ethnl.rss_get({"header": {"dev-index": cfg.ifindex}}) |
| 121 | + |
| 122 | + # Create context |
| 123 | + ctx_id = _ethtool_create(cfg, "-X", "context new") |
| 124 | + defer(ethtool, f"-X {cfg.ifname} context {ctx_id} delete") |
| 125 | + |
| 126 | + cfg.ethnl.rss_set({"header": {"dev-index": cfg.ifindex}, |
| 127 | + "context": ctx_id, "indir": [1]}) |
| 128 | + rss = cfg.ethnl.rss_get({"header": {"dev-index": cfg.ifindex}, |
| 129 | + "context": ctx_id}) |
| 130 | + ksft_eq(set(rss.get("indir", [-1])), {1}) |
| 131 | + |
| 132 | + ctx0 = cfg.ethnl.rss_get({"header": {"dev-index": cfg.ifindex}}) |
| 133 | + ksft_eq(ctx0, dflt) |
| 134 | + |
| 135 | + cfg.ethnl.rss_set({"header": {"dev-index": cfg.ifindex}, |
| 136 | + "context": ctx_id, "indir": [0, 1]}) |
| 137 | + rss = cfg.ethnl.rss_get({"header": {"dev-index": cfg.ifindex}, |
| 138 | + "context": ctx_id}) |
| 139 | + ksft_eq(set(rss.get("indir", [-1])), {0, 1}) |
| 140 | + |
| 141 | + ctx0 = cfg.ethnl.rss_get({"header": {"dev-index": cfg.ifindex}}) |
| 142 | + ksft_eq(ctx0, dflt) |
| 143 | + |
| 144 | + # Make sure we can't set the queue count below max queue used |
| 145 | + with ksft_raises(CmdExitFailure): |
| 146 | + ethtool(f"-L {cfg.ifname} combined 0 rx 1") |
| 147 | + with ksft_raises(CmdExitFailure): |
| 148 | + ethtool(f"-L {cfg.ifname} combined 1 rx 0") |
| 149 | + |
| 150 | + |
62 | 151 | def test_rxfh_indir_ntf(cfg):
|
63 | 152 | """
|
64 | 153 | Check that Netlink notifications are generated when RSS indirection
|
@@ -129,6 +218,7 @@ def main() -> None:
|
129 | 218 | """ Ksft boiler plate main """
|
130 | 219 |
|
131 | 220 | with NetDrvEnv(__file__, nsim_test=False) as cfg:
|
| 221 | + cfg.ethnl = EthtoolFamily() |
132 | 222 | ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg, ))
|
133 | 223 | ksft_exit()
|
134 | 224 |
|
|
0 commit comments