Browse Source

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>
Jouni Malinen 12 years ago
parent
commit
a311c61dd6

+ 27 - 0
tests/hwsim/hwsim_utils.py

@@ -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)

+ 2 - 9
tests/hwsim/p2p-group-formation.py

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

+ 66 - 0
tests/hwsim/run-p2p-tests.py

@@ -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()

+ 44 - 0
tests/hwsim/test_p2p_grpform.py

@@ -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)

+ 3 - 1
tests/hwsim/wpasupplicant.py

@@ -121,6 +121,8 @@ class WpaSupplicant:
             ev = self.mon.recv()
             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):
             raise Exception("Group could not be removed")