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. --- testsuite.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) (limited to 'testsuite.py') 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") -- cgit v1.2.3