Skip to contentSkip to conversation

auto-t: remove waitstatus_to_exitcode for better compatibility

PATCH New James Prestwood 1 participant 8 messages Mar 22, 2022

lore
Share & tools
lore

James Prestwood

author
#0 lore raw

PATCH 1/8 auto-t: remove waitstatus_to_exitcode for better compatibility

This was added in Python 3.9 which isn't always supported. Instead use the old way of checking the return status.

---
 autotests/testNetconfig/connection_test.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
autotests/testNetconfig/connection_test.py +2 -1
index 8eeffbbd..17788011 100644
@@ -41,7 +41,8 @@ class Test(unittest.TestCase):
 
         time.sleep(2)
         ret = os.system('ip addr show ' + device.name + ' | grep \'inet6 3ffe:501:ffff:100::\'')
-        self.assertEqual(os.waitstatus_to_exitcode(ret), 0)
+        self.assertTrue(os.WIFEXITED(ret))
+        self.assertEqual(os.WEXITSTATUS(ret), 0)
 
         device.disconnect()
 
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 2/8 auto-t: iwd.py: fix full_scan argument

This was not being properly honored when existing networks were already populated. This poses an issue for any test which uses full_scan after setting radio values such as signal strength.

---
 autotests/util/iwd.py | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
autotests/util/iwd.py +12 -11
index d6620da5..253fe25e 100755
@@ -492,17 +492,18 @@ class Device(IWDDBusAbstract):
            main sorting factor.
         '''
         ordered_networks = []
-        for bus_obj in self._station.GetOrderedNetworks():
-            ordered_network = OrderedNetwork(bus_obj, self._bus, self._namespace)
-            ordered_networks.append(ordered_network)
-
-        names = [x.name for x in ordered_networks]
-
-        # all() will always return true if 'list' is empty
-        if all(x in names for x in list) and len(names) > 0:
-            return ordered_networks
-        elif not scan_if_needed:
-            return None
+        if not full_scan:
+            for bus_obj in self._station.GetOrderedNetworks():
+                ordered_network = OrderedNetwork(bus_obj, self._bus, self._namespace)
+                ordered_networks.append(ordered_network)
+
+            names = [x.name for x in ordered_networks]
+
+            # all() will always return true if 'list' is empty
+            if all(x in names for x in list) and len(names) > 0:
+                return ordered_networks
+            elif not scan_if_needed:
+                return None
 
         condition = 'not obj.scanning'
         IWD._wait_for_object_condition(self, condition)
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH 3/8 auto-t: fixup testRoamRetry for better timing reliability

In reply to James Prestwood

Change a few critical checks that were failing sometimes:
- A few asserts were changed to wait_for_object_condition
- A 15 second timeout was removed (default used instead)
- Do a full scan at beginning of each test to clear any cached BSS's. The second test run was getting stale results and the RSSI values were not expected.

---
 autotests/testRoamRetry/fast_retry_test.py | 13 ++++++-------
 autotests/testRoamRetry/stop_retry_test.py |  7 +++----
 2 files changed, 9 insertions(+), 11 deletions(-)
autotests/testRoamRetry/fast_retry_test.py +6 -7
index c7de5055..b45daada 100644
@@ -63,7 +63,7 @@ class Test(unittest.TestCase):
         devices = wd.list_devices(1)
         device = devices[0]
 
-        ordered_network = device.get_ordered_network('TestRoamRetry')
+        ordered_network = device.get_ordered_network('TestRoamRetry', full_scan=True)
 
         self.assertEqual(ordered_network.type, NetworkType.psk)
 
@@ -75,18 +75,18 @@ class Test(unittest.TestCase):
         condition = 'obj.state == DeviceState.connected'
         wd.wait_for_object_condition(device, condition)
 
-        self.assertTrue(bss_hostapd[0].list_sta())
-        self.assertFalse(bss_hostapd[1].list_sta())
+        bss_hostapd[0].wait_for_event('AP-STA-CONNECTED %s' % device.address)
 
         wd.wait(5)
 
         # Now push the signal LOW, wait for iwd to attempt a roam, fail, and
-        # schedule another attempt for 60 seconds later
+        # schedule another attempt
         rule0.signal = -8000
 
         device.wait_for_event('no-roam-candidates')
 
         self.assertEqual(device.state, iwd.DeviceState.connected)
+
         self.assertTrue(bss_hostapd[0].list_sta())
         self.assertFalse(bss_hostapd[1].list_sta())
 
@@ -101,12 +101,11 @@ class Test(unittest.TestCase):
         wd.wait(1)
 
         # Assert low signal for BSS 0, check that iwd starts transition to BSS 1
-        # in less than 10 seconds.
         rule0.signal = -8000
         rule1.signal = -2000
 
         condition = 'obj.state == DeviceState.roaming'
-        wd.wait_for_object_condition(device, condition, max_wait=15)
+        wd.wait_for_object_condition(device, condition)
 
         # Check that iwd is on BSS 1 once out of roaming state and doesn't
         # go through 'disconnected', 'autoconnect', 'connecting' in between
@@ -114,7 +113,7 @@ class Test(unittest.TestCase):
         to_condition = 'obj.state == DeviceState.connected'
         wd.wait_for_object_change(device, from_condition, to_condition)
 
-        self.assertTrue(bss_hostapd[1].list_sta())
+        bss_hostapd[1].wait_for_event('AP-STA-CONNECTED %s' % device.address)
 
         device.disconnect()
 
autotests/testRoamRetry/stop_retry_test.py +3 -4
index f2f95990..3957d12d 100644
@@ -62,7 +62,7 @@ class Test(unittest.TestCase):
         devices = wd.list_devices(1)
         device = devices[0]
 
-        ordered_network = device.get_ordered_network('TestRoamRetry')
+        ordered_network = device.get_ordered_network('TestRoamRetry', full_scan=True)
 
         self.assertEqual(ordered_network.type, NetworkType.psk)
 
@@ -74,8 +74,7 @@ class Test(unittest.TestCase):
         condition = 'obj.state == DeviceState.connected'
         wd.wait_for_object_condition(device, condition)
 
-        self.assertTrue(bss_hostapd[0].list_sta())
-        self.assertFalse(bss_hostapd[1].list_sta())
+        bss_hostapd[0].wait_for_event('AP-STA-CONNECTED %s' % device.address)
 
         # Now push the signal below the RSSI threshold and check that iwd
         # connects to BSS 1
@@ -90,7 +89,7 @@ class Test(unittest.TestCase):
         to_condition = 'obj.state == DeviceState.connected'
         wd.wait_for_object_change(device, from_condition, to_condition)
 
-        self.assertTrue(bss_hostapd[1].list_sta())
+        bss_hostapd[1].wait_for_event('AP-STA-CONNECTED %s' % device.address)
 
         # Now make sure that we don't roam anymore. In order to catch this via
         # DeviceState, a suitable roaming target needs to be available. So jack
Signature · 1 line
2.34.1
author
#3 lore raw

PATCH 4/8 auto-t: use wait_for_event in testBSSBlacklist

In reply to James Prestwood

Depending on timing hostapd may not show a station with list_sta(). Instead use wait_for_event.

---
 autotests/testBSSBlacklist/connection_test.py | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
autotests/testBSSBlacklist/connection_test.py +9 -9
index 6a12174d..df3bd507 100644
@@ -33,7 +33,7 @@ class Test(unittest.TestCase):
 
         dev1, dev2 = wd.list_devices(2)
 
-        ordered_network = dev1.get_ordered_network("TestBlacklist")
+        ordered_network = dev1.get_ordered_network("TestBlacklist", full_scan=True)
 
         self.assertEqual(ordered_network.type, NetworkType.psk)
 
@@ -45,12 +45,12 @@ class Test(unittest.TestCase):
         condition = 'obj.state == DeviceState.connected'
         wd.wait_for_object_condition(dev1, condition)
 
-        self.assertIn(dev1.address, bss_hostapd[2].list_sta())
+        bss_hostapd[2].wait_for_event('AP-STA-CONNECTED %s' % dev1.address)
 
         # dev1 now connected, this should max out the first AP, causing the next
         # connection to fail to this AP.
 
-        ordered_network = dev2.get_ordered_network("TestBlacklist")
+        ordered_network = dev2.get_ordered_network("TestBlacklist", full_scan=True)
 
         self.assertEqual(ordered_network.type, NetworkType.psk)
 
@@ -64,7 +64,7 @@ class Test(unittest.TestCase):
 
         # We should have temporarily blacklisted the first BSS, and connected
         # to this one.
-        self.assertIn(dev2.address, bss_hostapd[1].list_sta())
+        bss_hostapd[1].wait_for_event('AP-STA-CONNECTED %s' % dev2.address)
 
         # Now check that the first BSS is still not blacklisted. We can
         # disconnect dev1, opening up the AP for more connections
@@ -83,7 +83,7 @@ class Test(unittest.TestCase):
         condition = 'obj.state == DeviceState.connected'
         wd.wait_for_object_condition(dev2, condition)
 
-        self.assertIn(dev2.address, bss_hostapd[2].list_sta())
+        bss_hostapd[2].wait_for_event('AP-STA-CONNECTED %s' % dev2.address)
 
         wd.unregister_psk_agent(psk_agent)
 
@@ -134,7 +134,7 @@ class Test(unittest.TestCase):
         condition = 'obj.state == DeviceState.connected'
         wd.wait_for_object_condition(device, condition)
 
-        self.assertIn(device.address, bss_hostapd[0].list_sta())
+        bss_hostapd[0].wait_for_event('AP-STA-CONNECTED %s' % device.address)
 
         wd.unregister_psk_agent(psk_agent)
 
@@ -214,7 +214,7 @@ class Test(unittest.TestCase):
         # should automatically try the next BSS in the list, which is
         # bss_hostapd[1]
         self.assertNotIn(device.address, bss_hostapd[0].list_sta())
-        self.assertIn(device.address, bss_hostapd[1].list_sta())
+        bss_hostapd[1].wait_for_event('AP-STA-CONNECTED %s' % device.address)
 
         rule0.drop = False
 
@@ -234,7 +234,7 @@ class Test(unittest.TestCase):
 
         # Same as before, make sure we didn't connect to the blacklisted AP.
         self.assertNotIn(device.address, bss_hostapd[0].list_sta())
-        self.assertIn(device.address, bss_hostapd[1].list_sta())
+        bss_hostapd[1].wait_for_event('AP-STA-CONNECTED %s' % device.address)
 
         # Wait for the blacklist to expire (10 seconds)
         elapsed = time.time() - start
@@ -264,7 +264,7 @@ class Test(unittest.TestCase):
         condition = 'obj.state == DeviceState.connected'
         wd.wait_for_object_condition(device, condition)
 
-        self.assertIn(device.address, bss_hostapd[0].list_sta())
+        bss_hostapd[0].wait_for_event('AP-STA-CONNECTED %s' % device.address)
 
         self.wd.unregister_psk_agent(psk_agent)
 
Signature · 1 line
2.34.1
author
#4 lore raw

PATCH 5/8 auto-t: use wait_for_event in testSAE-roam

In reply to James Prestwood

Depending on timing hostapd may not show a station with list_sta(). Instead use wait_for_event.

---
 autotests/testSAE-roam/connection_test.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
autotests/testSAE-roam/connection_test.py +7 -4
index 2409e0d1..4c49eaf8 100644
@@ -35,7 +35,8 @@ class Test(unittest.TestCase):
         condition = 'obj.state == DeviceState.connected'
         wd.wait_for_object_condition(device, condition)
 
-        self.assertTrue(self.bss_hostapd[0].list_sta())
+        self.bss_hostapd[0].wait_for_event('AP-STA-CONNECTED %s' % device.address)
+
         self.assertFalse(self.bss_hostapd[1].list_sta())
 
         testutil.test_iface_operstate(device.name)
@@ -54,7 +55,7 @@ class Test(unittest.TestCase):
         to_condition = 'obj.state == DeviceState.connected'
         wd.wait_for_object_change(device, from_condition, to_condition)
 
-        self.assertTrue(self.bss_hostapd[1].list_sta())
+        self.bss_hostapd[1].wait_for_event('AP-STA-CONNECTED %s' % device.address)
 
         testutil.test_iface_operstate(device.name)
         testutil.test_ifaces_connected(self.bss_hostapd[1].ifname, device.name)
@@ -72,8 +73,10 @@ class Test(unittest.TestCase):
         condition = 'obj.state != DeviceState.roaming'
         wd.wait_for_object_condition(device, condition)
 
-        self.assertEqual(device.state, iwd.DeviceState.connected)
-        self.assertTrue(self.bss_hostapd[2].list_sta())
+        condition = 'obj.state == DeviceState.connected'
+        wd.wait_for_object_condition(device, condition)
+
+        self.bss_hostapd[2].wait_for_event('AP-STA-CONNECTED %s' % device.address)
 
         testutil.test_iface_operstate(device.name)
         testutil.test_ifaces_connected(self.bss_hostapd[2].ifname, device.name)
Signature · 1 line
2.34.1
author
#5 lore raw

PATCH 6/8 dpp: fail if disconnected during DPP protocol

In reply to James Prestwood

If the connected BSS is NULL IWD was disconnected and this should trigger a protocol termination.

---
 src/dpp.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
src/dpp.c +11 -2
index f2421b69..de8e6e14 100644
@@ -1294,7 +1294,7 @@ static void dpp_presence_announce(struct dpp_sm *dpp)
 	dpp_send_frame(dpp, iov, 2, dpp->current_freq);
 }
 
-static void dpp_send_authenticate_request(struct dpp_sm *dpp)
+static bool dpp_send_authenticate_request(struct dpp_sm *dpp)
 {
 	uint8_t hdr[32];
 	uint8_t attrs[256];
@@ -1305,6 +1305,12 @@ static void dpp_send_authenticate_request(struct dpp_sm *dpp)
 	struct station *station = station_find(netdev_get_ifindex(dpp->netdev));
 	struct scan_bss *bss = station_get_connected_bss(station);
 
+	/* Got disconnected by the time the peer was discovered */
+	if (!bss) {
+		dpp_reset(dpp);
+		return false;
+	}
+
 	l_ecc_point_get_data(dpp->own_proto_public, i_proto_key,
 				sizeof(i_proto_key));
 
@@ -1337,6 +1343,8 @@ static void dpp_send_authenticate_request(struct dpp_sm *dpp)
 	iov[1].iov_len = ptr - attrs;
 
 	dpp_send_frame(dpp, iov, 2, dpp->current_freq);
+
+	return true;
 }
 
 static void dpp_roc_started(void *user_data)
@@ -1948,7 +1956,8 @@ static void dpp_handle_presence_announcement(struct dpp_sm *dpp,
 
 	dpp->state = DPP_STATE_AUTHENTICATING;
 
-	dpp_send_authenticate_request(dpp);
+	if (!dpp_send_authenticate_request(dpp))
+		return;
 
 	/*
 	 * Should we wait for an ACK then go offchannel?
Signature · 1 line
2.34.1
author
#6 lore raw

PATCH 7/8 dpp: set new_freq when configuring as initiator

In reply to James Prestwood

This is used to hold the current BSS frequency which will be used after IWD receives a presence announcement. Since this was not being set, the logic was always thinking there was a channel mismatch (0 != current_freq) and attempting to go offchannel to '0' which resulted in -EINVAL, and ultimately protocol termination.

---
 src/dpp.c | 2 ++
 1 file changed, 2 insertions(+)
src/dpp.c +2 -0
index de8e6e14..1719a89d 100644
@@ -2436,6 +2436,8 @@ static struct l_dbus_message *dpp_start_configurator_common(
 
 		if (!dpp->mcast_support)
 			dpp->state = DPP_STATE_AUTHENTICATING;
+
+		dpp->new_freq = bss->frequency;
 	} else
 		dpp->current_freq = bss->frequency;
 
Signature · 1 line
2.34.1
author
#7 lore raw

PATCH 8/8 auto-t: don't wait for wpa_supplicant to connect

In reply to James Prestwood

When configuring wpa_supplicant all we care about is that it received the configuration object. wpa_supplicant takes quite a bit of time to connect in some cases so waiting for that is unneeded.

This also increases the DPP timeout which may be required on slower systems or if the timing is particularly unlucky when receiving frames.

---
 autotests/testDPP/connection_test.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
autotests/testDPP/connection_test.py +3 -2
index b58620b8..ab3cbf95 100644
@@ -80,7 +80,7 @@ class Test(unittest.TestCase):
 
         self.wpas.dpp_enrollee_start(uri)
 
-        self.wpas.wait_for_event('DPP-CONF-RECEIVED')
+        self.wpas.wait_for_event('DPP-CONF-RECEIVED', timeout=30)
 
     def test_iwd_as_configurator_initiator(self):
         self.hapd.reload()
@@ -96,7 +96,7 @@ class Test(unittest.TestCase):
 
         self.device.dpp_start_configurator(uri)
 
-        self.hapd.wait_for_event('AP-STA-CONNECTED 42:00:00:00:00:00')
+        self.wpas.wait_for_event('DPP-CONF-RECEIVED', timeout=30)
 
     def setUp(self):
         self.wd = IWD(True)
@@ -118,6 +118,7 @@ class Test(unittest.TestCase):
         self.device.disconnect()
         self.device.dpp_stop()
         self.wpas.dpp_configurator_remove()
+        self.wpas.clean_up()
 
         self.wd = None
         self.device = None
Signature · 1 line
2.34.1