[PATCH] tests: use logger.exception to dump full traceback

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Benjamin Berg <benjamin.berg@xxxxxxxxx>

The log sometimes does not contain relevant information. Switch to use
logger.exception which dumps the full exception information. Note that
the logging happens with level ERROR, so it will be dumped to the
stdout/stderr by default.

Signed-off-by: Benjamin Berg <benjamin.berg@xxxxxxxxx>
---
 tests/hwsim/run-tests.py | 41 +++++++++++++---------------------------
 1 file changed, 13 insertions(+), 28 deletions(-)

diff --git a/tests/hwsim/run-tests.py b/tests/hwsim/run-tests.py
index ea00316ee9..eafec24797 100755
--- a/tests/hwsim/run-tests.py
+++ b/tests/hwsim/run-tests.py
@@ -49,8 +49,7 @@ def reset_devs(dev, apdev):
         try:
             d.reset()
         except Exception as e:
-            logger.info("Failed to reset device " + d.ifname)
-            print(str(e))
+            logger.exception("Failed to reset device " + d.ifname)
             ok = False
 
     wpas = None
@@ -75,8 +74,7 @@ def reset_devs(dev, apdev):
                 hapd.remove(iface)
         hapd.remove('as-erp')
     except Exception as e:
-        logger.info("Failed to remove hostapd interface")
-        print(str(e))
+        logger.exception("Failed to remove hostapd interface")
         ok = False
     return ok
 
@@ -94,8 +92,8 @@ def add_log_file(conn, test, run, type, path):
         conn.execute(sql, params)
         conn.commit()
     except Exception as e:
-        print("sqlite: " + str(e))
-        print("sql: %r" % (params, ))
+        logger.exception("sqlite:")
+        logger.error("sql: %r" % (params, ))
 
 def report(conn, prefill, build, commit, run, test, result, duration, logdir,
            sql_commit=True):
@@ -113,8 +111,8 @@ def report(conn, prefill, build, commit, run, test, result, duration, logdir,
             if sql_commit:
                 conn.commit()
         except Exception as e:
-            print("sqlite: " + str(e))
-            print("sql: %r" % (params, ))
+            logger.exception("sqlite:")
+            logger.error("sql: %r" % (params, ))
 
         if result == "FAIL":
             for log in ["log", "log0", "log1", "log2", "log3", "log5",
@@ -213,8 +211,7 @@ def rename_log(logdir, basename, testname, dev):
             dev.relog()
             subprocess.call(['chown', '-f', getpass.getuser(), srcname])
     except Exception as e:
-        logger.info("Failed to rename log files")
-        logger.info(e)
+        logger.exception("Failed to rename log files")
 
 def is_long_duration_test(t):
     return hasattr(t, "long_duration_test") and t.long_duration_test
@@ -377,8 +374,8 @@ def main():
                 try:
                     conn.execute(sql, params)
                 except Exception as e:
-                    print("sqlite: " + str(e))
-                    print("sql: %r" % (params,))
+                    logger.exception("sqlite:")
+                    logger.error("sql: %r" % (params,))
         if conn:
             conn.commit()
             conn.close()
@@ -568,8 +565,7 @@ def main():
                         raise Exception("Global PING failed for {}".format(d.ifname))
                     d.request("NOTE TEST-START " + name)
                 except Exception as e:
-                    logger.info("Failed to issue TEST-START before " + name + " for " + d.ifname)
-                    logger.info(e)
+                    logger.exception("Failed to issue TEST-START before " + name + " for " + d.ifname)
                     print("FAIL " + name + " - could not start test")
                     if conn:
                         conn.close()
@@ -622,17 +618,8 @@ def main():
                 logger.info("Skip test case: %s" % e)
                 skip_reason = e
                 result = "SKIP"
-            except NameError as e:
-                import traceback
-                logger.info(e)
-                traceback.print_exc()
-                result = "FAIL"
             except Exception as e:
-                import traceback
-                logger.info(e)
-                traceback.print_exc()
-                if args.loglevel == logging.WARNING:
-                    print("Exception: " + str(e))
+                logger.exception(f"Exception during test execution: {str(e)}")
                 result = "FAIL"
 
             # Work around some objects having __del__, we really should
@@ -649,8 +636,7 @@ def main():
                     d.dump_monitor()
                     d.request("NOTE TEST-STOP " + name)
                 except Exception as e:
-                    logger.info("Failed to issue TEST-STOP after {} for {}".format(name, d.ifname))
-                    logger.info(e)
+                    logger.exception("Failed to issue TEST-STOP after {} for {}".format(name, d.ifname))
                     result = "FAIL"
             if args.no_reset:
                 print("Leaving devices in current state")
@@ -674,8 +660,7 @@ def main():
             try:
                 hapd = HostapdGlobal()
             except Exception as e:
-                print("Failed to connect to hostapd interface")
-                print(str(e))
+                logger.exception("Failed to connect to hostapd interface")
                 reset_ok = False
                 result = "FAIL"
                 hapd = None
-- 
2.49.0


_______________________________________________
Hostap mailing list
Hostap@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/hostap



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux