README 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. Automated hostapd/wpa_supplicant testing with mac80211_hwsim
  2. ------------------------------------------------------------
  3. This directory contains testing infrastructure and test cases to run
  4. automated tests of full hostapd and wpa_supplicant functionality. This
  5. testing is done with the help of mac80211_hwsim which is Linux kernel
  6. driver that simulates IEEE 802.11 radios without requiring any
  7. additional hardware. This setup most of the hostapd and wpa_supplicant
  8. functionality (and large parts of the Linux cfg80211 and mac80211
  9. functionality for that matter) to be tested.
  10. mac80211_hwsim is loaded with five simulated radios to allow different
  11. device combinations to be tested. wlantest is used analyze raw packets
  12. captured through the hwsim0 monitor interface that capture all frames
  13. sent on all channels. wlantest is used to store the frames for
  14. analysis. Three wpa_supplicant processes are used to control three
  15. virtual radios and one hostapd process is used to dynamically control
  16. the other two virtual radios. wpa_supplicant/hostapd test functionality
  17. is used to verify that data connection (both unicast and broadcast)
  18. works between two netdevs.
  19. The python scripts and tools in this directory control test case
  20. execution. They interact wpa_supplicant and hostapd through control
  21. interfaces to perform the operations. In addition, wlantest_cli is used
  22. to verify that operations have been performed correctly and that the
  23. network connection works in the expected way.
  24. These test cases are run automatically against the hostap.git commits
  25. for regression testing and to help in keeping the hostap.git master
  26. branch in stable state. Results from these tests are available here:
  27. http://buildbot.w1.fi/hwsim/
  28. Building binaries for testing
  29. -----------------------------
  30. You will need to build (or use already built) components to be
  31. tested. These are available in the hostap.git repository and can be
  32. built for example as follows:
  33. cd ../../wpa_supplicant
  34. cp ../tests/hwsim/example-wpa_supplicant.config .config
  35. make clean
  36. make
  37. cd ../hostapd
  38. cp ../tests/hwsim/example-hostapd.config .config
  39. make clean
  40. make hostapd hostapd_cli hlr_auc_gw
  41. cd ../wlantest
  42. make clean
  43. make
  44. Alternatively, the build.sh script here can be used to run these steps
  45. with conditional creation of .config files only if they do not exist.
  46. The test scripts can find the binaries in the locations where they were
  47. built. It is also possible to install wlantest_cli somewhere on the path
  48. to use pre-built tools.
  49. Please note that some of the configuration parameters used to enable
  50. more testing coverage may require development packages that may not be
  51. installed by default in many distributions. For example, following
  52. Debian/Ubuntu packages are likely to be needed:
  53. - binutils-dev
  54. - libsqlite3-dev
  55. - libpcap-dev
  56. example-setup.txt provides more complete step-by-step example on how a
  57. test setup can be built.
  58. wpaspy
  59. ------
  60. The python scripts use wpaspy.py to interact with the wpa_supplicant
  61. control interface, but the run-tests.py script adds the (relative)
  62. path into the environment so it doesn't need to be installed.
  63. mac80211_hwsim
  64. --------------
  65. mac80211_hwsim kernel module is available from the upstream Linux
  66. kernel. Some Linux distributions enable it by default. If that's not the
  67. case, you can either enable it in the kernel configuration
  68. (CONFIG_MAC80211_HWSIM=m) and rebuild your kernel or use Backports with
  69. CPTCFG_MAC80211_HWSIM=m to replace the wireless LAN components in the
  70. base kernel.
  71. sudo
  72. ----
  73. Some parts of the testing process requires root privileges. The test
  74. scripts are currently using sudo to achieve this. To be able to run the
  75. tests, you'll probably want to enable sudo with a timeout to not expire
  76. password entry very quickly. For example, use this in the sudoers file:
  77. Defaults env_reset,timestamp_timeout=180
  78. Or on a dedicated test system, you could even disable password prompting
  79. with this in sudoers:
  80. %sudo ALL=NOPASSWD: ALL
  81. Other network interfaces
  82. ------------------------
  83. Some of the test scripts are still using hardcoded interface names, so
  84. the easiest way of making things work is to avoid using other network
  85. devices that may use conflicting interface names. For example, unload
  86. any wireless LAN driver before running the tests and make sure that
  87. wlan0..4 gets assigned as the interface names for the mac80211_hwsim
  88. radios. It may also be possible to rename the interface expectations in
  89. run-tests.py to allow other names to be used.
  90. Please also note that some commonly enabled tools, like NetworkManager,
  91. may end up trying to control new network interfaces automatically. This
  92. can result in conflicts with the test scripts and you may need to
  93. disable such network services or at least mark the mac80211_hwsim wlan#
  94. interfaces as umanaged. As an example, this can be done in
  95. /etc/NetworkManager/NetworkManager.conf with following addition:
  96. [keyfile]
  97. unmanaged-devices=mac:02:00:00:00:00:00;mac:02:00:00:00:01:00;mac:02:00:00:00:02:00;mac:02:00:00:00:03:00;mac:02:00:00:00:04:00
  98. Running tests
  99. -------------
  100. Simplest way to run a full set of the test cases is by running
  101. run-all.sh in tests/hwsim directory. This will use start.sh to load the
  102. mac80211_hwsim module and start wpa_supplicant, hostapd, and various
  103. test tools. run-tests.sh is then used to run through all the defined
  104. test cases and stop.sh to stop the programs and unload the kernel
  105. module.
  106. run-all.sh can be used to run the same test cases under different
  107. conditions:
  108. # run normal test cases
  109. ./run-all.sh
  110. # run normal test cases under valgrind
  111. ./run-all.sh valgrind
  112. # run normal test cases with Linux tracing
  113. ./run-all.sh trace
  114. # run normal test cases with multi channel support (see details below)
  115. ./run-all.sh channels=<num of channels>
  116. run-all.sh directs debug logs into the logs subdirectory (or $LOGDIR if
  117. present in the environment). Log file names include the current UNIX
  118. timestamp and a postfix to identify the specific log:
  119. - *.log0 = wpa_supplicant debug log for the first radio
  120. - *.log1 = wpa_supplicant debug log for the second radio
  121. - *.log2 = wpa_supplicant debug log for the third radio
  122. - *.hostapd = hostapd debug log
  123. - hwsim0 = wlantest debug log
  124. - hwsim0.pcapng = capture with all frames exchanged during the tests
  125. - *.log = debug prints from the test scripts
  126. - trace.dat = Linux tracing record (if enabled)
  127. - hlr_auc_gw - hlr_auc_gw (EAP-SIM/AKA/AKA' authentication) log
  128. - auth_serv - hostapd as RADIUS authentication server log
  129. For manual testing, ./start.sh can be used to initialize interfaces and
  130. programs and run-tests.py to execute one or more test
  131. cases. run-tests.py output verbosity can be controlled with -d (more
  132. verbose debug output) and -q (less verbose output) on the command
  133. line. "-f <module name>" (pointing to file test_<module name>.py) can be
  134. used to specify that all test cases from a single file are to be
  135. run. Test name as the last command line argument can be specified that a
  136. single test case is to be run (e.g., "./run-tests.py ap_pmf_required").
  137. Notice that some tests require the driver to support concurrent
  138. operation on multi channels in order to run. These tests will be skipped
  139. in case the driver does not support multi channels. To enable support
  140. for multi channel, the number of supported channel is passed as an
  141. argument to run-all.sh or start.sh
  142. Adding/modifying test cases
  143. ---------------------------
  144. All the test cases are defined in the test_*.py files. These are python
  145. scripts that can use the local helper classes to interact with the test
  146. components. While various python constructs can be used in the scripts,
  147. only a minimal level of python knowledge should really be needed to
  148. modify and add new test cases. The easiest starting point for this is
  149. likely to take a look at some of the example scripts. When working on a
  150. new test, run-tests.py with -d and the test case name on the command
  151. line is a convenient way of verifying functionality.
  152. run-tests.py will automatically import all test cases from the test_*.py
  153. files in this directory. All functions starting with the "test_" prefix
  154. in these files are assumed to be test cases. Each test case is named by
  155. the function name following the "test_" prefix.
  156. Results database
  157. ----------------
  158. run-tests.py can be requested to write results from the execution of
  159. each test case into an sqlite database. The "-S <path to database>" and
  160. "-b <build id>" command line arguments can be used to do that. The
  161. database must have been prepared before this, e.g., with following:
  162. cat | sqlite3 /tmp/example.db <<EOF
  163. CREATE TABLE results (test,result,run,time,duration,build,commitid);
  164. CREATE INDEX results_idx ON results (test);
  165. CREATE INDEX results_idx2 ON results (run);
  166. CREATE TABLE tests (test,description);
  167. CREATE UNIQUE INDEX tests_idx ON tests (test);
  168. CREATE TABLE logs (test,run,type,contents);
  169. CREATE INDEX logs_idx ON logs (test);
  170. CREATE INDEX logs_idx2 ON logs (run);
  171. EOF