blob: 75313b5458319d781832b9f58deb1612734cfdfc [file] [log] [blame]
mukesh agrawal8a3188d2011-12-01 20:56:44 +00001Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
mukesh agrawal70d3ebe2011-10-13 14:45:54 -07002Use of this source code is governed by a BSD-style license that can be
3found in the LICENSE file.
4
5Intro
6-----
7We test shill using two sets of tests: unit tests, and integration
8tests. The unit tests are built using Google Test [1] and Google Mock
9[2]; the integration tests use autotest [3].
10
11Running unit tests
12------------------
Prathmesh Prabhue7236b02014-02-13 17:54:56 -080013Here ${BOARD} is a valid board name, like link or x86-generic.
mukesh agrawal70d3ebe2011-10-13 14:45:54 -070014- build the shill_unittest target
15- run the resulting shill_unittest binary
Paul Stewart85a1bad2011-10-21 22:36:38 -070016- run the unit tests from your host machine under gdb
Paul Stewart3de88a02014-12-05 07:55:14 -080017 (chroot)$ FEATURES=test emerge-${BOARD} shill
Prathmesh Prabhue7236b02014-02-13 17:54:56 -080018 (chroot)$ gdb_x86_local --board ${BOARD} \
19 /build/${BOARD}/var/cache/portage/chromeos-base/platform2/out/Default/shill_unittest
Paul Stewart85a1bad2011-10-21 22:36:38 -070020 (Of course if the unit tests segfaulted, you wouldn't need the emerge
21 step since the build directory would have been retained in the course
22 of the test failing.)
Prathmesh Prabhue7236b02014-02-13 17:54:56 -080023- The emerge workflow given above is incremental. It uses ninja to rebuild only
24 relevant objects in the shill target.
25- You can restrict the test runs to only shill unittests by using
Paul Stewart3de88a02014-12-05 07:55:14 -080026 (chroot)$ P2_TEST_FILTER="shill::*" FEATURES=test emerge-${BOARD} shill
Prathmesh Prabhue7236b02014-02-13 17:54:56 -080027 The filter can be made more specific to include googletest filters like
28 "shill::CellularTest.StartGSMRegister"
mukesh agrawalcbfb34e2013-04-17 19:33:25 -070029- if you want to set a breakpoint in gdb, make sure to include the shill
30 namespace. e.g., run
31 (cros-gdb) b shill::EthernetService::GetStorageIdentifier
32 Breakpoint 2 at 0x5555563cc270: file ethernet_service.cc, line 63.
33 rather than
34 (cros-gdb) b EthernetService::GetStorageIdentifier
35 Function "EthernetService::GetStorageIdentifier" not defined.
36 Make breakpoint pending on future shared library load? (y or [n]) n
37
Prathmesh Prabhue7236b02014-02-13 17:54:56 -080038- alternate build command:
39 - Another way to build which uses the emerge command behind the scenes:
Paul Stewart3de88a02014-12-05 07:55:14 -080040 (chroot)$ cros_workon_make --board ${BOARD} shill
mukesh agrawalcbfb34e2013-04-17 19:33:25 -070041 - to see the actual compiler commands that are run:
42 (chroot)$ CFLAGS="-print-cmdline" cros_workon_make --reconf \
Paul Stewart3de88a02014-12-05 07:55:14 -080043 --board=${BOARD} shill
mukesh agrawalcbfb34e2013-04-17 19:33:25 -070044 - to abort compilation on the first error
Prathmesh Prabhue7236b02014-02-13 17:54:56 -080045 (chroot)$ MAKEFLAGS="--stop" cros_workon_make --test --board=${BOARD} \
Paul Stewart3de88a02014-12-05 07:55:14 -080046 --reconf shill
47
48Running unit tests with the address sanitizer
49---------------------------------------------
50USE="asan clang wimax" TEST_FILTER="shill::*" emerge-${BOARD} shill
51
52This also turns on "wimax" and its tests, since this is disabled on most
53platforms.
mukesh agrawal76a87fd2013-04-19 18:17:49 -070054
mukesh agrawal70d3ebe2011-10-13 14:45:54 -070055Running integration tests
56-------------------------
57- build a test image, suitable for a VM:
Prathmesh Prabhue7236b02014-02-13 17:54:56 -080058 (chroot) src/scripts$ ./build_packages --board=${BOARD}
59 (chroot) src/scripts$ ./build_image --board=${BOARD} \
Wade Guthrie8624e432012-04-11 11:12:00 -070060 --noenable_rootfs_verification test
Prathmesh Prabhue7236b02014-02-13 17:54:56 -080061 (chroot) src/scripts$ ./image_to_vm.sh --board=${BOARD} --test_image
mukesh agrawal70d3ebe2011-10-13 14:45:54 -070062
63- start the VM
mukesh agrawal5b6a7302012-11-19 14:25:14 -080064 (host)$ sudo kvm -m 2048 -vga std -pidfile /tmp/kvm.pid \
mukesh agrawal70d3ebe2011-10-13 14:45:54 -070065 -net nic,model=virtio -net user,hostfwd=tcp::9222-:22 \
Prathmesh Prabhue7236b02014-02-13 17:54:56 -080066 -hda <path to chroot>/src/build/images/${BOARD}/latest/chromiumos_qemu_image.bin
mukesh agrawal70d3ebe2011-10-13 14:45:54 -070067
mukesh agrawal5b6a7302012-11-19 14:25:14 -080068- DO NOT log in on the console.
69 (doing so will load a user profile onto shill's profile stack; this
70 interferes with the test profile that we use in the autotests)
mukesh agrawal70d3ebe2011-10-13 14:45:54 -070071
mukesh agrawal5b6a7302012-11-19 14:25:14 -080072- if you've modified the source after building the image, update shill on
73 the image, and then restart shill:
Wade Guthrie8624e432012-04-11 11:12:00 -070074 (chroot) src/scripts$ ./start_devserver
mukesh agrawal5b6a7302012-11-19 14:25:14 -080075 (chroot) src/scripts$ ssh-keygen -R '[127.0.0.1]:9222'
Prathmesh Prabhue7236b02014-02-13 17:54:56 -080076 (chroot) src/scripts$ emerge-${BOARD} platform2
77 (chroot) src/scripts$ cros deploy 127.0.0.1:9222 platform2
78
mukesh agrawal5b6a7302012-11-19 14:25:14 -080079 (chroot) src/scripts$ ssh -p 9222 root@127.0.0.1
mukesh agrawal5b6a7302012-11-19 14:25:14 -080080 localhost / # restart shill
mukesh agrawal70d3ebe2011-10-13 14:45:54 -070081
82- run the tests
Prathmesh Prabhue7236b02014-02-13 17:54:56 -080083 (chroot) src/scripts$ test_that 127.0.0.1 WiFiManager
84 --args="config_file=wifi_vm_config"
85 --ssh_options="-p 9222"
mukesh agrawal70d3ebe2011-10-13 14:45:54 -070086
Gaurav Shahd52caa52011-10-25 10:46:03 -070087 To run a specific test out of the test suite, use test_pat option to --args.
Gaurav Shahd52caa52011-10-25 10:46:03 -070088 # Example: To just run the 035CheckWEPKeySyntax test:
Prathmesh Prabhue7236b02014-02-13 17:54:56 -080089 (chroot) src/scripts$ test_that 127.0.0.1 WiFiManager
90 --args="config_file=wifi_vm_config test_pat=035CheckWEPKeySyntax"
91 --ssh_options="-p 9222"
Gaurav Shahd52caa52011-10-25 10:46:03 -070092
mukesh agrawal70d3ebe2011-10-13 14:45:54 -070093- configuration note: if you use a different port
94 (e.g. hostfwd=tcp::9223-:22), you'll need to change:
Prathmesh Prabhue7236b02014-02-13 17:54:56 -080095 - the ssh_port argument to test_that
mukesh agrawal70d3ebe2011-10-13 14:45:54 -070096 - the port numbers in
97 <chroot>/third_party/autotest/files/client/config/wifi_vm_config
98
99- debugging test failures
100 - "grep shill /var/log/messages" for log messages
101 - "grep wpa_supplicant /var/log/messages" for supplicant log messages
102 - "wpa_debug debug" to increase supplicant log level
103 - try resetting the test infrastructure
104 - rmmod mac80211_hwsim mac80211 cfg80211
105 - restart wpasupplicant
106 - rm /tmp/hostapd-test.control/*
mukesh agrawalc2f39fc2011-11-07 22:07:23 +0000107 - examine autotest log files
108 - check how far the test got before it failed
109 $ grep -a ': step ' <test output>/<suite name>/<suite name>.<test name>/debug/<suite name>.<test name>.INFO
110 e.g.
Prathmesh Prabhue7236b02014-02-13 17:54:56 -0800111 (chroot) $ grep -a ': step ' /tmp/test_that_latest/network_WiFiRoaming/network_WiFiRoaming.002Suspend/debug/network_WiFiRoaming.002Suspend.INFO
mukesh agrawalc2f39fc2011-11-07 22:07:23 +0000112 - read the log file
Prathmesh Prabhue7236b02014-02-13 17:54:56 -0800113 (chroot) $ LESSOPEN= less /tmp/test_that_latest/network_WiFiRoaming/network_WiFiRoaming.002Suspend/debug/network_WiFiRoaming.002Suspend.INFO
mukesh agrawalc2f39fc2011-11-07 22:07:23 +0000114
115 (LESSOPEN= prevents less from misinterpreting the logs as binary files,
116 and piping them through hexdump.)
mukesh agrawal70d3ebe2011-10-13 14:45:54 -0700117
118- additional test suites: we have a number of other WiFi test suites
119 (in addition to WiFiManager). these are: WiFiMatFunc, WiFiPerf,
120 WiFiRoaming, WiFiSecMat. the WiFiPerf tests are probably not too
121 relevant to shill (just yet), but the rest probably are.
122
123[1] http://code.google.com/p/googletest/
124[2] http://code.google.com/p/googlemock/
125[3] http://autotest.kernel.org/,
Gaurav Shahd52caa52011-10-25 10:46:03 -0700126 http://www.chromium.org/chromium-os/testing/testing-faq