| 1 | from rpython.flowspace.model import * |
| 2 | import py |
| 3 | |
| 4 | def test_mingraph(): |
| 5 | g = FunctionGraph("g", Block([])) |
| 6 | g.startblock.closeblock(Link([Constant(1)], g.returnblock)) |
| 7 | checkgraph(g) |
| 8 | |
| 9 | def template(): |
| 10 | g = FunctionGraph("g", Block([])) |
| 11 | g.startblock.closeblock(Link([Constant(1)], g.returnblock)) |
| 12 | checkgraph(g) |
| 13 | py.test.raises(AssertionError, checkgraph, g) |
| 14 | |
| 15 | |
| 16 | def test_exitlessblocknotexitblock(): |
| 17 | g = FunctionGraph("g", Block([])) |
| 18 | py.test.raises(AssertionError, checkgraph, g) |
| 19 | |
| 20 | |
| 21 | def test_nonvariableinputarg(): |
| 22 | b = Block([Constant(1)]) |
| 23 | g = FunctionGraph("g", b) |
| 24 | g.startblock.closeblock(Link([Constant(1)], g.returnblock)) |
| 25 | |
| 26 | py.test.raises(AssertionError, checkgraph, g) |
| 27 | |
| 28 | def test_multiplydefinedvars(): |
| 29 | v = Variable() |
| 30 | g = FunctionGraph("g", Block([v, v])) |
| 31 | g.startblock.closeblock(Link([v], g.returnblock)) |
| 32 | py.test.raises(AssertionError, checkgraph, g) |
| 33 | |
| 34 | v = Variable() |
| 35 | b = Block([v]) |
| 36 | b.operations.append(SpaceOperation("add", [Constant(1), Constant(2)], v)) |
| 37 | g = FunctionGraph("g", b) |
| 38 | g.startblock.closeblock(Link([v], g.returnblock)) |
| 39 | |
| 40 | py.test.raises(AssertionError, checkgraph, g) |
| 41 | |
| 42 | def test_varinmorethanoneblock(): |
| 43 | v = Variable() |
| 44 | g = FunctionGraph("g", Block([])) |
| 45 | g.startblock.operations.append(SpaceOperation("pos", [Constant(1)], v)) |
| 46 | b = Block([v]) |
| 47 | g.startblock.closeblock(Link([v], b)) |
| 48 | b.closeblock(Link([v], g.returnblock)) |
| 49 | py.test.raises(AssertionError, checkgraph, g) |
| 50 | |
| 51 | def test_useundefinedvar(): |
| 52 | v = Variable() |
| 53 | g = FunctionGraph("g", Block([])) |
| 54 | g.startblock.closeblock(Link([v], g.returnblock)) |
| 55 | py.test.raises(AssertionError, checkgraph, g) |
| 56 | |
| 57 | v = Variable() |
| 58 | g = FunctionGraph("g", Block([])) |
| 59 | g.startblock.exitswitch = v |
| 60 | g.startblock.closeblock(Link([Constant(1)], g.returnblock)) |
| 61 | py.test.raises(AssertionError, checkgraph, g) |
| 62 | |
| 63 | def test_invalid_arg(): |
| 64 | v = Variable() |
| 65 | g = FunctionGraph("g", Block([])) |
| 66 | g.startblock.operations.append(SpaceOperation("pos", [1], v)) |
| 67 | g.startblock.closeblock(Link([v], g.returnblock)) |
| 68 | py.test.raises(AssertionError, checkgraph, g) |
| 69 | |
| 70 | def test_invalid_links(): |
| 71 | g = FunctionGraph("g", Block([])) |
| 72 | g.startblock.closeblock(Link([Constant(1)], g.returnblock), Link([Constant(1)], g.returnblock)) |
| 73 | py.test.raises(AssertionError, checkgraph, g) |
| 74 | |
| 75 | v = Variable() |
| 76 | g = FunctionGraph("g", Block([v])) |
| 77 | g.startblock.exitswitch = v |
| 78 | g.startblock.closeblock(Link([Constant(1)], g.returnblock, True), |
| 79 | Link([Constant(1)], g.returnblock, True)) |
| 80 | py.test.raises(AssertionError, checkgraph, g) |
| 81 | |
| 82 | v = Variable() |
| 83 | g = FunctionGraph("g", Block([v])) |
| 84 | g.startblock.exitswitch = v |
| 85 | g.startblock.closeblock(Link([Constant(1)], g.returnblock)) |
| 86 | py.test.raises(AssertionError, checkgraph, g) |
| 87 |