From c68f9a61c653e2d5082f8eb89268920188f717d2 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sat, 9 Mar 2013 13:36:35 +0200 Subject: [PATCH] tests: Report group formation results as a dict Signed-hostap: Jouni Malinen --- tests/hwsim/test_p2p_grpform.py | 5 +++- tests/hwsim/wpasupplicant.py | 43 +++++++++++++++++++++++++++------ 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/tests/hwsim/test_p2p_grpform.py b/tests/hwsim/test_p2p_grpform.py index 30c415a61..65859a5cc 100644 --- a/tests/hwsim/test_p2p_grpform.py +++ b/tests/hwsim/test_p2p_grpform.py @@ -17,7 +17,10 @@ def go_neg_pin_authorized(i_dev, r_dev, i_intent=7, r_intent=7): pin = r_dev.wps_read_pin() logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname) r_dev.p2p_go_neg_auth(i_dev.p2p_dev_addr(), pin, "display") - i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), pin, "enter", timeout=15) + i_res = i_dev.p2p_go_neg_init(r_dev.p2p_dev_addr(), pin, "enter", timeout=15) + r_res = r_dev.p2p_go_neg_auth_result() + logger.debug("i_res: " + str(i_res)) + logger.debug("r_res: " + str(r_res)) r_dev.dump_monitor() i_dev.dump_monitor() logger.info("Group formed") diff --git a/tests/hwsim/wpasupplicant.py b/tests/hwsim/wpasupplicant.py index e3ccba60c..51f9907b6 100644 --- a/tests/hwsim/wpasupplicant.py +++ b/tests/hwsim/wpasupplicant.py @@ -9,6 +9,7 @@ import os import time import logging +import re import wpaspy logger = logging.getLogger(__name__) @@ -81,6 +82,26 @@ class WpaSupplicant: return True return False + def group_form_result(self, ev): + exp = r'<.>(P2P-GROUP-STARTED) ([^ ]*) ([^ ]*) ssid="(.*)" freq=([0-9]*) ((?:psk=.*)|(?:passphrase=".*")) go_dev_addr=([0-9a-f:]*)' + s = re.split(exp, ev) + if len(s) < 8: + raise Exception("Could not parse P2P-GROUP-STARTED") + res = {} + res['result'] = 'success' + res['ifname'] = s[2] + res['role'] = s[3] + res['ssid'] = s[4] + res['freq'] = s[5] + p = re.match(r'psk=([0-9a-f]*)', s[6]) + if p: + res['psk'] = p.group(1) + p = re.match(r'passphrase="(.*)"', s[6]) + if p: + res['passphrase'] = p.group(1) + res['go_dev_addr'] = s[7] + return res + def p2p_go_neg_auth(self, peer, pin, method): if not self.discover_peer(peer): raise Exception("Peer " + peer + " not found") @@ -90,6 +111,13 @@ class WpaSupplicant: return None raise Exception("P2P_CONNECT (auth) failed") + def p2p_go_neg_auth_result(self, timeout=1): + ev = self.wait_event("P2P-GROUP-STARTED", timeout); + if ev is None: + raise Exception("Group formation timed out") + self.dump_monitor() + return self.group_form_result(ev) + def p2p_go_neg_init(self, peer, pin, method, timeout=0): if not self.discover_peer(peer): raise Exception("Peer " + peer + " not found") @@ -99,22 +127,23 @@ class WpaSupplicant: if timeout == 0: self.dump_monitor() return None - if self.wait_event("P2P-GROUP-STARTED", timeout): - self.dump_monitor() - return None - raise Exception("Group formation timed out") + ev = self.wait_event("P2P-GROUP-STARTED", timeout) + if ev is None: + raise Exception("Group formation timed out") + self.dump_monitor() + return self.group_form_result(ev) raise Exception("P2P_CONNECT failed") def wait_event(self, event, timeout): count = 0 while count < timeout * 2: count = count + 1 - time.sleep(0.5) + time.sleep(0.1) while self.mon.pending(): ev = self.mon.recv() if event in ev: - return True - return False + return ev + return None def dump_monitor(self): while self.mon.pending():