From 5743006d36740cdb44a90442244af1df80ebd711 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sun, 17 Mar 2013 10:58:48 +0200 Subject: [PATCH] tests: Add P2P device discovery and provision discovery test case Signed-hostap: Jouni Malinen --- tests/hwsim/test_p2p_discovery.py | 75 +++++++++++++++++++++++++++++++ tests/hwsim/wpasupplicant.py | 3 ++ 2 files changed, 78 insertions(+) create mode 100644 tests/hwsim/test_p2p_discovery.py diff --git a/tests/hwsim/test_p2p_discovery.py b/tests/hwsim/test_p2p_discovery.py new file mode 100644 index 000000000..44f8aa37e --- /dev/null +++ b/tests/hwsim/test_p2p_discovery.py @@ -0,0 +1,75 @@ +#!/usr/bin/python +# +# P2P device discovery test cases +# Copyright (c) 2013, Jouni Malinen +# +# This software may be distributed under the terms of the BSD license. +# See README for more details. + +import logging +logger = logging.getLogger(__name__) + +def test_discovery(dev): + addr0 = dev[0].p2p_dev_addr() + addr1 = dev[1].p2p_dev_addr() + logger.info("Start device discovery") + dev[0].p2p_find() + dev[1].p2p_find() + ev0 = dev[0].wait_event(["P2P-DEVICE-FOUND"], timeout=15) + if ev0 is None: + raise Exception("Device discovery timed out") + ev1 = dev[1].wait_event(["P2P-DEVICE-FOUND"], timeout=15) + if ev1 is None: + raise Exception("Device discovery timed out") + dev[0].dump_monitor() + dev[1].dump_monitor() + if addr1 not in ev0: + raise Exception("Dev1 not found properly") + if addr0 not in ev1: + raise Exception("Dev0 not found properly") + + logger.info("Test provision discovery for display") + dev[0].request("P2P_PROV_DISC " + addr1 + " display") + ev1 = dev[1].wait_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=15) + if ev1 is None: + raise Exception("Provision discovery timed out") + if addr0 not in ev1: + raise Exception("Dev0 not in provision discovery event") + ev0 = dev[0].wait_event(["P2P-PROV-DISC-ENTER-PIN"], timeout=15) + if ev0 is None: + raise Exception("Provision discovery timed out") + if addr1 not in ev0: + raise Exception("Dev1 not in provision discovery event") + + logger.info("Test provision discovery for keypad") + dev[0].request("P2P_PROV_DISC " + addr1 + " keypad") + ev1 = dev[1].wait_event(["P2P-PROV-DISC-ENTER-PIN"], timeout=15) + if ev1 is None: + raise Exception("Provision discovery timed out") + if addr0 not in ev1: + raise Exception("Dev0 not in provision discovery event") + ev0 = dev[0].wait_event(["P2P-PROV-DISC-SHOW-PIN"], timeout=15) + if ev0 is None: + raise Exception("Provision discovery timed out") + if addr1 not in ev0: + raise Exception("Dev1 not in provision discovery event") + + logger.info("Test provision discovery for push button") + dev[0].request("P2P_PROV_DISC " + addr1 + " pbc") + ev1 = dev[1].wait_event(["P2P-PROV-DISC-PBC-REQ"], timeout=15) + if ev1 is None: + raise Exception("Provision discovery timed out") + if addr0 not in ev1: + raise Exception("Dev0 not in provision discovery event") + ev0 = dev[0].wait_event(["P2P-PROV-DISC-PBC-RESP"], timeout=15) + if ev0 is None: + raise Exception("Provision discovery timed out") + if addr1 not in ev0: + raise Exception("Dev1 not in provision discovery event") + + dev[0].p2p_stop_find + dev[1].p2p_stop_find + + +def add_tests(tests): + tests.append(test_discovery) diff --git a/tests/hwsim/wpasupplicant.py b/tests/hwsim/wpasupplicant.py index 5ca2cee37..8803dd288 100644 --- a/tests/hwsim/wpasupplicant.py +++ b/tests/hwsim/wpasupplicant.py @@ -101,6 +101,9 @@ class WpaSupplicant: return self.request("P2P_FIND type=social") return self.request("P2P_FIND") + def p2p_stop_find(self): + return self.request("P2P_STOP_FIND") + def wps_read_pin(self): #TODO: make this random self.pin = "12345670"