Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kconfig: tests: add a test for randconfig with dependent choices

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 <masahiroy@kernel.org>

+78
+22
scripts/kconfig/tests/choice_randomize/Kconfig
··· 1 + choice 2 + prompt "choose A or B" 3 + 4 + config A 5 + bool "A" 6 + 7 + config B 8 + bool "B" 9 + 10 + endchoice 11 + 12 + choice 13 + prompt "choose X or Y" 14 + depends on B 15 + 16 + config X 17 + bool "X" 18 + 19 + config Y 20 + bool "Y" 21 + 22 + endchoice
+34
scripts/kconfig/tests/choice_randomize/__init__.py
··· 1 + # SPDX-License-Identifier: GPL-2.0-only 2 + """ 3 + Randomize all dependent choices 4 + 5 + This is a somewhat tricky case for randconfig; the visibility of one choice is 6 + determined by a member of another choice. Randconfig should be able to generate 7 + all possible patterns. 8 + """ 9 + 10 + 11 + def test(conf): 12 + 13 + expected0 = False 14 + expected1 = False 15 + expected2 = False 16 + 17 + for i in range(100): 18 + assert conf.randconfig(seed=i) == 0 19 + 20 + if conf.config_matches('expected_config0'): 21 + expected0 = True 22 + elif conf.config_matches('expected_config1'): 23 + expected1 = True 24 + elif conf.config_matches('expected_config2'): 25 + expected2 = True 26 + else: 27 + assert False 28 + 29 + if expected0 and expected1 and expected2: 30 + break 31 + 32 + assert expected0 33 + assert expected1 34 + assert expected2
+6
scripts/kconfig/tests/choice_randomize/expected_config0
··· 1 + # 2 + # Automatically generated file; DO NOT EDIT. 3 + # Main menu 4 + # 5 + CONFIG_A=y 6 + # CONFIG_B is not set
+8
scripts/kconfig/tests/choice_randomize/expected_config1
··· 1 + # 2 + # Automatically generated file; DO NOT EDIT. 3 + # Main menu 4 + # 5 + # CONFIG_A is not set 6 + CONFIG_B=y 7 + CONFIG_X=y 8 + # CONFIG_Y is not set
+8
scripts/kconfig/tests/choice_randomize/expected_config2
··· 1 + # 2 + # Automatically generated file; DO NOT EDIT. 3 + # Main menu 4 + # 5 + # CONFIG_A is not set 6 + CONFIG_B=y 7 + # CONFIG_X is not set 8 + CONFIG_Y=y