README.rst 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. .. SPDX-License-Identifier: GPL-2.0
  2. Running driver tests
  3. ====================
  4. Networking driver tests are executed within kselftest framework like any
  5. other tests. They support testing both real device drivers and emulated /
  6. software drivers (latter mostly to test the core parts of the stack).
  7. SW mode
  8. ~~~~~~~
  9. By default, when no extra parameters are set or exported, tests execute
  10. against software drivers such as netdevsim. No extra preparation is required
  11. the software devices are created and destroyed as part of the test.
  12. In this mode the tests are indistinguishable from other selftests and
  13. (for example) can be run under ``virtme-ng`` like the core networking selftests.
  14. HW mode
  15. ~~~~~~~
  16. Executing tests against a real device requires external preparation.
  17. The netdevice against which tests will be run must exist, be running
  18. (in UP state) and be configured with an IP address.
  19. Refer to list of :ref:`Variables` later in this file to set up running
  20. the tests against a real device.
  21. Both modes required
  22. ~~~~~~~~~~~~~~~~~~~
  23. All tests in drivers/net must support running both against a software device
  24. and a real device. SW-only tests should instead be placed in net/ or
  25. drivers/net/netdevsim, HW-only tests in drivers/net/hw.
  26. Variables
  27. =========
  28. The variables can be set in the environment or by creating a net.config
  29. file in the same directory as this README file. Example::
  30. $ NETIF=eth0 ./some_test.sh
  31. or::
  32. $ cat tools/testing/selftests/drivers/net/net.config
  33. # Variable set in a file
  34. NETIF=eth0
  35. Local test (which don't require endpoint for sending / receiving traffic)
  36. need only the ``NETIF`` variable. Remaining variables define the endpoint
  37. and communication method.
  38. NETIF
  39. ~~~~~
  40. Name of the netdevice against which the test should be executed.
  41. When empty or not set software devices will be used.
  42. LOCAL_V4, LOCAL_V6, REMOTE_V4, REMOTE_V6
  43. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  44. Local and remote endpoint IP addresses.
  45. REMOTE_TYPE
  46. ~~~~~~~~~~~
  47. Communication method used to run commands on the remote endpoint.
  48. Test framework has built-in support for ``netns`` and ``ssh`` channels.
  49. ``netns`` assumes the "remote" interface is part of the same
  50. host, just moved to the specified netns.
  51. ``ssh`` communicates with remote endpoint over ``ssh`` and ``scp``.
  52. Using persistent SSH connections is strongly encouraged to avoid
  53. the latency of SSH connection setup on every command.
  54. Communication methods are defined by classes in ``lib/py/remote_{name}.py``.
  55. It should be possible to add a new method without modifying any of
  56. the framework, by simply adding an appropriately named file to ``lib/py``.
  57. REMOTE_ARGS
  58. ~~~~~~~~~~~
  59. Arguments used to construct the communication channel.
  60. Communication channel dependent::
  61. for netns - name of the "remote" namespace
  62. for ssh - name/address of the remote host
  63. Example
  64. =======
  65. Build the selftests::
  66. # make -C tools/testing/selftests/ TARGETS="drivers/net drivers/net/hw"
  67. "Install" the tests and copy them over to the target machine::
  68. # make -C tools/testing/selftests/ TARGETS="drivers/net drivers/net/hw" \
  69. install INSTALL_PATH=/tmp/ksft-net-drv
  70. # rsync -ra --delete /tmp/ksft-net-drv root@192.168.1.1:/root/
  71. On the target machine, running the tests will use netdevsim by default::
  72. [/root] # ./ksft-net-drv/run_kselftest.sh -t drivers/net:ping.py
  73. TAP version 13
  74. 1..1
  75. # timeout set to 45
  76. # selftests: drivers/net: ping.py
  77. # KTAP version 1
  78. # 1..3
  79. # ok 1 ping.test_v4
  80. # ok 2 ping.test_v6
  81. # ok 3 ping.test_tcp
  82. # # Totals: pass:3 fail:0 xfail:0 xpass:0 skip:0 error:0
  83. ok 1 selftests: drivers/net: ping.py
  84. Create a config with remote info::
  85. [/root] # cat > ./ksft-net-drv/drivers/net/net.config <<EOF
  86. NETIF=eth0
  87. LOCAL_V4=192.168.1.1
  88. REMOTE_V4=192.168.1.2
  89. REMOTE_TYPE=ssh
  90. REMOTE_ARGS=root@192.168.1.2
  91. EOF
  92. Run the test::
  93. [/root] # ./ksft-net-drv/drivers/net/ping.py
  94. KTAP version 1
  95. 1..3
  96. ok 1 ping.test_v4
  97. ok 2 ping.test_v6 # SKIP Test requires IPv6 connectivity
  98. ok 3 ping.test_tcp
  99. # Totals: pass:2 fail:0 xfail:0 xpass:0 skip:1 error:0