From 576d8ad123d7008bb463e4d11b288b0a761a021b Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Sat, 20 Apr 2019 22:29:03 +0200 Subject: [PATCH] autotests: In testutil obtain interface list dynamically For the interface connectivity tests obtain the lists of interfaces in use directly from the IWD class, which has the current list from DBus properties. --- autotests/util/iwd.py | 10 ++++++++++ autotests/util/testutil.py | 15 ++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/autotests/util/iwd.py b/autotests/util/iwd.py index 931e6a4d..0ba2e5ab 100755 --- a/autotests/util/iwd.py +++ b/autotests/util/iwd.py @@ -10,6 +10,7 @@ import threading import time import collections import datetime +import weakref from abc import ABCMeta, abstractmethod from enum import Enum @@ -834,6 +835,7 @@ class IWD(AsyncOpAbstract): _agent_manager_if = None _iwd_proc = None _devices = None + _instance = None def __init__(self, start_iwd_daemon = False, iwd_config_dir = IWD_CONFIG_DIR): @@ -875,6 +877,10 @@ class IWD(AsyncOpAbstract): self._devices = DeviceList(self) + # Weak to make sure the test's reference to @self is the only counted + # reference so that __del__ gets called when it's released + IWD._instance = weakref.ref(self) + def __del__(self): if self._iwd_proc is None: return @@ -1004,3 +1010,7 @@ class IWD(AsyncOpAbstract): reply_handler=self._success, error_handler=self._failure) self._wait_for_async_op() + + @staticmethod + def get_instance(): + return IWD._instance() diff --git a/autotests/util/testutil.py b/autotests/util/testutil.py index 4028c004..d1476736 100644 --- a/autotests/util/testutil.py +++ b/autotests/util/testutil.py @@ -6,6 +6,7 @@ import struct import select import wiphy +import iwd HWSIM_ETHERTYPE = 0x0800 HWSIM_PACKETLEN = 250 @@ -51,8 +52,11 @@ def tx(fromsock, tosock, src, dst): return (frame, fromsock, tosock, src, dst) def test_connected(if0=None, if1=None): - for wname in wiphy.wiphy_map: - for intf in wiphy.wiphy_map[wname]: + if if0 is None or if1 is None: + iwd_list = [dev.name for dev in iwd.IWD.get_instance().list_devices()] + non_iwd_list = [ifname for w in wiphy.wiphy_map.values() + for ifname in w.interface_map] + for intf in iwd_list + non_iwd_list: if if0 is None: if0 = intf elif if1 is None and intf != if0: @@ -120,11 +124,8 @@ IFF_UP = 1 << 0 IFF_RUNNING = 1 << 6 def test_iface_operstate(intf=None): - for wname in wiphy.wiphy_map: - w = wiphy.wiphy_map[wname] - for ifname in w: - if intf is None and w[ifname].use == 'iwd': - intf = ifname + if not intf: + intf = iwd.IWD.get_instance().list_devices()[0].name sock = socket.socket(socket.PF_PACKET, socket.SOCK_RAW)