tests: Add test execution mechanism

run-p2p-tests.py can now be used to run all P2P test cases. The
actual test cases are defined in test_p2p_*.py files.

Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2013-03-02 12:22:28 +02:00
parent 731e60f5c5
commit a311c61dd6
5 changed files with 142 additions and 10 deletions

View file

@ -0,0 +1,27 @@
#!/usr/bin/python
#
# hwsim testing utilities
# Copyright (c) 2013, Jouni Malinen <j@w1.fi>
#
# This software may be distributed under the terms of the BSD license.
# See README for more details.
import subprocess
import logging
logger = logging.getLogger(__name__)
def test_connectivity(ifname1, ifname2):
cmd = ["sudo",
"../../mac80211_hwsim/tools/hwsim_test",
ifname1,
ifname2]
try:
s = subprocess.check_output(cmd)
logger.debug(s)
except subprocess.CalledProcessError, e:
print "hwsim failed: " + str(e.returncode)
print e.output
raise
def test_connectivity_p2p(dev1, dev2):
test_connectivity(dev1.ifname, dev2.ifname)

View file

@ -10,19 +10,12 @@ import os
import sys import sys
import time import time
import subprocess import subprocess
import logging import logging
import hwsim_utils
from wpasupplicant import WpaSupplicant from wpasupplicant import WpaSupplicant
def test_connectivity(ifname1, ifname2):
cmd = ["sudo",
"../../mac80211_hwsim/tools/hwsim_test",
ifname1,
ifname2]
subprocess.check_call(cmd)
def main(): def main():
if len(sys.argv) > 1 and sys.argv[1] == '-d': if len(sys.argv) > 1 and sys.argv[1] == '-d':
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
@ -53,7 +46,7 @@ def main():
dev1.dump_monitor() dev1.dump_monitor()
print "Group formed" print "Group formed"
test_connectivity('wlan0', 'wlan1') hwsim_utils.test_connectivity('wlan0', 'wlan1')
dev0.remove_group('wlan0') dev0.remove_group('wlan0')
try: try:

66
tests/hwsim/run-p2p-tests.py Executable file
View file

@ -0,0 +1,66 @@
#!/usr/bin/python
#
# P2P tests
# Copyright (c) 2013, Jouni Malinen <j@w1.fi>
#
# This software may be distributed under the terms of the BSD license.
# See README for more details.
import os
import sys
import time
import logging
from wpasupplicant import WpaSupplicant
import test_p2p_grpform
def main():
if len(sys.argv) > 1 and sys.argv[1] == '-d':
logging.basicConfig(level=logging.DEBUG)
elif len(sys.argv) > 1 and sys.argv[1] == '-q':
logging.basicConfig(level=logging.WARNING)
else:
logging.basicConfig(level=logging.INFO)
dev0 = WpaSupplicant('wlan0')
dev1 = WpaSupplicant('wlan1')
dev2 = WpaSupplicant('wlan2')
dev = [ dev0, dev1, dev2 ]
for d in dev:
if not d.ping():
print d.ifname + ": No response from wpa_supplicant"
return
d.reset()
print "DEV: " + d.ifname + ": " + d.p2p_dev_addr()
tests = []
test_p2p_grpform.add_tests(tests)
passed = []
failed = []
for t in tests:
print "START " + t.__name__
for d in dev:
d.request("NOTE TEST-START " + t.__name__)
try:
t(dev)
passed.append(t.__name__)
print "PASS " + t.__name__
except Exception, e:
print e
failed.append(t.__name__)
print "FAIL " + t.__name__
for d in dev:
d.request("NOTE TEST-STOP " + t.__name__)
print "passed tests: " + str(passed)
print "failed tests: " + str(failed)
if len(failed):
sys.exit(1)
if __name__ == "__main__":
main()

View file

@ -0,0 +1,44 @@
#!/usr/bin/python
#
# P2P group formation test cases
# Copyright (c) 2013, Jouni Malinen <j@w1.fi>
#
# This software may be distributed under the terms of the BSD license.
# See README for more details.
import logging
logger = logging.getLogger(__name__)
import hwsim_utils
def go_neg_pin_authorized(i_dev, r_dev, i_intent=7, r_intent=7):
r_dev.p2p_listen()
i_dev.p2p_listen()
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)
r_dev.dump_monitor()
i_dev.dump_monitor()
logger.info("Group formed")
hwsim_utils.test_connectivity_p2p(r_dev, i_dev)
def test_grpform(dev):
go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=0)
dev[0].remove_group()
try:
dev[1].remove_group()
except:
pass
def test_grpform2(dev):
go_neg_pin_authorized(i_dev=dev[0], i_intent=0, r_dev=dev[1], r_intent=15)
dev[0].remove_group()
try:
dev[1].remove_group()
except:
pass
def add_tests(tests):
tests.append(test_grpform)
tests.append(test_grpform2)

View file

@ -121,6 +121,8 @@ class WpaSupplicant:
ev = self.mon.recv() ev = self.mon.recv()
logger.debug(self.ifname + ": " + ev) logger.debug(self.ifname + ": " + ev)
def remove_group(self, ifname): def remove_group(self, ifname=None):
if ifname is None:
ifname = self.ifname
if "OK" not in self.request("P2P_GROUP_REMOVE " + ifname): if "OK" not in self.request("P2P_GROUP_REMOVE " + ifname):
raise Exception("Group could not be removed") raise Exception("Group could not be removed")