From 7fca57e6ecc61062d6470fed3afd56e1697c823a Mon Sep 17 00:00:00 2001 From: Noam Cohen Date: Thu, 28 Nov 2024 20:13:17 +0100 Subject: [PATCH 1/2] coverage + fixes --- src/najaeda/najaeda/netlist.py | 28 ++++++++++++-------- test/najaeda/test_najaeda_netlist.py | 38 ++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src/najaeda/najaeda/netlist.py b/src/najaeda/najaeda/netlist.py index daf540ed..3003979b 100644 --- a/src/najaeda/najaeda/netlist.py +++ b/src/najaeda/najaeda/netlist.py @@ -264,10 +264,11 @@ def __str__(self) -> str: return str(self.inst) + " " + str(self.path) def get_child_instance(self, name: str): + childInst = self.inst.getModel().getInstance(name) + if childInst is None: + return None return Instance( - snl.SNLPath(self.path, self.inst.getModel().getInstance(name)), - self.inst.getModel().getInstance(name) - ) + snl.SNLPath(self.path, childInst), childInst) def get_child_instances(self): for inst in self.inst.getModel().getInstances(): @@ -294,10 +295,15 @@ def get_inst_term(self, name: str) -> InstTerm: def is_primitive(self) -> bool: return self.inst.getModel().isPrimitive() + def get_input_inst_terms(self): + for term in self.inst.getInstTerms(): + if term.getDirection() == snl.SNLTerm.Direction.Input: + yield InstTerm(self.path, term) + def get_output_inst_terms(self): for term in self.inst.getInstTerms(): if term.getDirection() == snl.SNLTerm.Direction.Output: - yield InstTerm(self.path.getHeadPath(), term) + yield InstTerm(self.path, term) def delete_instance(self, name: str): path = snl.SNLPath(self.path, self.inst.getModel().getInstance(name)) @@ -403,16 +409,16 @@ def create_net(self, name: str) -> Net: uniq = snl.SNLUniquifier(self.path) uniq_path = uniq.getPathUniqCollection() self.inst = tuple(uniq_path)[len(tuple(uniq_path)) - 1] - design = self.inst.getModel() - newSNLNet = snl.SNLScalarNet.create(design, name) + model = self.inst.getModel() + newSNLNet = snl.SNLScalarNet.create(model, name) return Net(self.path, newSNLNet) def create_bus_net(self, name: str, width: int, offset: int) -> list: uniq = snl.SNLUniquifier(self.path) uniq_path = uniq.getPathUniqCollection() self.inst = tuple(uniq_path)[len(tuple(uniq_path)) - 1] - design = self.inst.getModel() - newSNLNet = snl.SNLBusNet.create(design, width, offset, name) + model = self.inst.getModel() + newSNLNet = snl.SNLBusNet.create(model, width, offset, name) list = [] for i in range(width): list.append(Net(self.path, newSNLNet.getBit(i))) @@ -426,9 +432,9 @@ def get_term_list_for_bus(self, name: str) -> list: return list def get_net(self, name: str) -> Net: - for term in self.inst.getInstTerms(): - if term.getBitTerm().getName() == name: - return Net(self.path, term.getNet()) + net = self.inst.getModel().getNet(name) + if net is not None: + return Net(self.path, net) return None def get_net_list_for_bus(self, name: str) -> list: diff --git a/test/najaeda/test_najaeda_netlist.py b/test/najaeda/test_najaeda_netlist.py index df995f89..1689191e 100644 --- a/test/najaeda/test_najaeda_netlist.py +++ b/test/najaeda/test_najaeda_netlist.py @@ -82,6 +82,8 @@ def test_instance(self): instance.create_child_instance(self.submodel, "ins2") self.assertTrue(instance.get_number_of_child_instances() == 1) + self.assertIsNotNone(instance.get_child_instance("ins2")) + self.assertTrue(instance.get_child_instance("ins2").inst.getName() == "ins2") #Test bus term creation connection and disconnection instance3 = instance.create_child_instance(self.submodel, "ins3") @@ -95,8 +97,44 @@ def test_instance(self): self.assertTrue(len(netBitsForBus) == 5) for i in range(4): termsForBus[i].connect(netBitsForBus[i]) + + inputCount = 0 + for input in instance.get_input_inst_terms(): + self.assertTrue(input.is_input()) + self.assertFalse(input.is_output()) + inputCount += 1 + + self.assertTrue(inputCount == 6) + + outputCount = 0 + for output in instance.get_output_inst_terms(): + self.assertTrue(output.is_output()) + self.assertFalse(output.is_input()) + outputCount += 1 + + instance.create_input_term("I3") + instance.create_input_bus_term("I4", 4, -1) + instance.create_output_term("O2") + + inputCount = 0 + for input in instance.get_input_inst_terms(): + self.assertTrue(input.is_input()) + self.assertFalse(input.is_output()) + inputCount += 1 + + self.assertTrue(inputCount == 13) + + outputCount = 0 + for output in instance.get_output_inst_terms(): + self.assertTrue(output.is_output()) + self.assertFalse(output.is_input()) + outputCount += 1 + self.assertTrue(outputCount == 2) + self.assertIsNone(instance.get_net("created_net")) + instance.create_net("created_net") + self.assertIsNotNone(instance.get_net("created_net")) def test_equipotential(self): universe = snl.SNLUniverse.create() From 3dbd9a23264abf34478e93499424215c16dd247b Mon Sep 17 00:00:00 2001 From: Noam Cohen Date: Thu, 28 Nov 2024 20:38:34 +0100 Subject: [PATCH 2/2] lint fix --- src/najaeda/najaeda/netlist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/najaeda/najaeda/netlist.py b/src/najaeda/najaeda/netlist.py index 3003979b..2edcdab3 100644 --- a/src/najaeda/najaeda/netlist.py +++ b/src/najaeda/najaeda/netlist.py @@ -303,7 +303,7 @@ def get_input_inst_terms(self): def get_output_inst_terms(self): for term in self.inst.getInstTerms(): if term.getDirection() == snl.SNLTerm.Direction.Output: - yield InstTerm(self.path, term) + yield InstTerm(self.path, term) def delete_instance(self, name: str): path = snl.SNLPath(self.path, self.inst.getModel().getInstance(name))