52 lines
1.6 KiB
Java
52 lines
1.6 KiB
Java
|
package ch.usi.inf.sp.dom;
|
||
|
|
||
|
import ch.usi.inf.sp.cfg.BasicBlock;
|
||
|
|
||
|
import java.util.List;
|
||
|
|
||
|
import static org.junit.jupiter.api.Assertions.*;
|
||
|
|
||
|
/**
|
||
|
* These are static methods used in unit tests to assert properties on DominatorTrees.
|
||
|
*/
|
||
|
public class DominatorTreeAssertions {
|
||
|
|
||
|
public static void assertAllNodesMapToTheirBlocks(DominatorTree t) {
|
||
|
for (DominatorTreeNode n : t.getNodes()) {
|
||
|
assertSame(n, t.getNodeForBlock(n.getBlock()));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static void assertNodesHaveCorrectNumberOfParents(DominatorTree t) {
|
||
|
for (DominatorTreeNode node : t.getNodes()) {
|
||
|
if (node==t.getRoot()) {
|
||
|
assertEquals(0, node.getInEdges().size());
|
||
|
} else {
|
||
|
assertEquals(1, node.getInEdges().size());
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static void assertChildrenPointToParent(DominatorTree t) {
|
||
|
for (DominatorTreeNode parent : t.getNodes()) {
|
||
|
for (DominanceEdge e : parent.getOutEdges()) {
|
||
|
DominatorTreeNode child = e.getTo();
|
||
|
assertSame(parent, child.getInEdges().get(0).getFrom());
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static void assertPathToRoot(DominatorTree t, List<BasicBlock> pathToRoot) {
|
||
|
DominatorTreeNode child = null;
|
||
|
for (BasicBlock b: pathToRoot) {
|
||
|
DominatorTreeNode node = t.getNodeForBlock(b);
|
||
|
assertSame(b, node.getBlock());
|
||
|
if (child!=null) {
|
||
|
assertEquals(b, child.getInEdges().get(0).getFrom().getBlock());
|
||
|
}
|
||
|
child = node;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|