use of org.evosuite.graphs.cfg.ControlFlowEdge in project evosuite by EvoSuite.
the class ClassControlFlowGraph method importCFGEdges.
private void importCFGEdges(RawControlFlowGraph cfg, Map<BytecodeInstruction, CCFGCodeNode> temp) {
// add ControlFlowEdges as CCFGCodeEdges
for (ControlFlowEdge e : cfg.edgeSet()) {
if (e.isExceptionEdge())
continue;
CCFGCodeNode src = temp.get(cfg.getEdgeSource(e));
CCFGCodeNode target = temp.get(cfg.getEdgeTarget(e));
addEdge(src, target, new CCFGCodeEdge(e));
}
}
use of org.evosuite.graphs.cfg.ControlFlowEdge in project evosuite by EvoSuite.
the class ControlDependenceGraph method getAlternativeBlocks.
/**
* <p>getAlternativeBlocks</p>
*
* @param dependency a {@link org.evosuite.graphs.cfg.ControlDependency} object.
* @return a {@link java.util.Set} object.
*/
public Set<BasicBlock> getAlternativeBlocks(ControlDependency dependency) {
Set<BasicBlock> blocks = new LinkedHashSet<>();
Branch branch = dependency.getBranch();
BasicBlock block = branch.getInstruction().getBasicBlock();
for (ControlFlowEdge e : outgoingEdgesOf(block)) {
// TODO: Why can this be null?
if (e.getControlDependency() == null || e.getControlDependency().equals(dependency))
continue;
BasicBlock next = getEdgeTarget(e);
blocks.add(next);
getReachableBasicBlocks(blocks, next);
// blocks.addAll(getReachableBasicBlocks(next));
}
return blocks;
}
use of org.evosuite.graphs.cfg.ControlFlowEdge in project evosuite by EvoSuite.
the class ControlDependenceGraph method computeControlDependence.
private void computeControlDependence() {
ActualControlFlowGraph rcfg = cfg.computeReverseCFG();
DominatorTree<BasicBlock> dt = new DominatorTree<BasicBlock>(rcfg);
for (BasicBlock b : rcfg.vertexSet()) if (!b.isExitBlock()) {
logger.debug("DFs for: " + b.getName());
for (BasicBlock cd : dt.getDominatingFrontiers(b)) {
ControlFlowEdge orig = cfg.getEdge(cd, b);
if (!cd.isEntryBlock() && orig == null) {
// in for loops for example it can happen that cd and b
// were not directly adjacent to each other in the CFG
// but rather there were some intermediate nodes between
// them and the needed information is inside one of the
// edges
// from cd to the first intermediate node. more
// precisely cd is expected to be a branch and to have 2
// outgoing edges, one for evaluating to true (jumping)
// and one for false. one of them can be followed and b
// will eventually be reached, the other one can not be
// followed in that way. TODO TRY!
logger.debug("cd: " + cd.toString());
logger.debug("b: " + b.toString());
// TODO this is just for now! unsafe and probably not
// even correct!
Set<ControlFlowEdge> candidates = cfg.outgoingEdgesOf(cd);
if (candidates.size() < 2)
throw new IllegalStateException("unexpected");
boolean leadToB = false;
boolean skip = false;
for (ControlFlowEdge e : candidates) {
if (!e.hasControlDependency()) {
skip = true;
break;
}
if (cfg.leadsToNode(e, b)) {
if (leadToB)
orig = null;
// throw new
// IllegalStateException("unexpected");
leadToB = true;
orig = e;
}
}
if (skip)
continue;
if (!leadToB)
throw new IllegalStateException("unexpected");
}
if (orig == null)
logger.debug("orig still null!");
if (!addEdge(cd, b, new ControlFlowEdge(orig)))
throw new IllegalStateException("internal error while adding CD edge");
logger.debug(" " + cd.getName());
}
}
}
use of org.evosuite.graphs.cfg.ControlFlowEdge in project evosuite by EvoSuite.
the class ControlDependenceGraph method getReachableBasicBlocks.
private void getReachableBasicBlocks(Set<BasicBlock> blocks, BasicBlock start) {
for (ControlFlowEdge e : outgoingEdgesOf(start)) {
BasicBlock next = getEdgeTarget(e);
if (!blocks.contains(next)) {
blocks.add(next);
getReachableBasicBlocks(blocks, next);
// blocks.addAll(getReachableBasicBlocks(next));
}
}
// return blocks;
}
use of org.evosuite.graphs.cfg.ControlFlowEdge in project evosuite by EvoSuite.
the class ControlDependenceGraph method isDirectlyControlDependentOn.
/**
* Determines whether the given BasicBlock is directly control dependent on
* the given Branch. Meaning within this CDG there is an incoming
* ControlFlowEdge to this instructions BasicBlock holding the given Branch
* as it's branchInstruction.
*
* If b is null, it is assumed to be the root branch.
*
* If the given instruction is not known to this CDG an
* IllegalArgumentException is thrown.
*
* @param insBlock a {@link org.evosuite.graphs.cfg.BasicBlock} object.
* @param b a {@link org.evosuite.coverage.branch.Branch} object.
* @return a boolean.
*/
public boolean isDirectlyControlDependentOn(BasicBlock insBlock, Branch b) {
Set<ControlFlowEdge> incomming = incomingEdgesOf(insBlock);
if (incomming.size() == 1) {
for (ControlFlowEdge e : incomming) {
if (!e.hasControlDependency() && !e.isExceptionEdge()) {
return isDirectlyControlDependentOn(getEdgeSource(e), b);
}
}
}
boolean isRootDependent = isRootDependent(insBlock);
if (b == null)
return isRootDependent;
if (isRootDependent && b != null)
return false;
for (ControlFlowEdge e : incomming) {
Branch current = e.getBranchInstruction();
if (e.isExceptionEdge()) {
if (current != null)
throw new IllegalStateException("expect exception edges to have no BranchInstruction set");
else
continue;
}
if (current == null)
continue;
if (current.equals(b))
return true;
}
return false;
}
Aggregations