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

kconfig: tests: test randconfig for choice in choice

Commit 3b9a19e08960 ("kconfig: loop as long as we changed some symbols
in randconfig") fixed randconfig where a choice contains a sub-choice.
Prior to that commit, the sub-choice values were not set.

I am not sure whether this is an intended feature or just something
people discovered works, but it is used in the real world;
drivers/usb/gadget/legacy/Kconfig is source'd in a choice context,
then creates a sub-choice in it.

For the test case in this commit, there are 3 possible results.

Case 1:
CONFIG_A=y
# CONFIG_B is not set

Case 2:
# CONFIG_A is not set
CONFIG_B=y
CONFIG_C=y
# CONFIG_D is not set

Case 3:
# CONFIG_A is not set
CONFIG_B=y
# CONFIG_C is not set
CONFIG_D=y
CONFIG_E=y

So, this test iterates several times, and checks if the result is
either of the three.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Ulf Magnusson <ulfalizer@gmail.com>

+60
+33
scripts/kconfig/tests/rand_nested_choice/Kconfig
··· 1 + choice 2 + prompt "choice" 3 + 4 + config A 5 + bool "A" 6 + 7 + config B 8 + bool "B" 9 + 10 + if B 11 + choice 12 + prompt "sub choice" 13 + 14 + config C 15 + bool "C" 16 + 17 + config D 18 + bool "D" 19 + 20 + if D 21 + choice 22 + prompt "subsub choice" 23 + 24 + config E 25 + bool "E" 26 + 27 + endchoice 28 + endif # D 29 + 30 + endchoice 31 + endif # B 32 + 33 + endchoice
+16
scripts/kconfig/tests/rand_nested_choice/__init__.py
··· 1 + """ 2 + Set random values recursively in nested choices. 3 + 4 + Kconfig can create a choice-in-choice structure by using 'if' statement. 5 + randconfig should correctly set random choice values. 6 + 7 + Related Linux commit: 3b9a19e08960e5cdad5253998637653e592a3c29 8 + """ 9 + 10 + 11 + def test(conf): 12 + for i in range(20): 13 + assert conf.randconfig() == 0 14 + assert (conf.config_contains('expected_stdout0') or 15 + conf.config_contains('expected_stdout1') or 16 + conf.config_contains('expected_stdout2'))
+2
scripts/kconfig/tests/rand_nested_choice/expected_stdout0
··· 1 + CONFIG_A=y 2 + # CONFIG_B is not set
+4
scripts/kconfig/tests/rand_nested_choice/expected_stdout1
··· 1 + # CONFIG_A is not set 2 + CONFIG_B=y 3 + CONFIG_C=y 4 + # CONFIG_D is not set
+5
scripts/kconfig/tests/rand_nested_choice/expected_stdout2
··· 1 + # CONFIG_A is not set 2 + CONFIG_B=y 3 + # CONFIG_C is not set 4 + CONFIG_D=y 5 + CONFIG_E=y