Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
def test_add_edge_weak(graph):
    """Tests adding a weak edge to a graph."""
    graph.add_edge(graph["main_function"], ComparisonGraph.Side.LEFT,
                   ComparisonGraph.Edge("strength", "app/main.c", 61))
    graph.add_edge(graph["main_function"], ComparisonGraph.Side.RIGHT,
                   ComparisonGraph.Edge("strength.void", "app/main.c", 61))
    left_succesor_names = [
        edge.target_name for edge in graph["main_function"].successors[
            ComparisonGraph.Side.LEFT]
    ]
    right_successor_names = [
        edge.target_name for edge in graph["main_function"].successors[
            ComparisonGraph.Side.RIGHT]
    ]
    assert "strength" in left_succesor_names
    assert "strength.void" in right_successor_names
    assert "strength" not in right_successor_names
    assert "strength.void" not in left_succesor_names
    assert "strength.void" in [
        edge.target_name for edge in graph._normalize_edge_cache
    ]
Ejemplo n.º 4
0
def test_add_edge_strong(graph):
    """Tests adding a strong edge to a graph."""
    for side in ComparisonGraph.Side:
        graph.add_edge(graph["main_function"], side,
                       ComparisonGraph.Edge("missing", "app/main.c", 61))
        assert "missing" in [
            edge.target_name
            for edge in graph["main_function"].successors[side]
        ]
        assert "missing" not in [
            edge.target_name for edge in graph._normalize_edge_cache
        ]
Ejemplo n.º 5
0
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