Skip to contentSkip to conversation

station: Add generic Event signal

PATCH In review James Prestwood 2 participants 4 messages Aug 13, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 station: Add generic Event signal

This is meant to be used as a generic notification to autotests. For now 'no-roam-candidates' is the only event being sent. The idea is to extend these events to signal conditions that are otherwise undiscoverable in autotesting.

---
 src/station.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
src/station.c +23 -1
index 408ae887..d3482e2c 100644
@@ -153,6 +153,24 @@ static bool station_is_autoconnecting(struct station *station)
 			station->state == STATION_STATE_AUTOCONNECT_QUICK;
 }
 
+static bool station_debug_event(struct station *station, const char *name)
+{
+	struct l_dbus_message *signal;
+
+	if (!iwd_is_developer_mode())
+		return true;
+
+	l_debug("StationDebug.Event(%s)", name);
+
+	signal = l_dbus_message_new_signal(dbus_get_bus(),
+					netdev_get_path(station->netdev),
+					IWD_STATION_DEBUG_INTERFACE, "Event");
+
+	l_dbus_message_set_arguments(signal, "sav", name, 0);
+
+	return l_dbus_send(dbus_get_bus(), signal) != 0;
+}
+
 static void station_property_set_scanning(struct station *station,
 								bool scanning)
 {
@@ -1938,8 +1956,10 @@ next:
 		goto fail_free_bss;
 
 	/* See if we have anywhere to roam to */
-	if (!best_bss || scan_bss_addr_eq(best_bss, station->connected_bss))
+	if (!best_bss || scan_bss_addr_eq(best_bss, station->connected_bss)) {
+		station_debug_event(station, "no-roam-candidates");
 		goto fail_free_bss;
+	}
 
 	bss = network_bss_find_by_addr(network, best_bss->addr);
 	if (bss) {
@@ -3991,6 +4011,8 @@ static void station_setup_debug_interface(
 					station_debug_scan, "", "aq",
 					"frequencies");
 
+	l_dbus_interface_signal(interface, "Event", 0, "sav", "name", "data");
+
 	l_dbus_interface_property(interface, "AutoConnect", 0, "b",
 					station_property_get_autoconnect,
 					station_property_set_autoconnect);
Signature · 1 line
2.31.1
#1 lore raw

Hi James,

Quoted 7 lines · James Prestwood

This is meant to be used as a generic notification to autotests. For now 'no-roam-candidates' is the only event being sent. The idea is to extend these events to signal conditions that are otherwise undiscoverable in autotesting.

---
  src/station.c | 24 +++++++++++++++++++++++-
  1 file changed, 23 insertions(+), 1 deletion(-)

All applied, thanks.

Regards,
-Denis

#2 lore raw

PATCH v2 2/3 auto-t: iwd.py: add StationDebug.Event support

In reply to James Prestwood

Adds a new wait_for_event API which waits for a StationDebug.Event.

---
 autotests/util/iwd.py | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
autotests/util/iwd.py +29 -0
index b5546bcd..36b8f6f9 100755
@@ -233,9 +233,17 @@ class StationDebug(IWDDBusAbstract):
     def __init__(self, *args, **kwargs):
         self._debug_props = None
         self._debug_iface = None
+        self._last_event = None
+        self._last_event_data = []
 
         IWDDBusAbstract.__init__(self, *args, **kwargs)
 
+        self._iface.connect_to_signal("Event", self._event_handler)
+
+    def _event_handler(self, event, data):
+        self._last_event = event
+        self._last_event_data = data
+
     @property
     def autoconnect(self):
         return self._properties['AutoConnect']
@@ -244,6 +252,21 @@ class StationDebug(IWDDBusAbstract):
         frequencies = dbus.Array([dbus.UInt16(f) for f in frequencies])
         self._iface.Scan(frequencies)
 
+    def wait_for_event(self, event, timeout=10):
+        try:
+            if self._last_event is not None:
+                return self._last_event_data
+
+            ctx.non_block_wait(lambda s, e : s._last_event == e, timeout, self, event,
+                                exception=TimeoutError("waiting for StationDebug.Event"))
+
+            return self._last_event_data
+        finally:
+            # Consume the event
+            self._last_event_data = None
+            self._last_event = None
+
+
 class Device(IWDDBusAbstract):
     '''
         Class represents a network device object: net.connman.iwd.Device
@@ -596,6 +619,12 @@ class Device(IWDDBusAbstract):
 
         self._station_debug.scan(frequencies)
 
+    def wait_for_event(self, event, timeout=10):
+        if not self._station_debug:
+            self._station_debug = StationDebug(self._object_path)
+
+        self._station_debug.wait_for_event(event, timeout)
+
     def __str__(self, prefix = ''):
         return prefix + 'Device: ' + self.device_path + '\n'\
                + prefix + '\tName:\t\t' + self.name + '\n'\
Signature · 1 line
2.31.1
#3 lore raw

PATCH v2 3/3 auto-t: speed up testRoamRetry

In reply to James Prestwood

This test took quite a while to execute (~2 minutes on my machine) because there was simply no other way to test this scenario but waiting. Now the no-roam-candidates condition can be waited for rather than just sleeping for 20 seconds. Additionally the default RoamRetryInterval was being used which is 60 seconds. Instead main.conf can set this to 5 seconds and really cut down on the time to wait.

Part of a comment was also removed due to being incorrect. Even with neighbor reports IWD still must scan, its just that the scan is more limited and, in theory, faster.

---
 autotests/testRoamRetry/fast_retry_test.py | 7 +++----
 autotests/testRoamRetry/main.conf          | 2 ++
 autotests/testRoamRetry/stop_retry_test.py | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)
 create mode 100644 autotests/testRoamRetry/main.conf
autotests/testRoamRetry/fast_retry_test.py +3 -4
index d6324c31..e8b5455d 100644
@@ -82,7 +82,7 @@ class Test(unittest.TestCase):
         # schedule another attempt for 60 seconds later
         rule0.signal = -8000
 
-        wd.wait(20)
+        device.wait_for_event('no-roam-candidates')
 
         self.assertEqual(device.state, iwd.DeviceState.connected)
         self.assertTrue(bss_hostapd[0].list_sta())
@@ -99,13 +99,12 @@ 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. Because of the neighbor report a scan should
-        # not be necessary.
+        # 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=10)
+        wd.wait_for_object_condition(device, condition, max_wait=15)
 
         # Check that iwd is on BSS 1 once out of roaming state and doesn't
         # go through 'disconnected', 'autoconnect', 'connecting' in between
autotests/testRoamRetry/main.conf new file +2 -0
new file mode 100644
index 00000000..f0d1c0f4
@@ -0,0 +1,2 @@
+[General]
+RoamRetryInterval=5
autotests/testRoamRetry/stop_retry_test.py +1 -1
index be9776a5..3bf166d8 100644
@@ -99,7 +99,7 @@ class Test(unittest.TestCase):
 
         condition = 'obj.state == DeviceState.roaming'
         self.assertRaises(TimeoutError, wd.wait_for_object_condition, device,
-                          condition, max_wait=70)
+                          condition, max_wait=10)
 
         device.disconnect()
 
Signature · 1 line
2.31.1