From de8a45b6cee9757da6516c07780c572ae75d5bf0 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Mon, 4 Jan 2016 23:25:26 +0200 Subject: [PATCH] tests: Make P2P discovery on non-social channel cases more robust The test cases discovery_ctrl_char_in_devname and discovery_group_client tried to allow three P2P_FIND instances to be used before reporting an error. However, this did not really work properly since the second and third attempts would likely fail to start the initial special P2P_FIND scan due to an already ongoing p2p_scan operation. Fix this by stopping the previous P2P_FIND and waiting for the scan to complete if a retry is needed. Signed-off-by: Jouni Malinen --- tests/hwsim/test_p2p_discovery.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/hwsim/test_p2p_discovery.py b/tests/hwsim/test_p2p_discovery.py index c102fcc1c..22ce17381 100644 --- a/tests/hwsim/test_p2p_discovery.py +++ b/tests/hwsim/test_p2p_discovery.py @@ -124,7 +124,9 @@ def test_discovery_group_client(dev): hwsim_utils.test_connectivity_p2p(dev[0], dev[1]) logger.info("Try to discover a P2P client in a group") if not dev[2].discover_peer(dev[1].p2p_dev_addr(), social=False, timeout=10): + stop_p2p_find_and_wait(dev[2]) if not dev[2].discover_peer(dev[1].p2p_dev_addr(), social=False, timeout=10): + stop_p2p_find_and_wait(dev[2]) if not dev[2].discover_peer(dev[1].p2p_dev_addr(), social=False, timeout=10): raise Exception("Could not discover group client") @@ -159,6 +161,15 @@ def test_discovery_group_client(dev): if ev is None: raise Exception("Timeout on waiting for GO Negotiation Request") +def stop_p2p_find_and_wait(dev): + dev.request("P2P_STOP_FIND") + for i in range(10): + res = dev.get_driver_status_field("scan_state") + if "SCAN_STARTED" not in res and "SCAN_REQUESTED" not in res: + break + logger.debug("Waiting for final P2P_FIND scan to complete") + time.sleep(0.02) + def test_discovery_ctrl_char_in_devname(dev): """P2P device discovery and control character in Device Name""" try: @@ -177,7 +188,9 @@ def _test_discovery_ctrl_char_in_devname(dev): dev[1].scan_for_bss(bssid, freq=2422) dev[1].p2p_connect_group(addr0, pin, timeout=60, freq=2422) if not dev[2].discover_peer(addr1, social=False, freq=2422, timeout=5): + stop_p2p_find_and_wait(dev[2]) if not dev[2].discover_peer(addr1, social=False, freq=2422, timeout=5): + stop_p2p_find_and_wait(dev[2]) if not dev[2].discover_peer(addr1, social=False, freq=2422, timeout=5): raise Exception("Could not discover group client")