@Test public void testAddInterProceduralEdge(){ BytecodeInstruction cfg1stmt1 = testingUtils.mockNewStatement(className,"reverse()"); BytecodeInstruction cfg1stmt2 = testingUtils.mockNewStatement(className,"reverse()"); BytecodeInstruction cfg1stmt3 = testingUtils.mockNewStatement(className,"reverse()"); BytecodeInstruction cfg2stmt1 = testingUtils.mockNewStatement(className,"sum()"); BytecodeInstruction cfg2stmt2 = testingUtils.mockNewStatement(className,"sum()"); BytecodeInstruction cfg2stmt3 = testingUtils.mockNewStatement(className,"sum()"); BytecodeInstruction cfg2stmt4 = testingUtils.mockNewStatement(className,"sum()"); RawControlFlowGraph realRCFG1 = new BotsingRawControlFlowGraph(BotsingTestGenerationContext.getInstance().getClassLoaderForSUT(),"testClass","testMethod",0); RawControlFlowGraph rcfg1 = Mockito.spy(realRCFG1); rcfg1.addVertex(cfg1stmt1); rcfg1.addVertex(cfg1stmt2); rcfg1.addVertex(cfg1stmt3); BytecodeInstruction[][] edges = {{cfg1stmt1,cfg1stmt2},{cfg1stmt2,cfg1stmt3}}; testingUtils.addMockedEdge(edges,rcfg1); RawControlFlowGraph realRCFG2 = new BotsingRawControlFlowGraph(BotsingTestGenerationContext.getInstance().getClassLoaderForSUT(),"testClass","testMethod",0); RawControlFlowGraph rcfg2 = Mockito.spy(realRCFG2); rcfg1.addVertex(cfg2stmt1); rcfg1.addVertex(cfg2stmt2); rcfg1.addVertex(cfg2stmt3); rcfg1.addVertex(cfg2stmt4); BytecodeInstruction[][] edges2 = {{cfg2stmt1,cfg2stmt2},{cfg2stmt1,cfg2stmt3},{cfg2stmt1,cfg2stmt4}}; testingUtils.addMockedEdge(edges2,rcfg2); BotsingRawControlFlowGraph rawInterProceduralGraph = new BotsingRawControlFlowGraph(BotsingTestGenerationContext.getInstance().getClassLoaderForSUT(),"testClass","testMethod",0); rawInterProceduralGraph.clone(rcfg1); rawInterProceduralGraph.clone(rcfg2); Set<BytecodeInstruction> exitpoints = new HashSet<>(); exitpoints.add(cfg2stmt2); Mockito.doReturn(true).when(cfg2stmt3).isThrow(); exitpoints.add(cfg2stmt3); exitpoints.add(cfg2stmt4); rawInterProceduralGraph.addInterProceduralEdge(cfg1stmt2,cfg2stmt1,exitpoints); assertEquals(7,rawInterProceduralGraph.edgeCount()); assertFalse(rawInterProceduralGraph.containsEdge(cfg1stmt2,cfg1stmt3)); assertTrue(rawInterProceduralGraph.containsEdge(cfg2stmt2,cfg1stmt3)); assertFalse(rawInterProceduralGraph.containsEdge(cfg2stmt3,cfg1stmt3)); assertTrue(rawInterProceduralGraph.containsEdge(cfg2stmt4,cfg1stmt3)); }
public void addInterProceduralEdge(BytecodeInstruction src, BytecodeInstruction target, Set<BytecodeInstruction> targetGraphExitPoints) { Set<ControlFlowEdge> outgoingEdgesOfSrc = this.outgoingEdgesOf(src); boolean alreadyRedirected = false; for(BytecodeInstruction exitPoint : targetGraphExitPoints){ if(exitPoint.isThrow()){ LOG.debug("{} is a THROW. We omitted it for now",exitPoint); continue; } if(!alreadyRedirected){ for(ControlFlowEdge outgoingEdge: outgoingEdgesOfSrc){ this.redirectEdgeSource(outgoingEdge,exitPoint); } alreadyRedirected = true; }else{ for(ControlFlowEdge outgoingEdge: outgoingEdgesOfSrc){ this.addEdge(exitPoint,this.getEdgeTarget(outgoingEdge)); } } } if(!alreadyRedirected){ LOG.warn("method "+target.getMethodName()+" does not have any exit point"); } this.addEdge(src, target, false); }
BotsingRawControlFlowGraph extends RawControlFlowGraph { public void addInterProceduralEdge(BytecodeInstruction src, BytecodeInstruction target, Set<BytecodeInstruction> targetGraphExitPoints) { Set<ControlFlowEdge> outgoingEdgesOfSrc = this.outgoingEdgesOf(src); boolean alreadyRedirected = false; for(BytecodeInstruction exitPoint : targetGraphExitPoints){ if(exitPoint.isThrow()){ LOG.debug("{} is a THROW. We omitted it for now",exitPoint); continue; } if(!alreadyRedirected){ for(ControlFlowEdge outgoingEdge: outgoingEdgesOfSrc){ this.redirectEdgeSource(outgoingEdge,exitPoint); } alreadyRedirected = true; }else{ for(ControlFlowEdge outgoingEdge: outgoingEdgesOfSrc){ this.addEdge(exitPoint,this.getEdgeTarget(outgoingEdge)); } } } if(!alreadyRedirected){ LOG.warn("method "+target.getMethodName()+" does not have any exit point"); } this.addEdge(src, target, false); } }
BotsingRawControlFlowGraph extends RawControlFlowGraph { public void addInterProceduralEdge(BytecodeInstruction src, BytecodeInstruction target, Set<BytecodeInstruction> targetGraphExitPoints) { Set<ControlFlowEdge> outgoingEdgesOfSrc = this.outgoingEdgesOf(src); boolean alreadyRedirected = false; for(BytecodeInstruction exitPoint : targetGraphExitPoints){ if(exitPoint.isThrow()){ LOG.debug("{} is a THROW. We omitted it for now",exitPoint); continue; } if(!alreadyRedirected){ for(ControlFlowEdge outgoingEdge: outgoingEdgesOfSrc){ this.redirectEdgeSource(outgoingEdge,exitPoint); } alreadyRedirected = true; }else{ for(ControlFlowEdge outgoingEdge: outgoingEdgesOfSrc){ this.addEdge(exitPoint,this.getEdgeTarget(outgoingEdge)); } } } if(!alreadyRedirected){ LOG.warn("method "+target.getMethodName()+" does not have any exit point"); } this.addEdge(src, target, false); } BotsingRawControlFlowGraph(ClassLoader classLoader, String className, String methodName, int access); }
BotsingRawControlFlowGraph extends RawControlFlowGraph { public void addInterProceduralEdge(BytecodeInstruction src, BytecodeInstruction target, Set<BytecodeInstruction> targetGraphExitPoints) { Set<ControlFlowEdge> outgoingEdgesOfSrc = this.outgoingEdgesOf(src); boolean alreadyRedirected = false; for(BytecodeInstruction exitPoint : targetGraphExitPoints){ if(exitPoint.isThrow()){ LOG.debug("{} is a THROW. We omitted it for now",exitPoint); continue; } if(!alreadyRedirected){ for(ControlFlowEdge outgoingEdge: outgoingEdgesOfSrc){ this.redirectEdgeSource(outgoingEdge,exitPoint); } alreadyRedirected = true; }else{ for(ControlFlowEdge outgoingEdge: outgoingEdgesOfSrc){ this.addEdge(exitPoint,this.getEdgeTarget(outgoingEdge)); } } } if(!alreadyRedirected){ LOG.warn("method "+target.getMethodName()+" does not have any exit point"); } this.addEdge(src, target, false); } BotsingRawControlFlowGraph(ClassLoader classLoader, String className, String methodName, int access); void clone(RawControlFlowGraph cfg); void addInterProceduralEdge(BytecodeInstruction src, BytecodeInstruction target, Set<BytecodeInstruction> targetGraphExitPoints); void addGeneralEntryPoint(BytecodeInstruction src); @Override BasicBlock determineBasicBlockFor(BytecodeInstruction instruction); void cloneAsNewNode(BytecodeInstruction source, RawControlFlowGraph cfg); void addEdges(BytecodeInstruction src,BytecodeInstruction target, boolean isException); }
BotsingRawControlFlowGraph extends RawControlFlowGraph { public void addInterProceduralEdge(BytecodeInstruction src, BytecodeInstruction target, Set<BytecodeInstruction> targetGraphExitPoints) { Set<ControlFlowEdge> outgoingEdgesOfSrc = this.outgoingEdgesOf(src); boolean alreadyRedirected = false; for(BytecodeInstruction exitPoint : targetGraphExitPoints){ if(exitPoint.isThrow()){ LOG.debug("{} is a THROW. We omitted it for now",exitPoint); continue; } if(!alreadyRedirected){ for(ControlFlowEdge outgoingEdge: outgoingEdgesOfSrc){ this.redirectEdgeSource(outgoingEdge,exitPoint); } alreadyRedirected = true; }else{ for(ControlFlowEdge outgoingEdge: outgoingEdgesOfSrc){ this.addEdge(exitPoint,this.getEdgeTarget(outgoingEdge)); } } } if(!alreadyRedirected){ LOG.warn("method "+target.getMethodName()+" does not have any exit point"); } this.addEdge(src, target, false); } BotsingRawControlFlowGraph(ClassLoader classLoader, String className, String methodName, int access); void clone(RawControlFlowGraph cfg); void addInterProceduralEdge(BytecodeInstruction src, BytecodeInstruction target, Set<BytecodeInstruction> targetGraphExitPoints); void addGeneralEntryPoint(BytecodeInstruction src); @Override BasicBlock determineBasicBlockFor(BytecodeInstruction instruction); void cloneAsNewNode(BytecodeInstruction source, RawControlFlowGraph cfg); void addEdges(BytecodeInstruction src,BytecodeInstruction target, boolean isException);  }