Skip to content

Commit

Permalink
Adapted tests to basic block changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kc611 committed Jul 7, 2023
1 parent 7ce552e commit f04eeb9
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 33 deletions.
5 changes: 0 additions & 5 deletions numba_rvsdg/tests/test_byteflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def test_constructor(self):
begin=0,
end=8,
_jump_targets=(),
backedges=(),
)
self.assertEqual(block.name, "python_bytecode_block_0")
self.assertEqual(block.begin, 0)
Expand All @@ -134,7 +133,6 @@ def test_is_jump_target(self):
_jump_targets=(
name_gen.new_block_name(block_names.PYTHON_BYTECODE),
),
backedges=(),
)
self.assertEqual(block.jump_targets, ("python_bytecode_block_1",))
self.assertFalse(block.is_exiting)
Expand All @@ -146,7 +144,6 @@ def test_get_instructions(self):
begin=0,
end=8,
_jump_targets=(),
backedges=(),
)
expected = [
Instruction(
Expand Down Expand Up @@ -243,7 +240,6 @@ def test_build_basic_blocks(self):
begin=0,
end=10,
_jump_targets=(),
backedges=(),
)
}
)
Expand All @@ -267,7 +263,6 @@ def test_from_bytecode(self):
begin=0,
end=10,
_jump_targets=(),
backedges=(),
)
}
)
Expand Down
8 changes: 6 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,11 @@ 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)


x = TestBahmannFigures()
x.test_figure_3()
7 changes: 2 additions & 5 deletions numba_rvsdg/tests/test_scfg.py
Original file line number Diff line number Diff line change
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
22 changes: 11 additions & 11 deletions numba_rvsdg/tests/test_simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# flow = ByteFlow.from_bytecode(foo)
# #pprint(flow.scfg)
# flow = flow.restructure()
# flow.restructure()
# #pprint(flow.scfg)
# # pprint(rtsflow.scfg)
# ByteFlowRenderer().render_byteflow(flow).view()
Expand Down Expand Up @@ -42,7 +42,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 +57,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 +76,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 +95,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 +119,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 +143,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 +159,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 +173,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 All @@ -190,5 +190,5 @@ def foo(s, e):
self._run(foo, flow, {"s": 23, "e": 28})


if __name__ == "__main__":
unittest.main()
# if __name__ == "__main__":
# unittest.main()
6 changes: 3 additions & 3 deletions numba_rvsdg/tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ def test_backedge_not_exiting(self):
'1': ['2', '5']
'2': ['6']
'3': []
'4': ['1', '3']
'4': ['3', '1']
'5': ['4']
'6': ['4']
backedges:
Expand Down Expand Up @@ -810,7 +810,7 @@ def test_multi_back_edge_with_backedge_from_header(self):
'1': ['5', '2']
'2': ['6', '7']
'3': []
'4': ['1', '3']
'4': ['3', '1']
'5': ['4']
'6': ['4']
'7': ['4']
Expand Down Expand Up @@ -876,7 +876,7 @@ def test_double_exit(self):
'2': ['3', '6']
'3': ['7', '8']
'4': []
'5': ['1', '4']
'5': ['4', '1']
'6': ['5']
'7': ['5']
'8': ['5']
Expand Down
8 changes: 1 addition & 7 deletions numba_rvsdg/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,12 @@ def assertSCFGEqual(
# Add the jump targets as corresponding nodes in block mapping
# dictionary. Since order must be same we can simply add zip
# functionality as the correspondence function for nodes
for jt1, jt2 in zip(node.jump_targets, second_node.jump_targets):
for jt1, jt2 in zip(node._jump_targets, second_node._jump_targets):
if node.name == exiting:
continue
block_mapping[jt1] = jt2
stack.append(jt1)

for be1, be2 in zip(node.backedges, second_node.backedges):
if node.name == exiting:
continue
block_mapping[be1] = be2
stack.append(be1)

def assertYAMLEqual(
self, first_yaml: SCFG, second_yaml: SCFG, head_map: dict
):
Expand Down

0 comments on commit f04eeb9

Please sign in to comment.