def test_get_div(self): tree = ClockTree(self.dev) FixedClock(name='test', tree=self.tree, freq=123456) div = Divider(name='div', tree=self.tree, parent='test', div=2) self.assertEqual(div._get_div(), 2) div = Divider(name='div', tree=self.tree, parent='test', div_field=self.dev.TEST1.TESTA.A3) self.assertEqual(int(div._get_div()), 3) div = Divider(name='div', tree=self.tree, parent='test', div_field=self.dev.TEST1.TESTA.A3, div_type=Divider.POWER_OF_TWO) self.assertEqual(int(div._get_div()), 8) div = Divider(name='div', tree=self.tree, parent='test', div_field=self.dev.TEST1.TESTA.A3, table={ 3: 12, 4: 16 }) self.assertEqual(int(div._get_div()), 12) self.dev.TEST1.TESTA.A3.write(2) with self.assertRaises(InvalidDivider): div._get_div() div = Divider(name='div', tree=self.tree, parent='test', div_field=self.dev.TEST1.TESTA.A3, div_type=9999) with self.assertRaises(InvalidDivider): div._get_div() div = Divider(name='div', tree=self.tree, parent='test', get_div=ext_get_div) self.assertTrue(div.build()) self.assertEqual(int(div._get_div()), 3)
def test_build(self): div = Divider() self.assertFalse(div.build()) div = Divider(parent='test') self.assertFalse(div.build()) div = Divider(parent='test', div=2) self.assertTrue(div.build()) table = {0: 1, 1: 4, 2: 16} div = Divider(parent='test', table=table) self.assertFalse(div.build()) div = Divider(parent='test', table=table, div_field=self.dev.TEST1.TESTA.A3) self.assertTrue(div.build()) div = Divider(parent='test', table=table) self.assertFalse(div.build()) div = Divider(parent='test', div_field=self.dev.TEST1.TESTA.A3) self.assertTrue(div.build())