[PATCH net 1/4] selftests/tc-testing: pass mp_pm via initialiser
From: Florian Westphal <fw@strlen.de>
Date: 2026-08-19 20:42:36
Subsystem:
kernel selftest framework, the rest · Maintainers:
Shuah Khan, Shuah Khan, Linus Torvalds
The script doesn't work for me:
-- ns/SubPlugin.__init__
Executing 1205 tests in parallel and 89 in serial
Using 39 batches and 4 workers
multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
File "/usr/lib/python3.14/multiprocessing/pool.py", line 125, in worker
result = (True, func(*args, **kwds))
~~~~^^^^^^^^^^^^^^^
File "/usr/lib/python3.14/multiprocessing/pool.py", line 48, in mapstar
return list(map(*args))
File "tools/testing/selftests/tc-testing/tdc.py", line 604, in __mp_runner
(_, tsr) = test_runner(mp_pm, mp_args, tests)
^^^^^
NameError: name 'mp_pm' is not defined
Assisted-by: ollama:gemma4:26b
Signed-off-by: Florian Westphal <fw@strlen.de>
---
tools/testing/selftests/tc-testing/tdc.py | 27 ++++++++++++++++-------
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/tools/testing/selftests/tc-testing/tdc.py b/tools/testing/selftests/tc-testing/tdc.py
index 511d66c36a2a..19b8a1fd1c71 100755
--- a/tools/testing/selftests/tc-testing/tdc.py
+++ b/tools/testing/selftests/tc-testing/tdc.py@@ -600,6 +600,18 @@ def mp_bins(alltests): return (serial, parallel) +mp_pm = None +mp_args = None + +def __mp_init__(pm, args): + """ + This function is called once when each worker process starts. + It sets the global variables in the child process's memory space. + """ + global mp_pm, mp_args + mp_pm = pm + mp_args = args + def __mp_runner(tests): (_, tsr) = test_runner(mp_pm, mp_args, tests) return tsr._testsuite
@@ -615,14 +627,13 @@ def test_runner_mp(pm, args, alltests): print("Executing {} tests in parallel and {} in serial".format(len(parallel), len(serial))) print("Using {} batches and {} workers".format(len(batches), args.mp)) - # We can't pickle these objects so workaround them - global mp_pm - mp_pm = pm - - global mp_args - mp_args = args - - with Pool(args.mp) as p: + # Use the 'initializer' to pass the unpickleable/shared objects + # to each worker process exactly once upon startup. + with Pool( + processes=args.mp, + initializer=__mp_init__, + initargs=(pm, args) + ) as p: pres = p.map(__mp_runner, batches) tsr = TestSuiteReport()
--
2.54.0