From 6cd59688b86551665b4833f0e1bafa5e9670e5a6 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Fri, 27 Dec 2019 18:14:09 +0200 Subject: [PATCH] tests: Fix thread handling in P2P GO Negotiation test cases Some of the error paths in go_neg_pbc() and go_neg_pin() did not wait for the helper thread to complete processing. This could result in unexpected behavior when the test case could have exited while the thread was still performing tasks for the GO Negotiation. This could result in getting stuck in one of the following test cases with "go_neg_init_pbc thread caught an exception from p2p_go_neg_init: Group formation timed out" showing up in the log. This was hit, e.g., with the following test sequence: no_go_freq p2p_channel_drv_pref_autogo Signed-off-by: Jouni Malinen --- tests/hwsim/p2p_utils.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/hwsim/p2p_utils.py b/tests/hwsim/p2p_utils.py index df9f7f971..bfd8e2e44 100644 --- a/tests/hwsim/p2p_utils.py +++ b/tests/hwsim/p2p_utils.py @@ -248,10 +248,17 @@ def go_neg_pin(i_dev, r_dev, i_intent=None, r_intent=None, i_method='enter', r_m logger.debug("Wait for GO Negotiation Request on r_dev") ev = r_dev.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15) if ev is None: + t.join() raise Exception("GO Negotiation timed out") r_dev.dump_monitor() logger.debug("Re-initiate GO Negotiation from r_dev") - r_res = r_dev.p2p_go_neg_init(i_dev.p2p_dev_addr(), pin, r_method, go_intent=r_intent, timeout=20) + try: + r_res = r_dev.p2p_go_neg_init(i_dev.p2p_dev_addr(), pin, r_method, + go_intent=r_intent, timeout=20) + except Exception as e: + logger.info("go_neg_pin - r_dev.p2p_go_neg_init() exception: " + str(e)) + t.join() + raise logger.debug("r_res: " + str(r_res)) r_dev.dump_monitor() t.join() @@ -328,14 +335,21 @@ def go_neg_pbc(i_dev, r_dev, i_intent=None, r_intent=None, i_freq=None, r_freq=N logger.debug("Wait for GO Negotiation Request on r_dev") ev = r_dev.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15) if ev is None: + t.join() raise Exception("GO Negotiation timed out") r_dev.dump_monitor() # Allow some time for the GO Neg Resp to go out before initializing new # GO Negotiation. time.sleep(0.2) logger.debug("Re-initiate GO Negotiation from r_dev") - r_res = r_dev.p2p_go_neg_init(i_dev.p2p_dev_addr(), None, "pbc", - go_intent=r_intent, timeout=20, freq=r_freq) + try: + r_res = r_dev.p2p_go_neg_init(i_dev.p2p_dev_addr(), None, "pbc", + go_intent=r_intent, timeout=20, + freq=r_freq) + except Exception as e: + logger.info("go_neg_pbc - r_dev.p2p_go_neg_init() exception: " + str(e)) + t.join() + raise logger.debug("r_res: " + str(r_res)) r_dev.dump_monitor() t.join()