linux/tools/testing/selftests/drivers/net
Jakub Kicinski c58c18be88 Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net
Merge in late fixes to prepare for the 6.17 net-next PR.

Conflicts:

net/core/neighbour.c
  1bbb76a899 ("neighbour: Fix null-ptr-deref in neigh_flush_dev().")
  13a936bb99 ("neighbour: Protect tbl->phash_buckets[] with a dedicated mutex.")
  03dc03fa04 ("neighbor: Add NTF_EXT_VALIDATED flag for externally validated entries")

Adjacent changes:

drivers/net/usb/usbnet.c
  0d9cfc9b8c ("net: usbnet: Avoid potential RCU stall on LINK_CHANGE event")
  2c04d279e8 ("net: usb: Convert tasklet API to new bottom half workqueue mechanism")

net/ipv6/route.c
  31d7d67ba1 ("ipv6: annotate data-races around rt->fib6_nsiblings")
  1caf272972 ("ipv6: adopt dst_dev() helper")
  3b3ccf9ed0 ("net: Remove unnecessary NULL check for lwtunnel_fill_encap()")

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2025-07-26 11:49:45 -07:00
..
bonding selftests: bonding: fix incorrect mac address 2025-03-11 13:19:27 +01:00
dsa selftests: net: tc_taprio: new test 2025-04-29 14:44:34 -07:00
hw Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2025-07-26 11:49:45 -07:00
lib selftests: net: Skip test if IPv6 is not configured 2025-07-25 11:25:34 -07:00
microchip selftests: microchip: add test for QoS support on KSZ9477 switch family 2024-05-08 10:35:11 +01:00
mlxsw selftests: forwarding: lib: Split setup_wait() 2025-06-26 17:53:07 -07:00
netdevsim netdevsim: add fw_update_flash_chunk_time_ms debugfs knobs 2025-07-23 17:08:56 -07:00
ocelot selftests: net: tsn_lib: add window_size argument to isochron_do() 2025-04-29 14:44:34 -07:00
team selftests: net: validate team flags propagation 2025-05-20 18:12:58 -07:00
virtio_net selftests: virtio_net: add forgotten config options 2024-06-20 07:10:32 -07:00
.gitignore selftests: net: move xdp_helper to net/lib 2025-04-28 15:49:10 -07:00
config selftests: drv-net: Test queue xsk attribute 2025-02-17 16:46:03 -08:00
hds.py selftests: drv-net: test random value for hds-thresh 2025-04-07 11:00:00 -07:00
Makefile selftests: drv-net: Test XDP_PASS/DROP support 2025-07-22 18:15:53 -07:00
napi_id.py selftests/drivers/net: Support ipv6 for napi_id test 2025-07-17 18:56:14 -07:00
napi_id_helper.c selftests/drivers/net: Support ipv6 for napi_id test 2025-07-17 18:56:14 -07:00
netcons_basic.sh selftests: net: Add IPv6 support to netconsole basic tests 2025-07-07 18:52:57 -07:00
netcons_cmdline.sh selftests: net: add netconsole test for cmdline configuration 2025-06-16 15:18:34 -07:00
netcons_fragmented_msg.sh netconsole: selftest: Add test for fragmented messages 2025-02-04 18:09:21 -08:00
netcons_overflow.sh netconsole: selftest: verify userdata entry limit 2025-01-09 18:06:36 -08:00
netcons_sysdata.sh selftests: netconsole: Add tests for 'msgid' feature in sysdata 2025-06-18 10:46:10 +01:00
netpoll_basic.py selftests: net: add netpoll basic functionality test 2025-07-16 17:25:49 -07:00
ping.py selftests: drv-net: Make command requirements explicit 2025-07-24 18:52:00 -07:00
queues.py selftests: net: move xdp_helper to net/lib 2025-04-28 15:49:10 -07:00
README.rst selftests: net: report output format as TAP 13 in Python tests 2025-03-03 15:03:19 -08:00
shaper.py testing: net-drv: add basic shaper test 2024-10-10 08:30:23 -07:00
stats.py selftests: drv-net: stats: use skip instead of xfail for unsupported features 2025-06-23 17:06:25 -07:00
xdp.py selftests: drv-net: Wait for bkg socat to start 2025-07-25 16:57:28 -07:00

.. SPDX-License-Identifier: GPL-2.0

Running driver tests
====================

Networking driver tests are executed within kselftest framework like any
other tests. They support testing both real device drivers and emulated /
software drivers (latter mostly to test the core parts of the stack).

SW mode
~~~~~~~

By default, when no extra parameters are set or exported, tests execute
against software drivers such as netdevsim. No extra preparation is required
the software devices are created and destroyed as part of the test.
In this mode the tests are indistinguishable from other selftests and
(for example) can be run under ``virtme-ng`` like the core networking selftests.

HW mode
~~~~~~~

Executing tests against a real device requires external preparation.
The netdevice against which tests will be run must exist, be running
(in UP state) and be configured with an IP address.

Refer to list of :ref:`Variables` later in this file to set up running
the tests against a real device.

Both modes required
~~~~~~~~~~~~~~~~~~~

All tests in drivers/net must support running both against a software device
and a real device. SW-only tests should instead be placed in net/ or
drivers/net/netdevsim, HW-only tests in drivers/net/hw.

Variables
=========

The variables can be set in the environment or by creating a net.config
file in the same directory as this README file. Example::

  $ NETIF=eth0 ./some_test.sh

or::

  $ cat tools/testing/selftests/drivers/net/net.config
  # Variable set in a file
  NETIF=eth0

Local test (which don't require endpoint for sending / receiving traffic)
need only the ``NETIF`` variable. Remaining variables define the endpoint
and communication method.

NETIF
~~~~~

Name of the netdevice against which the test should be executed.
When empty or not set software devices will be used.

LOCAL_V4, LOCAL_V6, REMOTE_V4, REMOTE_V6
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Local and remote endpoint IP addresses.

REMOTE_TYPE
~~~~~~~~~~~

Communication method used to run commands on the remote endpoint.
Test framework has built-in support for ``netns`` and ``ssh`` channels.
``netns`` assumes the "remote" interface is part of the same
host, just moved to the specified netns.
``ssh`` communicates with remote endpoint over ``ssh`` and ``scp``.
Using persistent SSH connections is strongly encouraged to avoid
the latency of SSH connection setup on every command.

Communication methods are defined by classes in ``lib/py/remote_{name}.py``.
It should be possible to add a new method without modifying any of
the framework, by simply adding an appropriately named file to ``lib/py``.

REMOTE_ARGS
~~~~~~~~~~~

Arguments used to construct the communication channel.
Communication channel dependent::

  for netns - name of the "remote" namespace
  for ssh - name/address of the remote host

Example
=======

Build the selftests::

  # make -C tools/testing/selftests/ TARGETS="drivers/net drivers/net/hw"

"Install" the tests and copy them over to the target machine::

  # make -C tools/testing/selftests/ TARGETS="drivers/net drivers/net/hw" \
     install INSTALL_PATH=/tmp/ksft-net-drv

  # rsync -ra --delete /tmp/ksft-net-drv root@192.168.1.1:/root/

On the target machine, running the tests will use netdevsim by default::

  [/root] # ./ksft-net-drv/run_kselftest.sh -t drivers/net:ping.py
  TAP version 13
  1..1
  # timeout set to 45
  # selftests: drivers/net: ping.py
  # TAP version 13
  # 1..3
  # ok 1 ping.test_v4
  # ok 2 ping.test_v6
  # ok 3 ping.test_tcp
  # # Totals: pass:3 fail:0 xfail:0 xpass:0 skip:0 error:0
  ok 1 selftests: drivers/net: ping.py

Create a config with remote info::

  [/root] # cat > ./ksft-net-drv/drivers/net/net.config <<EOF
  NETIF=eth0
  LOCAL_V4=192.168.1.1
  REMOTE_V4=192.168.1.2
  REMOTE_TYPE=ssh
  REMOTE_ARGS=root@192.168.1.2
  EOF

Run the test::

  [/root] # ./ksft-net-drv/drivers/net/ping.py
  TAP version 13
  1..3
  ok 1 ping.test_v4
  ok 2 ping.test_v6 # SKIP Test requires IPv6 connectivity
  ok 3 ping.test_tcp
  # Totals: pass:2 fail:0 xfail:0 xpass:0 skip:1 error:0