Skip to contentSkip to conversation

auto-t: fix testAgent use of Process

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

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 auto-t: fix testAgent use of Process

This test was accessing the subprocess object and calling terminate which ends up causing issues with test-runners own process cleanup. Instead kill() should be used.

---
 autotests/testAgent/agent_test.py | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
autotests/testAgent/agent_test.py +4 -6
index 7d3b6119..e2d6e49e 100644
@@ -58,14 +58,13 @@ class Test(unittest.TestCase):
     def test_connection_with_other_agent(self):
         wd = IWD()
 
-        iwctl = ctx.start_process(['iwctl', '-P', 'secret_ssid2']).pid
+        iwctl = ctx.start_process(['iwctl', '-P', 'secret_ssid2'])
         # Let iwctl to start and register its agent.
         wd.wait(2)
 
         self.check_connection(wd, 'ssid2')
 
-        iwctl.terminate()
-        iwctl.communicate()
+        iwctl.kill()
 
         IWD.clear_storage()
 
@@ -73,7 +72,7 @@ class Test(unittest.TestCase):
 
         wd = IWD()
 
-        iwctl = ctx.start_process(['iwctl', '-P', 'secret_ssid2']).pid
+        iwctl = ctx.start_process(['iwctl', '-P', 'secret_ssid2'])
         # Let iwctl to start and register its agent.
         wd.wait(2)
 
@@ -84,8 +83,7 @@ class Test(unittest.TestCase):
 
         wd.unregister_psk_agent(psk_agent)
 
-        iwctl.terminate()
-        iwctl.communicate()
+        iwctl.kill()
 
         IWD.clear_storage()
 
Signature · 1 line
2.31.1
#1 lore raw

Hi James,

Quoted 7 lines · James Prestwood

This test was accessing the subprocess object and calling terminate which ends up causing issues with test-runners own process cleanup. Instead kill() should be used.

---
  autotests/testAgent/agent_test.py | 10 ++++------
  1 file changed, 4 insertions(+), 6 deletions(-)

All applied, thanks.

Regards,
-Denis

#2 lore raw

PATCH 2/6 auto-t: use prefix on hotspot anqp test

In reply to James Prestwood

The hotspot ANQP delay test was setting a global delay on all packets which had some unintended consequences. At the time this was the only way of simulating the test scenario but now hwsim supports prefix matching so only the ANQP request/response will be delayed.

---
 autotests/testHotspot/anqp_delay_test.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
autotests/testHotspot/anqp_delay_test.py +4 -3
index 67c12025..323e1fd3 100644
@@ -65,14 +65,15 @@ class Test(unittest.TestCase):
 
         # Force the case where ANQP does not finish before Connect() comes in
         rule0.delay = 100
+        rule0.prefix = '0d'
 
-        ordered_network.network_object.connect()
-
-        rule0.delay = 1
+        ordered_network.network_object.connect(wait=False)
 
         condition = 'obj.state == DeviceState.connected'
         wd.wait_for_object_condition(device, condition)
 
+        hapd.wait_for_event('AP-STA-CONNECTED')
+
         testutil.test_iface_operstate()
         testutil.test_ifaces_connected(device.name, hapd.ifname)
 
Signature · 1 line
2.31.1
#3 lore raw

PATCH 3/6 auto-t: cleanup dhcpd.leases[~] in testNetconfig

In reply to James Prestwood
---
 autotests/testNetconfig/connection_test.py | 10 ++++++++--
 autotests/testNetconfig/static_test.py     | 10 ++++++++--
 2 files changed, 16 insertions(+), 4 deletions(-)
autotests/testNetconfig/connection_test.py +8 -2
index 43dab243..99fe734c 100644
@@ -48,6 +48,13 @@ class Test(unittest.TestCase):
 
     @classmethod
     def setUpClass(cls):
+        def remove_lease():
+            try:
+                os.remove('/tmp/dhcpd.leases')
+                os.remove('/tmp/dhcpd.leases~')
+            except:
+                pass
+
         hapd = HostapdCLI()
         # TODO: This could be moved into test-runner itself if other tests ever
         #       require this functionality (p2p, FILS, etc.). Since its simple
@@ -57,14 +64,13 @@ class Test(unittest.TestCase):
         ctx.start_process(['touch', '/tmp/dhcpd.leases'], wait=True)
         cls.dhcpd_pid = ctx.start_process(['dhcpd', '-f', '-cf', '/tmp/dhcpd.conf',
                                             '-lf', '/tmp/dhcpd.leases',
-                                            hapd.ifname])
+                                            hapd.ifname], cleanup=remove_lease)
 
     @classmethod
     def tearDownClass(cls):
         IWD.clear_storage()
         ctx.stop_process(cls.dhcpd_pid)
         cls.dhcpd_pid = None
-        os.remove('/tmp/dhcpd.leases')
 
 if __name__ == '__main__':
     unittest.main(exit=True)
autotests/testNetconfig/static_test.py +8 -2
index 7d908423..21384a7b 100644
@@ -75,6 +75,13 @@ class Test(unittest.TestCase):
 
     @classmethod
     def setUpClass(cls):
+        def remove_lease():
+            try:
+                os.remove('/tmp/dhcpd.leases')
+                os.remove('/tmp/dhcpd.leases~')
+            except:
+                pass
+
         hapd = HostapdCLI()
         # TODO: This could be moved into test-runner itself if other tests ever
         #       require this functionality (p2p, FILS, etc.). Since its simple
@@ -84,14 +91,13 @@ class Test(unittest.TestCase):
         ctx.start_process(['touch', '/tmp/dhcpd.leases'], wait=True)
         cls.dhcpd_pid = ctx.start_process(['dhcpd', '-f', '-cf', '/tmp/dhcpd.conf',
                                             '-lf', '/tmp/dhcpd.leases',
-                                            hapd.ifname])
+                                            hapd.ifname], cleanup=remove_lease)
         IWD.copy_to_storage('ssidTKIP.psk', '/tmp/storage')
 
     @classmethod
     def tearDownClass(cls):
         IWD.clear_storage()
         cls.dhcpd_pid.kill()
-        os.system('rm -rf /tmp/dhcpd.leases')
 
 if __name__ == '__main__':
     unittest.main(exit=True)
Signature · 1 line
2.31.1
#4 lore raw

PATCH 4/6 auto-t: ead.py: remove wait_for_object_condition

In reply to James Prestwood

Instead the class method IWD._wait_for_object_condition can be used.

---
 autotests/testEAD/connection_test.py |  4 ++--
 autotests/util/ead.py                | 19 -------------------
 2 files changed, 2 insertions(+), 21 deletions(-)
autotests/testEAD/connection_test.py +2 -2
index 7f23f0d6..a858831d 100644
@@ -22,10 +22,10 @@ class Test(unittest.TestCase):
         adapter = ead.list_adapters(1)[0]
 
         condition = 'obj.connected == True'
-        ead.wait_for_object_condition(adapter, condition)
+        IWD._wait_for_object_condition(adapter, condition)
 
         condition = 'obj.authenticated == True'
-        ead.wait_for_object_condition(adapter, condition)
+        IWD._wait_for_object_condition(adapter, condition)
 
         ctx.stop_process(p)
     @classmethod
autotests/util/ead.py +0 -19
index 8f333a8a..06716914 100644
@@ -103,22 +103,3 @@ class EAD(iwd.AsyncOpAbstract):
                             exception=TimeoutError('EAD has no associated devices'))
 
         return list(self._adapters.values())
-
-    def wait_for_object_condition(self, obj, condition_str, max_wait = 50):
-        self._wait_timed_out = False
-        def wait_timeout_cb():
-            self._wait_timed_out = True
-            return False
-
-        try:
-            timeout = GLib.timeout_add_seconds(max_wait, wait_timeout_cb)
-            context = ctx.mainloop.get_context()
-            while not eval(condition_str):
-                context.iteration(may_block=True)
-                if self._wait_timed_out and ctx.args.gdb == None:
-                    raise TimeoutError('[' + condition_str + ']'\
-                                       ' condition was not met in '\
-                                       + str(max_wait) + ' sec')
-        finally:
-            if not self._wait_timed_out:
-                GLib.source_remove(timeout)
Signature · 1 line
2.31.1
#5 lore raw

PATCH 5/6 test-runner: start dmesg early with --follow

In reply to James Prestwood

dmesg was being called at the very end of testing and dumped into a log file. If many tests were run this could take quite a long time and was timing out the default process wait. Instead --follow can be used (basically like 'tail') which prints messages as they come and avoids the time consuming full dump at the end.

---
 tools/test-runner | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tools/test-runner +6 -6
index 90a5f87a..5b8bdaf5 100755
@@ -604,8 +604,9 @@ class Namespace:
 		if not env:
 			env = os.environ.copy()
 
-		# In case this process needs DBus...
-		env['DBUS_SYSTEM_BUS_ADDRESS'] = self.dbus_address
+		if hasattr(self, "dbus_address"):
+			# In case this process needs DBus...
+			env['DBUS_SYSTEM_BUS_ADDRESS'] = self.dbus_address
 
 		p = Process(args, ctx=self, namespace=ns, env=env, **kwargs)
 
@@ -1403,10 +1404,6 @@ def run_auto_tests(ctx, args):
 	shutil.rmtree('/tmp/secrets')
 	os.remove('/tmp/phonesim.conf')
 
-	# Write out kernel log
-	if ctx.args.log:
-		ctx.start_process(["dmesg"], wait=True)
-
 def run_unit_tests(ctx, args):
 	os.chdir(args.testhome + '/unit')
 	units = build_unit_list(args)
@@ -1484,6 +1481,9 @@ def run_tests():
 				shutil.rmtree(f)
 			else:
 				os.remove(f)
+
+		# Start writing out kernel log
+		config.ctx.start_process(["dmesg", '--follow'])
 	elif args.monitor:
 		parent = os.path.abspath(os.path.join(args.monitor, os.pardir))
 		mount('mondir', parent, '9p', 0, 'trans=virtio,version=9p2000.L,msize=10240')
Signature · 1 line
2.31.1
#6 lore raw

PATCH 6/6 test-runner: don't always print failure to remove ctrl interface

In reply to James Prestwood

This can happen, particularly with SAQuery when hostapd is forcefully killed. Better to only print when running in debug mode.

---
 tools/test-runner | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/test-runner +1 -1
index 5b8bdaf5..7e89d71c 100755
@@ -541,7 +541,7 @@ class Hostapd:
 		try:
 			os.remove(self.global_ctrl_iface)
 		except:
-			dbg("Failed to remove %s" % self.global_ctrl_iface)
+			print("Failed to remove %s" % self.global_ctrl_iface)
 
 		self.instances = None
 
Signature · 1 line
2.31.1