Skip to content

Commit

Permalink
Merge pull request #6395 from jeffng-or/enable-odb-python-unittests
Browse files Browse the repository at this point in the history
Updated ODB python unit tests and hooked them up to CTest-based regre…
  • Loading branch information
maliberty authored Jan 6, 2025
2 parents 74c7c59 + 0d00a33 commit 2f86990
Show file tree
Hide file tree
Showing 16 changed files with 140 additions and 260 deletions.
8 changes: 8 additions & 0 deletions src/odb/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ or_integration_tests(
dump_netlists
dump_netlists_withfill
parser_unit_test
test_block
test_bterm
test_destroy
test_group
test_inst
test_iterm
test_module
test_net
)

# Skipped
Expand Down
60 changes: 37 additions & 23 deletions src/odb/test/unitTestsPython/helper.py → src/odb/test/helper.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import opendbpy as odb
import odb
import openroad
from openroad import Design


def createSimpleDB():
db = odb.dbDatabase.create()
tech = odb.dbTech.create(db)
db = Design.createDetachedDb()
tech = odb.dbTech.create(db, "simple_tech")
L1 = odb.dbTechLayer_create(tech, "L1", "ROUTING")
lib = odb.dbLib.create(db, "lib")
lib = odb.dbLib.create(db, "lib", tech, "/")
odb.dbChip.create(db)
# Creating Master and2 and or2
and2 = createMaster2X1(lib, "and2", 1000, 1000, "a", "b", "o")
Expand All @@ -14,8 +16,8 @@ def createSimpleDB():


def createMultiLayerDB():
db = odb.dbDatabase.create()
tech = odb.dbTech.create(db)
db = Design.createDetachedDb()
tech = odb.dbTech.create(db, "multi_tech")

m1 = odb.dbTechLayer_create(tech, "M1", "ROUTING")
m1.setWidth(2000)
Expand Down Expand Up @@ -44,7 +46,7 @@ def createMultiLayerDB():
# +-----
def create1LevelBlock(db, lib, parent):
blockName = "1LevelBlock"
block = odb.dbBlock_create(parent, blockName, ",")
block = odb.dbBlock_create(parent, blockName, lib.getTech(), ",")
# Creating Master and2 and instance inst
and2 = lib.findMaster("and2")
inst = odb.dbInst.create(block, and2, "inst")
Expand All @@ -59,9 +61,12 @@ def create1LevelBlock(db, lib, parent):
OUT = odb.dbBTerm.create(n3, "OUT")
OUT.setIoType("OUTPUT")
# connecting nets
odb.dbITerm.connect(inst, n1, inst.getMaster().findMTerm("a"))
odb.dbITerm.connect(inst, n2, inst.getMaster().findMTerm("b"))
odb.dbITerm.connect(inst, n3, inst.getMaster().findMTerm("o"))
a = inst.findITerm("a")
a.connect(n1)
b = inst.findITerm("b")
b.connect(n2)
o = inst.findITerm("o")
o.connect(n3)
return block


Expand All @@ -79,7 +84,7 @@ def create1LevelBlock(db, lib, parent):
# +-----
def create2LevelBlock(db, lib, parent):
blockName = "2LevelBlock"
block = odb.dbBlock_create(parent, blockName, ",")
block = odb.dbBlock_create(parent, blockName, lib.getTech(), ",")

and2 = lib.findMaster("and2")
or2 = lib.findMaster("or2")
Expand Down Expand Up @@ -107,18 +112,27 @@ def create2LevelBlock(db, lib, parent):
OUT = odb.dbBTerm.create(n7, "OUT")
OUT.setIoType("OUTPUT")
# connecting nets
odb.dbITerm.connect(i1, n1, i1.getMaster().findMTerm("a"))
odb.dbITerm.connect(i1, n2, i1.getMaster().findMTerm("b"))
odb.dbITerm.connect(i1, n5, i1.getMaster().findMTerm("o"))

odb.dbITerm.connect(i2, n3, i2.getMaster().findMTerm("a"))
odb.dbITerm.connect(i2, n4, i2.getMaster().findMTerm("b"))
odb.dbITerm.connect(i2, n6, i2.getMaster().findMTerm("o"))

odb.dbITerm.connect(i3, n5, i3.getMaster().findMTerm("a"))
odb.dbITerm.connect(i3, n6, i3.getMaster().findMTerm("b"))
odb.dbITerm.connect(i3, n7, i3.getMaster().findMTerm("o"))

i1_a = i1.findITerm("a")
i1_a.connect(n1)
i1_b = i1.findITerm("b")
i1_b.connect(n2)
i1_o = i1.findITerm("o")
i1_o.connect(n5)
# connect i2
i2_a = i2.findITerm("a")
i2_a.connect(n3)
i2_b = i2.findITerm("b")
i2_b.connect(n4)
i2_o = i2.findITerm("o")
i2_o.connect(n6)
# connect i3
i3_a = i3.findITerm("a")
i3_a.connect(n5)
i3_b = i3.findITerm("b")
i3_b.connect(n6)
i3_o = i3.findITerm("o")
i3_o.connect(n7)
# connect pins
P1 = odb.dbBPin_create(IN1)
P2 = odb.dbBPin_create(IN2)
P3 = odb.dbBPin_create(IN3)
Expand Down
14 changes: 14 additions & 0 deletions src/odb/test/odbUnitTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import unittest


class TestCase(unittest.TestCase):
# Function to change a value and test the change effect
def changeAndTest(self, obj, SetterName, GetterName, expectedVal, *args):
getattr(obj, SetterName)(*args)
self.assertEqual(getattr(obj, GetterName)(), expectedVal)

def check(self, obj, GetterName, expectedVal, *args):
self.assertEqual(getattr(obj, GetterName)(*args), expectedVal)

def change(self, obj, SetterName, *args):
return getattr(obj, SetterName)(*args)
100 changes: 0 additions & 100 deletions src/odb/test/regression-py.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import opendbpy as odb
import odb
import helper
import odbUnitTest
import unittest


def placeInst(inst, x, y):
Expand All @@ -22,7 +23,6 @@ def setUp(self):
self.extcornerblock = self.block.createExtCornerBlock(1)
odb.dbTechNonDefaultRule_create(self.block, "non_default_1")
self.parentRegion = odb.dbRegion_create(self.block, "parentRegion")
self.childRegion = odb.dbRegion_create(self.parentRegion, "childRegion")

def tearDown(self):
self.db.destroy(self.db)
Expand Down Expand Up @@ -60,10 +60,6 @@ def test_find(self):
self.assertEqual(
self.block.findRegion("parentRegion").getName(), "parentRegion"
)
self.assertEqual(self.block.findRegion("childRegion").getName(), "childRegion")
self.assertEqual(
self.block.findRegion("childRegion").getParent().getName(), "parentRegion"
)

def check_box_rect(self, min_x, min_y, max_x, max_y):
box = self.block.getBBox()
Expand Down Expand Up @@ -144,5 +140,4 @@ def test_bbox4(self):


if __name__ == "__main__":
odbUnitTest.mainParallel(TestBlock)
# odbUnitTest.main()
unittest.main()
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import opendbpy as odb
import odb
import helper
import odbUnitTest
import unittest


class TestBTerm(odbUnitTest.TestCase):
Expand Down Expand Up @@ -40,5 +41,4 @@ def test_disconnect(self):


if __name__ == "__main__":
odbUnitTest.mainParallel(TestBTerm)
# odbUnitTest.main()
unittest.main()
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import opendbpy as odb
import odb
import helper
import odbUnitTest
import unittest

# destroying dbInst, dbNet, dbBTerm, dbBlock, dbBPin, dbWire, dbCapNode,
# dbCcSeg, dbLib, dbSWire, dbObstruction, dbRegion
Expand Down Expand Up @@ -151,31 +152,16 @@ def test_destroy_obstruction(self):

def setup_regions(self):
parentRegion = odb.dbRegion_create(self.block, "parentRegion")
childRegion = odb.dbRegion_create(parentRegion, "childRegion")
childRegion.addInst(self.i1)
return parentRegion, childRegion
return parentRegion

def test_create_regions(self):
parentRegion, childRegion = self.setup_regions()
self.assertEqual(self.i1.getRegion().getName(), childRegion.getName())
self.assertEqual(len(parentRegion.getChildren()), 1)
self.assertEqual(len(childRegion.getChildren()), 0)
self.assertEqual(parentRegion.getChildren()[0].getName(), childRegion.getName())
self.assertEqual(len(self.block.getRegions()), 2)
self.assertEqual(self.i1.getRegion().getName(), childRegion.getName())
self.assertEqual(childRegion.getParent().getName(), parentRegion.getName())
self.assertIsNone(parentRegion.getParent())

def test_destroy_region_child(self):
parentRegion, childRegion = self.setup_regions()
childRegion.destroy(childRegion)
parentRegion = self.setup_regions()
self.assertIsNone(self.i1.getRegion())
self.assertEqual(len(parentRegion.getChildren()), 0)
self.assertEqual(len(self.block.getRegions()), 1)
self.assertEqual(self.block.getRegions()[0].getName(), parentRegion.getName())

def test_destroy_region_parent(self):
parentRegion, childRegion = self.setup_regions()
parentRegion = self.setup_regions()
parentRegion.destroy(parentRegion)
self.assertEqual(len(self.block.getRegions()), 0)

Expand All @@ -189,5 +175,4 @@ def test_destroy_trackgrid(self):


if __name__ == "__main__":
odbUnitTest.mainParallel(TestDestroy)
# odbUnitTest.main()
unittest.main()
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import opendbpy as odb
import odb
import helper
import odbUnitTest
import unittest


##################
Expand All @@ -13,7 +14,8 @@ def setUp(self):
self.db, self.lib = helper.createSimpleDB()
self.block = helper.create1LevelBlock(self.db, self.lib, self.db.getChip())
self.group = odb.dbGroup_create(self.block, "group")
self.domain = odb.dbGroup_create(self.block, "domain", 0, 0, 100, 100)
self.domain = odb.dbRegion_create(self.block, "domain")
odb.dbBox_create(self.domain, 0, 0, 100, 100)
self.child = odb.dbGroup_create(self.block, "child")
self.master_mod = odb.dbModule_create(self.block, "master_mod")
self.parent_mod = odb.dbModule_create(self.block, "parent_mod")
Expand All @@ -26,10 +28,12 @@ def tearDown(self):

def test_default(self):
self.check(self.group, "getName", "group")
print("")
self.assertEqual(self.block.findGroup("group").getName(), "group")
self.assertEqual(len(self.block.getGroups()), 3)
self.assertEqual(self.domain.getBox().xMax(), 100)
self.assertEqual(len(self.block.getGroups()), 2)
self.assertEqual(len(self.block.getRegions()), 1)
region_boundaries = self.domain.getBoundaries()
self.assertEqual(len(region_boundaries), 1)
self.assertEqual(region_boundaries[0].xMax(), 100)
self.group.addModInst(self.i1)
self.assertEqual(self.group.getModInsts()[0].getName(), "i1")
self.assertEqual(self.i1.getGroup().getName(), "group")
Expand All @@ -53,4 +57,4 @@ def test_default(self):


if __name__ == "__main__":
odbUnitTest.mainParallel(TestModule)
unittest.main()
Loading

0 comments on commit 2f86990

Please sign in to comment.