From b59b618a0ce85632742ff92a5be2bab690a75e42 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Fri, 3 Nov 2017 03:17:58 +0100 Subject: Add initial selftests for .assignable Comprehensive selftests are important here, because the allno/yesconfig.py scripts only check the upper and lower bound, and allnoconfig disables modules. Found a bug for non-selected m-visible tristates, where n didn't show up in sym.assignable. Everything matches menuconfig after fixing that. Still need to test symbols in choices with different modes, imply, and .assignable for choices. --- tests/Kassignable | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 tests/Kassignable (limited to 'tests/Kassignable') diff --git a/tests/Kassignable b/tests/Kassignable new file mode 100644 index 0000000..97cb322 --- /dev/null +++ b/tests/Kassignable @@ -0,0 +1,105 @@ +config MODULES + bool "modules" + option modules + + +# Things that should never be .assignable + +if UNDEFINED && "const" +endif + +config NO_PROMPT + +config STRING + string "string" + +config INT + int "int" + +config HEX + hex "hex" + + +# Non-selected symbols + +config Y_VIS_BOOL + bool "y-vis bool" + +config M_VIS_BOOL + bool "m-vis bool" if m + +config N_VIS_BOOL + bool "n-vis bool" if n + +config Y_VIS_TRI + tristate "y-vis tri" + +config M_VIS_TRI + tristate "m-vis tri" if m + +config N_VIS_TRI + tristate "n-vis tri" if n + + +# Symbols selected to y + +config Y_SELECTOR + def_tristate y + + select Y_SEL_Y_VIS_BOOL + select Y_SEL_M_VIS_BOOL + select Y_SEL_N_VIS_BOOL + + select Y_SEL_Y_VIS_TRI + select Y_SEL_M_VIS_TRI + select Y_SEL_N_VIS_TRI + +config Y_SEL_Y_VIS_BOOL + bool "y-sel y-vis bool" + +config Y_SEL_M_VIS_BOOL + bool "y-sel m-vis bool" if m + +config Y_SEL_N_VIS_BOOL + bool "y-sel n-vis bool" if n + +config Y_SEL_Y_VIS_TRI + tristate "y-sel y-vis tri" + +config Y_SEL_M_VIS_TRI + bool "y-sel m-vis tri" if m + +config Y_SEL_N_VIS_TRI + bool "y-sel n-vis tri" if n + + +# Symbols selected to m + +config M_SELECTOR + def_tristate m + + select M_SEL_Y_VIS_BOOL + select M_SEL_M_VIS_BOOL + select M_SEL_N_VIS_BOOL + + select M_SEL_Y_VIS_TRI + select M_SEL_M_VIS_TRI + select M_SEL_N_VIS_TRI + +config M_SEL_Y_VIS_BOOL + bool "m-sel y-vis bool" + +config M_SEL_M_VIS_BOOL + bool "m-sel m-vis bool" if m + +config M_SEL_N_VIS_BOOL + bool "m-sel n-vis bool" if n + +config M_SEL_Y_VIS_TRI + tristate "m-sel y-vis tri" + +config M_SEL_M_VIS_TRI + tristate "m-sel m-vis tri" if m + +config M_SEL_N_VIS_TRI + tristate "m-sel n-vis tri" if n -- cgit v1.2.3 From b74cd303f763fbdc1307830b6333354d65733ef8 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Fri, 3 Nov 2017 05:19:54 +0100 Subject: Test .assignable for imply, find C menuconfig bug A tristate implied to y can't be set to m. Other than that, imply doesn't affect assignable values. Fix some copy-paste type errors too. In the C menuconfig, a tristate with m visibility implied to y gets stuck if you change it with space. Look into that later. Test case: config MODULES def_bool y option modules config Y_IMPLIER def_tristate y imply Y_IMP_M_VIS_TRI config Y_IMP_M_VIS_TRI tristate "y-imp m-vis tri" if m --- tests/Kassignable | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- testsuite.py | 16 +++++++++++++ 2 files changed, 82 insertions(+), 2 deletions(-) (limited to 'tests/Kassignable') diff --git a/tests/Kassignable b/tests/Kassignable index 97cb322..e600a39 100644 --- a/tests/Kassignable +++ b/tests/Kassignable @@ -67,10 +67,10 @@ config Y_SEL_Y_VIS_TRI tristate "y-sel y-vis tri" config Y_SEL_M_VIS_TRI - bool "y-sel m-vis tri" if m + tristate "y-sel m-vis tri" if m config Y_SEL_N_VIS_TRI - bool "y-sel n-vis tri" if n + tristate "y-sel n-vis tri" if n # Symbols selected to m @@ -103,3 +103,67 @@ config M_SEL_M_VIS_TRI config M_SEL_N_VIS_TRI tristate "m-sel n-vis tri" if n + + +# Symbols implied to y + +config Y_IMPLIER + def_tristate y + + imply Y_IMP_Y_VIS_BOOL + imply Y_IMP_M_VIS_BOOL + imply Y_IMP_N_VIS_BOOL + + imply Y_IMP_Y_VIS_TRI + imply Y_IMP_M_VIS_TRI + imply Y_IMP_N_VIS_TRI + +config Y_IMP_Y_VIS_BOOL + bool "y-imp y-vis bool" + +config Y_IMP_M_VIS_BOOL + bool "y-imp m-vis bool" if m + +config Y_IMP_N_VIS_BOOL + bool "y-imp n-vis bool" if n + +config Y_IMP_Y_VIS_TRI + tristate "y-imp y-vis tri" + +config Y_IMP_M_VIS_TRI + tristate "y-imp m-vis tri" if m + +config Y_IMP_N_VIS_TRI + tristate "y-imp n-vis tri" if n + + +# Symbols implied to m (never affects assignable values) + +config M_IMPLIER + def_tristate m + + imply M_IMP_Y_VIS_BOOL + imply M_IMP_M_VIS_BOOL + imply M_IMP_N_VIS_BOOL + + imply M_IMP_Y_VIS_TRI + imply M_IMP_M_VIS_TRI + imply M_IMP_N_VIS_TRI + +config M_IMP_Y_VIS_BOOL + bool "m-imp y-vis bool" + +config M_IMP_M_VIS_BOOL + bool "m-imp m-vis bool" if m + +config M_IMP_N_VIS_BOOL + bool "m-imp n-vis bool" if n + +config M_IMP_Y_VIS_TRI + tristate "m-imp y-vis tri" + +config M_IMP_M_VIS_TRI + tristate "m-imp m-vis tri" if m + +config M_IMP_N_VIS_TRI + tristate "m-imp n-vis tri" if n diff --git a/testsuite.py b/testsuite.py index 11d3ef6..17c7f9e 100644 --- a/testsuite.py +++ b/testsuite.py @@ -918,6 +918,22 @@ g verify_assignable("M_SEL_M_VIS_TRI", (1 ,)) verify_assignable("M_SEL_N_VIS_TRI", ( )) + # Symbols implied to y + verify_assignable("Y_IMP_Y_VIS_BOOL", (0, 2)) + verify_assignable("Y_IMP_M_VIS_BOOL", (0, 2)) # Visibility promoted + verify_assignable("Y_IMP_N_VIS_BOOL", ( )) + verify_assignable("Y_IMP_Y_VIS_TRI", (0, 2)) # m removed by imply + verify_assignable("Y_IMP_M_VIS_TRI", (0, 2)) # m promoted to y by imply + verify_assignable("Y_IMP_N_VIS_TRI", ( )) + + # Symbols implied to m (never affects assignable values) + verify_assignable("M_IMP_Y_VIS_BOOL", (0, 2)) + verify_assignable("M_IMP_M_VIS_BOOL", (0, 2)) # Visibility promoted + verify_assignable("M_IMP_N_VIS_BOOL", ( )) + verify_assignable("M_IMP_Y_VIS_TRI", (0, 1, 2)) # m removed by imply + verify_assignable("M_IMP_M_VIS_TRI", (0, 1 )) # m promoted to y by imply + verify_assignable("M_IMP_N_VIS_TRI", ( )) + print("Testing object relations") -- cgit v1.2.3 From d1ea825a1d9d8bfc9496926b6a800ad58581b09a Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Fri, 3 Nov 2017 06:13:23 +0100 Subject: Add .assignable selftests for choice symbols --- tests/Kassignable | 34 ++++++++++++++++++++++++++++++++++ testsuite.py | 44 ++++++++++++++++++++++++++++++++------------ 2 files changed, 66 insertions(+), 12 deletions(-) (limited to 'tests/Kassignable') diff --git a/tests/Kassignable b/tests/Kassignable index e600a39..fe88abe 100644 --- a/tests/Kassignable +++ b/tests/Kassignable @@ -167,3 +167,37 @@ config M_IMP_M_VIS_TRI config M_IMP_N_VIS_TRI tristate "m-imp n-vis tri" if n + + +# Symbols in y-mode choice + +choice Y_CHOICE + bool "y-mode choice" + +config Y_CHOICE_BOOL + bool "y-mode choice bool" + +config Y_CHOICE_TRISTATE + tristate "y-mode choice tristate" + +config Y_CHOICE_N_VIS_TRISTATE + tristate "y-mode choice tristate invisible" if n + +endchoice + + +# Symbols in m/y-mode choice + +choice MY_CHOICE + tristate "m/y-mode choice" + +config MY_CHOICE_BOOL + bool "m/y-mode choice bool" + +config MY_CHOICE_TRISTATE + tristate "m/y-mode choice tristate" + +config MY_CHOICE_N_VIS_TRISTATE + tristate "m/y-mode choice tristate invisible" if n + +endchoice diff --git a/testsuite.py b/testsuite.py index bd62c91..dd0fe7c 100644 --- a/testsuite.py +++ b/testsuite.py @@ -859,25 +859,28 @@ g c = Kconfig("Kconfiglib/tests/Kassignable") - def verify_assignable_imp(item, assignable): + def verify_assignable_imp(item, assignable, test_assign): verify(item.assignable == assignable, "Incorrect assignable values for {}. " "Should be {}, was {}." .format(item.name, assignable, item.assignable)) - # Verify that the values can actually be assigned too - for val in item.assignable: - item.set_value(val) - verify(item.tri_value == val, - "Unable to set {} to {}, even though " - "it was in .assignable" - .format(item.name, val)) + # Verify that the values can actually be assigned too, except for + # choices in y mode, where setting the user value to n doesn't change + # the value + if test_assign: + for val in item.assignable: + item.set_value(val) + verify(item.tri_value == val, + "Unable to set {} to {}, even though " + "it was in .assignable" + .format(item.name, val)) - def verify_assignable(sym_name, assignable): - verify_assignable_imp(c.syms[sym_name], assignable) + def verify_assignable(sym_name, assignable, test_assign=True): + verify_assignable_imp(c.syms[sym_name], assignable, test_assign) def verify_const_unassignable(sym_name): - verify_assignable_imp(c.const_syms[sym_name], ()) + verify_assignable_imp(c.const_syms[sym_name], (), False) # Test with modules enabled first c.modules.set_value(2) @@ -915,7 +918,7 @@ g verify_assignable("M_SEL_M_VIS_BOOL", ( 2,)) # Visibility/value promoted verify_assignable("M_SEL_N_VIS_BOOL", ( )) verify_assignable("M_SEL_Y_VIS_TRI", (1, 2 )) - verify_assignable("M_SEL_M_VIS_TRI", (1 ,)) + verify_assignable("M_SEL_M_VIS_TRI", (1, )) verify_assignable("M_SEL_N_VIS_TRI", ( )) # Symbols implied to y @@ -934,6 +937,23 @@ g verify_assignable("M_IMP_M_VIS_TRI", (0, 1 )) verify_assignable("M_IMP_N_VIS_TRI", ( )) + # Symbols in y-mode choice + verify_assignable("Y_CHOICE_BOOL", (0, 2), test_assign=False) + verify_assignable("Y_CHOICE_TRISTATE", (0, 2), test_assign=False) + verify_assignable("Y_CHOICE_N_VIS_TRISTATE", ( )) + + # Symbols in m/y-mode choice, starting out in m mode + verify_assignable("MY_CHOICE_BOOL", ( )) + verify_assignable("MY_CHOICE_TRISTATE", (0, 1)) + verify_assignable("MY_CHOICE_N_VIS_TRISTATE", ( )) + + c.named_choices["MY_CHOICE"].set_value(2) + + # Symbols in m/y-mode choice, now in y mode + verify_assignable("MY_CHOICE_BOOL", (0, 2), test_assign=False) + verify_assignable("MY_CHOICE_TRISTATE", (0, 2), test_assign=False) + verify_assignable("MY_CHOICE_N_VIS_TRISTATE", ( )) + print("Testing object relations") -- cgit v1.2.3 From de2e7f766f247d4e8701dcca9fc921f1d0230463 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Fri, 3 Nov 2017 06:40:40 +0100 Subject: Test Choice.assignable, fix for optional choices Could never return 0 as a valid assignable value previously. --- kconfiglib.py | 2 +- tests/Kassignable | 26 ++++++++++++++++++++++++++ testsuite.py | 17 ++++++++++++++--- 3 files changed, 41 insertions(+), 4 deletions(-) (limited to 'tests/Kassignable') diff --git a/kconfiglib.py b/kconfiglib.py index 612fc58..ae86b2a 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -3190,7 +3190,7 @@ class Choice(object): if vis == 2: if not self.is_optional: return (2,) if self.type == BOOL else (1, 2) - return (2,) + return (0, 2) if self.type == BOOL else (0, 1, 2) # vis == 1 diff --git a/tests/Kassignable b/tests/Kassignable index fe88abe..f134a74 100644 --- a/tests/Kassignable +++ b/tests/Kassignable @@ -201,3 +201,29 @@ config MY_CHOICE_N_VIS_TRISTATE tristate "m/y-mode choice tristate invisible" if n endchoice + + +# Choices with some other possible modes + +choice NMY_CHOICE + tristate "n/m/y-mode choice" + optional +endchoice + +choice NY_CHOICE + bool "n/y-mode choice" + optional +endchoice + +choice NM_CHOICE + tristate "n/m-mode choice" if m + optional +endchoice + +choice M_CHOICE + tristate "m-mode choice" if m +endchoice + +choice N_CHOICE + tristate "n-mode choice" if n +endchoice diff --git a/testsuite.py b/testsuite.py index dd0fe7c..3abcbb0 100644 --- a/testsuite.py +++ b/testsuite.py @@ -879,12 +879,12 @@ g def verify_assignable(sym_name, assignable, test_assign=True): verify_assignable_imp(c.syms[sym_name], assignable, test_assign) - def verify_const_unassignable(sym_name): - verify_assignable_imp(c.const_syms[sym_name], (), False) - # Test with modules enabled first c.modules.set_value(2) + def verify_const_unassignable(sym_name): + verify_assignable_imp(c.const_syms[sym_name], (), False) + # Things that shouldn't be .assignable verify_const_unassignable("n") verify_const_unassignable("m") @@ -954,6 +954,17 @@ g verify_assignable("MY_CHOICE_TRISTATE", (0, 2), test_assign=False) verify_assignable("MY_CHOICE_N_VIS_TRISTATE", ( )) + def verify_choice_assignable(choice_name, assignable): + verify_assignable_imp(c.named_choices[choice_name], assignable, True) + + verify_choice_assignable("Y_CHOICE", ( 2,)) + verify_choice_assignable("MY_CHOICE", ( 1, 2 )) + verify_choice_assignable("NMY_CHOICE", (0, 1, 2 )) + verify_choice_assignable("NY_CHOICE", (0, 2 )) + verify_choice_assignable("NM_CHOICE", (0, 1 )) + verify_choice_assignable("M_CHOICE", ( 1, )) + verify_choice_assignable("N_CHOICE", ( )) + print("Testing object relations") -- cgit v1.2.3