Skip to content

Commit

Permalink
Refactored the test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
kc611 committed Aug 2, 2023
1 parent a1f1316 commit adeeacf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 53 deletions.
28 changes: 14 additions & 14 deletions numba_rvsdg/tests/test_byteflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,29 +114,29 @@ def test_constructor(self):
name=name_gen.new_block_name(block_names.PYTHON_BYTECODE),
begin=0,
end=8,
_jump_targets=(),
backedges=(),
_jump_targets=[],
backedges=[],
)
self.assertEqual(block.name, "python_bytecode_block_0")
self.assertEqual(block.begin, 0)
self.assertEqual(block.end, 8)
self.assertFalse(block.fallthrough)
self.assertTrue(block.is_exiting)
self.assertEqual(block.jump_targets, ())
self.assertEqual(block.backedges, ())
self.assertEqual(block.jump_targets, [])
self.assertEqual(block.backedges, [])

def test_is_jump_target(self):
name_gen = NameGenerator()
block = PythonBytecodeBlock(
name=name_gen.new_block_name(block_names.PYTHON_BYTECODE),
begin=0,
end=8,
_jump_targets=(
_jump_targets=[
name_gen.new_block_name(block_names.PYTHON_BYTECODE),
),
backedges=(),
],
backedges=[],
)
self.assertEqual(block.jump_targets, ("python_bytecode_block_1",))
self.assertEqual(block.jump_targets, ["python_bytecode_block_1"])
self.assertFalse(block.is_exiting)

def test_get_instructions(self):
Expand All @@ -145,8 +145,8 @@ def test_get_instructions(self):
name=name_gen.new_block_name(block_names.PYTHON_BYTECODE),
begin=0,
end=8,
_jump_targets=(),
backedges=(),
_jump_targets=[],
backedges=[],
)
expected = [
Instruction(
Expand Down Expand Up @@ -242,8 +242,8 @@ def test_build_basic_blocks(self):
name=new_name,
begin=0,
end=10,
_jump_targets=(),
backedges=(),
_jump_targets=[],
backedges=[],
)
}
)
Expand All @@ -266,8 +266,8 @@ def test_from_bytecode(self):
name=new_name,
begin=0,
end=10,
_jump_targets=(),
backedges=(),
_jump_targets=[],
backedges=[],
)
}
)
Expand Down
4 changes: 2 additions & 2 deletions numba_rvsdg/tests/test_figures.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def test_figure_3(self):
flow = FlowInfo.from_bytecode(bc)
scfg = flow.build_basicblocks()
byteflow = ByteFlow(bc=bc, scfg=scfg)
byteflow = byteflow.restructure()
byteflow.restructure()

x, _ = SCFG.from_yaml(fig_3_yaml)
self.assertSCFGEqual(x, byteflow.scfg)
Expand Down Expand Up @@ -473,7 +473,7 @@ def test_figure_4(self):
flow = FlowInfo.from_bytecode(bc)
scfg = flow.build_basicblocks()
byteflow = ByteFlow(bc=bc, scfg=scfg)
byteflow = byteflow.restructure()
byteflow.restructure()

x, _ = SCFG.from_yaml(fig_4_yaml)
self.assertSCFGEqual(x, byteflow.scfg)
9 changes: 3 additions & 6 deletions numba_rvsdg/tests/test_scfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def test_scfg_iter(self):
block_0 = name_gen.new_block_name(block_names.BASIC)
block_1 = name_gen.new_block_name(block_names.BASIC)
expected = [
(block_0, BasicBlock(name=block_0, _jump_targets=(block_1,))),
(block_0, BasicBlock(name=block_0, _jump_targets=[block_1])),
(block_1, BasicBlock(name=block_1)),
]
scfg, _ = SCFG.from_yaml(
Expand Down Expand Up @@ -192,17 +192,14 @@ def foo(n):

def test_concealed_region_view_iter(self):
flow = ByteFlow.from_bytecode(self.foo)
restructured = flow._restructure_loop()
flow._restructure_loop()
expected = [
("python_bytecode_block_0", PythonBytecodeBlock),
("loop_region_0", RegionBlock),
("python_bytecode_block_3", PythonBytecodeBlock),
]
received = list(
(
(k, type(v))
for k, v in restructured.scfg.concealed_region_view.items()
)
((k, type(v)) for k, v in flow.scfg.concealed_region_view.items())
)
self.assertEqual(expected, received)

Expand Down
39 changes: 8 additions & 31 deletions numba_rvsdg/tests/test_simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,6 @@
from numba_rvsdg.tests.simulator import Simulator
import unittest

# flow = ByteFlow.from_bytecode(foo)
# #pprint(flow.scfg)
# flow = flow.restructure()
# #pprint(flow.scfg)
# # pprint(rtsflow.scfg)
# ByteFlowRenderer().render_byteflow(flow).view()
# print(dis(foo))
#
# sim = Simulator(flow, foo.__globals__)
# ret = sim.run(dict(x=1))
# assert ret == foo(x=1)
#
# #sim = Simulator(flow, foo.__globals__)
# #ret = sim.run(dict(x=100))
# #assert ret == foo(x=100)

# You can use the following snipppet to visually debug the restructured
# byteflow:
#
# ByteFlowRenderer().render_byteflow(flow).view()
#
#


class SimulatorTest(unittest.TestCase):
def _run(self, func, flow, kwargs):
Expand All @@ -42,7 +19,7 @@ def foo(x):
return c

flow = ByteFlow.from_bytecode(foo)
flow = flow.restructure()
flow.restructure()

# if case
self._run(foo, flow, {"x": 1})
Expand All @@ -57,7 +34,7 @@ def foo(x):
return c

flow = ByteFlow.from_bytecode(foo)
flow = flow.restructure()
flow.restructure()

# loop bypass case
self._run(foo, flow, {"x": 0})
Expand All @@ -76,7 +53,7 @@ def foo(x):
return c

flow = ByteFlow.from_bytecode(foo)
flow = flow.restructure()
flow.restructure()

# loop bypass case
self._run(foo, flow, {"x": 0})
Expand All @@ -95,7 +72,7 @@ def foo(x):
return c

flow = ByteFlow.from_bytecode(foo)
flow = flow.restructure()
flow.restructure()

# loop bypass case
self._run(foo, flow, {"x": 0})
Expand All @@ -119,7 +96,7 @@ def foo(x):
return c

flow = ByteFlow.from_bytecode(foo)
flow = flow.restructure()
flow.restructure()

# no loop
self._run(foo, flow, {"x": 0})
Expand All @@ -143,7 +120,7 @@ def foo(x):
return c

flow = ByteFlow.from_bytecode(foo)
flow = flow.restructure()
flow.restructure()

# loop bypass
self._run(foo, flow, {"x": 0})
Expand All @@ -159,7 +136,7 @@ def foo(x, y):
return (x > 0 and x < 10) or (y > 0 and y < 10)

flow = ByteFlow.from_bytecode(foo)
flow = flow.restructure()
flow.restructure()

self._run(foo, flow, {"x": 5, "y": 5})

Expand All @@ -173,7 +150,7 @@ def foo(s, e):
return c

flow = ByteFlow.from_bytecode(foo)
flow = flow.restructure()
flow.restructure()

# no looping
self._run(foo, flow, {"s": 0, "e": 0})
Expand Down

0 comments on commit adeeacf

Please sign in to comment.