Mercurial > lcfOS
diff test/testgraph.py @ 284:05184b95fa16
Moved tests to seperate folder
author | Windel Bouwman |
---|---|
date | Fri, 15 Nov 2013 13:43:22 +0100 |
parents | python/testgraph.py@02385f62f250 |
children | 7b38782ed496 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/testgraph.py Fri Nov 15 13:43:22 2013 +0100 @@ -0,0 +1,81 @@ +#!/usr/bin/python + +import unittest +import graph +import interferencegraph +import flowgraph +import ir +from irmach import AbstractInstruction as AI +from target import Nop + + +class GraphTestCase(unittest.TestCase): + def testEdge(self): + g = graph.Graph() + n1 = graph.Node(g) + g.addNode(n1) + n2 = graph.Node(g) + g.addNode(n2) + g.addEdge(n1, n2) + self.assertTrue(g.hasEdge(n2, n1)) + self.assertTrue(g.hasEdge(n1, n2)) + g.delNode(n1) + g.delNode(n2) + + def testDegree(self): + g = graph.Graph() + n1 = graph.Node(g) + g.addNode(n1) + n2 = graph.Node(g) + g.addNode(n2) + n3 = graph.Node(g) + g.addNode(n3) + g.addEdge(n1, n2) + g.addEdge(n1, n3) + self.assertEqual(2, n1.Degree) + self.assertEqual(1, n2.Degree) + g.delNode(n2) + self.assertEqual(1, n1.Degree) + + +class DigraphTestCase(unittest.TestCase): + pass + + +class InterferenceGraphTestCase(unittest.TestCase): + def testNormalUse(self): + t1 = ir.Temp('t1') + t2 = ir.Temp('t2') + t3 = ir.Temp('t3') + t4 = ir.Temp('t4') + t5 = ir.Temp('t5') + t6 = ir.Temp('t6') + instrs = [] + instrs.append(AI(Nop, dst=[t1])) + instrs.append(AI(Nop, dst=[t2])) + instrs.append(AI(Nop, dst=[t3])) + cfg = flowgraph.FlowGraph(instrs) + ig = interferencegraph.InterferenceGraph(cfg) + + def testCombine(self): + t1 = ir.Temp('t1') + t2 = ir.Temp('t2') + t3 = ir.Temp('t3') + t4 = ir.Temp('t4') + instrs = [] + instrs.append(AI(Nop, dst=[t1])) + instrs.append(AI(Nop, dst=[t2])) + instrs.append(AI(Nop, dst=[t3])) + instrs.append(AI(Nop, dst=[t4], src=[t3])) + instrs.append(AI(Nop, src=[t4])) + instrs.append(AI(Nop, src=[t1])) + instrs.append(AI(Nop, src=[t2])) + cfg = flowgraph.FlowGraph(instrs) + ig = interferencegraph.InterferenceGraph(cfg) + ig.Combine(ig.getNode(t4), ig.getNode(t3)) + self.assertIs(ig.getNode(t4), ig.getNode(t3)) + + +if __name__ == '__main__': + unittest.main() +