def test_build_sequence_branch(self) -> None: sequencer = DummySequencer() block = DummyInstructionBlock() delegator = DummySequencingElement() if_branch = DummySequencingElement() else_branch = DummySequencingElement() trigger = Trigger() condition = HardwareCondition(trigger) condition.build_sequence_branch(delegator, if_branch, else_branch, sequencer, {}, {}, {}, {}, instruction_block=block) self.assertEqual(2, len(block.embedded_blocks)) if_block = block.embedded_blocks[0] else_block = block.embedded_blocks[1] self.assertEqual( [ CJMPInstruction(trigger, InstructionPointer(if_block)), GOTOInstruction(InstructionPointer(else_block)) ], block.instructions, "The expected jump instruction were not generated by HardwareConditon." ) self.assertEqual( InstructionPointer(block, 2), if_block.return_ip, "The return address of the if branch block was set wrongly by HardwareConditon." ) self.assertEqual( InstructionPointer(block, 2), else_block.return_ip, "The return address of the else branch block was set wrongly by HardwareConditon." ) self.assertEqual( { if_block: [(if_branch, {}, {}, {}, {})], else_block: [(else_branch, {}, {}, {}, {})] }, sequencer.sequencing_stacks, "HardwareCondition did not correctly push the branch elements to the stack" )
def test_build_sequence_branch(self) -> None: sequencer = DummySequencer() block = DummyInstructionBlock() delegator = DummySequencingElement() if_branch = DummySequencingElement() else_branch = DummySequencingElement() trigger = Trigger() condition = HardwareCondition(trigger) condition.build_sequence_branch(delegator, if_branch, else_branch, sequencer, {}, {}, block) self.assertEqual(2, len(block.embedded_blocks)) if_block = block.embedded_blocks[0] else_block = block.embedded_blocks[1] self.assertEqual([CJMPInstruction(trigger, if_block, 0), GOTOInstruction(else_block, 0)], block.instructions, "The expected jump instruction were not generated by HardwareConditon.") self.assertEqual(InstructionPointer(block, 2), if_block.return_ip, "The return address of the if branch block was set wrongly by HardwareConditon.") self.assertEqual(InstructionPointer(block, 2), else_block.return_ip, "The return address of the else branch block was set wrongly by HardwareConditon.") self.assertEqual({if_block: [(if_branch, {}, {})], else_block: [(else_branch, {}, {})]}, sequencer.sequencing_stacks, "HardwareCondition did not correctly push the branch elements to the stack")