mirror-linux/tools/testing/selftests/drivers/net
Yohei Kojima 75df712cdd selftests: netdevsim: add carrier state consistency test
This commit adds a test case for netdevsim carrier state consistency.
Specifically, the added test verifies the carrier state during the
following operations:

1. Unlink two netdevsims
2. ifdown one netdevsim, then ifup again
3. Link the netdevsims again
4. ifdown one netdevsim, then ifup again

These steps verifies that the carrier is UP iff two netdevsims are
linked and ifuped.

Signed-off-by: Yohei Kojima <yk@y-koj.net>
Link: https://patch.msgid.link/481e2729e53b6074ebfc0ad85764d8feb244de8c.1767624906.git.yk@y-koj.net
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2026-01-06 18:04:01 -08:00
..
bonding selftests: bonding: add delay before each xvlan_over_bond connectivity check 2025-11-28 20:16:22 -08:00
dsa selftests: net: unify the Makefile formats 2025-10-06 13:14:06 -07:00
hw selftests: drv-net: Bring back tool() to driver __init__s 2026-01-06 17:52:08 -08:00
lib selftests: drv-net: introduce Iperf3Runner for measurement use cases 2025-12-01 17:18:41 -08:00
microchip
mlxsw selftests: forwarding: lib: Add an autodefer variant of simple_if_init() 2025-09-26 17:48:40 -07:00
netdevsim selftests: netdevsim: add carrier state consistency test 2026-01-06 18:04:01 -08:00
ocelot selftests: net: tsn_lib: add window_size argument to isochron_do() 2025-04-29 14:44:34 -07:00
team selftests: net: unify the Makefile formats 2025-10-06 13:14:06 -07:00
virtio_net selftests: net: unify the Makefile formats 2025-10-06 13:14:06 -07:00
.gitignore selftests: net: relocate gro and toeplitz tests to drivers/net 2025-11-20 18:19:29 -08:00
Makefile selftests: drv-net: add a Python version of the GRO test 2025-11-20 18:19:30 -08:00
README.rst selftests: net: report output format as TAP 13 in Python tests 2025-03-03 15:03:19 -08:00
config selftests: net: sort configs 2025-10-06 13:12:59 -07:00
gro.c Significant patch series in this pull request: 2025-12-06 14:01:20 -08:00
gro.py selftests: drv-net: add a Python version of the GRO test 2025-11-20 18:19:30 -08:00
hds.py selftests: drv-net: make linters happy with our imports 2025-10-07 12:12:44 +02: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
napi_threaded.py selftests: drv-net: adjust tests before defaulting to shell=False 2025-09-02 16:09:36 -07:00
netcons_basic.sh selftests: netconsole: ensure required log level is set on netcons_basic 2025-11-24 18:52:20 -08:00
netcons_cmdline.sh selftests: netconsole: Validate interface selection by MAC address 2025-08-13 17:28:27 -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: Increase MAX_USERDATA_ITEMS 2025-11-20 18:47:18 -08:00
netcons_sysdata.sh selftests: netconsole: Add tests for 'msgid' feature in sysdata 2025-06-18 10:46:10 +01:00
netcons_torture.sh selftest: netcons: create a torture test 2025-11-10 18:34:44 -08: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
psp.py selftests: drv-net: psp: fix test names in ipver_test_builder() 2025-12-23 12:05:04 +01:00
psp_responder.c selftests: drv-net: add PSP responder 2025-09-30 15:17:22 +02:00
queues.py selftests: net: move xdp_helper to net/lib 2025-04-28 15:49:10 -07:00
ring_reconfig.py selftests: drv-net: replace the nsim ring test with a drv-net one 2025-10-30 17:32:18 -07:00
shaper.py testing: net-drv: add basic shaper test 2024-10-10 08:30:23 -07:00
stats.py selftests: drv-net: Limit the max number of queues in procfs_downup_hammer 2025-11-12 18:04:18 -08:00
xdp.py selftests: drv-net: xdp: use variants for qstat tests 2025-11-20 18:19:29 -08:00

README.rst

.. 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