From cf3a9d8f067ed2764a7495cef16a7b8281d453a3 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Mon, 28 Dec 2015 17:31:16 +0200 Subject: [PATCH] tests: Clear p2p_add_cli_chan explicitly in test cases where it is used This parameter is used only in couple of test cases and there is no need to maintain the code to reset it in WpaSupplicant::reset(). Signed-off-by: Jouni Malinen --- tests/hwsim/test_p2p_grpform.py | 88 ++++++++++++++++++------------ tests/hwsim/test_p2p_persistent.py | 24 ++++---- tests/hwsim/wpasupplicant.py | 1 - 3 files changed, 66 insertions(+), 47 deletions(-) diff --git a/tests/hwsim/test_p2p_grpform.py b/tests/hwsim/test_p2p_grpform.py index 9f70a09ec..899bacbe8 100644 --- a/tests/hwsim/test_p2p_grpform.py +++ b/tests/hwsim/test_p2p_grpform.py @@ -402,51 +402,67 @@ def test_grpform_no_5ghz_world_roaming(dev): def test_grpform_no_5ghz_add_cli(dev): """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1""" - dev[0].request("SET p2p_add_cli_chan 1") - dev[1].request("SET p2p_add_cli_chan 1") - [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0, - r_dev=dev[1], r_intent=14, - test_data=False) - check_grpform_results(i_res, r_res) - if int(i_res['freq']) > 4000: - raise Exception("Unexpected channel - did not follow world roaming rules") - remove_group(dev[0], dev[1]) + try: + dev[0].request("SET p2p_add_cli_chan 1") + dev[1].request("SET p2p_add_cli_chan 1") + [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0, + r_dev=dev[1], r_intent=14, + test_data=False) + check_grpform_results(i_res, r_res) + if int(i_res['freq']) > 4000: + raise Exception("Unexpected channel - did not follow world roaming rules") + remove_group(dev[0], dev[1]) + finally: + dev[0].request("SET p2p_add_cli_chan 0") + dev[1].request("SET p2p_add_cli_chan 0") def test_grpform_no_5ghz_add_cli2(dev): """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (reverse)""" - dev[0].request("SET p2p_add_cli_chan 1") - dev[1].request("SET p2p_add_cli_chan 1") - [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=14, - r_dev=dev[1], r_intent=0, - test_data=False) - check_grpform_results(i_res, r_res) - if int(i_res['freq']) > 4000: - raise Exception("Unexpected channel - did not follow world roaming rules") - remove_group(dev[0], dev[1]) + try: + dev[0].request("SET p2p_add_cli_chan 1") + dev[1].request("SET p2p_add_cli_chan 1") + [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=14, + r_dev=dev[1], r_intent=0, + test_data=False) + check_grpform_results(i_res, r_res) + if int(i_res['freq']) > 4000: + raise Exception("Unexpected channel - did not follow world roaming rules") + remove_group(dev[0], dev[1]) + finally: + dev[0].request("SET p2p_add_cli_chan 0") + dev[1].request("SET p2p_add_cli_chan 0") def test_grpform_no_5ghz_add_cli3(dev): """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (intent 15)""" - dev[0].request("SET p2p_add_cli_chan 1") - dev[1].request("SET p2p_add_cli_chan 1") - [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0, - r_dev=dev[1], r_intent=15, - test_data=False) - check_grpform_results(i_res, r_res) - if int(i_res['freq']) > 4000: - raise Exception("Unexpected channel - did not follow world roaming rules") - remove_group(dev[0], dev[1]) + try: + dev[0].request("SET p2p_add_cli_chan 1") + dev[1].request("SET p2p_add_cli_chan 1") + [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=0, + r_dev=dev[1], r_intent=15, + test_data=False) + check_grpform_results(i_res, r_res) + if int(i_res['freq']) > 4000: + raise Exception("Unexpected channel - did not follow world roaming rules") + remove_group(dev[0], dev[1]) + finally: + dev[0].request("SET p2p_add_cli_chan 0") + dev[1].request("SET p2p_add_cli_chan 0") def test_grpform_no_5ghz_add_cli4(dev): """P2P group formation with passive scan 5 GHz and p2p_add_cli_chan=1 (reverse; intent 15)""" - dev[0].request("SET p2p_add_cli_chan 1") - dev[1].request("SET p2p_add_cli_chan 1") - [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, - r_dev=dev[1], r_intent=0, - test_data=False) - check_grpform_results(i_res, r_res) - if int(i_res['freq']) > 4000: - raise Exception("Unexpected channel - did not follow world roaming rules") - remove_group(dev[0], dev[1]) + try: + dev[0].request("SET p2p_add_cli_chan 1") + dev[1].request("SET p2p_add_cli_chan 1") + [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15, + r_dev=dev[1], r_intent=0, + test_data=False) + check_grpform_results(i_res, r_res) + if int(i_res['freq']) > 4000: + raise Exception("Unexpected channel - did not follow world roaming rules") + remove_group(dev[0], dev[1]) + finally: + dev[0].request("SET p2p_add_cli_chan 0") + dev[1].request("SET p2p_add_cli_chan 0") def test_grpform_incorrect_pin(dev): """P2P GO Negotiation with incorrect PIN""" diff --git a/tests/hwsim/test_p2p_persistent.py b/tests/hwsim/test_p2p_persistent.py index b9201bc96..fdcb66f3f 100644 --- a/tests/hwsim/test_p2p_persistent.py +++ b/tests/hwsim/test_p2p_persistent.py @@ -465,16 +465,20 @@ def test_persistent_group_already_running(dev): def test_persistent_group_add_cli_chan(dev): """P2P persistent group formation and re-invocation with p2p_add_cli_chan=1""" - dev[0].request("SET p2p_add_cli_chan 1") - dev[1].request("SET p2p_add_cli_chan 1") - form(dev[0], dev[1]) - dev[1].request("BSS_FLUSH 0") - dev[1].scan(freq="2412", only_new=True) - dev[1].scan(freq="2437", only_new=True) - dev[1].scan(freq="2462", only_new=True) - dev[1].request("BSS_FLUSH 0") - invite_from_cli(dev[0], dev[1]) - invite_from_go(dev[0], dev[1]) + try: + dev[0].request("SET p2p_add_cli_chan 1") + dev[1].request("SET p2p_add_cli_chan 1") + form(dev[0], dev[1]) + dev[1].request("BSS_FLUSH 0") + dev[1].scan(freq="2412", only_new=True) + dev[1].scan(freq="2437", only_new=True) + dev[1].scan(freq="2462", only_new=True) + dev[1].request("BSS_FLUSH 0") + invite_from_cli(dev[0], dev[1]) + invite_from_go(dev[0], dev[1]) + finally: + dev[0].request("SET p2p_add_cli_chan 0") + dev[1].request("SET p2p_add_cli_chan 0") def test_persistent_invalid_group_add(dev): """Invalid P2P_GROUP_ADD command""" diff --git a/tests/hwsim/wpasupplicant.py b/tests/hwsim/wpasupplicant.py index 2f8290ecd..3da8a5ceb 100644 --- a/tests/hwsim/wpasupplicant.py +++ b/tests/hwsim/wpasupplicant.py @@ -122,7 +122,6 @@ class WpaSupplicant: if not "OK" in res: logger.info("FLUSH to " + self.ifname + " failed: " + res) self.global_request("REMOVE_NETWORK all") - self.global_request("SET p2p_add_cli_chan 0") self.global_request("SET p2p_pref_chan ") self.global_request("SET p2p_no_group_iface 1") self.global_request("SET p2p_go_intent 7")