diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2017-11-03 03:17:58 +0100 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2017-11-03 03:24:56 +0100 |
| commit | b59b618a0ce85632742ff92a5be2bab690a75e42 (patch) | |
| tree | 7f6c737c88e660633193ee79376cab249e5aa85b | |
| parent | b3d65345e010628a100f6a9f0b0817b0bd462543 (diff) | |
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.
| -rw-r--r-- | kconfiglib.py | 4 | ||||
| -rw-r--r-- | tests/Kassignable | 105 | ||||
| -rw-r--r-- | testsuite.py | 66 |
3 files changed, 173 insertions, 2 deletions
diff --git a/kconfiglib.py b/kconfiglib.py index 8bb8957..612fc58 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -2726,8 +2726,10 @@ class Symbol(object): # vis == 1 + # Must be a tristate here, because bool m visibility gets promoted to y + if not rev_dep_val: - return (1,) if expr_value(self.weak_rev_dep) != 2 else (2,) + return (0, 1) if expr_value(self.weak_rev_dep) != 2 else (0, 2) if rev_dep_val == 2: return (2,) 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 diff --git a/testsuite.py b/testsuite.py index e750cbf..11d3ef6 100644 --- a/testsuite.py +++ b/testsuite.py @@ -415,7 +415,7 @@ def run_selftests(): except KconfigSyntaxError: pass else: - fail('expected eval_string("{}") to throw KconfigSyntaxError, ' \ + fail('expected eval_string("{}") to throw KconfigSyntaxError, ' "didn't".format(expr)) # The C implementation's parser can be pretty lax about syntax. Kconfiglib @@ -855,6 +855,70 @@ g assign_and_verify("HEX_m", "0x123") + print("Testing .assignable") + + c = Kconfig("Kconfiglib/tests/Kassignable") + + def verify_assignable_imp(item, assignable): + 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)) + + def verify_assignable(sym_name, assignable): + verify_assignable_imp(c.syms[sym_name], assignable) + + def verify_const_unassignable(sym_name): + verify_assignable_imp(c.const_syms[sym_name], ()) + + # Test with modules enabled first + c.modules.set_value(2) + + # Things that shouldn't be .assignable + verify_const_unassignable("n") + verify_const_unassignable("m") + verify_const_unassignable("y") + verify_const_unassignable("const") + verify_const_unassignable("UNAME_RELEASE") + verify_assignable("UNDEFINED", ()) + verify_assignable("NO_PROMPT", ()) + verify_assignable("STRING", ()) + verify_assignable("INT", ()) + verify_assignable("HEX", ()) + + # Non-selected symbols + verify_assignable("Y_VIS_BOOL", (0, 2)) + verify_assignable("M_VIS_BOOL", (0, 2)) # Visibility promoted + verify_assignable("N_VIS_BOOL", ( )) + verify_assignable("Y_VIS_TRI", (0, 1, 2)) + verify_assignable("M_VIS_TRI", (0, 1 )) + verify_assignable("N_VIS_TRI", ( )) + + # Symbols selected to y + verify_assignable("Y_SEL_Y_VIS_BOOL", (2,)) + verify_assignable("Y_SEL_M_VIS_BOOL", (2,)) # Visibility promoted + verify_assignable("Y_SEL_N_VIS_BOOL", ( )) + verify_assignable("Y_SEL_Y_VIS_TRI", (2,)) + verify_assignable("Y_SEL_M_VIS_TRI", (2,)) + verify_assignable("Y_SEL_N_VIS_TRI", ( )) + + # Symbols selected to m + verify_assignable("M_SEL_Y_VIS_BOOL", ( 2,)) # Value promoted + 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_N_VIS_TRI", ( )) + + print("Testing object relations") c = Kconfig("Kconfiglib/tests/Krelation") |
