From c9aa430896d72f203bfa27957911a14e81d7fe19 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Thu, 31 Oct 2013 12:46:42 +0200 Subject: [PATCH] tests: Split run-tests.py logger info into per test case files The run-tests.py -l argument does not take an argument value anymore. Instead, debug output is directed to a separate file .log for each test case. Signed-hostap: Jouni Malinen --- tests/hwsim/README | 2 +- tests/hwsim/hostapd.py | 2 +- tests/hwsim/hwsim_utils.py | 2 +- tests/hwsim/run-all.sh | 2 +- tests/hwsim/run-tests.py | 33 +++++++++++++++++++++++++----- tests/hwsim/test_ap_dynamic.py | 2 +- tests/hwsim/test_ap_eap.py | 2 +- tests/hwsim/test_ap_ft.py | 2 +- tests/hwsim/test_ap_hs20.py | 2 +- tests/hwsim/test_ap_pmf.py | 2 +- tests/hwsim/test_ap_roam.py | 2 +- tests/hwsim/test_ap_tdls.py | 2 +- tests/hwsim/test_ap_wps.py | 2 +- tests/hwsim/test_gas.py | 2 +- tests/hwsim/test_ibss.py | 2 +- tests/hwsim/test_nfc_wps.py | 2 +- tests/hwsim/test_p2p_autogo.py | 2 +- tests/hwsim/test_p2p_discovery.py | 2 +- tests/hwsim/test_p2p_grpform.py | 2 +- tests/hwsim/test_p2p_invitation.py | 2 +- tests/hwsim/test_p2p_persistent.py | 2 +- tests/hwsim/test_p2p_service.py | 2 +- tests/hwsim/wlantest.py | 2 +- tests/hwsim/wpasupplicant.py | 2 +- 24 files changed, 51 insertions(+), 28 deletions(-) diff --git a/tests/hwsim/README b/tests/hwsim/README index dd4dcae17..42884831f 100644 --- a/tests/hwsim/README +++ b/tests/hwsim/README @@ -141,7 +141,7 @@ timestamp and a postfix to identify the specific log: - hwsim0 = wlantest debug log - hwsim0.pcapng = capture with all frames exchanged during the tests - tcpdump = tcpdump output -- run = debug prints from the test scripts +- *.log = debug prints from the test scripts - trace.dat = Linux tracing record (if enabled) - hlr_auc_gw - hlr_auc_gw (EAP-SIM/AKA/AKA' authentication) log - auth_serv - hostapd as RADIUS authentication server log diff --git a/tests/hwsim/hostapd.py b/tests/hwsim/hostapd.py index 7d6e7b143..161a34c36 100644 --- a/tests/hwsim/hostapd.py +++ b/tests/hwsim/hostapd.py @@ -11,7 +11,7 @@ import time import logging import wpaspy -logger = logging.getLogger(__name__) +logger = logging.getLogger() hapd_ctrl = '/var/run/hostapd' hapd_global = '/var/run/hostapd-global' diff --git a/tests/hwsim/hwsim_utils.py b/tests/hwsim/hwsim_utils.py index 365fbb257..42856fe9e 100644 --- a/tests/hwsim/hwsim_utils.py +++ b/tests/hwsim/hwsim_utils.py @@ -9,7 +9,7 @@ import os import subprocess import logging -logger = logging.getLogger(__name__) +logger = logging.getLogger() def test_connectivity(ifname1, ifname2): if os.path.isfile("../../mac80211_hwsim/tools/hwsim_test"): diff --git a/tests/hwsim/run-all.sh b/tests/hwsim/run-all.sh index 126380e62..9a33c3252 100755 --- a/tests/hwsim/run-all.sh +++ b/tests/hwsim/run-all.sh @@ -63,7 +63,7 @@ if ! ./start.sh $CONCURRENT $VALGRIND $TRACE; then exit 1 fi -./run-tests.py -D --logdir "$LOGDIR" $TRACE_ARGS -l run $DB -e failed -r results.txt $CONCURRENT_TESTS $@ || errors=1 +./run-tests.py -D --logdir "$LOGDIR" $TRACE_ARGS -l $DB -e failed -r results.txt $CONCURRENT_TESTS $@ || errors=1 ./stop-wifi.sh diff --git a/tests/hwsim/run-tests.py b/tests/hwsim/run-tests.py index 9908dc569..536456eb5 100755 --- a/tests/hwsim/run-tests.py +++ b/tests/hwsim/run-tests.py @@ -15,7 +15,7 @@ import argparse import subprocess import logging -logger = logging.getLogger(__name__) +logger = logging.getLogger() sys.path.append('../../wpaspy') @@ -101,8 +101,8 @@ def main(): help="verbose debug output") group.add_argument('-q', const=logging.WARNING, action='store_const', dest='loglevel', help="be quiet") - group.add_argument('-l', metavar='', dest='logfile', - help='debug log filename (in log directory)') + group.add_argument('-l', action='store_true', dest='logfile', + help='store debug log to a file (in log directory)') parser.add_argument('-e', metavar="", dest='errorfile', nargs='?', const="failed", @@ -142,11 +142,17 @@ def main(): sys.exit(2) if args.logfile: - logging.basicConfig(filename=os.path.join(args.logdir, args.logfile), - level=logging.DEBUG) + logger.setLevel(logging.DEBUG) + file_name = os.path.join(args.logdir, 'run-tests.log') + log_handler = logging.FileHandler(file_name) + fmt = "%(asctime)s %(levelname)s %(message)s" + log_formatter = logging.Formatter(fmt) + log_handler.setFormatter(log_formatter) + logger.addHandler(log_handler) log_to_file = True else: logging.basicConfig(level=args.loglevel) + log_handler = None log_to_file = False if args.loglevel == logging.WARNING: print_res = True @@ -216,6 +222,15 @@ def main(): if args.testmodules: if not t.__module__.replace('test_', '', 1) in args.testmodules: continue + + if log_handler: + log_handler.stream.close() + logger.removeHandler(log_handler) + file_name = os.path.join(args.logdir, name + '.log') + log_handler = logging.FileHandler(file_name) + log_handler.setFormatter(log_formatter) + logger.addHandler(log_handler) + with DataCollector(args.logdir, name, args.tracing, args.dmesg): logger.info("START " + name) if log_to_file: @@ -282,6 +297,14 @@ def main(): logger.info(e) reset_devs(dev, apdev) + if log_handler: + log_handler.stream.close() + logger.removeHandler(log_handler) + file_name = os.path.join(args.logdir, 'run-tests.log') + log_handler = logging.FileHandler(file_name) + log_handler.setFormatter(log_formatter) + logger.addHandler(log_handler) + if conn: conn.close() diff --git a/tests/hwsim/test_ap_dynamic.py b/tests/hwsim/test_ap_dynamic.py index 49b88ca8f..515aae05c 100644 --- a/tests/hwsim/test_ap_dynamic.py +++ b/tests/hwsim/test_ap_dynamic.py @@ -9,7 +9,7 @@ import time import subprocess import logging -logger = logging.getLogger(__name__) +logger = logging.getLogger() import hwsim_utils import hostapd diff --git a/tests/hwsim/test_ap_eap.py b/tests/hwsim/test_ap_eap.py index cf6c982f5..3ada01214 100644 --- a/tests/hwsim/test_ap_eap.py +++ b/tests/hwsim/test_ap_eap.py @@ -9,7 +9,7 @@ import time import subprocess import logging -logger = logging.getLogger(__name__) +logger = logging.getLogger() import os.path import hwsim_utils diff --git a/tests/hwsim/test_ap_ft.py b/tests/hwsim/test_ap_ft.py index c206bcf10..c78ad3515 100644 --- a/tests/hwsim/test_ap_ft.py +++ b/tests/hwsim/test_ap_ft.py @@ -9,7 +9,7 @@ import time import subprocess import logging -logger = logging.getLogger(__name__) +logger = logging.getLogger() import hwsim_utils import hostapd diff --git a/tests/hwsim/test_ap_hs20.py b/tests/hwsim/test_ap_hs20.py index 60ec1a719..cb9ee1fe2 100644 --- a/tests/hwsim/test_ap_hs20.py +++ b/tests/hwsim/test_ap_hs20.py @@ -9,7 +9,7 @@ import time import subprocess import logging -logger = logging.getLogger(__name__) +logger = logging.getLogger() import os.path import subprocess diff --git a/tests/hwsim/test_ap_pmf.py b/tests/hwsim/test_ap_pmf.py index 33e023b57..4645d445d 100644 --- a/tests/hwsim/test_ap_pmf.py +++ b/tests/hwsim/test_ap_pmf.py @@ -9,7 +9,7 @@ import time import subprocess import logging -logger = logging.getLogger(__name__) +logger = logging.getLogger() import hwsim_utils import hostapd diff --git a/tests/hwsim/test_ap_roam.py b/tests/hwsim/test_ap_roam.py index 3a966f7fc..a9d671ccd 100644 --- a/tests/hwsim/test_ap_roam.py +++ b/tests/hwsim/test_ap_roam.py @@ -9,7 +9,7 @@ import time import subprocess import logging -logger = logging.getLogger(__name__) +logger = logging.getLogger() import hwsim_utils import hostapd diff --git a/tests/hwsim/test_ap_tdls.py b/tests/hwsim/test_ap_tdls.py index b906a2be9..5c2b2efad 100644 --- a/tests/hwsim/test_ap_tdls.py +++ b/tests/hwsim/test_ap_tdls.py @@ -8,7 +8,7 @@ import time import logging -logger = logging.getLogger(__name__) +logger = logging.getLogger() import hwsim_utils from hostapd import HostapdGlobal diff --git a/tests/hwsim/test_ap_wps.py b/tests/hwsim/test_ap_wps.py index 0587e4c15..486dd206e 100644 --- a/tests/hwsim/test_ap_wps.py +++ b/tests/hwsim/test_ap_wps.py @@ -9,7 +9,7 @@ import time import subprocess import logging -logger = logging.getLogger(__name__) +logger = logging.getLogger() import hwsim_utils import hostapd diff --git a/tests/hwsim/test_gas.py b/tests/hwsim/test_gas.py index 5078fe193..33ee72122 100644 --- a/tests/hwsim/test_gas.py +++ b/tests/hwsim/test_gas.py @@ -8,7 +8,7 @@ import time import logging -logger = logging.getLogger(__name__) +logger = logging.getLogger() import re import hostapd diff --git a/tests/hwsim/test_ibss.py b/tests/hwsim/test_ibss.py index c0f614e59..5d9e20ad7 100644 --- a/tests/hwsim/test_ibss.py +++ b/tests/hwsim/test_ibss.py @@ -7,7 +7,7 @@ # See README for more details. import logging -logger = logging.getLogger(__name__) +logger = logging.getLogger() import time import re diff --git a/tests/hwsim/test_nfc_wps.py b/tests/hwsim/test_nfc_wps.py index 275212b24..eab6d1a9d 100644 --- a/tests/hwsim/test_nfc_wps.py +++ b/tests/hwsim/test_nfc_wps.py @@ -9,7 +9,7 @@ import time import subprocess import logging -logger = logging.getLogger(__name__) +logger = logging.getLogger() import hwsim_utils import hostapd diff --git a/tests/hwsim/test_p2p_autogo.py b/tests/hwsim/test_p2p_autogo.py index 507e74e6d..d90797b0b 100644 --- a/tests/hwsim/test_p2p_autogo.py +++ b/tests/hwsim/test_p2p_autogo.py @@ -9,7 +9,7 @@ import time import subprocess import logging -logger = logging.getLogger(__name__) +logger = logging.getLogger() import hwsim_utils from wlantest import Wlantest diff --git a/tests/hwsim/test_p2p_discovery.py b/tests/hwsim/test_p2p_discovery.py index f1029c82c..84bd36ed5 100644 --- a/tests/hwsim/test_p2p_discovery.py +++ b/tests/hwsim/test_p2p_discovery.py @@ -7,7 +7,7 @@ # See README for more details. import logging -logger = logging.getLogger(__name__) +logger = logging.getLogger() import hwsim_utils diff --git a/tests/hwsim/test_p2p_grpform.py b/tests/hwsim/test_p2p_grpform.py index 90844c736..8df6e33e1 100644 --- a/tests/hwsim/test_p2p_grpform.py +++ b/tests/hwsim/test_p2p_grpform.py @@ -7,7 +7,7 @@ # See README for more details. import logging -logger = logging.getLogger(__name__) +logger = logging.getLogger() import time import threading import Queue diff --git a/tests/hwsim/test_p2p_invitation.py b/tests/hwsim/test_p2p_invitation.py index 7d53a1af8..db8441ea3 100644 --- a/tests/hwsim/test_p2p_invitation.py +++ b/tests/hwsim/test_p2p_invitation.py @@ -7,7 +7,7 @@ # See README for more details. import logging -logger = logging.getLogger(__name__) +logger = logging.getLogger() import hwsim_utils diff --git a/tests/hwsim/test_p2p_persistent.py b/tests/hwsim/test_p2p_persistent.py index 7f166b207..a4be1812a 100644 --- a/tests/hwsim/test_p2p_persistent.py +++ b/tests/hwsim/test_p2p_persistent.py @@ -7,7 +7,7 @@ # See README for more details. import logging -logger = logging.getLogger(__name__) +logger = logging.getLogger() import hwsim_utils diff --git a/tests/hwsim/test_p2p_service.py b/tests/hwsim/test_p2p_service.py index 5a412879d..7ac4a149f 100644 --- a/tests/hwsim/test_p2p_service.py +++ b/tests/hwsim/test_p2p_service.py @@ -7,7 +7,7 @@ # See README for more details. import logging -logger = logging.getLogger(__name__) +logger = logging.getLogger() import hwsim_utils diff --git a/tests/hwsim/wlantest.py b/tests/hwsim/wlantest.py index c39320eb6..d9dc5cefe 100644 --- a/tests/hwsim/wlantest.py +++ b/tests/hwsim/wlantest.py @@ -12,7 +12,7 @@ import subprocess import logging import wpaspy -logger = logging.getLogger(__name__) +logger = logging.getLogger() class Wlantest: def __init__(self): diff --git a/tests/hwsim/wpasupplicant.py b/tests/hwsim/wpasupplicant.py index 00d5f953a..8986f2f0a 100644 --- a/tests/hwsim/wpasupplicant.py +++ b/tests/hwsim/wpasupplicant.py @@ -13,7 +13,7 @@ import re import subprocess import wpaspy -logger = logging.getLogger(__name__) +logger = logging.getLogger() wpas_ctrl = '/var/run/wpa_supplicant' class WpaSupplicant: