tests: Convert "hwsim-SKIP" exception to use a custom class

This makes the design a bit cleaner for catching the exceptions.

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2015-01-07 13:41:31 +02:00
parent 910eb5b525
commit 51c5aeb42a
5 changed files with 24 additions and 18 deletions

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python2
#
# Test case executor
# Copyright (c) 2013-2014, Jouni Malinen <j@w1.fi>
# Copyright (c) 2013-2015, Jouni Malinen <j@w1.fi>
#
# This software may be distributed under the terms of the BSD license.
# See README for more details.
@ -27,6 +27,7 @@ from wpasupplicant import WpaSupplicant
from hostapd import HostapdGlobal
from check_kernel import check_kernel
from wlantest import Wlantest
from utils import HwsimSkip
def set_term_echo(fd, enabled):
[iflag, oflag, cflag, lflag, ispeed, ospeed, cc] = termios.tcgetattr(fd)
@ -441,14 +442,14 @@ def main():
result = "SKIP"
else:
result = "PASS"
except HwsimSkip, e:
logger.info("Skip test case: %s" % e)
result = "SKIP"
except Exception, e:
if str(e) == "hwsim-SKIP":
result = "SKIP"
else:
logger.info(e)
if args.loglevel == logging.WARNING:
print "Exception: " + str(e)
result = "FAIL"
logger.info(e)
if args.loglevel == logging.WARNING:
print "Exception: " + str(e)
result = "FAIL"
for d in dev:
try:
d.dump_monitor()

View file

@ -19,6 +19,7 @@ except ImportError:
import hostapd
from wpasupplicant import WpaSupplicant
from utils import HwsimSkip
from test_ap_tdls import connect_2sta_open
WPAS_DBUS_SERVICE = "fi.w1.wpa_supplicant1"
@ -35,7 +36,7 @@ WPAS_DBUS_PERSISTENT_GROUP = "fi.w1.wpa_supplicant1.PersistentGroup"
def prepare_dbus(dev):
if not dbus_imported:
logger.info("No dbus module available")
raise Exception("hwsim-SKIP")
raise HwsimSkip("No dbus module available")
try:
from dbus.mainloop.glib import DBusGMainLoop
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
@ -46,8 +47,7 @@ def prepare_dbus(dev):
if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
return (bus,wpas_obj,path,if_obj)
except Exception, e:
logger.info("No D-Bus support available: " + str(e))
raise Exception("hwsim-SKIP")
raise HwsimSkip("Could not connect to D-Bus: %s" % e)
class TestDbus(object):
def __init__(self, bus):

View file

@ -15,6 +15,7 @@ except ImportError:
dbus_imported = False
import hostapd
from utils import HwsimSkip
from test_dbus import TestDbus, start_ap
WPAS_DBUS_OLD_SERVICE = "fi.epitest.hostap.WPASupplicant"
@ -25,8 +26,7 @@ WPAS_DBUS_OLD_NETWORK = "fi.epitest.hostap.WPASupplicant.Network"
def prepare_dbus(dev):
if not dbus_imported:
logger.info("No dbus module available")
raise Exception("hwsim-SKIP")
raise HwsimSkip("No dbus module available")
try:
from dbus.mainloop.glib import DBusGMainLoop
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
@ -37,8 +37,7 @@ def prepare_dbus(dev):
if_obj = bus.get_object(WPAS_DBUS_OLD_SERVICE, path)
return (bus,wpas_obj,path,if_obj)
except Exception, e:
logger.info("No D-Bus support available: " + str(e))
raise Exception("hwsim-SKIP")
raise HwsimSkip("Could not connect to D-Bus: %s" % e)
class TestDbusOldWps(TestDbus):
def __init__(self, bus):

View file

@ -12,6 +12,7 @@ import subprocess
import hostapd
from wpasupplicant import WpaSupplicant
from utils import HwsimSkip
def check_scan(dev, params, other_started=False, test_busy=False):
if not other_started:
@ -698,8 +699,7 @@ def _test_scan_random_mac(dev, apdev, params):
raise Exception("Invalid MAC_RAND_SCAN accepted: " + args)
if dev[0].get_driver_status_field('capa.mac_addr_rand_scan_supported') != '1':
logger.info("Driver does not support random MAC address for scanning")
raise Exception("hwsim-SKIP")
raise HwsimSkip("Driver does not support random MAC address for scanning")
tests = [ "all enable=1",
"all enable=1 addr=f2:11:22:33:44:55 mask=ff:ff:ff:ff:ff:ff",

View file

@ -1,5 +1,5 @@
# Testing utilities
# Copyright (c) 2013, Jouni Malinen <j@w1.fi>
# Copyright (c) 2013-2015, Jouni Malinen <j@w1.fi>
#
# This software may be distributed under the terms of the BSD license.
# See README for more details.
@ -13,3 +13,9 @@ def get_ifnames():
if len(val) == 2:
ifnames.append(val[0].strip(' '))
return ifnames
class HwsimSkip(Exception):
def __init__(self, reason):
self.reason = reason
def __str__(self):
return self.reason