diff options
author | Masahiro Yamada <yamada.masahiro@socionext.com> | 2018-03-13 05:12:10 -0400 |
---|---|---|
committer | Masahiro Yamada <yamada.masahiro@socionext.com> | 2018-03-25 13:04:04 -0400 |
commit | 3e4888c2e3d77d70edb905364cd70059a52a1343 (patch) | |
tree | 2ae6e086d4442cc153be0e4d73c787fd3c98c45c | |
parent | beaaddb625400e4a561d2d8443f9df2aa3f9a899 (diff) |
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>
5 files changed, 60 insertions, 0 deletions
diff --git a/scripts/kconfig/tests/rand_nested_choice/Kconfig b/scripts/kconfig/tests/rand_nested_choice/Kconfig new file mode 100644 index 000000000000..c591d512929f --- /dev/null +++ b/scripts/kconfig/tests/rand_nested_choice/Kconfig | |||
@@ -0,0 +1,33 @@ | |||
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 | ||
diff --git a/scripts/kconfig/tests/rand_nested_choice/__init__.py b/scripts/kconfig/tests/rand_nested_choice/__init__.py new file mode 100644 index 000000000000..e729a4e85218 --- /dev/null +++ b/scripts/kconfig/tests/rand_nested_choice/__init__.py | |||
@@ -0,0 +1,16 @@ | |||
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')) | ||
diff --git a/scripts/kconfig/tests/rand_nested_choice/expected_stdout0 b/scripts/kconfig/tests/rand_nested_choice/expected_stdout0 new file mode 100644 index 000000000000..05450f3d4eb5 --- /dev/null +++ b/scripts/kconfig/tests/rand_nested_choice/expected_stdout0 | |||
@@ -0,0 +1,2 @@ | |||
1 | CONFIG_A=y | ||
2 | # CONFIG_B is not set | ||
diff --git a/scripts/kconfig/tests/rand_nested_choice/expected_stdout1 b/scripts/kconfig/tests/rand_nested_choice/expected_stdout1 new file mode 100644 index 000000000000..37ab29584157 --- /dev/null +++ b/scripts/kconfig/tests/rand_nested_choice/expected_stdout1 | |||
@@ -0,0 +1,4 @@ | |||
1 | # CONFIG_A is not set | ||
2 | CONFIG_B=y | ||
3 | CONFIG_C=y | ||
4 | # CONFIG_D is not set | ||
diff --git a/scripts/kconfig/tests/rand_nested_choice/expected_stdout2 b/scripts/kconfig/tests/rand_nested_choice/expected_stdout2 new file mode 100644 index 000000000000..849ff47e9848 --- /dev/null +++ b/scripts/kconfig/tests/rand_nested_choice/expected_stdout2 | |||
@@ -0,0 +1,5 @@ | |||
1 | # CONFIG_A is not set | ||
2 | CONFIG_B=y | ||
3 | # CONFIG_C is not set | ||
4 | CONFIG_D=y | ||
5 | CONFIG_E=y | ||