* [PATCH] kconfig: tests: avoid mutating extra_env dicts in Conf
@ 2026-12-03 1:39 ` Pavee Zheng
0 siblings, 0 replies; 2+ messages in thread
From: Pavee Zheng via B4 Relay @ 2026-12-03 1:39 UTC (permalink / raw)
To: Nathan Chancellor, Nicolas Schier, Julian Braha, Masahiro Yamada,
Ulf Magnusson
Cc: linux-kbuild, Pavee Zheng
From: Pavee Zheng <pavee.zheng@gmail.com>
Conf._run_conf() and Conf._allconfig() both use a mutable default
argument (extra_env={}) and mutate extra_env in place:
- Conf._allconfig() writes extra_env['KCONFIG_ALLCONFIG'] when
all_config is set. After any call to allyesconfig(), allmodconfig(),
allnoconfig(), or alldefconfig() with all_config, subsequent calls
with all_config=None in the same pytest session inherit the stale
KCONFIG_ALLCONFIG entry from the shared default dictionary.
- Conf._run_conf() writes extra_env['srctree'], mutating both its
default dictionary and caller-owned dictionaries passed via
extra_env (such as warn_changed_input in
scripts/kconfig/tests/warn_changed_input/__init__.py).
Default extra_env to None in both methods. In _run_conf(), merge
extra_env into the local env dictionary and set env['srctree'] there
instead of mutating extra_env. In _allconfig(), build a fresh local
dictionary copy before inserting KCONFIG_ALLCONFIG.
Found with ruff (B006) and prepared with AI coding assistant help.
Verified with ruff (B006,F,E,W), scripts/checkpatch.pl --strict, and in
a Linux container with "make testconfig" (35 passed) plus an end-to-end
regression check against the compiled scripts/kconfig/conf binary
confirming no KCONFIG_ALLCONFIG leak across calls and no mutation of
caller-owned extra_env dictionaries.
Fixes: 022a4bf6b59d ("kconfig: tests: add framework for Kconfig unit testing")
Fixes: c9aa7d862144 ("kconfig: tests: support KCONFIG_SEED for the randconfig runner")
Signed-off-by: Pavee Zheng <pavee.zheng@gmail.com>
---
| 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
--git a/scripts/kconfig/tests/conftest.py b/scripts/kconfig/tests/conftest.py
index d22c080a4e40..38e6ab2c264a 100644
--- a/scripts/kconfig/tests/conftest.py
+++ b/scripts/kconfig/tests/conftest.py
@@ -37,7 +37,7 @@ class Conf:
# runners
def _run_conf(self, mode, dot_config=None, out_file='.config',
- interactive=False, in_keys=None, extra_env={},
+ interactive=False, in_keys=None, extra_env=None,
silent=False):
"""Run text-based Kconfig executable and save the result.
@@ -54,9 +54,6 @@ class Conf:
command.append('-s')
command += [mode, 'Kconfig']
- # Override 'srctree' environment to make the test as the top directory
- extra_env['srctree'] = self._test_dir
-
# Clear all KCONFIG_* environment variables
env = {
varname: os.environ[varname]
@@ -64,6 +61,12 @@ class Conf:
if not varname.startswith("KCONFIG_")
}
+ if extra_env:
+ env.update(extra_env)
+
+ # Override 'srctree' environment to make the test as the top directory
+ env['srctree'] = self._test_dir
+
# Run Kconfig in a temporary directory.
# This directory is automatically removed when done.
with tempfile.TemporaryDirectory() as temp_dir:
@@ -78,7 +81,7 @@ class Conf:
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=temp_dir,
- env=dict(env, **extra_env))
+ env=env)
# If input key sequence is given, feed it to stdin.
if in_keys:
@@ -176,7 +179,8 @@ class Conf:
defconfig_path = os.path.join(self._test_dir, defconfig)
return self._run_conf('--defconfig={}'.format(defconfig_path))
- def _allconfig(self, mode, all_config, extra_env={}):
+ def _allconfig(self, mode, all_config, extra_env=None):
+ extra_env = dict(extra_env) if extra_env else {}
if all_config:
all_config_path = os.path.join(self._test_dir, all_config)
extra_env['KCONFIG_ALLCONFIG'] = all_config_path
---
base-commit: 799dd936553182df5770dde7f38d94c8337df75a
change-id: 20261203-patch-kconfig-tests-extra-env-02d8f573c5b0
Best regards,
--
Pavee Zheng <pavee.zheng@gmail.com>
^ permalink raw reply related [flat|nested] 2+ messages in thread* [PATCH] kconfig: tests: avoid mutating extra_env dicts in Conf
@ 2026-12-03 1:39 ` Pavee Zheng
0 siblings, 0 replies; 2+ messages in thread
From: Pavee Zheng @ 2026-12-03 1:39 UTC (permalink / raw)
To: Nathan Chancellor, Nicolas Schier, Julian Braha, Masahiro Yamada,
Ulf Magnusson
Cc: linux-kbuild, Pavee Zheng
Conf._run_conf() and Conf._allconfig() both use a mutable default
argument (extra_env={}) and mutate extra_env in place:
- Conf._allconfig() writes extra_env['KCONFIG_ALLCONFIG'] when
all_config is set. After any call to allyesconfig(), allmodconfig(),
allnoconfig(), or alldefconfig() with all_config, subsequent calls
with all_config=None in the same pytest session inherit the stale
KCONFIG_ALLCONFIG entry from the shared default dictionary.
- Conf._run_conf() writes extra_env['srctree'], mutating both its
default dictionary and caller-owned dictionaries passed via
extra_env (such as warn_changed_input in
scripts/kconfig/tests/warn_changed_input/__init__.py).
Default extra_env to None in both methods. In _run_conf(), merge
extra_env into the local env dictionary and set env['srctree'] there
instead of mutating extra_env. In _allconfig(), build a fresh local
dictionary copy before inserting KCONFIG_ALLCONFIG.
Found with ruff (B006) and prepared with AI coding assistant help.
Verified with ruff (B006,F,E,W), scripts/checkpatch.pl --strict, and in
a Linux container with "make testconfig" (35 passed) plus an end-to-end
regression check against the compiled scripts/kconfig/conf binary
confirming no KCONFIG_ALLCONFIG leak across calls and no mutation of
caller-owned extra_env dictionaries.
Fixes: 022a4bf6b59d ("kconfig: tests: add framework for Kconfig unit testing")
Fixes: c9aa7d862144 ("kconfig: tests: support KCONFIG_SEED for the randconfig runner")
Signed-off-by: Pavee Zheng <pavee.zheng@gmail.com>
---
| 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
--git a/scripts/kconfig/tests/conftest.py b/scripts/kconfig/tests/conftest.py
index d22c080a4e40..38e6ab2c264a 100644
--- a/scripts/kconfig/tests/conftest.py
+++ b/scripts/kconfig/tests/conftest.py
@@ -37,7 +37,7 @@ class Conf:
# runners
def _run_conf(self, mode, dot_config=None, out_file='.config',
- interactive=False, in_keys=None, extra_env={},
+ interactive=False, in_keys=None, extra_env=None,
silent=False):
"""Run text-based Kconfig executable and save the result.
@@ -54,9 +54,6 @@ class Conf:
command.append('-s')
command += [mode, 'Kconfig']
- # Override 'srctree' environment to make the test as the top directory
- extra_env['srctree'] = self._test_dir
-
# Clear all KCONFIG_* environment variables
env = {
varname: os.environ[varname]
@@ -64,6 +61,12 @@ class Conf:
if not varname.startswith("KCONFIG_")
}
+ if extra_env:
+ env.update(extra_env)
+
+ # Override 'srctree' environment to make the test as the top directory
+ env['srctree'] = self._test_dir
+
# Run Kconfig in a temporary directory.
# This directory is automatically removed when done.
with tempfile.TemporaryDirectory() as temp_dir:
@@ -78,7 +81,7 @@ class Conf:
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=temp_dir,
- env=dict(env, **extra_env))
+ env=env)
# If input key sequence is given, feed it to stdin.
if in_keys:
@@ -176,7 +179,8 @@ class Conf:
defconfig_path = os.path.join(self._test_dir, defconfig)
return self._run_conf('--defconfig={}'.format(defconfig_path))
- def _allconfig(self, mode, all_config, extra_env={}):
+ def _allconfig(self, mode, all_config, extra_env=None):
+ extra_env = dict(extra_env) if extra_env else {}
if all_config:
all_config_path = os.path.join(self._test_dir, all_config)
extra_env['KCONFIG_ALLCONFIG'] = all_config_path
---
base-commit: 799dd936553182df5770dde7f38d94c8337df75a
change-id: 20261203-patch-kconfig-tests-extra-env-02d8f573c5b0
Best regards,
--
Pavee Zheng <pavee.zheng@gmail.com>
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-03 1:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 1:39 [PATCH] kconfig: tests: avoid mutating extra_env dicts in Conf Pavee Zheng via B4 Relay
2026-12-03 1:39 ` Pavee Zheng
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.