def test_root_node_is_not_in_a_function(): """Test that if root node is not in a function, then nothing is dominated.""" builder = programl.GraphBuilder() a = builder.AddNode(type=programl_pb2.Node.STATEMENT) annotator = dominator_tree.DominatorTreeAnnotator(builder.proto) g = builder.g annotator.Annotate(g, root_node=a) assert g.graph["data_flow_steps"] == 0
def test_Annotate_g1(g1: programl_pb2.ProgramGraph): """Test dominator tree for a small """ annotator = dominator_tree.DominatorTreeAnnotator(g1) g = annotator.g annotator.Annotate(g, root_node=0) assert g.graph["data_flow_positive_node_count"] == 4 assert g.graph["data_flow_steps"] == 2 # Features assert g.nodes[0]["x"] == [-1, 1] assert g.nodes[1]["x"] == [-1, 0] assert g.nodes[2]["x"] == [-1, 0] assert g.nodes[3]["x"] == [-1, 0] assert g.nodes[4]["x"] == [-1, 0] # Labels assert g.nodes[0]["y"] == dominator_tree.DOMINATED assert g.nodes[1]["y"] == dominator_tree.DOMINATED assert g.nodes[2]["y"] == dominator_tree.DOMINATED assert g.nodes[3]["y"] == dominator_tree.DOMINATED assert g.nodes[4]["y"] == dominator_tree.NOT_DOMINATED
def test_MakeAnnotated_real_protos(real_proto: programl_pb2.ProgramGraph, ): """Opaque black-box test of reachability annotator.""" annotator = dominator_tree.DominatorTreeAnnotator(real_proto) annotated = annotator.MakeAnnotated(10) assert len(annotated.graphs) <= 10