From patchwork Wed Mar 20 16:52:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13598019 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02F8769DE6; Wed, 20 Mar 2024 16:52:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710953536; cv=none; b=i0a7/8WJvFueVQeDo4oTQAQh2xUbu4uh2Sq012yibIlFuE9y4O+V0a6g71D4SWLge4Aw5onWjB+ovVmQxyvNY+pxWkp4WyevO0pGRsNkmzja/V0E1fKjk3KzWwdzD/xPrxfamYhNihgD2tTTHALJwNrL8eZhIg6q+9mXBDk4tWg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710953536; c=relaxed/simple; bh=NR9sR85xAHzVG2coKJ4Iltba6VffU0YEvzAwFcIjHWc=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=n0dCU42xCq8hiuYlLze3PG+yXmEBNpPr9MVUNpGZJvo5I+DLQXIBJEmB9mcp2TlxJCL+5givKQvlWlUCxX5XW6/sB382nLsEeuONDxppsskWhG31BACMYFG4sNELlONg7SrEcJZtwMJB744Xhvk5WMgZTb5lRYB6/TEQcRMCCoY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YgZmBreY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YgZmBreY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3DCCC433F1; Wed, 20 Mar 2024 16:52:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710953535; bh=NR9sR85xAHzVG2coKJ4Iltba6VffU0YEvzAwFcIjHWc=; h=From:To:Cc:Subject:Date:From; b=YgZmBreYRE7m98v1KM/B01ectHsmH12QI3mmlwiGA7v+pLyLzaQtfJUD30qV51z1J 38t3lYNfPJjfyD/NcyFu1Xc4JMyQcF+Sb1A2qv0JwqhAFWPktUhCx0N7Tr36xbqz46 K+ezG3ePOdijFH20nwlDDYEY3k1v9A79DJFs+t4PtfTpSQ3YRiXsnt/89r2Cq8mVY9 33fFL1DxYyo28MsfL6oCAUzVoBZQRcsk3SbnVhS//RFUJAMF/lTq1xpQYmUaAfVpN0 JVaC5AIZJT8V9jWhQZKLRpse1abcq+g4QX5RHY5j5WLuTQ/4BcOxob9JGL44OCE43i b2aqJrDD4luAQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 1/3] kconfig: tests: support KCONFIG_SEED for the randconfig runner Date: Thu, 21 Mar 2024 01:52:09 +0900 Message-Id: <20240320165211.697584-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This will help get consistent results for randconfig tests. Signed-off-by: Masahiro Yamada --- 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 af8774a5697c..2a2a7e2da060 100644 --- a/scripts/kconfig/tests/conftest.py +++ b/scripts/kconfig/tests/conftest.py @@ -154,12 +154,10 @@ 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): + def _allconfig(self, mode, all_config, extra_env={}): if all_config: all_config_path = os.path.join(self._test_dir, all_config) - extra_env = {'KCONFIG_ALLCONFIG': all_config_path} - else: - extra_env = {} + extra_env['KCONFIG_ALLCONFIG'] = all_config_path return self._run_conf('--{}config'.format(mode), extra_env=extra_env) @@ -195,13 +193,19 @@ class Conf: """ return self._allconfig('alldef', all_config) - def randconfig(self, all_config=None): + def randconfig(self, all_config=None, seed=None): """Run randconfig. all_config: fragment config file for KCONFIG_ALLCONFIG (optional) + seed: the seed for randconfig (optional) returncode: exit status of the Kconfig executable """ - return self._allconfig('rand', all_config) + if seed is not None: + extra_env = {'KCONFIG_SEED': hex(seed)} + else: + extra_env = {} + + return self._allconfig('rand', all_config, extra_env=extra_env) def savedefconfig(self, dot_config): """Run savedefconfig. From patchwork Wed Mar 20 16:52:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13598020 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27B8369DFA; Wed, 20 Mar 2024 16:52:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710953537; cv=none; b=h0r/3UX9/eriq4V55HfI9Ai98XnHIES/PuyxEVH+Dlv5byok12SAMxmyq+nyXoqZzj4Xzn1j/3R7ueEG763ePsZGHOF2E0ncCxgsMWY7hztuhLCRh1YVh9jNPE+PaTYFIP+4fhoN03S6PVwQlAOZAgrhau9cOqQ9gKwCz23/AYw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710953537; c=relaxed/simple; bh=3XG2pYGXkbO1NNRb5gyk8bO2cOKjk6ghc6qKHY09iDU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=N1okaVcOvS7Z7vnvsdU95WSH74ZRYbrZ82IMu+u/SlaUilZRKQsN5ZfKsh5Wn/OZfGjRi++W6r43xKRNrM2AVJIKPk/x6UsrvBTc988kKiqsVVWjWO/JlVxTBEu1pYCEKSf5B0Vp76f3V6hb8d5WBCQ7NNsXys65w7oHw1+8mu8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qco+60JJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qco+60JJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 028F0C43390; Wed, 20 Mar 2024 16:52:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710953536; bh=3XG2pYGXkbO1NNRb5gyk8bO2cOKjk6ghc6qKHY09iDU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qco+60JJc9PsvJFPkg02B+v/2PD8QBUdM7N/uxUBj8Hz5uq7Nti508Z4O25JCDz7D skEvOr7gsELsMwOAyg0X8gDTRdB/Gvkq6h2rp+ObZds34pMax4IbdRZfCl5cGWlQMV 661T0cnZXqyJ5woPqNT+QgZNUwV4y1xp0j+IUiuFeKt4kh9HgwyaRfKkcQwBGPOk80 Aa2SZwdD8ocxVtgdaTnAAPbNOpWQ42bQmJNBGJn2HClBhHxPwK4myFQPDmfEztvRvb yBpHpmbiY4HLvOJN6b8Ebvumf4CPy1zTdi7osv+RIVWEVSm79BOf/08v5EpM9BFtvK bfDIsvkE2ppPA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 2/3] kconfig: tests: add a test for randconfig with dependent choices Date: Thu, 21 Mar 2024 01:52:10 +0900 Message-Id: <20240320165211.697584-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240320165211.697584-1-masahiroy@kernel.org> References: <20240320165211.697584-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since commit 3b9a19e08960 ("kconfig: loop as long as we changed some symbols in randconfig"), conf_set_all_new_symbols() is repeated until there is no more choice left to be shuffled. The motivation was to shuffle a choice nested in another choice. Although commit 09d5873e4d1f ("kconfig: allow only 'config', 'comment', and 'if' inside 'choice'") disallowed the nested choice structure, we must still keep 3b9a19e08960 because there are still cases where conf_set_all_new_symbols() must iterate. scripts/kconfig/tests/choice_randomize/Kconfig is the test case. The second choice depends on 'B', which is the member of the first choice. With 3b9a19e08960 reverted, we would never get the pattern specified by scripts/kconfig/tests/choice_randomize/expected_config2. A real example can be found in lib/Kconfig.debug. Without 3b9a19e08960, the randconfig would not shuffle the "Compressed Debug information" choice, which depends on DEBUG_INFO, which is derived from another choice "Debug information". My goal is to refactor Kconfig so that randconfig will work more simply, without using the loop. For now, let's add a test case to ensure all dependent choices are shuffled, as it is a somewhat tricky case for the current Kconfig. Signed-off-by: Masahiro Yamada --- .../kconfig/tests/choice_randomize/Kconfig | 22 ++++++++++++ .../tests/choice_randomize/__init__.py | 34 +++++++++++++++++++ .../tests/choice_randomize/expected_config0 | 6 ++++ .../tests/choice_randomize/expected_config1 | 8 +++++ .../tests/choice_randomize/expected_config2 | 8 +++++ 5 files changed, 78 insertions(+) create mode 100644 scripts/kconfig/tests/choice_randomize/Kconfig create mode 100644 scripts/kconfig/tests/choice_randomize/__init__.py create mode 100644 scripts/kconfig/tests/choice_randomize/expected_config0 create mode 100644 scripts/kconfig/tests/choice_randomize/expected_config1 create mode 100644 scripts/kconfig/tests/choice_randomize/expected_config2 diff --git a/scripts/kconfig/tests/choice_randomize/Kconfig b/scripts/kconfig/tests/choice_randomize/Kconfig new file mode 100644 index 000000000000..93a1699ce3cb --- /dev/null +++ b/scripts/kconfig/tests/choice_randomize/Kconfig @@ -0,0 +1,22 @@ +choice + prompt "choose A or B" + +config A + bool "A" + +config B + bool "B" + +endchoice + +choice + prompt "choose X or Y" + depends on B + +config X + bool "X" + +config Y + bool "Y" + +endchoice diff --git a/scripts/kconfig/tests/choice_randomize/__init__.py b/scripts/kconfig/tests/choice_randomize/__init__.py new file mode 100644 index 000000000000..d380045be79c --- /dev/null +++ b/scripts/kconfig/tests/choice_randomize/__init__.py @@ -0,0 +1,34 @@ +# SPDX-License-Identifier: GPL-2.0-only +""" +Randomize all dependent choices + +This is a somewhat tricky case for randconfig; the visibility of one choice is +determined by a member of another choice. Randconfig should be able to generate +all possible patterns. +""" + + +def test(conf): + + expected0 = False + expected1 = False + expected2 = False + + for i in range(100): + assert conf.randconfig(seed=i) == 0 + + if conf.config_matches('expected_config0'): + expected0 = True + elif conf.config_matches('expected_config1'): + expected1 = True + elif conf.config_matches('expected_config2'): + expected2 = True + else: + assert False + + if expected0 and expected1 and expected2: + break + + assert expected0 + assert expected1 + assert expected2 diff --git a/scripts/kconfig/tests/choice_randomize/expected_config0 b/scripts/kconfig/tests/choice_randomize/expected_config0 new file mode 100644 index 000000000000..f69227323759 --- /dev/null +++ b/scripts/kconfig/tests/choice_randomize/expected_config0 @@ -0,0 +1,6 @@ +# +# Automatically generated file; DO NOT EDIT. +# Main menu +# +CONFIG_A=y +# CONFIG_B is not set diff --git a/scripts/kconfig/tests/choice_randomize/expected_config1 b/scripts/kconfig/tests/choice_randomize/expected_config1 new file mode 100644 index 000000000000..bf83784c9b2a --- /dev/null +++ b/scripts/kconfig/tests/choice_randomize/expected_config1 @@ -0,0 +1,8 @@ +# +# Automatically generated file; DO NOT EDIT. +# Main menu +# +# CONFIG_A is not set +CONFIG_B=y +CONFIG_X=y +# CONFIG_Y is not set diff --git a/scripts/kconfig/tests/choice_randomize/expected_config2 b/scripts/kconfig/tests/choice_randomize/expected_config2 new file mode 100644 index 000000000000..38f93a8f37bd --- /dev/null +++ b/scripts/kconfig/tests/choice_randomize/expected_config2 @@ -0,0 +1,8 @@ +# +# Automatically generated file; DO NOT EDIT. +# Main menu +# +# CONFIG_A is not set +CONFIG_B=y +# CONFIG_X is not set +CONFIG_Y=y From patchwork Wed Mar 20 16:52:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13598021 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B21D6A00C; Wed, 20 Mar 2024 16:52:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710953538; cv=none; b=QH4g46qsH8vMvP97KI98MzySLqiRZ9Ydb4YMYo7nIOxtF/Vok8QBFOwV/yOSJIXLecpEPKojkzABwGTotvxycUYLF/mZVQJoW5FB/ksCYbjARiu5vY8l7s1htTccGkT441iuwbvd1Iq4tScCcpb0WPon4FC6avMYvcXuI+dmd2Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710953538; c=relaxed/simple; bh=oH45crn/4yGs/ur5w7wZpa4kx7+grNNIEqXM5CcoE7U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=j93ad2mcGgBpwwWnEd/97E0A8I206+aBQ+6n7Hp8pO4OlHqnXKhlKVCBYyUJFhejJ2bPDY9uaS+8JlySkeLUL9fCOUWtyh24AHJx3j3xK/RxL7/gbrxWInNQz5fmWgEx1wbzTmBCQLRCiruxb12URbcbXjCH7BZwXYdgeVYU5fw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DdIoDaO2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DdIoDaO2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E191C433C7; Wed, 20 Mar 2024 16:52:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710953537; bh=oH45crn/4yGs/ur5w7wZpa4kx7+grNNIEqXM5CcoE7U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DdIoDaO2PwVD0nbFM9RA7zE4uWmIJNFVwjOycSnxHZqBt0sWms7zcIvojWgk789Pw 0DaGpBgR3vPY1myLHQZ+MGdwOmCXkQELe+Si7p4Yal2aaLwf2Epaj1qJ5D6EO+iGIE 2wFuIdY6Tof4Th4KAt+4etowD8hoBk+u69MviMu27dBU0yOq/5grYOHC4x/776C6qW bwHxTMHgBFK3OJAHd/TWtA3hgMKVmabMM6LY+jNd9tZ+lPMH2gVoAZXg0JsVYVodWl uFhtSTl2QPKlUOTlmGwhJDfwzWjPPAJVozeoA3pnQx0X4lEsDUNRBIHFP3wmwbAeLX jQrnTe4HhC8fg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 3/3] kconfig: tests: test dependency after shuffling choices Date: Thu, 21 Mar 2024 01:52:11 +0900 Message-Id: <20240320165211.697584-3-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240320165211.697584-1-masahiroy@kernel.org> References: <20240320165211.697584-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Commit c8fb7d7e48d1 ("kconfig: fix broken dependency in randconfig- generated .config") fixed the issue, but I did not add a test case. This commit adds a test case that emulates the reported situation. The test would fail without c8fb7d7e48d1. To handle the choice "choose X", FOO must be calculated beforehand. FOO depends on A, which is a member of another choice "choose A or B". Kconfig _temporarily_ assumes the value of A to proceed. The choice "choose A or B" will be shuffled later, but the result may or may not meet "FOO depends on A". Kconfig should invalidate the symbol values and recompute them. In the real example for ARCH=arm64, the choice "Instrumentation type" needs the value of CPU_BIG_ENDIAN. The choice "Endianness" will be shuffled later. Signed-off-by: Masahiro Yamada --- .../kconfig/tests/choice_randomize2/Kconfig | 32 +++++++++++++++++++ .../tests/choice_randomize2/__init__.py | 18 +++++++++++ .../tests/choice_randomize2/expected_config0 | 8 +++++ .../tests/choice_randomize2/expected_config1 | 7 ++++ .../tests/choice_randomize2/expected_config2 | 6 ++++ 5 files changed, 71 insertions(+) create mode 100644 scripts/kconfig/tests/choice_randomize2/Kconfig create mode 100644 scripts/kconfig/tests/choice_randomize2/__init__.py create mode 100644 scripts/kconfig/tests/choice_randomize2/expected_config0 create mode 100644 scripts/kconfig/tests/choice_randomize2/expected_config1 create mode 100644 scripts/kconfig/tests/choice_randomize2/expected_config2 diff --git a/scripts/kconfig/tests/choice_randomize2/Kconfig b/scripts/kconfig/tests/choice_randomize2/Kconfig new file mode 100644 index 000000000000..530cf2ef7f47 --- /dev/null +++ b/scripts/kconfig/tests/choice_randomize2/Kconfig @@ -0,0 +1,32 @@ +choice + prompt "This is always invisible" + depends on n + +config DUMMY + bool "DUMMY" + +endchoice + +choice + prompt "Choose A or B" + +config A + bool "A" + +config B + bool "B" + +endchoice + +config FOO + bool "FOO" + depends on A + +choice + prompt "Choose X" + depends on FOO + +config X + bool "X" + +endchoice diff --git a/scripts/kconfig/tests/choice_randomize2/__init__.py b/scripts/kconfig/tests/choice_randomize2/__init__.py new file mode 100644 index 000000000000..2066757b80b9 --- /dev/null +++ b/scripts/kconfig/tests/choice_randomize2/__init__.py @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: GPL-2.0-only +""" +Randomize choices with correct dependencies + +When shuffling a choice may potentially disrupt certain dependencies, symbol +values must be recalculated. + +Related Linux commits: + - c8fb7d7e48d11520ad24808cfce7afb7b9c9f798 +""" + + +def test(conf): + for i in range(20): + assert conf.randconfig(seed=i) == 0 + assert (conf.config_matches('expected_config0') or + conf.config_matches('expected_config1') or + conf.config_matches('expected_config2')) diff --git a/scripts/kconfig/tests/choice_randomize2/expected_config0 b/scripts/kconfig/tests/choice_randomize2/expected_config0 new file mode 100644 index 000000000000..5c9e1c172c15 --- /dev/null +++ b/scripts/kconfig/tests/choice_randomize2/expected_config0 @@ -0,0 +1,8 @@ +# +# Automatically generated file; DO NOT EDIT. +# Main menu +# +CONFIG_A=y +# CONFIG_B is not set +CONFIG_FOO=y +CONFIG_X=y diff --git a/scripts/kconfig/tests/choice_randomize2/expected_config1 b/scripts/kconfig/tests/choice_randomize2/expected_config1 new file mode 100644 index 000000000000..5b975d91bef1 --- /dev/null +++ b/scripts/kconfig/tests/choice_randomize2/expected_config1 @@ -0,0 +1,7 @@ +# +# Automatically generated file; DO NOT EDIT. +# Main menu +# +CONFIG_A=y +# CONFIG_B is not set +# CONFIG_FOO is not set diff --git a/scripts/kconfig/tests/choice_randomize2/expected_config2 b/scripts/kconfig/tests/choice_randomize2/expected_config2 new file mode 100644 index 000000000000..5a5ebb90d1d7 --- /dev/null +++ b/scripts/kconfig/tests/choice_randomize2/expected_config2 @@ -0,0 +1,6 @@ +# +# Automatically generated file; DO NOT EDIT. +# Main menu +# +# CONFIG_A is not set +CONFIG_B=y