diff mbox

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

Message ID 1455711269-12929-24-git-send-email-janusz.dziedzic@tieto.com
State Changes Requested
Headers show

Commit Message

Janusz.Dziedzic@tieto.com Feb. 17, 2016, 12:14 p.m. UTC
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@tieto.com>
---
 tests/remote/run-tests.py | 160 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 160 insertions(+)
 create mode 100755 tests/remote/run-tests.py

Comments

Jouni Malinen Feb. 20, 2016, 3:37 p.m. UTC | #1
On Wed, Feb 17, 2016 at 01:14:26PM +0100, Janusz Dziedzic wrote:
> 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

What is the purpose of adding a separate directory for these instead of
using tests/hwsim? I've always assumed that it would be possible to
eventually share many of the test cases in tests/hwsim/test_*.py for
both local hwsim and remote cases.
 
> diff --git a/tests/remote/run-tests.py 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.

Please add a copyright statement in addition to the license terms into
new files.

> +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"}]

This type of configuration should be read from a configuration file so
that there is no need to modify files that are checked into git to match
the local network setup.
Janusz.Dziedzic@tieto.com Feb. 21, 2016, 12:58 p.m. UTC | #2
On 20 February 2016 at 16:37, Jouni Malinen <j@w1.fi> wrote:
> On Wed, Feb 17, 2016 at 01:14:26PM +0100, Janusz Dziedzic wrote:
>> 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
>
> What is the purpose of adding a separate directory for these instead of
> using tests/hwsim? I've always assumed that it would be possible to
> eventually share many of the test cases in tests/hwsim/test_*.py for
> both local hwsim and remote cases.
>
That was my first idea to use same test cases for both hwsim and
remote implementation.
This could be possible in case test cases will use only devs, apdevs
params, but most of
them don't work such way:
- they are using a lot of global functionality that will work only
  with hwsim driver (hwsim_utils, subprocess, ).
- TP tests, WMM tests seems useless for hwsim driver
-  I also move wpa_suplicant/hostapd startup/termination to the test
cases, while
   we don't know what kind of hw requirement will be needed
- current devs params mean wpasupplicant is already run and ready to
handle ctrl event
- Also added some kind of reference device table (that we will know
works quite good)
  and DUTs - with hwsim params we don't split this
- WpaSupplicant/Hostapd constructors are called from test cases with
fixed params
   eg. global_iface='/tmp/wpas-wlan5'

I will check this once again to see if we can reuse hwsim test cases
in remote configuration.
Thanks for review.

BR
Janusz

>> diff --git a/tests/remote/run-tests.py 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.
>
> Please add a copyright statement in addition to the license terms into
> new files.
>
>> +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"}]
>
> This type of configuration should be read from a configuration file so
> that there is no need to modify files that are checked into git to match
> the local network setup.
>
> --
> Jouni Malinen                                            PGP id EFC895FA
diff mbox

Patch

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