diff --git a/autotests/test1AP/connectDisconnectTest.py b/autotests/test1AP/connectDisconnectTest.py index c7a3c2c7..ad1b5e1d 100755 --- a/autotests/test1AP/connectDisconnectTest.py +++ b/autotests/test1AP/connectDisconnectTest.py @@ -7,17 +7,31 @@ import dbus import time import logging import os -from random import randrange -from subprocess import Popen +from subprocess import Popen, PIPE, STDOUT import sys sys.path.append('../utility') #needed to import all the utility modules import utility +import pty class TestConnectDisconnect(unittest.TestCase): def doConnectDisconnect(self): objectList = utility.getObjectList(bus) - networkToConnect = utility.getNetworkToConnectTo(objectList) + # start simpleAgent + master, slave = pty.openpty() + proc = Popen([sys.executable, '../utility/simpleAgent.py'], + stdin=PIPE, stdout=slave, close_fds=True) + stdout_handle = os.fdopen(master) + if stdout_handle.readline().rstrip() == "AGENT_REGISTERED": + logger.debug("Agent Registered") + else: + logger.debug("Agent failed to register") + + # close the handles + stdout_handle.close() + os.close(slave) + + networkToConnect = utility.getNetworkToConnectTo(objectList) # check if networkToConnect is not null. If yes, restart program # so that the network list is updated. Alternatively, we can scan # for networks. @@ -27,9 +41,6 @@ class TestConnectDisconnect(unittest.TestCase): os.execl(sys.executable, sys.executable, * sys.argv) self.assertNotEqual(networkToConnect, "") - # start simpleAgent - proc = Popen([sys.executable, '../utility/simpleAgent.py']) - time.sleep(2) network = dbus.Interface(bus.get_object(utility.IWD_SERVICE, networkToConnect), utility.IWD_NETWORK_INTERFACE) @@ -69,9 +80,6 @@ class TestConnectDisconnect(unittest.TestCase): if bus.name_has_owner(utility.IWD_SERVICE) == True: break self.doConnectDisconnect() - #watch doesn't seem to work. So used name_has_owner - #watch = bus.watch_name_owner(utility.IWD_SERVICE, - # self.doConnectDisconnect) @classmethod def setUpClass(cls): diff --git a/autotests/test2AP/twoNetworksTest.py b/autotests/test2AP/twoNetworksTest.py index 38753a83..28a99bf5 100755 --- a/autotests/test2AP/twoNetworksTest.py +++ b/autotests/test2AP/twoNetworksTest.py @@ -9,11 +9,12 @@ import dbus.mainloop.glib import time import threading import logging -from subprocess import Popen +from subprocess import Popen, PIPE, STDOUT import sys import os sys.path.append('../utility') #needed to import all the utlilty modules import utility +import pty def getSecondNetworkToConnect(objectList, firstNetworkName): logger.debug(sys._getframe().f_code.co_name) @@ -32,8 +33,19 @@ class TestTwoNetworks(unittest.TestCase): # connect to network B. disconnect from network B. def connectToNetwork(self, networkToConnect): # start simpleAgent - proc = Popen([sys.executable, '../utility/simpleAgent.py']) - time.sleep(2) + master, slave = pty.openpty() + proc = Popen([sys.executable, '../utility/simpleAgent.py'], + stdin=PIPE, stdout=slave, close_fds=True) + stdout_handle = os.fdopen(master) + if stdout_handle.readline().rstrip() == "AGENT_REGISTERED": + logger.debug("Agent Registered") + else: + logger.debug("Agent failed to register") + + # close the handles + stdout_handle.close() + os.close(slave) + network = dbus.Interface(bus.get_object(utility.IWD_SERVICE, networkToConnect), utility.IWD_NETWORK_INTERFACE) diff --git a/autotests/utility/simpleAgent.py b/autotests/utility/simpleAgent.py index 83d800f6..358efe26 100755 --- a/autotests/utility/simpleAgent.py +++ b/autotests/utility/simpleAgent.py @@ -9,7 +9,6 @@ import logging import traceback import threading import time - import sys sys.path.append('../utility') #needed to import all the utlilty modules import utility @@ -55,6 +54,8 @@ def registerAgent(bus, mainloop): try: manager.RegisterAgent(pathAgent) logger.debug("Registered iwd agent") + # this will be received by stdout in the parent + print("AGENT_REGISTERED") except: logger.debug("Error in registering path") logger.debug(traceback.print_exc(file=sys.stdout))