mbox series

[net-next,v2,0/7] selftests: net: groundwork for YNL-based tests

Message ID 20240403023426.1762996-1-kuba@kernel.org (mailing list archive)
Headers show
Series selftests: net: groundwork for YNL-based tests | expand

Message

Jakub Kicinski April 3, 2024, 2:34 a.m. UTC
Currently the options for writing networking tests are C, bash or
some mix of the two. YAML/Netlink gives us the ability to easily
interface with Netlink in higher level laguages. In particular,
there is a Python library already available in tree, under tools/net.
Add the scaffolding which allows writing tests using this library.

The "scaffolding" is needed because the library lives under
tools/net and uses YAML files from under Documentation/.
So we need a small amount of glue code to find those things
and add them to TEST_FILES.

This series adds both a basic SW sanity test and driver
test which can be run against netdevsim or a real device.
When I develop core code I usually test with netdevsim,
then a real device, and then a backport to Meta's kernel.
Because of the lack of integration, until now I had
to throw away the (YNL-based) test script and netdevsim code.

Running tests in tree directly:

 $ ./tools/testing/selftests/net/nl_netdev.py
 KTAP version 1
 1..2
 ok 1 nl_netdev.empty_check
 ok 2 nl_netdev.lo_check
 # Totals: pass:2 fail:0 xfail:0 xpass:0 skip:0 error:0

in tree via make:

 $ make -C tools/testing/selftests/ TARGETS=net \
	TEST_PROGS=nl_netdev.py TEST_GEN_PROGS="" run_tests
  [ ... ]

and installed externally, all seem to work:

 $ make -C tools/testing/selftests/ TARGETS=net \
	install INSTALL_PATH=/tmp/ksft-net
 $ /tmp/ksft-net/run_kselftest.sh -t net:nl_netdev.py
  [ ... ]

For driver tests I followed the lead of net/forwarding and
get the device name from env and/or a config file.

v2: (see patches for minor changes)
 - don't add to TARGETS, create a deperate variable with deps
 - support and use with
 - support and use passing arguments to tests
v1: https://lore.kernel.org/all/20240402010520.1209517-1-kuba@kernel.org/

Jakub Kicinski (7):
  netlink: specs: define ethtool header flags
  tools: ynl: copy netlink error to NlError
  selftests: net: add scaffolding for Netlink tests in Python
  selftests: nl_netdev: add a trivial Netlink netdev test
  netdevsim: report stats by default, like a real device
  selftests: drivers: add scaffolding for Netlink tests in Python
  testing: net-drv: add a driver test for stats reporting

 Documentation/netlink/specs/ethtool.yaml      |   6 +
 drivers/net/netdevsim/ethtool.c               |  11 ++
 drivers/net/netdevsim/netdev.c                |  45 +++++++
 tools/net/ynl/lib/ynl.py                      |   3 +-
 tools/testing/selftests/Makefile              |  10 +-
 tools/testing/selftests/drivers/net/Makefile  |   7 ++
 .../testing/selftests/drivers/net/README.rst  |  30 +++++
 .../selftests/drivers/net/lib/py/__init__.py  |  17 +++
 .../selftests/drivers/net/lib/py/env.py       |  52 ++++++++
 tools/testing/selftests/drivers/net/stats.py  |  86 +++++++++++++
 tools/testing/selftests/net/Makefile          |   1 +
 tools/testing/selftests/net/lib/Makefile      |   8 ++
 .../testing/selftests/net/lib/py/__init__.py  |   7 ++
 tools/testing/selftests/net/lib/py/consts.py  |   9 ++
 tools/testing/selftests/net/lib/py/ksft.py    |  96 ++++++++++++++
 tools/testing/selftests/net/lib/py/nsim.py    | 118 ++++++++++++++++++
 tools/testing/selftests/net/lib/py/utils.py   |  47 +++++++
 tools/testing/selftests/net/lib/py/ynl.py     |  49 ++++++++
 tools/testing/selftests/net/nl_netdev.py      |  24 ++++
 19 files changed, 624 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/selftests/drivers/net/Makefile
 create mode 100644 tools/testing/selftests/drivers/net/README.rst
 create mode 100644 tools/testing/selftests/drivers/net/lib/py/__init__.py
 create mode 100644 tools/testing/selftests/drivers/net/lib/py/env.py
 create mode 100755 tools/testing/selftests/drivers/net/stats.py
 create mode 100644 tools/testing/selftests/net/lib/Makefile
 create mode 100644 tools/testing/selftests/net/lib/py/__init__.py
 create mode 100644 tools/testing/selftests/net/lib/py/consts.py
 create mode 100644 tools/testing/selftests/net/lib/py/ksft.py
 create mode 100644 tools/testing/selftests/net/lib/py/nsim.py
 create mode 100644 tools/testing/selftests/net/lib/py/utils.py
 create mode 100644 tools/testing/selftests/net/lib/py/ynl.py
 create mode 100755 tools/testing/selftests/net/nl_netdev.py

Comments

patchwork-bot+netdevbpf@kernel.org April 4, 2024, 5:40 p.m. UTC | #1
Hello:

This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue,  2 Apr 2024 19:34:19 -0700 you wrote:
> Currently the options for writing networking tests are C, bash or
> some mix of the two. YAML/Netlink gives us the ability to easily
> interface with Netlink in higher level laguages. In particular,
> there is a Python library already available in tree, under tools/net.
> Add the scaffolding which allows writing tests using this library.
> 
> The "scaffolding" is needed because the library lives under
> tools/net and uses YAML files from under Documentation/.
> So we need a small amount of glue code to find those things
> and add them to TEST_FILES.
> 
> [...]

Here is the summary with links:
  - [net-next,v2,1/7] netlink: specs: define ethtool header flags
    https://git.kernel.org/netdev/net-next/c/1d056bf9a4c1
  - [net-next,v2,2/7] tools: ynl: copy netlink error to NlError
    https://git.kernel.org/netdev/net-next/c/b269d2b4a523
  - [net-next,v2,3/7] selftests: net: add scaffolding for Netlink tests in Python
    (no matching commit)
  - [net-next,v2,4/7] selftests: nl_netdev: add a trivial Netlink netdev test
    (no matching commit)
  - [net-next,v2,5/7] netdevsim: report stats by default, like a real device
    (no matching commit)
  - [net-next,v2,6/7] selftests: drivers: add scaffolding for Netlink tests in Python
    (no matching commit)
  - [net-next,v2,7/7] testing: net-drv: add a driver test for stats reporting
    (no matching commit)

You are awesome, thank you!