def test_absort_graph(graph): """Tests the absorb graph function, especially whether vertex replacing works properly.""" new_graph = ComparisonGraph() # This vertex should replace the old one (which is assumed equal). new_graph["missing"] = ComparisonGraph.Vertex(dup("missing"), Result.Kind.NOT_EQUAL, dup("app/mod.c"), dup(665)) # This vertex should not replace the old one. new_graph["do_check"] = ComparisonGraph.Vertex(dup("do_check"), Result.Kind.EQUAL, dup("app/mod.c"), dup(665)) # This vertex should replace the old one (it has more successors). new_graph["strength"] = ComparisonGraph.Vertex(dup("strength"), Result.Kind.NOT_EQUAL, dup("app/test.h"), (5, 5)) for side in ComparisonGraph.Side: new_graph.add_edge(new_graph["strength"], side, ComparisonGraph.Edge("missing", "app/w.c", 6)) new_graph.add_edge(new_graph["strength"], side, ComparisonGraph.Edge("main_function", "app/w.c", 7)) graph.absorb_graph(new_graph) assert graph["missing"].result == Result.Kind.NOT_EQUAL assert graph["do_check"].result == Result.Kind.NOT_EQUAL assert graph["strength"].result == Result.Kind.NOT_EQUAL
def vertices(): yield [ ComparisonGraph.Vertex(dup("f"), Result.Kind.EQUAL, ("/test/f1/1.ll", "/test/f2/2.ll")), ComparisonGraph.Vertex(dup("h"), Result.Kind.NOT_EQUAL, ("/test/f1/1.ll", "/test/f2/3.ll")), ComparisonGraph.Vertex(dup("g"), Result.Kind.NOT_EQUAL, ("/test/f1/1.ll", "/test/f2/2.ll")) ]
def graph_uncachable(): """Graph used to test the marking of uncachable vertices.""" graph = ComparisonGraph() graph["f1"] = ComparisonGraph.Vertex(dup("f1"), Result.Kind.EQUAL, dup("app/f1.c"), dup(10)) graph["f2"] = ComparisonGraph.Vertex(dup("f2"), Result.Kind.EQUAL, dup("include/h1.h"), dup(20)) graph["f3"] = ComparisonGraph.Vertex(dup("f3"), Result.Kind.ASSUMED_EQUAL, dup("app/f2.c"), dup(20)) for side in ComparisonGraph.Side: graph.add_edge(graph["f1"], side, ComparisonGraph.Edge("f2", "app/f1.c", 11)) graph.add_edge(graph["f2"], side, ComparisonGraph.Edge("f3", "include/h1.c", 21)) yield graph
def test_add_vertex_strong(graph): """Tests adding a strong vertex to the graph.""" graph["test"] = ComparisonGraph.Vertex(dup("test"), Result.Kind.EQUAL, dup("app/main.c"), (81, 82)) assert "test" in graph.vertices assert graph["test"].names == dup("test") assert graph["test"].result == Result.Kind.EQUAL assert graph["test"].files == dup("app/main.c") assert graph["test"].lines == (81, 82) assert graph["test"] not in graph._weak_vertex_cache
def test_add_vertex_weak(graph): """Tests adding a weak vertex to the graph.""" graph["test.void"] = ComparisonGraph.Vertex(("test", "test.void"), Result.Kind.EQUAL, dup("app/main.c"), (81, 82)) assert "test.void" in graph.vertices assert graph["test.void"].names == ("test", "test.void") assert graph["test.void"].result == Result.Kind.EQUAL assert graph["test.void"].files == dup("app/main.c") assert graph["test.void"].lines == (81, 82) assert graph["test.void"] in graph._weak_vertex_cache
def test_cachability_reset_after_absorb(graph_uncachable): """Tests whether the cachable attribute is reset to true after replacing the assumed equal vertex causing the uncachability.""" graph_uncachable.normalize() graph_uncachable.populate_predecessor_lists() graph_uncachable.mark_uncachable_from_assumed_equal() assert not graph_uncachable["f2"].cachable graph_to_merge = ComparisonGraph() graph_to_merge["f3"] = ComparisonGraph.Vertex(dup("f3"), Result.Kind.NOT_EQUAL, dup("app/f2.c"), dup(20)) graph_uncachable.absorb_graph(graph_to_merge) assert graph_uncachable["f2"].cachable
def graph(): g = ComparisonGraph() # Vertices g["main_function"] = ComparisonGraph.Vertex(dup("main_function"), Result.Kind.EQUAL, dup("app/main.c"), dup(51)) g["side_function"] = ComparisonGraph.Vertex(dup("side_function"), Result.Kind.EQUAL, dup("app/main.c"), dup(255)) g["do_check"] = ComparisonGraph.Vertex(dup("do_check"), Result.Kind.NOT_EQUAL, dup("app/main.c"), dup(105)) g["missing"] = ComparisonGraph.Vertex(dup("missing"), Result.Kind.ASSUMED_EQUAL, dup("app/mod.c"), dup(665)) g["looping"] = ComparisonGraph.Vertex(dup("looping"), Result.Kind.EQUAL, dup("app/main.c"), (81, 82)) # Weak variant of "strength" function vertex (e.g. void-returning on the # right side) g["strength.void"] = ComparisonGraph.Vertex(("strength", "strength.void"), Result.Kind.EQUAL, dup("app/main.c"), (5, 5)) # Strong variant of "strength" functin vertex g["strength"] = ComparisonGraph.Vertex( ("strength", "strength"), Result.Kind.EQUAL, dup("app/test.h"), (5, 5)) # Non-function differences g["do_check"].nonfun_diffs.append( ComparisonGraph.SyntaxDiff( "MACRO", "do_check", dup([ { "function": "_MACRO", "file": "test.c", "line": 1 }, { "function": "__MACRO", "file": "test.c", "line": 2 }, { "function": "___MACRO", "file": "test.c", "line": 3 }, ]), ("5", "5L"))) g["do_check"].nonfun_diffs.append( ComparisonGraph.TypeDiff( "struct file", "do_check", dup([ { "function": "struct file (type)", "file": "include/file.h", "line": 121 }, ]), dup("include/file.h"), dup(121))) # Edges for side in ComparisonGraph.Side: g.add_edge(g["main_function"], side, ComparisonGraph.Edge("do_check", "app/main.c", 58)) g.add_edge(g["main_function"], side, ComparisonGraph.Edge("side_function", "app/main.c", 59)) g.add_edge(g["do_check"], side, ComparisonGraph.Edge("missing", "app/main.c", 60)) g.add_edge(g["do_check"], side, ComparisonGraph.Edge("looping", "app/main.c", 74)) g.add_edge(g["looping"], side, ComparisonGraph.Edge("main_function", "app/main.c", 85)) # Strong call of "strength" g.add_edge(g["looping"], side, ComparisonGraph.Edge("strength", "app/main.c", 86)) g.add_edge(g["strength"], side, ComparisonGraph.Edge("missing", "app/w.c", 6)) # Weak call of "strength" g.add_edge(g["side_function"], ComparisonGraph.Side.LEFT, ComparisonGraph.Edge("strength", "app/main.c", 260)) g.add_edge(g["side_function"], ComparisonGraph.Side.RIGHT, ComparisonGraph.Edge("strength.void", "app/main.c", 260)) yield g