testing_tools.doxygen 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. /**
  2. \page testing_tools Testing and development tools
  3. [ \ref eapol_test "eapol_test" |
  4. \ref preauth_test "preauth_test" |
  5. \ref driver_test "driver_test" |
  6. \ref unit_tests "Unit tests" |
  7. \ref wpa_trace "Tracing code" ]
  8. %wpa_supplicant source tree includes number of testing and development
  9. tools that make it easier to test the programs without having to setup
  10. a full test setup with wireless cards. In addition, these tools can be
  11. used to implement automatic tests suites.
  12. \section eapol_test eapol_test - EAP peer and RADIUS client testing
  13. eapol_test is a program that links together the same EAP peer
  14. implementation that %wpa_supplicant is using and the RADIUS
  15. authentication client code from hostapd. In addition, it has minimal
  16. glue code to combine these two components in similar ways to IEEE
  17. 802.1X/EAPOL Authenticator state machines. In other words, it
  18. integrates IEEE 802.1X Authenticator (normally, an access point) and
  19. IEEE 802.1X Supplicant (normally, a wireless client) together to
  20. generate a single program that can be used to test EAP methods without
  21. having to setup an access point and a wireless client.
  22. The main uses for eapol_test are in interoperability testing of EAP
  23. methods against RADIUS servers and in development testing for new EAP
  24. methods. It can be easily used to automate EAP testing for
  25. interoperability and regression since the program can be run from
  26. shell scripts without require additional test components apart from a
  27. RADIUS server. For example, the automated EAP tests described in
  28. eap_testing.txt are implemented with eapol_test. Similarly, eapol_test
  29. could be used to implement an automated regression test suite for a
  30. RADIUS authentication server.
  31. eapol_test uses the same build time configuration file, .config, as
  32. %wpa_supplicant. This file is used to select which EAP methods are
  33. included in eapol_test. This program is not built with the default
  34. Makefile target, so a separate make command needs to be used to
  35. compile the tool:
  36. \verbatim
  37. make eapol_test
  38. \endverbatim
  39. The resulting eapol_test binary has following command like options:
  40. \verbatim
  41. usage:
  42. eapol_test [-nWS] -c<conf> [-a<AS IP>] [-p<AS port>] [-s<AS secret>] \
  43. [-r<count>] [-t<timeout>] [-C<Connect-Info>] \
  44. [-M<client MAC address>]
  45. eapol_test scard
  46. eapol_test sim <PIN> <num triplets> [debug]
  47. options:
  48. -c<conf> = configuration file
  49. -a<AS IP> = IP address of the authentication server, default 127.0.0.1
  50. -p<AS port> = UDP port of the authentication server, default 1812
  51. -s<AS secret> = shared secret with the authentication server, default 'radius'
  52. -r<count> = number of re-authentications
  53. -W = wait for a control interface monitor before starting
  54. -S = save configuration after authentiation
  55. -n = no MPPE keys expected
  56. -t<timeout> = sets timeout in seconds (default: 30 s)
  57. -C<Connect-Info> = RADIUS Connect-Info (default: CONNECT 11Mbps 802.11b)
  58. -M<client MAC address> = Set own MAC address (Calling-Station-Id,
  59. default: 02:00:00:00:00:01)
  60. \endverbatim
  61. As an example,
  62. \verbatim
  63. eapol_test -ctest.conf -a127.0.0.1 -p1812 -ssecret -r1
  64. \endverbatim
  65. tries to complete EAP authentication based on the network
  66. configuration from test.conf against the RADIUS server running on the
  67. local host. A re-authentication is triggered to test fast
  68. re-authentication. The configuration file uses the same format for
  69. network blocks as %wpa_supplicant.
  70. \section preauth_test preauth_test - WPA2 pre-authentication and EAP peer testing
  71. preauth_test is similar to eapol_test in the sense that in combines
  72. EAP peer implementation with something else, in this case, with WPA2
  73. pre-authentication. This tool can be used to test pre-authentication
  74. based on the code that %wpa_supplicant is using. As such, it tests
  75. both the %wpa_supplicant implementation and the functionality of an
  76. access point.
  77. preauth_test is built with:
  78. \verbatim
  79. make preauth_test
  80. \endverbatim
  81. and it uses following command line arguments:
  82. \verbatim
  83. usage: preauth_test <conf> <target MAC address> <ifname>
  84. \endverbatim
  85. For example,
  86. \verbatim
  87. preauth_test test.conf 02:11:22:33:44:55 eth0
  88. \endverbatim
  89. would use network configuration from test.conf to try to complete
  90. pre-authentication with AP using BSSID 02:11:22:33:44:55. The
  91. pre-authentication packets would be sent using the eth0 interface.
  92. \section driver_test driver_test - driver interface for testing wpa_supplicant
  93. %wpa_supplicant was designed to support number of different ways to
  94. communicate with a network device driver. This design uses \ref
  95. driver_wrapper "driver interface API" and number of driver interface
  96. implementations. One of these is driver_test.c, i.e., a test driver
  97. interface that is actually not using any drivers. Instead, it provides
  98. a mechanism for running %wpa_supplicant without having to have a
  99. device driver or wireless LAN hardware for that matter.
  100. driver_test can be used to talk directly with hostapd's driver_test
  101. component to create a test setup where one or more clients and access
  102. points can be tested within one test host and without having to have
  103. multiple wireless cards. This makes it easier to test the core code in
  104. %wpa_supplicant, and hostapd for that matter. Since driver_test uses
  105. the same driver API than any other driver interface implementation,
  106. the core code of %wpa_supplicant and hostapd can be tested with the
  107. same coverage as one would get when using real wireless cards. The
  108. only area that is not tested is the driver interface implementation
  109. (driver_*.c).
  110. Having the possibility to use simulated network components makes it
  111. much easier to do development testing while adding new features and to
  112. reproduce reported bugs. As such, it is often easiest to just do most
  113. of the development and bug fixing without using real hardware. Once
  114. the driver_test setup has been used to implement a new feature or fix
  115. a bug, the end result can be verified with wireless LAN cards. In many
  116. cases, this may even be unnecessary, depending on what area the
  117. feature/bug is relating to. Of course, changes to driver interfaces
  118. will still require use of real hardware.
  119. Since multiple components can be run within a single host, testing of
  120. complex network configuration, e.g., large number of clients
  121. association with an access point, becomes quite easy. All the tests
  122. can also be automated without having to resort to complex test setup
  123. using remote access to multiple computers.
  124. driver_test can be included in the %wpa_supplicant build in the same
  125. way as any other driver interface, i.e., by adding the following line
  126. into .config:
  127. \verbatim
  128. CONFIG_DRIVER_TEST=y
  129. \endverbatim
  130. When running %wpa_supplicant, the test interface is selected by using
  131. \a -Dtest command line argument. The interface name (\a -i argument)
  132. can be selected arbitrarily, i.e., it does not need to match with any
  133. existing network interface. The interface name is used to generate a
  134. MAC address, so when using multiple clients, each should use a
  135. different interface, e.g., \a sta1, \a sta2, and so on.
  136. %wpa_supplicant and hostapd are configured in the same way as they
  137. would be for normal use. Following example shows a simple test setup
  138. for WPA-PSK.
  139. hostapd is configured with following psk-test.conf configuration file:
  140. \verbatim
  141. driver=test
  142. interface=ap1
  143. logger_stdout=-1
  144. logger_stdout_level=0
  145. debug=2
  146. dump_file=/tmp/hostapd.dump
  147. test_socket=/tmp/Test/ap1
  148. ssid=jkm-test-psk
  149. wpa=1
  150. wpa_key_mgmt=WPA-PSK
  151. wpa_pairwise=TKIP
  152. wpa_passphrase=12345678
  153. \endverbatim
  154. and started with following command:
  155. \verbatim
  156. hostapd psk-test.conf
  157. \endverbatim
  158. %wpa_supplicant uses following configuration file:
  159. \verbatim
  160. driver_param=test_socket=/tmp/Test/ap1
  161. network={
  162. ssid="jkm-test-psk"
  163. key_mgmt=WPA-PSK
  164. psk="12345678"
  165. }
  166. \endverbatim
  167. %wpa_supplicant can then be started with following command:
  168. \verbatim
  169. wpa_supplicant -Dtest -cpsk-test.conf -ista1 -ddK
  170. \endverbatim
  171. If run without debug information, i.e., with
  172. \verbatim
  173. wpa_supplicant -Dtest -cpsk-test.conf -ista1
  174. \endverbatim
  175. %wpa_supplicant completes authentication and prints following events:
  176. \verbatim
  177. Trying to associate with 02:b8:a6:62:08:5a (SSID='jkm-test-psk' freq=0 MHz)
  178. Associated with 02:b8:a6:62:08:5a
  179. WPA: Key negotiation completed with 02:b8:a6:62:08:5a [PTK=TKIP GTK=TKIP]
  180. CTRL-EVENT-CONNECTED - Connection to 02:b8:a6:62:08:5a completed (auth)
  181. \endverbatim
  182. If test setup is using multiple clients, it is possible to run
  183. multiple %wpa_supplicant processes. Alternatively, the support for
  184. multiple interfaces can be used with just one process to save some
  185. resources on single-CPU systems. For example, following command runs
  186. two clients:
  187. \verbatim
  188. ./wpa_supplicant -Dtest -cpsk-test.conf -ista1 \
  189. -N -Dtest -cpsk-test.conf -ista2
  190. \endverbatim
  191. This shows following event log:
  192. \verbatim
  193. Trying to associate with 02:b8:a6:62:08:5a (SSID='jkm-test-psk' freq=0 MHz)
  194. Associated with 02:b8:a6:62:08:5a
  195. WPA: Key negotiation completed with 02:b8:a6:62:08:5a [PTK=TKIP GTK=TKIP]
  196. CTRL-EVENT-CONNECTED - Connection to 02:b8:a6:62:08:5a completed (auth)
  197. Trying to associate with 02:b8:a6:62:08:5a (SSID='jkm-test-psk' freq=0 MHz)
  198. Associated with 02:b8:a6:62:08:5a
  199. WPA: Key negotiation completed with 02:b8:a6:62:08:5a [PTK=TKIP GTK=TKIP]
  200. CTRL-EVENT-CONNECTED - Connection to 02:b8:a6:62:08:5a completed (auth)
  201. \endverbatim
  202. hostapd shows this with following events:
  203. \verbatim
  204. ap1: STA 02:b5:64:63:30:63 IEEE 802.11: associated
  205. ap1: STA 02:b5:64:63:30:63 WPA: pairwise key handshake completed (WPA)
  206. ap1: STA 02:b5:64:63:30:63 WPA: group key handshake completed (WPA)
  207. ap1: STA 02:2a:c4:18:5b:f3 IEEE 802.11: associated
  208. ap1: STA 02:2a:c4:18:5b:f3 WPA: pairwise key handshake completed (WPA)
  209. ap1: STA 02:2a:c4:18:5b:f3 WPA: group key handshake completed (WPA)
  210. \endverbatim
  211. By default, driver_param is simulating a driver that uses the WPA/RSN
  212. IE generated by %wpa_supplicant. Driver-generated IE and AssocInfo
  213. events can be tested by adding \a use_associnfo=1 to the \a driver_param
  214. line in the configuration file. For example:
  215. \verbatim
  216. driver_param=test_socket=/tmp/Test/ap1 use_associnfo=1
  217. \endverbatim
  218. \section unit_tests Unit tests
  219. Number of the components (.c files) used in %wpa_supplicant define
  220. their own unit tests for automated validation of the basic
  221. functionality. Most of the tests for cryptographic algorithms are
  222. using standard test vectors to validate functionality. These tests can
  223. be useful especially when verifying port to a new CPU target.
  224. The test programs are collected in the tests subdirectory. All
  225. automated unit tests can be run with
  226. \verbatim
  227. make run-tests
  228. \endverbatim
  229. This make target builds and runs each test and terminates with zero
  230. exit code if all tests were completed successfully.
  231. \section wpa_trace Tracing code for developer debuggin
  232. %wpa_supplicant and hostapd can be built with tracing code that will
  233. track and analyze memory allocations and other resource registrations
  234. and certain API uses. If incorrect use is detected, a backtrace of the
  235. call location (and/or allocation location) is shown. This can also be
  236. used to detect certain categories of memory leaks and report them
  237. automatically when the program is terminated. The report will also
  238. include information about forgotten eloop events.
  239. The trace code can be enabled with CONFIG_WPA_TRACE=y build
  240. option. More verbose backtrace information can be generated if libbfd
  241. is available and the binaries are not stripped of symbol
  242. information. This is enabled with CONFIG_WPA_TRACE_BFD=y.
  243. For example, a memory leak (forgotten os_free() call) would show up
  244. like this when the program is terminated:
  245. \verbatim
  246. MEMLEAK[0x82d200]: len 128
  247. WPA_TRACE: memleak - START
  248. [0]: ./wpa_supplicant(os_malloc+0x59) [0x41a5e9]
  249. os_malloc() ../src/utils/os_unix.c:359
  250. [1]: ./wpa_supplicant(os_zalloc+0x16) [0x41a676]
  251. os_zalloc() ../src/utils/os_unix.c:418
  252. [2]: ./wpa_supplicant(wpa_supplicant_init+0x38) [0x48b508]
  253. wpa_supplicant_init() wpa_supplicant.c:2315
  254. [3]: ./wpa_supplicant(main+0x2f3) [0x491073]
  255. main() main.c:252
  256. WPA_TRACE: memleak - END
  257. MEMLEAK: total 128 bytes
  258. \endverbatim
  259. Another type of error that can be detected is freeing of memory area
  260. that was registered for some use and is still be referenced:
  261. \verbatim
  262. WPA_TRACE: Freeing referenced memory - START
  263. [2]: ./wpa_supplicant(os_free+0x5c) [0x41a53c]
  264. os_free() ../src/utils/os_unix.c:411
  265. [3]: ./wpa_supplicant(wpa_supplicant_remove_iface+0x30) [0x48b380]
  266. wpa_supplicant_remove_iface() wpa_supplicant.c:2259
  267. [4]: ./wpa_supplicant(wpa_supplicant_deinit+0x20) [0x48b3e0]
  268. wpa_supplicant_deinit() wpa_supplicant.c:2430
  269. [5]: ./wpa_supplicant(main+0x357) [0x4910d7]
  270. main() main.c:276
  271. WPA_TRACE: Freeing referenced memory - END
  272. WPA_TRACE: Reference registration - START
  273. [1]: ./wpa_supplicant [0x41c040]
  274. eloop_trace_sock_add_ref() ../src/utils/eloop.c:94
  275. [2]: ./wpa_supplicant(wpa_supplicant_ctrl_iface_deinit+0x17) [0x473247]
  276. wpa_supplicant_ctrl_iface_deinit() ctrl_iface_unix.c:436
  277. [3]: ./wpa_supplicant [0x48b21c]
  278. wpa_supplicant_cleanup() wpa_supplicant.c:378
  279. wpa_supplicant_deinit_iface() wpa_supplicant.c:2155
  280. [4]: ./wpa_supplicant(wpa_supplicant_remove_iface+0x30) [0x48b380]
  281. wpa_supplicant_remove_iface() wpa_supplicant.c:2259
  282. [5]: ./wpa_supplicant(wpa_supplicant_deinit+0x20) [0x48b3e0]
  283. wpa_supplicant_deinit() wpa_supplicant.c:2430
  284. [6]: ./wpa_supplicant(main+0x357) [0x4910d7]
  285. main() main.c:276
  286. WPA_TRACE: Reference registration - END
  287. Aborted
  288. \endverbatim
  289. This type of error results in showing backtraces for both the location
  290. where the incorrect freeing happened and the location where the memory
  291. area was marked referenced.
  292. */