From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796261981; b=LypWzovTAT0YGjLrEO5EQmUrYPQX200m1Dha4v2IReFo8GOD0nNgmzvogPqk7SoVp/dB 5//WJwpg5EKpFHculbNEYG+kzAFmxqLWz0C2l2gaCBiQszD9NVeJqhHrvfoVdfM5spIBS 8BGIyRnu9VqG3WWvXK32qFzhJ565AUGsbVqyPHBUwSg+29/VSWJ/c0hHEu5onyNf8UjID qUWvYeo8tjmrw2BdOPGnNu3S2pb3Sq4sP0NamQdfF7RjDMd2Q6ngUAIeBYCQtTCcupEnd Y9pIHNLMxP4kobAQxkmWIOui0Q1x0PwLJEj2OfvJzKcq9GJS0aWr+3+jKUUI6bRaJ4Q== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796261981; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=lOO9c68t6hQMofP1cY1ydO0H5fQgpnUHmsWMuPFBFAM=; b=LwXWA8AV/1aZTGkCVOa6QUWznCAIS6MGlp1WhiezWrY7z3/Ytd2EKcm+wt60oAqCylv2 XozxL7J1HYw7HqIkMKDf6MemOgHmrYee73BX6L3JYHqzC309oJ2k5BKLPp+MefjwYsXXO 0UkqEdaulgzpNvXXgAZc+JwnGh8SkKS8X9UCNbP8Yy9CNrR2a6LRkhuSzpmnBLSdjUdO5 crBEs1F/+xZ9tBSVyV+ivfamzKW1jmJnFvXG76x1P+nWJAl0UgxEA3GbIFzPFRSIkEe6u o2l0yOxP3KdaoljhlTx9CsoPCI8P+pRQg+F6CEoowR2O0/ncxmOrjyQjizU+po4tBEQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=irvZ8A8L; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02720606A322 for ; Thu, 3 Dec 2026 01:39:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=irvZ8A8L Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796261980; b=WYOO5N6Xnu1lsp1eItQvkUjB+0whr3EaVtePomHkUMxahKzuNiSncBi+GerhVeeJld2x yZ9t4B7AZSAPsj3PTrjnM+eV8/enyGqztzlsBzlHA2CimEBoZzRtFKhRa7gOWQ4ZHIn+5 u0SR4UABlh/sDNlj5hSw2Fv+0oIZfHQc4DeLvvKp4UzGmH0oSboZJbqLXJuxiwo8xmTYL +Qd36SC2LaEDrNaolaWecCKBTEcfoElNw+3GIiETTh/rwDyPG9bNc7e2Fvt5mtnek5dTm doYNY0F79tOuvpAzRVpDgWV3JlgsW/56bcUiMp3hxVh1P6s6IQFGkVY1/ZqeYFFb2hA== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796261980; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=lOO9c68t6hQMofP1cY1ydO0H5fQgpnUHmsWMuPFBFAM=; b=F1ajiZWMFNJ5HcPPTi70ZqdbtZrONxOEUplmTaObswRbduTc1clXo7B3CzFyOfHoyrq1 2KGSNmVPBpsAw5x/Ed8BNHpasoZ5xu0gW6i59rqOLoHEcGiQ3FqS/+PAjpSL5cm1mZEuq lcN0Mks/plwvGb46PjBxGXSRC+q9EcSNDEISPXCGePY1tVrQt5REcQIbFiCpM3S7UmlXZ rm1LHtN1juJP+1ID3UbW92ZELRUN0rbkRWtPgjuSRVkyb7YpU347ywywos+l/Sp2r0kwy WYuoBJQsUaYbKod1jhHeU8r3I2DNozyzmhs/Lo1hC71/QmkPzJSUdGtpst6M+l22NPw== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 071BA1F00893; Thu, 3 Dec 2026 01:39:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796261980; bh=lOO9c68t6hQMofP1cY1ydO0H5fQgpnUHmsWMuPFBFAM=; h=From:Date:Subject:To:Cc:Reply-To; b=irvZ8A8Lg59LEUEHni17AXAFr72BHCqkvEEJMCj1FcNzkFhwzv9PAItlNDvMZtqPS e8ccuktalY/RMEoVy4AXdVtke4I2h3j2h5vLcNwkqb5hwyhOqOfaUEGKZsNYYqmhIJ yoKrYqL7qstHICgHKZ7u1ohz09GnDNSu/Tz/QCMM7VtfslAfOnqYAlsuNQkO8tzP9R J2WfHvPWS69aXAyDJYpQyKLp1DufdgBU8B6ktqupCPw6o3uyeofr4LEcFkQbGjyWhb 5xWqXa8mK6x8JqPonBxDAGGQIpB3J2BtQmA4fve1CbTqqLcnRtXx9+dbBmeI2PuMwk DANL1e6fiIpEg== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 857D34F6F8; Thu, 3 Dec 2026 01:39:39 +0000 (UTC) From: Pavee Zheng via B4 Relay Date: Thu, 03 Dec 2026 09:39:36 +0800 Subject: [PATCH] kconfig: tests: avoid mutating extra_env dicts in Conf X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261203-patch-kconfig-tests-extra-env-v1-1-e48cf80d6d59@gmail.com> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/yXMwQqDMAwA0F+RnBeoFbexXxk71JhqNqjSZCKI/ 75Oj+/yNlDOwgqPaoPMi6hMqaC+VEBjSAOj9MXgnb/W3jU4B6MRPzSlKAMaqynyajkgpwWd7++ xvTXUdg7KMWeOsh7/83Vav92byf4p7PsPH2bwZYEAAAA= X-Change-ID: 20261203-patch-kconfig-tests-extra-env-02d8f573c5b0 To: Nathan Chancellor , Nicolas Schier , Julian Braha , Masahiro Yamada , Ulf Magnusson Cc: linux-kbuild@vger.kernel.org, Pavee Zheng X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796261978; l=4175; i=pavee.zheng@gmail.com; s=20261203; h=from:subject:message-id; bh=y1XITE1q1zR/O5GZh78iXD0JaXSbB45hmVbyMpMb7jA=; b=EtKAAs9PLWDKCPnuuRd4u9iLX8TnUUtSmkG+LcH1xHdP2xpgtpO+ZRQ1zyG9S97Ob8CRKfDV5 e8N7iDlpuQlDubfTDk357EyzA6xeBD7neA02P8GN/K/yyUOaduumnFt X-Developer-Key: i=pavee.zheng@gmail.com; a=ed25519; pk=tKWX/JHvHgKJscWsVefc3+t39eSysVDI8/ZkQl1Rlyo= X-Endpoint-Received: by B4 Relay for pavee.zheng@gmail.com/20261203 with auth_id=1729 X-Original-From: Pavee Zheng Reply-To: pavee.zheng@gmail.com Content-Transfer-Encoding: 7bit From: 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 --- scripts/kconfig/tests/conftest.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --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 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pavee Zheng Date: Thu, 03 Dec 2026 09:39:36 +0800 Subject: [PATCH] kconfig: tests: avoid mutating extra_env dicts in Conf MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261203-patch-kconfig-tests-extra-env-v1-1-e48cf80d6d59@gmail.com> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/yXMwQqDMAwA0F+RnBeoFbexXxk71JhqNqjSZCKI/ 75Oj+/yNlDOwgqPaoPMi6hMqaC+VEBjSAOj9MXgnb/W3jU4B6MRPzSlKAMaqynyajkgpwWd7++ xvTXUdg7KMWeOsh7/83Vav92byf4p7PsPH2bwZYEAAAA= X-Change-ID: 20261203-patch-kconfig-tests-extra-env-02d8f573c5b0 To: Nathan Chancellor , Nicolas Schier , Julian Braha , Masahiro Yamada , Ulf Magnusson Cc: linux-kbuild@vger.kernel.org, Pavee Zheng X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796261978; l=4175; i=pavee.zheng@gmail.com; s=20261203; h=from:subject:message-id; bh=y1XITE1q1zR/O5GZh78iXD0JaXSbB45hmVbyMpMb7jA=; b=EtKAAs9PLWDKCPnuuRd4u9iLX8TnUUtSmkG+LcH1xHdP2xpgtpO+ZRQ1zyG9S97Ob8CRKfDV5 e8N7iDlpuQlDubfTDk357EyzA6xeBD7neA02P8GN/K/yyUOaduumnFt X-Developer-Key: i=pavee.zheng@gmail.com; a=ed25519; pk=tKWX/JHvHgKJscWsVefc3+t39eSysVDI8/ZkQl1Rlyo= X-Endpoint-Received: by B4 Relay for pavee.zheng@gmail.com/20261203 with auth_id=1729 List-Id: B4 Relay Submissions 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 --- scripts/kconfig/tests/conftest.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --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