Commit Graph

339 Commits

Author SHA1 Message Date
James Prestwood 0772d4b61a auto-t: introduce pure python test-runner re-write
This patch completely re-writes test-runner in Python. This was done
because the existing C test-runner had some clunky work arounds and
maintaining or adding new features was starting to become a huge pain.

There were a few aspects of test-runner which continually had to
be dealt with when adding any new functionality:

 * Argument parsing: Adding new arguments to test-runner wasn't so
   bad, but if you wanted those arguments passed into the VM it
   became a huge pain. Arguments needed to be parsed, then re-formatted
   into the qemu command line, then re-parsed in a special order
   (backwards) once in the VM. The burden for adding new arguments was
   quite high so it was avoided (at least by me) at all costs.
 * The separation between C and Python: The tests are all written in
   python, but the executables, radios, and interfaces were all created
   from C. The way we solved this was by encoding the require info as
   environment variables, then parsing those from Python. It worked,
   but it was, again, a huge pain.
 * Process management: It started with all processes being launched
   from C, but eventually tests required the ability to start IWD, or
   kill hostapd ungracefully in order to test certain functionality.
   Since the processes were tracked in C, Python had no way of
   signalling that it killed a process and when it started one C had
   no idea. This was mitigated (basically by killall), but it was
   no where close to an elegant solution.

Re-writing test-runner in python solves all these problems and will
be much easier to maintain.

 * Argument parsing: Now all arguments are forwarded automatically
   to the VM. The ArgParse library takes care of parsing and each
   argument is stored in a dictionary.
 * Separation between C and Python: No more C, so no more separation.
 * Process management: Python will now manage all processes. This
   allows a test to kill, restart, or start a new process and not
   have to remember the PID or to kill it after the test.

There are a few more important aspects of the python implementation
that should now be considered when writing new tests:

 * The IWD constructor now has different default arugments. IWD
   will always be started unless specified and the configuration
   directory will always be /tmp
 * Any non *.py file in the test directory will be copied to /tmp.
   This avoids the need for 'tmpfs_extra_stuff' completely.
 * ctrl_interface will automatically be appended to every hostapd
   config. There is no need to include this in a config file from
   now on.
 * Test cleanup is extremely important. All tests get run in the
   same interpreter now and the tests themselves are actually loaded
   as python modules. This means e.g. if you somehow kept a reference
   to IWD() any subsequent tests would not start since IWD is still
   running.
 * For debugging, the test context can be printed which shows running
   processes, radios, and interfaces.

Three non-native python modules were used: PrettyTable, colored, and
pyroute2

$ pip3 install prettytable
$ pip3 install termcolor
$ pip3 install pyroute2
2020-09-10 17:59:49 -05:00
James Prestwood 9594b03a35 auto-t: prepare autotests for test-runner re-write
The tests basically remained the same with a few minor changes.
The wiphy_map and in turn hostapd_map are no longer used. This
was already partially converted a long time ago when the 'config'
parameter was added to HostapdCLI. This patch fully converts all
autotests to use 'config' rather than looking up by interface.

Some test scripts were named 'test.py' which was fine before but
the new rewrite actually loads each python test as a module. The
name 'test' is too ambiguous and causes issues due to a native
python module with the same name. All of these files were
renamed to 'connection_test.py'.
2020-09-10 17:59:49 -05:00
James Prestwood f85fcf2f21 auto-t: make testSAQuery more reliable
First, looking for DeviceState.connected gives a much better indication
if we are actually connected vs the connected property on the network
object. Second, its good practice to also check that hostapd sees that
the station is connected.
2020-07-15 14:43:34 -05:00
James Prestwood 933be89812 auto-t: fix hostapd.ungraceful_restart
Restarting hostapd from python was actually leaking memory and
causing the hostapd object to stay referenced in python. The
GLib timeout in wait_for_event was the ultimate cause, but this
had no come to light because no tests restarted hostapd then
used wait_for_event.

In addition, any use of wait_for_event after a restart would
cause an exception because the event socket was never re-attached
after hostapd restarted.

Now we properly clean up the timeout in wait_for_event and
re-initialize the hostapd object on restart.
2020-07-15 14:43:29 -05:00
James Prestwood 0fdc3b3ed6 auto-t: remove busy wait for eapol reauth
Many tests force a reauth after the initial connection. When the tests
were written there was no way of ensuring the reauth completed except
waiting (IWD.wait()). Now we can wait for hostapd events in the tests,
which is faster and more reliable than busy waiting.
2020-07-08 18:29:01 -05:00
James Prestwood 38c8fe06a4 auto-t: increase wait time for blacklist test
This test was not reliably passing. Busy waiting is not really reliable,
but in this specific case its really the only option as the blacklist
must expire based on time.
2020-07-08 18:28:58 -05:00
James Prestwood e70b252e19 auto-t: add test for delayed ANQP response 2020-06-12 15:04:43 -05:00
James Prestwood cb35e9fe65 auto-t: add 'Delay' property to hwsim python module 2020-06-12 15:04:40 -05:00
Tim Kourt 8be7aae079 auto-t: Validate Connect after ConnectHiddenNetwork 2020-06-09 21:58:52 -05:00
Tim Kourt 7ef7894218 auto-t: Add async API call for connect_hidden_network 2020-06-09 21:58:52 -05:00
Tim Kourt cc66050b90 auto-t: Test Agent ops 2020-05-13 05:50:45 -05:00
Tim Kourt cbfaef09d6 auto-t: Remove bogus logic
Device object has no property named 'connected'.
client_connect has no member dev2
2020-05-02 07:03:05 -05:00
Tim Kourt 7cc8111817 auto-t: Use changed get_ordered_network API
Rely on internal scan and wait implementation of get_ordered_network
to obtain the known networks
2020-05-02 07:03:05 -05:00
Tim Kourt ae4b361f79 auto-t: Return None instead of empty known net list
To match the original behavior of get_ordered_networks,
return None for the empty list of known networks after the scan
is complete
2020-05-02 07:03:05 -05:00
Tim Kourt 2e5f7404c0 auto-t: Rename test case to reflect its purpose 2020-05-02 07:03:05 -05:00
Tim Kourt 7f3f5c18dc auto-t: Remove unnecessary disconnect calls
With the introduction of AutoConnect=False network setting the
initial disconnect calls are no longer needed
2020-05-02 07:03:05 -05:00
James Prestwood b600440ea2 auto-t: use scan_if_needed for testConnectAutoconnect
In certain cases the autoconnect portion of each subtest was connecting
to the network so fast that the check for obj.scanning was never successful
since IWD was already connected (and in turn not scanning). Since the
autoconnect path will wait for the device to be connected there really isn't
a reason to wait for any scanning conditions. The normal connect path does
need to wait for scanning though, and for this we can now use the new
scan_if_needed parameter to get_ordered_networks.
2020-05-02 06:40:23 -05:00
James Prestwood da3f66ea68 auto-t: add optional scan argument to get_ordered_network(s)
There is a very common block of code inside many autotests
which goes something like:

device.scan()
condition = 'obj.scanning'
wd.wait_for_object_condition(device, condition)
condition = 'not obj.scanning'
wd.wait_for_object_condition(device, condition)
network = device.get_ordered_network('an-ssid')

When you see the same pattern in nearly all the tests this shows
we need a helper. Basic autotests which merely check that a
connection succeeded should not need to write the same code again
and again. This code ends up being copy-pasted which can lead to
bugs.

There is also a code pattern which attempts to get ordered
networks, and if this fails it scans and tries again. This, while
not optimal, does prevent unneeded scanning by first checking if
any networks already exist.

This patch solves both the code reuse issue as well as the recovery
if get_ordered_network(s) fails. A new optional parameter was
added to get_ordered_network(s) which is False by default. If True
get_ordered_network(s) will perform a scan if the initial call
yields no networks. Tests will now be able to simply call
get_ordered_network(s) without performing a scan before hand.
2020-05-02 06:40:23 -05:00
James Prestwood 8126899eda auto-t: change blacklist test RSSI values
These values were meant only to force IWD's BSS preference but
since the RSSI's were so low in some cases this caused a roam
immediately after connecting. This patch changes the RSSI values
to prevent a roam from happening.
2020-05-01 23:01:42 -05:00
Tim Kourt 57ce53f1ac auto-t: Fix event order
In addition, use the conditional wait for the expected number
of known networks
2020-04-09 16:46:31 -05:00
Tim Kourt 000b533194 auto-t: Remove unused imports 2020-04-09 16:46:31 -05:00
Tim Kourt d3339ddb72 auto-t: Use proper connection status indicator
'Connected' property of the network object is set before the connection
attempt is made and does not indicate a connection success. Therefore,
use device status property to identify the connection status of the device.
2020-04-09 16:46:31 -05:00
James Prestwood 83128c797f auto-t: check linkmode/operstate in adhoc test (open)
A previous patch fixed the linkmode/operstate for open AdHoc networks.
2020-04-08 16:35:06 -05:00
James Prestwood 72bf3aa1f5 auto-t: remove iwd_config_dir from autotests
This is no longer needed unless setting a different
directory than /tmp
2020-03-21 00:10:36 -05:00
James Prestwood 9eb0f973f3 auto-t: fix testAddressRandomization
This test was dependent on having a local main.conf in /etc/iwd
2020-03-21 00:10:34 -05:00
James Prestwood e7a9a43410 auto-t: add test for AddressRandomization option
Tests all cases of AddressRandomization=network

1. Deterministic generation per-network (default)
2. Full randomization per-network
3. Address override per-network
2020-03-18 18:15:16 -05:00
Tim Kourt 40ad8be113 auto-t: Test PEAPv0 cryptobinding 2020-02-03 11:34:29 -06:00
Torstein Husebø 759dbdd37f treewide: fix typos 2020-01-21 16:03:28 -06:00
James Prestwood 38fa76faf5 auto-t: use stand alone radius server for testFT-FILS-SHA384
This fixes the test with recent hostapd versions
2020-01-06 11:18:48 -06:00
James Prestwood c01751c2b3 auto-t: use stand alone radius server for testFT-FILS-SHA256
This fixes the test with recent hostapd versions
2020-01-06 11:18:48 -06:00
James Prestwood 112f1f2bef auto-t: use stand alone radius server for testFILS
This fixes the test with recent hostapd versions
2020-01-06 11:18:48 -06:00
James Prestwood 40a79dc90b auto-t: add RRM test for scan duration
mac80211_hwsim does not actually support SET_SCAN_DWELL, but since we are
not setting duration mandatory the request should still be accepted.
2019-11-15 14:17:25 -06:00
James Prestwood c961dafc50 auto-t: let testEAP-TTLS-MSCHAPv2 use HostapdCLI easier
This test made it past the initial refactor to use HostapdCLI with the
'config' parameter. This avoids the need to iterate the hostapd map in
the actual test.
2019-11-14 15:23:03 -06:00
James Prestwood 0c586dc8ca auto-t: give testEAP-TTLS-MSCHAPv2 a longer timeout
When logging is turned on this test consistently fails due to a
timeout. Giving it a bit more time allows it to pass.
2019-11-14 15:23:03 -06:00
James Prestwood dcbdbac2f8 auto-t: fix intermittent failures in testEAP-MSCHAPV2
Occationally autoconnect would start which was not expected in the
test. This is fixed by disabling autoconnect in the provisioning files.
2019-11-14 12:58:18 -06:00
James Prestwood a3817ba015 auto-t: add ctrl_interface to testHotspot
This is now required for any test using HostapdCLI
2019-11-13 16:37:17 -06:00
James Prestwood 088ed86f3d auto-t: add ctrl_interface to testHT-VHT
This is now required for any test using HostapdCLI
2019-11-13 16:37:17 -06:00
James Prestwood 5e98a1bbe5 auto-t: add ctrl_interface to testFILS
This is now required for any test using HostapdCLI
2019-11-13 16:37:17 -06:00
James Prestwood 7c2f73148c auto-t: add ctrl_interface to testOWE
This is now required for any test using HostapdCLI
2019-11-13 16:37:17 -06:00
James Prestwood b45242562b auto-t: add RRM autotest
This test merely verifies hostapd receieved our measurement reports
and verified they were valid. Hostapd does not verify the actual
beacon report body. Really, the only way to test this is on an
actual network which makes these requests.
2019-11-07 12:26:19 -06:00
James Prestwood 87bd9f4c6e auto-t: support hostapd event processing
Hostapd has a feature where you can connect to its control socket and
receive events it generates. Currently we only send commands via this
socket.

First we open the socket (/var/run/hostapd/<iface>) and send the
ATTACH command. This tells hostapd we are ready and after this any
events will be sent over this socket.

A new API, wait_for_event, was added which takes an event string and
waits for some timeout. The glib event loop has been integrated into
this, though its not technically async since we are selecting over a
socket which blocks. To mitigate this a small timeout was chosen for
each select call and then wrapped in a while loop which waits for the
full timeout.
2019-11-04 14:42:17 -06:00
Denis Kenzior 22cba31c8b auto-t: update to the new AgentManager path 2019-10-28 18:08:54 -05:00
James Prestwood 4fcb6c3cc6 auto-t: update testEAP-TLS to use HostapdCLI
This test did not use the updated HostapdCLI where you can specify
a config file rather than iterate hostapd list.
2019-10-28 15:01:36 -05:00
James Prestwood 14df50a0ab auto-t: fix random failures in testEAP-MSCHAPV2
Its difficult to know 100%, but this random test failures appeared
to be caused by two issues. One was that get_ordered_network is being
checked for None, when it was returning a zero length array. Because
of this the scanning block was never executed in any cases. This was
fixed in the previous commit. The other issue was the disconnect at
the start of the tests. The disconnect will cause all pending scans
to cancel, which appeared to cause the scanning block below to be
skipped over quickly if the timing was right. Then, afterwards,
getting a single network failed because scanning was not complete.
2019-10-28 15:01:33 -05:00
James Prestwood fc9342f751 auto-t: return None with get_ordered_network(s)
If no networks are found, return None rather than an empty
array. This is easier to check by the caller (and was assumed
in some cases). Also add an exception to get_ordered_network
if no network is found.
2019-10-28 14:59:58 -05:00
Denis Kenzior d12ee292aa treewide: Use CamelCase for disable_anqp setting 2019-10-24 23:18:23 -05:00
Denis Kenzior e540978633 treewide: Use CamelCase for [Scan] settings 2019-10-24 15:58:08 -05:00
Denis Kenzior 19a85a85e7 treewide: Rename EAP mtu key to MTU 2019-10-24 13:51:20 -05:00
Denis Kenzior d66139fe34 treewide: Switch to CamelCase for Blacklist settings 2019-10-24 13:38:11 -05:00
Denis Kenzior aa13f5458d auto-t: Rename setting Autoconnect to AutoConnect 2019-10-24 13:04:53 -05:00