From 840d65fe069297fb1d088b85e3164465ace4d467 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Sat, 28 Oct 2017 05:18:37 +0200 Subject: Test suite work, cleanup, const sym invalidation fix --- testsuite.py | 186 ++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 132 insertions(+), 54 deletions(-) (limited to 'testsuite.py') diff --git a/testsuite.py b/testsuite.py index 711a0fb..4af7c19 100644 --- a/testsuite.py +++ b/testsuite.py @@ -56,7 +56,7 @@ def fail(msg=None): global all_passed all_passed = False if msg is not None: - print("Fail: " + msg) + print("fail: " + msg) def verify(cond, msg): if not cond: @@ -587,6 +587,18 @@ choice c = kconfiglib.Config("Kconfiglib/tests/Krepr", warn=False) + verify_repr(c.n, """ + +""") + + verify_repr(c.m, """ + +""") + + verify_repr(c.y, """ + +""") + verify_repr(c.syms["UNDEFINED"], """ """) @@ -596,7 +608,13 @@ choice """) verify_repr(c.syms["VISIBLE"], """ - + +""") + + c.syms["VISIBLE"].set_value("y") + + verify_repr(c.syms["VISIBLE"], """ + """) verify_repr(c.syms["DIR_DEP_N"], """ @@ -612,7 +630,7 @@ choice """) verify_repr(c.syms["CHOICE_1"], """ - + """) verify_repr(c.modules, """ @@ -623,66 +641,72 @@ choice print("Testing Choice.__repr__()") verify_repr(c.named_choices["CHOICE"], """ - + """) c.named_choices["CHOICE"].set_value("y") verify_repr(c.named_choices["CHOICE"], """ - + """) c.syms["CHOICE_2"].set_value("y") verify_repr(c.named_choices["CHOICE"], """ - + +""") + + c.syms["CHOICE_1"].set_value("m") + + verify_repr(c.named_choices["CHOICE"], """ + """) verify_repr(c.syms["CHOICE_HOOK"].nodes[0].next.item, """ - + """) print("Testing MenuNode.__repr__()") verify_repr(c.syms["BASIC"].nodes[0], """ - + """) verify_repr(c.syms["DIR_DEP_N"].nodes[0], """ - + """) verify_repr(c.syms["MULTI_DEF"].nodes[0], """ - + """) verify_repr(c.syms["MULTI_DEF"].nodes[1], """ - + """) verify_repr(c.syms["MENUCONFIG"].nodes[0], """ - + """) verify_repr(c.named_choices["CHOICE"].nodes[0], """ - + """) verify_repr(c.syms["CHOICE_HOOK"].nodes[0].next, """ - + """) verify_repr(c.syms["NO_VISIBLE_IF_HOOK"].nodes[0].next, """ - + """) verify_repr(c.syms["VISIBLE_IF_HOOK"].nodes[0].next, """ - + """) verify_repr(c.syms["COMMENT_HOOK"].nodes[0].next, """ - + """) @@ -869,14 +893,14 @@ g def verify_menu_visibility(menu, no_module_vis, module_vis): c.modules.set_value("n") - menu_vis = kconfiglib.eval_expr(menu.node.dep) + menu_vis = kconfiglib.expr_value(menu.node.dep) verify(menu_vis == no_module_vis, "menu \"{}\" should have visibility '{}' without modules, " "has visibility '{}'" .format(menu.title, no_module_vis, menu_vis)) c.modules.set_value("y") - menu_vis = kconfiglib.eval_expr(menu.node.dep) + menu_vis = kconfiglib.expr_value(menu.node.dep) verify(menu_vis == module_vis, "menu \"{}\" should have visibility '{}' with modules, " "has visibility '{}'". @@ -939,14 +963,14 @@ g def verify_comment_visibility(comment, no_module_vis, module_vis): c.modules.set_value("n") # TODO: uninternalize - comment_vis = kconfiglib.eval_expr(comment.node.dep) + comment_vis = kconfiglib.expr_value(comment.node.dep) verify(comment_vis == no_module_vis, "comment \"{}\" should have visibility '{}' without " "modules, has visibility '{}'". format(comment.text, no_module_vis, comment_vis)) c.modules.set_value("y") - comment_vis = kconfiglib.eval_expr(comment.node.dep) + comment_vis = kconfiglib.expr_value(comment.node.dep) verify(comment_vis == module_vis, "comment \"{}\" should have visibility '{}' with " "modules, has visibility '{}'". @@ -1731,11 +1755,11 @@ def run_compatibility_tests(): # (generated by the C implementation) should be compared to ._config # (generated by us) after each invocation. all_arch_tests = [(test_load, False), - (test_config_absent, True), - (test_call_all, False), + (test_alldefconfig, True), + (test_sanity, False), (test_all_no, True), - (test_all_yes, True), (test_all_no_simpler, True), + (test_all_yes, True), # Needs to report success/failure for each arch/defconfig # combo, hence False. (test_defconfig, False)] @@ -1857,49 +1881,78 @@ def test_all_yes(conf, arch): else: shell("make allyesconfig") -def test_call_all(conf, arch): +def test_sanity(conf, arch): """ - Call all public methods on all symbols, choices, and TODO menu nodes for - all architectures to make sure we never crash or hang. (Nearly all public - methods: some are hard to test like this, but are exercised by other - tests.) + Do sanity checks on each configuration and call all public methods on all + symbols, choices, and menu nodes for all architectures to make sure we + never crash or hang. """ print("For {}...".format(arch)) + conf.modules + conf.defconfig_list conf.defconfig_filename - conf.mainmenu_text conf.enable_undef_warnings() conf.disable_undef_warnings() - conf.disable_warnings() conf.enable_warnings() + conf.disable_warnings() + conf.mainmenu_text conf.unset_values() # Python 2/3 compatible - for _, s in conf.syms.items(): - s.__str__() - s.__repr__() - s.assignable - s.type - s.str_value - s.tri_value - s.visibility - s.unset_value() + for _, sym in conf.syms.items(): + if sym.name != "UNAME_RELEASE": + verify(not sym.is_constant, sym.name + " in 'syms' and constant") + + verify(sym not in conf.const_syms, + sym.name + " in both 'syms' and 'const_syms'") + + for dep in sym._direct_dependents: + verify(not dep.is_constant, + "the constant symbol {} depends on {}" + .format(dep.name, sym.name)) + + sym.__repr__() + sym.__str__() + sym.assignable + conf.disable_warnings() + sym.set_value("y") + conf.enable_warnings() + sym.str_value + sym.tri_value + sym.type + sym.unset_value() + sym.user_str_value + sym.user_tri_value + sym.visibility + + for sym in conf.defined_syms: + verify(sym.nodes, sym.name + " is defined but lacks menu nodes") + + for _, sym in conf.const_syms.items(): + verify(sym.is_constant, + '"{}" is in const_syms but not marked constant' + .format(sym.name)) - # TODO: verify that constant symbols do not: - # 1) have a non-empty dep - # 2) have nodes + verify(not sym.nodes, + '"{}" is constant but has menu nodes' + .format(sym.name)) - # TODO: Look for weird stuff in the dictionaries + verify(not sym._direct_dependents, + '"{}" is constant but is a dependency of some symbol' + .format(sym.name)) - # TODO: infinite recursion action - #for _, s in conf.const_syms.items(): - # s.__str__() - # s.__repr__() - # s.assignable - # s.type - # s.value - # s.visibility - # s.unset_value() + sym.__repr__() + sym.__str__() + sym.assignable + conf.disable_warnings() + sym.set_value("y") + conf.enable_warnings() + sym.str_value + sym.tri_value + sym.type + sym.unset_value() + sym.visibility # Cheat with internals for c in conf._choices: @@ -1907,13 +1960,38 @@ def test_call_all(conf, arch): c.__repr__() c.str_value c.tri_value + c.user_str_value + c.user_tri_value c.assignable c.selection c.default_selection c.type c.visibility -def test_config_absent(conf, arch): + # Menu nodes + + node = conf.top_node + + while 1: + # Everything else should be well exercised elsewhere + node.__repr__() + + if node.list is not None: + node = node.list + + elif node.next is not None: + node = node.next + + else: + while node.parent is not None: + node = node.parent + if node.next is not None: + node = node.next + break + else: + break + +def test_alldefconfig(conf, arch): """ Verify that Kconfiglib generates the same .config as 'make alldefconfig', for each architecture -- cgit v1.2.3