Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: drv-net: extend the README with more info and example

Add more info to the README. It's also now copied to GitHub for
increased visibility:

https://github.com/linux-netdev/nipa/wiki/Running-driver-tests

Reviewed-by: Willem de Bruijn <willemb@google.com>
Link: https://lore.kernel.org/r/20240425222341.309778-2-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+85 -12
+85 -12
tools/testing/selftests/drivers/net/README.rst
··· 1 - Running tests 2 - ============= 1 + .. SPDX-License-Identifier: GPL-2.0 3 2 4 - Tests are executed within kselftest framework like any other tests. 5 - By default tests execute against software drivers such as netdevsim. 6 - All tests must support running against a real device (SW-only tests 7 - should instead be placed in net/ or drivers/net/netdevsim, HW-only 8 - tests in drivers/net/hw). 3 + Running driver tests 4 + ==================== 9 5 10 - Set appropriate variables to point the tests at a real device. 6 + Networking driver tests are executed within kselftest framework like any 7 + other tests. They support testing both real device drivers and emulated / 8 + software drivers (latter mostly to test the core parts of the stack). 9 + 10 + SW mode 11 + ~~~~~~~ 12 + 13 + By default, when no extra parameters are set or exported, tests execute 14 + against software drivers such as netdevsim. No extra preparation is required 15 + the software devices are created and destroyed as part of the test. 16 + In this mode the tests are indistinguishable from other selftests and 17 + (for example) can be run under ``virtme-ng`` like the core networking selftests. 18 + 19 + HW mode 20 + ~~~~~~~ 21 + 22 + Executing tests against a real device requires external preparation. 23 + The netdevice against which tests will be run must exist, be running 24 + (in UP state) and be configured with an IP address. 25 + 26 + Refer to list of :ref:`Variables` later in this file to set up running 27 + the tests against a real device. 28 + 29 + Both modes required 30 + ~~~~~~~~~~~~~~~~~~~ 31 + 32 + All tests in drivers/net must support running both against a software device 33 + and a real device. SW-only tests should instead be placed in net/ or 34 + drivers/net/netdevsim, HW-only tests in drivers/net/hw. 11 35 12 36 Variables 13 37 ========= 14 38 15 - Variables can be set in the environment or by creating a net.config 39 + The variables can be set in the environment or by creating a net.config 16 40 file in the same directory as this README file. Example:: 17 41 18 42 $ NETIF=eth0 ./some_test.sh ··· 47 23 # Variable set in a file 48 24 NETIF=eth0 49 25 50 - Please note that the config parser is very simple, if there are 51 - any non-alphanumeric characters in the value it needs to be in 52 - double quotes. 26 + Local test (which don't require endpoint for sending / receiving traffic) 27 + need only the ``NETIF`` variable. Remaining variables define the endpoint 28 + and communication method. 53 29 54 30 NETIF 55 31 ~~~~~ ··· 85 61 86 62 for netns - name of the "remote" namespace 87 63 for ssh - name/address of the remote host 64 + 65 + Example 66 + ======= 67 + 68 + Build the selftests:: 69 + 70 + # make -C tools/testing/selftests/ TARGETS="drivers/net drivers/net/hw" 71 + 72 + "Install" the tests and copy them over to the target machine:: 73 + 74 + # make -C tools/testing/selftests/ TARGETS="drivers/net drivers/net/hw" \ 75 + install INSTALL_PATH=/tmp/ksft-net-drv 76 + 77 + # rsync -ra --delete /tmp/ksft-net-drv root@192.168.1.1:/root/ 78 + 79 + On the target machine, running the tests will use netdevsim by default:: 80 + 81 + [/root] # ./ksft-net-drv/run_kselftest.sh -t drivers/net:ping.py 82 + TAP version 13 83 + 1..1 84 + # timeout set to 45 85 + # selftests: drivers/net: ping.py 86 + # KTAP version 1 87 + # 1..3 88 + # ok 1 ping.test_v4 89 + # ok 2 ping.test_v6 90 + # ok 3 ping.test_tcp 91 + # # Totals: pass:3 fail:0 xfail:0 xpass:0 skip:0 error:0 92 + ok 1 selftests: drivers/net: ping.py 93 + 94 + Create a config with remote info:: 95 + 96 + [/root] # cat > ./ksft-net-drv/drivers/net/net.config <<EOF 97 + NETIF=eth0 98 + LOCAL_V4=192.168.1.1 99 + REMOTE_V4=192.168.1.2 100 + REMOTE_TYPE=ssh 101 + REMOTE_ARGS=root@192.168.1.2 102 + EOF 103 + 104 + Run the test:: 105 + 106 + [/root] # ./ksft-net-drv/drivers/net/ping.py 107 + KTAP version 1 108 + 1..3 109 + ok 1 ping.test_v4 110 + ok 2 ping.test_v6 # SKIP Test requires IPv6 connectivity 111 + ok 3 ping.test_tcp 112 + # Totals: pass:2 fail:0 xfail:0 xpass:0 skip:1 error:0