From 39e662308214bf27dc43a1a4f117b1dee17d8cac Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sun, 22 May 2022 11:46:09 +0300 Subject: [PATCH] tests: Work around reentrant logging issues due to __del__ misuse 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 --- tests/hwsim/run-tests.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/hwsim/run-tests.py b/tests/hwsim/run-tests.py index 019533f54..0784575f2 100755 --- a/tests/hwsim/run-tests.py +++ b/tests/hwsim/run-tests.py @@ -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: