[PATCH v2 22/22] tests: add remote test example file

Janusz Dziedzic janusz.dziedzic at tieto.com
Sun Feb 7 05:07:55 PST 2016


This file contain simple example how to
use and tests remote clients.

1) .config file should include CTRL UDP configuration
   eg. udp-remote
2) you should be able to login/execute command to
   remote hosts using authorized-keys.
   eg. ssh root at hostname id

In this example we simply setup AP (open) and next
connect to this ap, next connectivity (ping) is
validated.

eg. test for hwsim
modprobe mac80211_hwsim
./remote_test_example.py

Signed-off-by: Janusz Dziedzic <janusz.dziedzic at tieto.com>
---
 tests/hwsim/remote_test_example.py | 134 +++++++++++++++++++++++++++++++++++++
 1 file changed, 134 insertions(+)
 create mode 100755 tests/hwsim/remote_test_example.py

diff --git a/tests/hwsim/remote_test_example.py b/tests/hwsim/remote_test_example.py
new file mode 100755
index 0000000..3e92fe3
--- /dev/null
+++ b/tests/hwsim/remote_test_example.py
@@ -0,0 +1,134 @@
+#!/usr/bin/python
+#
+# This software may be distributed under the terms of the BSD license.
+# See README for more details.
+
+import os
+import sys
+import time
+
+scriptsdir = os.path.dirname(os.path.realpath(sys.modules[__name__].__file__))
+sys.path.append(os.path.join(scriptsdir, '..', '..', 'wpaspy'))
+
+import wpaspy
+from wpasupplicant import WpaSupplicant
+import hostapd
+
+# This is some kind of utils
+def get_ping_packet_loss(ping_res):
+    loss_line = ""
+    lines = ping_res.splitlines()
+    for line in lines:
+        if line.find("packet loss") != -1:
+            loss_line = line
+            break;
+
+    if loss_line == "":
+        return "100%"
+
+    sections = loss_line.split(",")
+
+    for section in sections:
+        if section.find("packet loss") != -1:
+            words = section.split()
+            return words[0]
+
+    return "100%"
+
+def get_ipv6(client, ifname=None):
+    res = -1
+    if ifname is None:
+        ifname = client.ifname
+    status, buf = client.execute("ifconfig " + ifname)
+    lines = buf.splitlines()
+
+    for line in lines:
+        res = line.find("Scope:Link")
+        if res != -1:
+            break
+
+    if res != -1:
+        words = line.split()
+        if words[0] == "inet6" and words[1] == "addr:":
+            addr_mask = words[2]
+            addr = addr_mask.split("/")
+            return addr[0]
+
+    return "unknown"
+
+def check_connectivity(a, b):
+    ipv6_addr_a = get_ipv6(a.host)
+    ipv6_addr_b = get_ipv6(b.host)
+
+    time.sleep(1)
+
+    status, buf = a.host.execute("ping6 -w 5 -I " + a.ifname + " " + ipv6_addr_b)
+    if status != 0:
+        print buf
+        raise Exception("ping " + a.ifname + " >> " + b.ifname)
+
+    a_b = get_ping_packet_loss(buf)
+
+    status, buf = b.host.execute("ping6 -w 5 -I " + b.ifname + " " + ipv6_addr_a)
+    if status != 0:
+        print buf
+        raise Exception("ping " + b.ifname + " >> " + a.ifname)
+
+    b_a = get_ping_packet_loss(buf)
+
+    print "ping6 " + a.ifname + " >> " + b.ifname + "packet loss: " + a_b
+    print "ping6 " + b.ifname + " >> " + a.ifname + "packet loss: " + b_a
+
+# Simple example of test case
+def test_ap_open(dev, apdev):
+    """AP with open mode (no security) configuration"""
+    hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" }, hostname=apdev[0]['hostname'], port=apdev[0]['port'])
+    dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
+                   bg_scan_period="0")
+    ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
+    if ev is None:
+        raise Exception("No connection event received from hostapd")
+
+    check_connectivity(hapd, dev[0])
+
+    dev[0].request("DISCONNECT")
+    ev = hapd.wait_event([ "AP-STA-DISCONNECTED" ], timeout=5)
+    if ev is None:
+        raise Exception("No disconnection event received from hostapd")
+
+def main():
+    setup_hw = "./tests/setup_hw.sh"
+    hostapd = "./tests/hostapd"
+    wpa_supplicant = "./tests/wpa_supplicant"
+
+    wpaspy.debug = True
+
+    sta = wpaspy.Host(host = "localhost", ifname="wlan0", port="9877")
+    ap = wpaspy.Host(host = "localhost", ifname="wlan1", port="8877")
+
+    # setup hw, modprobe ...
+    sta.execute(setup_hw + " -I " + sta.ifname)
+    ap.execute(setup_hw + " -I " + ap.ifname)
+
+    # run hostapd/wpa_supplicant
+    status, buf = sta.execute(wpa_supplicant + " -B -g udp:" + sta.port)
+    if status != 0:
+        raise Exception("Could not run wpa_supplicant");
+
+    status, buf = ap.execute(hostapd + " -B -ddt -g udp:" + ap.port)
+    if status != 0:
+        raise Exception("Could not run hostapd")
+
+
+    client = WpaSupplicant(hostname=sta.host, global_iface="udp", global_port=sta.port)
+    client.interface_add(sta.ifname)
+
+    dev = [client]
+    apdev = [ ]
+    apdev.append({"ifname": ap.ifname, "hostname": ap.host, "port": ap.port})
+
+    # now run test cases
+    test_ap_open(dev, apdev)
+
+if __name__ == "__main__":
+        main()
-- 
1.9.1




More information about the Hostap mailing list