Skip to content

Commit 47ad168

Browse files
committed
kconfig: tests: add a test for randconfig with dependent choices
Since commit 3b9a19e ("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 09d5873 ("kconfig: allow only 'config', 'comment', and 'if' inside 'choice'") disallowed the nested choice structure, we must still keep 3b9a19e 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 3b9a19e 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 3b9a19e, 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 <[email protected]>
1 parent c9aa7d8 commit 47ad168

File tree

5 files changed

+78
-0
lines changed

5 files changed

+78
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# Automatically generated file; DO NOT EDIT.
3+
# Main menu
4+
#
5+
CONFIG_A=y
6+
# CONFIG_B is not set
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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

0 commit comments

Comments
 (0)