]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Work around reentrant logging issues due to __del__ misuse
authorJohannes Berg <johannes.berg@intel.com>
Sun, 22 May 2022 08:46:09 +0000 (11:46 +0300)
committerJouni Malinen <j@w1.fi>
Sun, 22 May 2022 08:46:57 +0000 (11:46 +0300)
Unfortunately, some objects (WlantestCapture, WpaSupplicant
and wpaspy.Ctrl) use __del__ and actually have some logic
there. This is more or less wrong, and we should be using
context managers for it. However, cleaning that up is a
pretty large task.

Unfortunately, __del__ can cause reentrant logging which is
wrong too, because it might be invoked while in the middle
of a logging call, and the __del__ of these objects closes
connections and logs while doing that.

Since we're (likely) using cpython, we can work around this
by explicitly calling gc.collect() in a context where the
logging and close is fine, not only ensuring that all the
connections are closed properly before the next test, but
also fixing the issue with reentrant logging.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
tests/hwsim/run-tests.py

index 019533f544235605f1983d2f1ecd0b9c4b2e4585..0784575f283d15bff800e487cb5757093c1cfc0d 100755 (executable)
@@ -8,6 +8,7 @@
 
 import os
 import re
+import gc
 import sys
 import time
 from datetime import datetime
@@ -576,6 +577,15 @@ def main():
                 if args.loglevel == logging.WARNING:
                     print("Exception: " + str(e))
                 result = "FAIL"
+
+            # Work around some objects having __del__, we really should
+            # use context managers, but that's complex. Doing this here
+            # will (on cpython at least) at make sure those objects that
+            # are no longer reachable will be collected now, invoking
+            # __del__() on them. This then ensures that __del__() isn't
+            # invoked at a bad time, e.g. causing recursion in locking.
+            gc.collect()
+
             open('/dev/kmsg', 'w').write('TEST-STOP %s @%.6f\n' % (name, time.time()))
             for d in dev:
                 try: