Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coverage #162

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions src/najaeda/najaeda/netlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
)
self.equi = snl.SNLEquipotential(ito)

def __eq__(self, value):
return self.equi == value.equi

def get_inst_terms(self):
for term in self.equi.getInstTermOccurrences():
yield InstTerm(
Expand Down Expand Up @@ -50,6 +53,32 @@
def __eq__(self, value):
return self.net == value.net and self.path == value.path

def __ne__(self, value):
return not self == value

def __lt__(self, value):
if self.path != value.path:
return self.path < value.path
return self.net < value.net

Check warning on line 62 in src/najaeda/najaeda/netlist.py

View check run for this annotation

Codecov / codecov/patch

src/najaeda/najaeda/netlist.py#L62

Added line #L62 was not covered by tests

def __le__(self, value):
if self.path != value.path:
return self.path < value.path
return self.net <= value.net

Check warning on line 67 in src/najaeda/najaeda/netlist.py

View check run for this annotation

Codecov / codecov/patch

src/najaeda/najaeda/netlist.py#L67

Added line #L67 was not covered by tests

def __gt__(self, value):
if self.path != value.path:
return self.path > value.path
return self.net > value.net

Check warning on line 72 in src/najaeda/najaeda/netlist.py

View check run for this annotation

Codecov / codecov/patch

src/najaeda/najaeda/netlist.py#L72

Added line #L72 was not covered by tests

def __ge__(self, value):
if self.path != value.path:
return self.path > value.path
return self.net >= value.net

Check warning on line 77 in src/najaeda/najaeda/netlist.py

View check run for this annotation

Codecov / codecov/patch

src/najaeda/najaeda/netlist.py#L77

Added line #L77 was not covered by tests

def __str__(self):
return str(self.net)

def get_name(self) -> str:
return self.net.getName()

Expand All @@ -67,7 +96,7 @@
self.term = term

def __eq__(self, other) -> bool:
return self.path == other.path and self.term == other.term
return self.term == other.term

def __ne__(self, other) -> bool:
return not self == other
Expand Down Expand Up @@ -151,11 +180,9 @@
return Net(self.path, self.term.getNet())

def get_instance(self):
inst = self.term.getInstance()
path = snl.SNLPath(self.path, inst)
return Instance(path, inst)
return Instance(self.path, self.term.getInstance())

def get_flat_fanout(self) -> Equipotential:
def get_flat_fanout(self):
return self.get_equipotential().get_all_leaf_readers()

def get_equipotential(self) -> Equipotential:
Expand Down Expand Up @@ -233,6 +260,9 @@
def __eq__(self, other) -> bool:
return self.inst == other.inst and self.path == other.path

def __str__(self) -> str:
return str(self.inst) + " " + str(self.path)

Check warning on line 264 in src/najaeda/najaeda/netlist.py

View check run for this annotation

Codecov / codecov/patch

src/najaeda/najaeda/netlist.py#L264

Added line #L264 was not covered by tests

def get_child_instance(self, name: str):
return Instance(
snl.SNLPath(self.path, self.inst.getModel().getInstance(name)),
Expand Down
79 changes: 79 additions & 0 deletions test/najaeda/test_najaeda_netlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,85 @@
instance.get_inst_term("I0").connect(netlist.Net(path0, i0_net))
self.assertTrue(instance.get_inst_term("I0").get_net() == netlist.Net(path1, i0_net))

netlistNet1 = netlist.Net(path1, i0_net)
netlistNet2 = netlist.Net(path2, i0_net_sub)
self.assertTrue(netlistNet1 != netlistNet2)
self.assertTrue(netlistNet2 == netlistNet2)
self.assertTrue(netlistNet1 == netlist.Net(path1, i0_net))
self.assertTrue(netlistNet2 == netlist.Net(path2, i0_net_sub))
self.assertTrue(netlistNet1 < netlistNet2)
self.assertTrue(netlistNet1 <= netlistNet2)
self.assertTrue(netlistNet2 > netlistNet1)
self.assertTrue(netlistNet2 >= netlistNet1)
print(netlistNet1)

def testTopTerm(self):
universe = snl.SNLUniverse.create()
db = snl.SNLDB.create(universe)
lib = snl.SNLLibrary.create(db)
self.primitives = snl.SNLLibrary.createPrimitives(db)
self.top = snl.SNLDesign.create(lib)
universe.setTopDesign(self.top)
self.i0 = snl.SNLScalarTerm.create(self.top, snl.SNLTerm.Direction.Input, "I0")
self.i1 = snl.SNLScalarTerm.create(self.top, snl.SNLTerm.Direction.Input, "I1")

top_term = netlist.TopTerm(self.i0)
top_term2 = netlist.TopTerm(self.i1)

self.assertTrue(top_term == top_term)
self.assertTrue(top_term != top_term2)
self.assertTrue(top_term < top_term2)
self.assertTrue(top_term <= top_term2)
self.assertTrue(top_term2 > top_term)
self.assertTrue(top_term2 >= top_term)
print(top_term)

def testInstTerm(self):
universe = snl.SNLUniverse.create()
db = snl.SNLDB.create(universe)
lib = snl.SNLLibrary.create(db)
self.primitives = snl.SNLLibrary.createPrimitives(db)
self.top = snl.SNLDesign.create(lib)
universe.setTopDesign(self.top)
self.model = snl.SNLDesign.create(lib, "model")
self.submodel = snl.SNLDesign.createPrimitive(self.primitives, "submodel")
self.i0 = snl.SNLScalarTerm.create(self.model, snl.SNLTerm.Direction.Input, "I0")
self.i1 = snl.SNLBusTerm.create(self.model, snl.SNLTerm.Direction.Input, 4, 0, "I1")
self.o = snl.SNLScalarTerm.create(self.model, snl.SNLTerm.Direction.Output, "O")
self.i0sub = snl.SNLScalarTerm.create(self.submodel, snl.SNLTerm.Direction.Input, "I0")
self.i1sub = snl.SNLBusTerm.create(self.submodel, snl.SNLTerm.Direction.Input, 4, 0, "I1")
self.osub = snl.SNLScalarTerm.create(self.submodel, snl.SNLTerm.Direction.Output, "O")
ins2 = snl.SNLInstance.create(self.model, self.submodel, "ins2")
ins1 = snl.SNLInstance.create(self.top, self.model, "ins1")

path0 = snl.SNLPath()
path1 = snl.SNLPath(path0, ins1)
path2 = snl.SNLPath(path1, ins2)
instance = netlist.Instance(path1, ins1)
instTerm0 = instance.get_inst_term("I0")
instTerm1 = instance.get_inst_term("I1")
instance2 = netlist.Instance(path2, ins2)
inst2Term0 = instance2.get_inst_term("I0")
inst2Term1 = instance2.get_inst_term("I1")

self.assertTrue(instTerm0 == instTerm0)
self.assertTrue(instTerm0 != instTerm1)
self.assertTrue(instTerm0 < instTerm1)
self.assertTrue(instTerm0 <= instTerm1)
self.assertTrue(instTerm1 > instTerm0)
self.assertTrue(instTerm1 >= instTerm0)
self.assertTrue(instTerm0.get_instance().inst == instance.inst)
count = 0
for to in instTerm1.get_flat_fanout():
count += 1

Check warning on line 244 in test/najaeda/test_najaeda_netlist.py

View check run for this annotation

Codecov / codecov/patch

test/najaeda/test_najaeda_netlist.py#L244

Added line #L244 was not covered by tests
self.assertTrue(count == 0)
self.assertTrue(instTerm0.get_equipotential() == netlist.Equipotential(instTerm0))
self.assertTrue(instTerm0.is_input())
self.assertFalse(instTerm0.is_output())





if __name__ == '__main__':
faulthandler.enable()
Expand Down
Loading