tests: Reset wlan5 device before RELOG command
[mech_eap.git] / tests / hwsim / run-tests.py
index c7cc77a..499263f 100755 (executable)
@@ -18,6 +18,12 @@ import termios
 import logging
 logger = logging.getLogger()
 
+try:
+    import sqlite3
+    sqlite3_imported = True
+except ImportError:
+    sqlite3_imported = False
+
 scriptsdir = os.path.dirname(os.path.realpath(sys.modules[__name__].__file__))
 sys.path.append(os.path.join(scriptsdir, '..', '..', 'wpaspy'))
 
@@ -80,7 +86,7 @@ def add_log_file(conn, test, run, type, path):
     if contents is None:
         return
     sql = "INSERT INTO logs(test,run,type,contents) VALUES(?, ?, ?, ?)"
-    params = (test, run, type, contents)
+    params = (test, run, type, sqlite3.Binary(contents))
     try:
         conn.execute(sql, params)
         conn.commit()
@@ -231,7 +237,9 @@ def main():
         sys.exit(2)
 
     if args.database:
-        import sqlite3
+        if not sqlite3_imported:
+            print "No sqlite3 module found"
+            sys.exit(2)
         conn = sqlite3.connect(args.database)
         conn.execute('CREATE TABLE IF NOT EXISTS results (test,result,run,time,duration,build,commitid)')
         conn.execute('CREATE TABLE IF NOT EXISTS tests (test,description)')
@@ -244,13 +252,13 @@ def main():
 
     # read the modules from the modules file
     if args.mfile:
-       args.testmodules = []
-       with open(args.mfile) as f:
-           for line in f.readlines():
-               line = line.strip()
-               if not line or line.startswith('#'):
-                   continue
-               args.testmodules.append(line)
+        args.testmodules = []
+        with open(args.mfile) as f:
+            for line in f.readlines():
+                line = line.strip()
+                if not line or line.startswith('#'):
+                    continue
+                    args.testmodules.append(line)
 
     tests_to_run = []
     if args.tests:
@@ -392,6 +400,7 @@ def main():
             t = tests_to_run.pop(0)
 
         name = t.__name__.replace('test_', '', 1)
+        open('/dev/kmsg', 'w').write('running hwsim test case %s\n' % name)
         if log_handler:
             log_handler.stream.close()
             logger.removeHandler(log_handler)
@@ -444,8 +453,15 @@ def main():
             except HwsimSkip, e:
                 logger.info("Skip test case: %s" % e)
                 result = "SKIP"
+            except NameError, e:
+                import traceback
+                logger.info(e)
+                traceback.print_exc()
+                result = "FAIL"
             except Exception, e:
+                import traceback
                 logger.info(e)
+                traceback.print_exc()
                 if args.loglevel == logging.WARNING:
                     print "Exception: " + str(e)
                 result = "FAIL"
@@ -457,6 +473,10 @@ def main():
                     logger.info("Failed to issue TEST-STOP after {} for {}".format(name, d.ifname))
                     logger.info(e)
                     result = "FAIL"
+            if args.no_reset:
+                print "Leaving devices in current state"
+            else:
+                reset_ok = reset_devs(dev, apdev)
             wpas = None
             try:
                 wpas = WpaSupplicant(global_iface="/tmp/wpas-wlan5")
@@ -467,10 +487,6 @@ def main():
                 pass
             if wpas:
                 wpas.close_ctrl()
-            if args.no_reset:
-                print "Leaving devices in current state"
-            else:
-                reset_ok = reset_devs(dev, apdev)
 
             for i in range(0, 3):
                 rename_log(args.logdir, 'log' + str(i), name, dev[i])
@@ -483,7 +499,13 @@ def main():
                 result = "FAIL"
                 hapd = None
             rename_log(args.logdir, 'hostapd', name, hapd)
+            if hapd:
+                del hapd
+                hapd = None
 
+            # Use None here since this instance of Wlantest() will never be
+            # used for remote host hwsim tests on real hardware.
+            Wlantest.setup(None)
             wt = Wlantest()
             rename_log(args.logdir, 'hwsim0.pcapng', name, wt)
             rename_log(args.logdir, 'hwsim0', name, wt)