aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2018-03-13 05:12:10 -0400
committerMasahiro Yamada <yamada.masahiro@socionext.com>2018-03-25 13:04:04 -0400
commit3e4888c2e3d77d70edb905364cd70059a52a1343 (patch)
tree2ae6e086d4442cc153be0e4d73c787fd3c98c45c
parentbeaaddb625400e4a561d2d8443f9df2aa3f9a899 (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>
-rw-r--r--scripts/kconfig/tests/rand_nested_choice/Kconfig33
-rw-r--r--scripts/kconfig/tests/rand_nested_choice/__init__.py16
-rw-r--r--scripts/kconfig/tests/rand_nested_choice/expected_stdout02
-rw-r--r--scripts/kconfig/tests/rand_nested_choice/expected_stdout14
-rw-r--r--scripts/kconfig/tests/rand_nested_choice/expected_stdout25
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 @@
1choice
2 prompt "choice"
3
4config A
5 bool "A"
6
7config B
8 bool "B"
9
10if B
11choice
12 prompt "sub choice"
13
14config C
15 bool "C"
16
17config D
18 bool "D"
19
20if D
21choice
22 prompt "subsub choice"
23
24config E
25 bool "E"
26
27endchoice
28endif # D
29
30endchoice
31endif # B
32
33endchoice
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"""
2Set random values recursively in nested choices.
3
4Kconfig can create a choice-in-choice structure by using 'if' statement.
5randconfig should correctly set random choice values.
6
7Related Linux commit: 3b9a19e08960e5cdad5253998637653e592a3c29
8"""
9
10
11def 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 @@
1CONFIG_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
2CONFIG_B=y
3CONFIG_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
2CONFIG_B=y
3# CONFIG_C is not set
4CONFIG_D=y
5CONFIG_E=y