selftests: drv-net: replace the nsim ring test with a drv-net one
Subsystems (6)
Jakub Kicinski
maintainerPATCH v2 1/1 selftests: drv-net: replace the nsim ring test with a drv-net one
We are trying to move away from netdevsim-only tests and towards tests which can be run both against netdevsim and real drivers.
Replace the simple bash script we have for checking ethtool -g/-G on netdevsim with a Python test tweaking those params as well as channel count.
The new test is not exactly equivalent to the netdevsim one, but real drivers don't often support random ring sizes, let alone modifying max values via debugfs.
---
v2:
- add the new test to Makefile and remove the old one turns out NIPA checking for Makefile presence was busted
v1: https://lore.kernel.org/[email protected]
--- tools/testing/selftests/drivers/net/Makefile | 1 + .../selftests/drivers/net/netdevsim/Makefile | 1 - .../drivers/net/netdevsim/ethtool-ring.sh | 85 --------- .../selftests/drivers/net/ring_reconfig.py | 167 ++++++++++++++++++ 4 files changed, 168 insertions(+), 86 deletions(-) delete mode 100755 tools/testing/selftests/drivers/net/netdevsim/ethtool-ring.sh create mode 100755 tools/testing/selftests/drivers/net/ring_reconfig.py
tools/testing/selftests/drivers/net/Makefile +1 -0
@@ -22,6 +22,7 @@ TEST_PROGS := \ ping.py \ psp.py \ queues.py \ + ring_reconfig.py \ shaper.py \ stats.py \ xdp.py \
tools/testing/selftests/drivers/net/netdevsim/Makefile +0 -1
@@ -8,7 +8,6 @@ TEST_PROGS := \ ethtool-features.sh \ ethtool-fec.sh \ ethtool-pause.sh \ - ethtool-ring.sh \ fib.sh \ fib_notifications.sh \ hw_stats_l3.sh \
tools/testing/selftests/drivers/net/netdevsim/ethtool-ring.sh deleted +0 -85
85 lines not on this page · raw message
tools/testing/selftests/drivers/net/ring_reconfig.py new file +167 -0
167 lines not on this page · raw message
Signature · 1 line
2.51.0
Andrew Lunn
maintainertools/testing/selftests/drivers/net/ring_reconfig.py line 47
Quoted 11 lines
tools/testing/selftests/drivers/net/ring_reconfig.py new file +11
-0+ def test_config(config): + try: + cfg.eth.channels_set(ehdr | config) + get = cfg.eth.channels_get(ehdr) + for k, v in config.items(): + ksft_eq(get.get(k, 0), v) + except NlError as e: + failed.append(mix) + ksft_pr("Can't set", config, e) + else: + ksft_pr("Okay", config)
We expect failure to leave the configuration unchanged. So i would actually do:
try:
before = get() set() except: after = get() fail(after != before)
Also, does nlError contain the error code?
fail(e.errcode not in (EINVAL, EOPNOTSUPP))
It would be good to detect and fail ENOTSUPP, which does appear every so often, when it should not.
tools/testing/selftests/drivers/net/ring_reconfig.py line 133
Quoted 12 lines
tools/testing/selftests/drivers/net/ring_reconfig.py new file +12
-0+ # Try to reach min on all settings + for param in params: + val = rings[param] + while True: + try: + cfg.eth.rings_set({'header':{'dev-index': cfg.ifindex}, + param: val // 2}) + val //= 2 + if val <= 1: + break + except NlError: + break
Is 0 ever valid? I would actually test 0 and make sure it fails with EINVAL, or EOPNOTSUPP. Getting range checks wrong is a typical bug, so it is good to test them. The happy days cases are boring because developers tend to test those, so they are hardly worth testings. Its the edge cases which should be tested.
Andrew
Jakub Kicinski
maintainerQuoted 15 lines · On Mon, 27 Oct 2025 20:46:00 +0100 Andrew Lunn wrote:
tools/testing/selftests/drivers/net/ring_reconfig.py line 47
Quoted 11 lines
tools/testing/selftests/drivers/net/ring_reconfig.py new file +11
-0+ def test_config(config): + try: + cfg.eth.channels_set(ehdr | config) + get = cfg.eth.channels_get(ehdr) + for k, v in config.items(): + ksft_eq(get.get(k, 0), v) + except NlError as e: + failed.append(mix) + ksft_pr("Can't set", config, e) + else: + ksft_pr("Okay", config)We expect failure to leave the configuration unchanged. So i would actually do:
Quoted 6 lines
try:
before = get() set() except: after = get() fail(after != before)
Please allow me to introduce you to the magic of defer() ;) This registers a command to run after the test completely exits:
+ defer(cfg.eth.channels_set, ehdr | restore)
Quoted 6 lines
Also, does nlError contain the error code?
fail(e.errcode not in (EINVAL, EOPNOTSUPP))It would be good to detect and fail ENOTSUPP, which does appear every so often, when it should not.
Dunno, checkpatch warns about ENOTSUPP. I don't that think checking for funny error codes in every test scales :(
Quoted 13 lines
tools/testing/selftests/drivers/net/ring_reconfig.py line 133
Quoted 12 lines
tools/testing/selftests/drivers/net/ring_reconfig.py new file +12
-0+ # Try to reach min on all settings + for param in params: + val = rings[param] + while True: + try: + cfg.eth.rings_set({'header':{'dev-index': cfg.ifindex}, + param: val // 2}) + val //= 2 + if val <= 1: + break + except NlError: + break
Quoted 5 lines
Is 0 ever valid? I would actually test 0 and make sure it fails with EINVAL, or EOPNOTSUPP. Getting range checks wrong is a typical bug, so it is good to test them. The happy days cases are boring because developers tend to test those, so they are hardly worth testings. Its the edge cases which should be tested.
I believe that 0 is a valid settings. I don't have much experience with devices which support it. But presumably using 0 to disable mini/jumbo rings would make sense for example? And max validation is done by the core so nothing interesting to explore there at the driver level :(
Andrew Lunn
maintainerQuoted 16 lines · Jakub Kicinski
Quoted 15 lines · On Mon, 27 Oct 2025 20:46:00 +0100 Andrew Lunn wrote:
tools/testing/selftests/drivers/net/ring_reconfig.py line 47
Quoted 11 lines
tools/testing/selftests/drivers/net/ring_reconfig.py new file +11
-0+ def test_config(config): + try: + cfg.eth.channels_set(ehdr | config) + get = cfg.eth.channels_get(ehdr) + for k, v in config.items(): + ksft_eq(get.get(k, 0), v) + except NlError as e: + failed.append(mix) + ksft_pr("Can't set", config, e) + else: + ksft_pr("Okay", config)We expect failure to leave the configuration unchanged. So i would actually do:
Quoted 8 lines
Quoted 6 lines
try:
before = get() set() except: after = get() fail(after != before)Please allow me to introduce you to the magic of
defer();)
That is why i don't like magic, especially in tests which have no documentation of the expected results. For me, tests should be dumb, often boringly repetitive, and at least 50% comments, explaining what is being tested, what the expected outcome is, and most importantly, why that is the expected outcome.
Quoted 6 lines
This registers a command to run after the test completely exits:
+
defer(cfg.eth.channels_set, ehdr | restore)Quoted 2 lines
Also, does nlError contain the error code?
Quoted 7 lines
Quoted 4 lines
fail(e.errcode not in (EINVAL, EOPNOTSUPP))It would be good to detect and fail ENOTSUPP, which does appear every so often, when it should not.
Dunno, checkpatch warns about ENOTSUPP. I don't that think checking for funny error codes in every test scales :(
How about in the nlError constructor? That gives you a single location, and you can accept EINVAL, EOPNOTSUPP, ENODEV, ENOMEM, maybe ETOOBIG. Cause the test to fail for everything else. If anybody reports test failures with other errno values, the list can be expanded, if they are sensible.
Quoted 19 lines
Quoted 13 lines
tools/testing/selftests/drivers/net/ring_reconfig.py line 133
Quoted 12 lines
tools/testing/selftests/drivers/net/ring_reconfig.py new file +12
-0+ # Try to reach min on all settings + for param in params: + val = rings[param] + while True: + try: + cfg.eth.rings_set({'header':{'dev-index': cfg.ifindex}, + param: val // 2}) + val //= 2 + if val <= 1: + break + except NlError: + breakQuoted 5 lines
Is 0 ever valid? I would actually test 0 and make sure it fails with EINVAL, or EOPNOTSUPP. Getting range checks wrong is a typical bug, so it is good to test them. The happy days cases are boring because developers tend to test those, so they are hardly worth testings. Its the edge cases which should be tested.
Quoted 4 lines
I believe that 0 is a valid settings. I don't have much experience with devices which support it. But presumably using 0 to disable mini/jumbo rings would make sense for example? And max validation is done by the core so nothing interesting to explore there at the driver level :(
Looking at the code, it seems to cost nothing to actually test 0, if you say it could be valid. That might also find an off-by-one error, if it causes something to go negative/large positive.
Andrew
Jakub Kicinski
maintainerQuoted 12 lines · On Tue, 28 Oct 2025 03:05:03 +0100 Andrew Lunn wrote:
Quoted 11 lines · Jakub Kicinski
Quoted 9 lines · On Mon, 27 Oct 2025 20:46:00 +0100 Andrew Lunn wrote:
We expect failure to leave the configuration unchanged. So i would actually do:
try:
before = get() set() except: after = get() fail(after != before)
Quoted 7 lines
Quoted 1 line
Please allow me to introduce you to the magic of
defer();)That is why i don't like magic, especially in tests which have no documentation of the expected results. For me, tests should be dumb, often boringly repetitive, and at least 50% comments, explaining what is being tested, what the expected outcome is, and most importantly, why that is the expected outcome.
We actively avoid creating framework-y stuff.
defer() is one of the few things we added. Single config change is fine but undoing a sequence of actions quickly becomes gnarly. And defer() itself is very straightforward.. once you know about it ;)
https://github.com/linux-netdev/nipa/wiki/Guidance-for-test-authors
Quoted 11 lines
Quoted 11 lines
This registers a command to run after the test completely exits:
+
defer(cfg.eth.channels_set, ehdr | restore)Quoted 6 lines
Also, does nlError contain the error code?
fail(e.errcode not in (EINVAL, EOPNOTSUPP))It would be good to detect and fail ENOTSUPP, which does appear every so often, when it should not.
Quoted 8 lines
Quoted 2 lines
Dunno, checkpatch warns about ENOTSUPP. I don't that think checking for funny error codes in every test scales :(
How about in the nlError constructor? That gives you a single location, and you can accept EINVAL, EOPNOTSUPP, ENODEV, ENOMEM, maybe ETOOBIG. Cause the test to fail for everything else. If anybody reports test failures with other errno values, the list can be expanded, if they are sensible.
Maybe it's just my subjective preference but I think we need to be judicious about what we test. I see no value in checking errno here. This is mostly a "crash test", IOW must common issues it will find will be crashes, WARN()s or broken device. Nothing subtle.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Is 0 ever valid? I would actually test 0 and make sure it fails with EINVAL, or EOPNOTSUPP. Getting range checks wrong is a typical bug, so it is good to test them. The happy days cases are boring because developers tend to test those, so they are hardly worth testings. Its the edge cases which should be tested.
Quoted 8 lines
Quoted 4 lines
I believe that 0 is a valid settings. I don't have much experience with devices which support it. But presumably using 0 to disable mini/jumbo rings would make sense for example? And max validation is done by the core so nothing interesting to explore there at the driver level :(
Looking at the code, it seems to cost nothing to actually test 0, if you say it could be valid. That might also find an off-by-one error, if it causes something to go negative/large positive.
Okay. But for the record I'd strongly prefer it the level of nit picking was correlated with reviewer's authorship of tests :/