[PATCH v3 23/26] tests: add remote dir and run-tests.py

Janusz Dziedzic janusz.dziedzic at tieto.com
Wed Feb 17 04:14:26 PST 2016


Adde remote dir and move development to this
directory.

./run-test.py print help with available DUTs and TESTs
./run-test.py <DUT> all - will run all tests
./run-test.py <DUT> tests_list - will run only specyfic test cases

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

diff --git a/tests/remote/run-tests.py b/tests/remote/run-tests.py
new file mode 100755
index 0000000..2a3649b
--- /dev/null
+++ b/tests/remote/run-tests.py
@@ -0,0 +1,160 @@
+#!/usr/bin/python
+#
+# This software may be distributed under the terms of the BSD license.
+# See README for more details.
+
+import os
+import re
+import sys
+import time
+import traceback
+
+import logging
+logger = logging.getLogger()
+
+scriptsdir = os.path.dirname(os.path.realpath(sys.modules[__name__].__file__))
+sys.path.append(os.path.join(scriptsdir, '..', '..', 'wpaspy'))
+sys.path.append(os.path.join(scriptsdir, '..', 'hwsim'))
+
+import wpaspy
+
+#
+# Environtment configuration
+#
+setup_params = {"setup_hw" : "./tests/setup_hw.sh",
+                "hostapd" : "./tests/hostapd",
+                "wpa_supplicant" : "./tests/wpa_supplicant",
+                "iperf" : "iperf3",
+                "country" : "PL",
+                "log_dir" : "/tmp/"}
+
+devices = [{"hostname": "192.168.254.58", "ifname" : "wlan0", "port": "9877", "name" : "t2-ath9k", "flags" : "AP_HT40 STA_HT40"},
+           {"hostname": "192.168.254.58", "ifname" : "wlan1", "port": "9877", "name" : "t2-ath10k", "flags" : "AP_VHT80"},
+           {"hostname": "192.168.254.58", "ifname" : "wlan3", "port": "9877", "name" : "t2-intel7260", "flags" : "STA_VHT80"}]
+
+duts = [{"hostname": "192.168.254.50", "ifname" : "wlan0", "port": "9877", "name" : "t1-ath9k-dut"},
+        {"hostname": "192.168.254.50", "ifname" : "wlan1", "port": "9877", "name" : "t1-ath10k-dut"},
+        {"hostname": "192.168.254.58", "ifname" : "wlan1", "port": "8878", "name" : "t2-ath10k-dut"}]
+
+#
+# HWSIM
+#devices = [{"hostname": "localhost", "ifname": "wlan0", "port": "9878", "name": "hwsim0"}]
+#duts = [{"hostname": "localhost", "ifname": "wlan1", "port": "8878", "name": "hwsim1"}]
+#
+
+def main(dut=None, ref=None, requested_tests = ["help"]):
+    # put logs in log_dir
+    if os.path.exists("./logs/current"):
+        os.unlink("./logs/current")
+    log_dir = "./logs/" + time.strftime("%Y_%m_%d_%H_%M_%S")
+    if not os.path.exists(log_dir):
+        os.makedirs(log_dir)
+    os.symlink(os.path.join("../", log_dir), "./logs/current")
+
+    setup_params['local_log_dir'] = log_dir
+
+    # configure logger
+    logger.setLevel(logging.DEBUG)
+
+    stdout_handler = logging.StreamHandler()
+    stdout_handler.setLevel(logging.WARNING)
+    logger.addHandler(stdout_handler)
+
+    formatter = logging.Formatter('%(asctime)s - %(message)s')
+    file_name = os.path.join(log_dir, 'run-tests.log')
+    log_handler = logging.FileHandler(file_name)
+    log_handler.setLevel(logging.DEBUG)
+    log_handler.setFormatter(formatter)
+    logger.addHandler(log_handler)
+
+    # import available tests
+    all_tests = 0
+    tests = []
+    failed = []
+    test_modules = []
+    files = os.listdir(scriptsdir)
+    for t in files:
+        m = re.match(r'(test_.*)\.py$', t)
+        if m:
+            mod = __import__(m.group(1))
+            test_modules.append(mod.__name__.replace('test_', '', 1))
+            for key,val in mod.__dict__.iteritems():
+                if key.startswith("test_"):
+                    tests.append(val)
+                    all_tests = all_tests + 1
+    test_names = list(set([t.__name__.replace('test_', '', 1) for t in tests]))
+
+    # sort the list
+    test_names.sort()
+    tests.sort()
+
+    # print help
+    if requested_tests[0] == "help":
+        print "Usage:"
+        print "\t./run-tests.py <dut_name> all"
+        print "\t./run-tests.py <dut_name> <tests_list>"
+        print "\nAvailable DUTs:"
+        for dut in duts:
+            print "\t", dut['name']
+        print "\nAvailable tests:"
+        for test in test_names:
+            print "\t", test
+        return
+
+    # setup test we should run
+    tests_to_run = []
+    if requested_tests[0] == "all":
+        tests_to_run = tests
+    else:
+        all_tests = 0
+        for test in requested_tests:
+            t = None
+            for tt in tests:
+                name = tt.__name__.replace('test_', '', 1)
+                if name == test:
+                    t = tt
+                    break
+            if not t:
+                logger_warning("test case: " + test + " NOT-FOUND")
+                continue
+            tests_to_run.append(t)
+            all_tests = all_tests + 1
+
+
+    # now run test cases
+    logger.warning("TC - using DUT: " + str(dut))
+    test_no = 1
+    for test in tests_to_run:
+        try:
+            logger.warning("TC - " + test.__doc__ + " (" + str(test_no) + "/" + str(all_tests) + ")")
+            setup_params['tc_name'] = test.__name__.replace('test_', '', 1)
+            res, append = test(devices, duts, setup_params, ref, dut)
+            if res == 0:
+                logger.warning("TC - PASS (" + append + ")")
+            else:
+                logger.warning("TC - FAILED")
+                failed.append(test.__name__.replace('test_', '', 1))
+        except KeyboardInterrupt:
+            raise
+        except:
+            logger.warning("TC - FAILED")
+            logger.info(traceback.format_exc())
+            failed.append(test.__name__.replace('test_', '', 1))
+        test_no = test_no + 1
+
+    if len(failed) > 0:
+        logger.warning("Failed test cases:")
+        for test in failed:
+            logger.warning("\t" + test)
+
+
+if __name__ == "__main__":
+    if len(sys.argv) > 2:
+        tests = []
+        sys.argv.pop(0)
+        dut = sys.argv.pop(0)
+        for arg in sys.argv:
+            tests.append(arg)
+        main(dut = dut, requested_tests = tests)
+    else:
+        main()
-- 
1.9.1




More information about the Hostap mailing list