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 <johannes.berg@intel.com>
This commit is contained in:
Johannes Berg 2022-05-22 11:46:09 +03:00 committed by Jouni Malinen
parent 72641f924e
commit 39e6623082

View file

@ -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: