def test_hook_inspect(self): """ Test hook interface for valid inspect behavior """ arch, hooks, entities = self._generate_architecture() # valid case rmsg = arch.hook({'inspect': hooks}) self.assertEqual(rmsg['reg']['state'], 255) self.assertEqual(rmsg['clk']['state'], 0) self.assertEqual(rmsg['rst']['state'], 0) self.assertEqual(rmsg['d_bus']['state'], 0) self.assertEqual(rmsg['q_bus']['state'], 0) self.assertEqual(rmsg['const_1']['state'], 1) # invalid missing hook in architecture rmsg = arch.hook({'inspect': ['test']}) self.assertTrue('error' in rmsg['test']) # invalid not an iterable type rmsg = arch.hook({'inspect': 7}) self.assertTrue('error' in rmsg['architecture-hooks-inspect']) # invalid not an iterable type rmsg = arch.hook({'inspect': None}) self.assertTrue('error' in rmsg['architecture-hooks-inspect']) # invalid hook type does not support inspect hooks.update( {'test': Adder(8, hooks['d_bus'], hooks['q_bus'], Bus(8))}) rmsg = arch.hook({'inspect': ['test']}) self.assertTrue('error' in rmsg['test']) # invalid string is not used as an iterable hooks.update( {'test': Adder(8, hooks['d_bus'], hooks['q_bus'], Bus(8))}) rmsg = arch.hook({'inspect': 'test'}) self.assertTrue('error' in rmsg['architecture-hooks-inspect']) # test with empty arch = Architecture(0.25, Clock(1), Reset(), None, OrderedDict(), OrderedDict()) arch.hook({'inspect': []})
def test_hook_generate(self): """ Test hook interface for valid generate behavior """ arch, hooks, entities = self._generate_architecture() # valid operation rmsg = arch.hook({'inspect': ['clk']}) self.assertEqual(rmsg['clk']['state'], 0) rmsg = arch.hook( {'generate': { 'name': 'clk', 'parameters': { 'state': 1 } }}) self.assertTrue('clk' in rmsg) self.assertTrue(rmsg['clk']['success']) rmsg = arch.hook({'inspect': ['clk']}) self.assertEqual(rmsg['clk']['state'], 1) # invalid (lack of entity name) rmsg = arch.hook( {'generate': { 'came': 'clk', 'parameters': { 'state': 0 } }}) self.assertTrue('error' in rmsg['architecture-hooks-generate']) rmsg = arch.hook({'inspect': ['clk']}) self.assertEqual(rmsg['clk']['state'], 1) # invalid hook is not in architecture rmsg = arch.hook( {'generate': { 'name': 'test', 'parameters': { 'state': 0 } }}) self.assertTrue('error' in rmsg['test']) # invalid, hook does not support generate rmsg = arch.hook( {'generate': { 'name': 'reg', 'parameters': { 'state': 0 } }}) self.assertTrue('error' in rmsg['reg']) rmsg = arch.hook({'inspect': ['reg']}) self.assertEqual(rmsg['reg']['state'], 255) # test with empty arch = Architecture(0.25, Clock(1), Reset(), None, OrderedDict(), OrderedDict()) rmsg = arch.hook( {'generate': { 'name': 'test', 'parameters': { 'state': 99 } }}) self.assertTrue('error' in rmsg['test'])