tests: Increase P2P SD test coverage

Verify cases both with multiple peers (one of which not advertising any
services) and with multiple SD queries.

Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
This commit is contained in:
Jouni Malinen 2014-02-20 16:17:48 +02:00 committed by Jouni Malinen
parent f667e031c9
commit 66a6331501

View file

@ -29,7 +29,7 @@ def add_extra_services(dev):
for i in range(0, 100):
dev.request("P2P_SERVICE_ADD upnp 10 uuid:" + str(uuid.uuid4()) + "::upnp:rootdevice")
def run_sd(dev, dst, query, exp_query=None, fragment=False):
def run_sd(dev, dst, query, exp_query=None, fragment=False, query2=None):
addr0 = dev[0].p2p_dev_addr()
addr1 = dev[1].p2p_dev_addr()
add_bonjour_services(dev[0])
@ -40,6 +40,8 @@ def run_sd(dev, dst, query, exp_query=None, fragment=False):
dev[1].request("P2P_FLUSH")
dev[1].request("P2P_SERV_DISC_REQ " + dst + " " + query)
if query2:
dev[1].request("P2P_SERV_DISC_REQ " + dst + " " + query2)
if not dev[1].discover_peer(addr0, social=True, force_find=True):
raise Exception("Peer " + addr0 + " not found")
@ -50,14 +52,27 @@ def run_sd(dev, dst, query, exp_query=None, fragment=False):
raise Exception("Unexpected service discovery request source")
if exp_query is None:
exp_query = query
if exp_query not in ev:
if exp_query not in ev and (query2 is None or query2 not in ev):
raise Exception("Unexpected service discovery request contents")
ev = dev[1].wait_event(["P2P-SERV-DISC-RESP"], timeout=10)
if ev is None:
raise Exception("Service discovery timed out")
if addr0 not in ev:
raise Exception("Unexpected service discovery response source")
if query2:
ev_list = []
for i in range(0, 4):
ev = dev[1].wait_event(["P2P-SERV-DISC-RESP"], timeout=10)
if ev is None:
raise Exception("Service discovery timed out")
if addr0 in ev:
ev_list.append(ev)
if len(ev_list) == 2:
break
return ev_list
for i in range(0, 2):
ev = dev[1].wait_event(["P2P-SERV-DISC-RESP"], timeout=10)
if ev is None:
raise Exception("Service discovery timed out")
if addr0 in ev:
break
return ev
def test_p2p_service_discovery(dev):
@ -69,6 +84,35 @@ def test_p2p_service_discovery(dev):
if "496e7465726e6574" not in ev:
raise Exception("Unexpected service discovery response contents (UPnP)")
def test_p2p_service_discovery2(dev):
"""P2P service discovery with one peer having no services"""
dev[2].p2p_listen()
for dst in [ "00:00:00:00:00:00", dev[0].p2p_dev_addr() ]:
ev = run_sd(dev, dst, "02000001")
if "0b5f6166706f766572746370c00c000c01" not in ev:
raise Exception("Unexpected service discovery response contents (Bonjour)")
if "496e7465726e6574" not in ev:
raise Exception("Unexpected service discovery response contents (UPnP)")
def test_p2p_service_discovery_multiple_queries(dev):
"""P2P service discovery with multiple queries"""
for dst in [ "00:00:00:00:00:00", dev[0].p2p_dev_addr() ]:
ev = run_sd(dev, dst, "02000201", query2="02000101")
if "0b5f6166706f766572746370c00c000c01" not in ev[0] + ev[1]:
raise Exception("Unexpected service discovery response contents (Bonjour)")
if "496e7465726e6574" not in ev[0] + ev[1]:
raise Exception("Unexpected service discovery response contents (UPnP)")
def test_p2p_service_discovery_multiple_queries2(dev):
"""P2P service discovery with multiple queries with one peer having no services"""
dev[2].p2p_listen()
for dst in [ "00:00:00:00:00:00", dev[0].p2p_dev_addr() ]:
ev = run_sd(dev, dst, "02000201", query2="02000101")
if "0b5f6166706f766572746370c00c000c01" not in ev[0] + ev[1]:
raise Exception("Unexpected service discovery response contents (Bonjour)")
if "496e7465726e6574" not in ev[0] + ev[1]:
raise Exception("Unexpected service discovery response contents (UPnP)")
def test_p2p_service_discovery_fragmentation(dev):
"""P2P service discovery with fragmentation"""
for dst in [ "00:00:00:00:00:00", dev[0].p2p_dev_addr() ]: