diff --git a/src/odb/src/swig/common/odb.i b/src/odb/src/swig/common/odb.i index 8f82b85afba..e53eda67e97 100644 --- a/src/odb/src/swig/common/odb.i +++ b/src/odb/src/swig/common/odb.i @@ -56,7 +56,7 @@ using namespace odb; %typemap(out) (uint) = (int); %typemap(out) (uint64) = (long); %typemap(out) (int64_t) = (long); -%apply int* OUTPUT {int* x, int* y}; +%apply int* OUTPUT {int* x, int* y, int& ext}; %ignore odb::dbTechLayerAntennaRule::pwl_pair; %ignore odb::dbTechLayerAntennaRule::getDiffPAR() const; @@ -88,6 +88,8 @@ using namespace odb; %include "dbhelpers.i" %include "dbdiff.i" +%rename(getPoint_ext) odb::dbWireDecoder::getPoint(int& x, int& y, int& ext) const; + %include "odb/dbViaParams.h" %include "odb/dbWireCodec.h" %include "odb/dbBlockCallBackObj.h" @@ -98,3 +100,4 @@ using namespace odb; %include "odb/wOrder.h" std::string generateMacroPlacementString(odb::dbBlock* block); + diff --git a/src/odb/test/CMakeLists.txt b/src/odb/test/CMakeLists.txt index 70509211839..e9d44812a32 100644 --- a/src/odb/test/CMakeLists.txt +++ b/src/odb/test/CMakeLists.txt @@ -62,6 +62,7 @@ or_integration_tests( test_iterm test_module test_net + test_wire_codec ) # Skipped diff --git a/src/odb/test/helper.tcl b/src/odb/test/helper.tcl new file mode 100644 index 00000000000..8f149b56b7e --- /dev/null +++ b/src/odb/test/helper.tcl @@ -0,0 +1,211 @@ +# Converted from helper.py + +proc createSimpleDB {{use_default_db 0}} { + if {$use_default_db} { + set db [ord::get_db] + } else { + set db [odb::dbDatabase_create] + } + set tech [odb::dbTech_create $db "simple_tech"] + set L1 [odb::dbTechLayer_create $tech "L1" "ROUTING"] + set lib [odb::dbLib_create $db "lib" $tech "/"] + set chip [odb::dbChip_create $db] + set and2 [createMaster2X1 $lib "and2" 1000 1000 "a" "b" "o"] + set or2 [createMaster2X1 $lib "or2" 500 500 "a" "b" "o"] + return [list $db $lib] +} + +proc createMultiLayerDB {} { + set db [odb::dbDatabase_create] + set tech [odb::dbTech_create $db "multi_tech"] + + set m1 [odb::dbTechLayer_create $tech "M1" "ROUTING"] + $m1 setWidth 2000 + set m2 [odb::dbTechLayer_create $tech "M2" "ROUTING"] + $m2 setWidth 2000 + set m3 [odb::dbTechLayer_create $tech "M3" "ROUTING"] + $m3 setWidth 2000 + + set v12 [odb::dbTechVia_create $tech "VIA12"] + odb::dbBox_create $v12 $m1 0 0 2000 2000 + odb::dbBox_create $v12 $m2 0 0 2000 2000 + + set v23 [odb::dbTechVia_create $tech "VIA23"] + odb::dbBox_create $v23 $m2 0 0 2000 2000 + odb::dbBox_create $v23 $m3 0 0 2000 2000 + + return [list $db $tech $m1 $m2 $m3 $v12 $v23] +} + +# logical expr OUT = (IN1&IN2) +# +# (n1) +----- +# IN1--------|a \ (n3) +# (n2) | (i1)o|-----------OUT +# IN2--------|b / +# +----- +proc create1LevelBlock {db lib parent} { + set blockName "1LevelBlock" + set block [odb::dbBlock_create $parent $blockName [$lib getTech] ","] + # Creating Master and2 and instance inst + set and2 [$lib findMaster "and2"] + set inst [odb::dbInst_create $block $and2 "inst"] + # creating our nets + set n1 [odb::dbNet_create $block "n1"] + set n2 [odb::dbNet_create $block "n2"] + set n3 [odb::dbNet_create $block "n3"] + set IN1 [odb::dbBTerm_create $n1 "IN1"] + $IN1 setIoType "INPUT" + set IN2 [odb::dbBTerm_create $n2 "IN2"] + $IN2 setIoType "INPUT" + set OUT [odb::dbBTerm_create $n3 "OUT"] + $OUT setIoType "OUTPUT" + # connecting nets + set a [$inst findITerm "a"] + $a connect $n1 + set b [$inst findITerm "b"] + $b connect $n2 + set o [$inst findITerm "o"] + $o connect $n3 + return $block +} + + +# logical expr OUT = (IN1&IN2) | (IN3&IN4) +# (n1) +----- +# IN1--------|a \ (n5) +# (n2) | (i1)o|-----------+ +# IN2--------|b / | +------- +# +----- +--------\a \ (n7) +# ) (i3)o|---------------OUT +# (n3) +----- +--------/b / +# IN3--------|a \ (n6) | +------- +# (n4) | (i2)o|-----------+ +# IN4--------|b / +# +----- +proc create2LevelBlock { db lib parent } { + set blockName "2LevelBlock" + set block [odb::dbBlock_create $parent $blockName [$lib getTech] ","] + + set and2 [$lib findMaster "and2"] + set or2 [$lib findMaster "or2"] + # creating instances + set i1 [odb::dbInst_create $block $and2 "i1"] + set i2 [odb::dbInst_create $block $and2 "i2"] + set i3 [odb::dbInst_create $block $or2 "i3"] + # creating nets and block terms + set n1 [odb::dbNet_create $block "n1"] + set n2 [odb::dbNet_create $block "n2"] + set n3 [odb::dbNet_create $block "n3"] + set n4 [odb::dbNet_create $block "n4"] + set n5 [odb::dbNet_create $block "n5"] + set n6 [odb::dbNet_create $block "n6"] + set n7 [odb::dbNet_create $block "n7"] + + set IN1 [odb::dbBTerm_create $n1 "IN1"] + $IN1 setIoType "INPUT" + set IN2 [odb::dbBTerm_create $n2 "IN2"] + $IN2 setIoType "INPUT" + set IN3 [odb::dbBTerm_create $n3 "IN3"] + $IN3 setIoType "INPUT" + set IN4 [odb::dbBTerm_create $n4 "IN4"] + $IN4 setIoType "INPUT" + set OUT [odb::dbBTerm_create $n7 "OUT"] + $OUT setIoType "OUTPUT" + # connecting $nets + set i1_a [$i1 findITerm "a"] + $i1_a connect $n1 + set i1_b [$i1 findITerm "b"] + $i1_b connect $n2 + set i1_o [$i1 findITerm "o"] + $i1_o connect $n5 + + set i2_a [$i2 findITerm "a"] + $i2_a connect $n3 + set i2_b [$i2 findITerm "b"] + $i2_b connect $n4 + set i2_o [$i2 findITerm "o"] + $i2_o connect $n6 + + set i3_a [$i3 findITerm "a"] + $i3_a connect $n5 + set i3_b [$i3 findITerm "b"] + $i3_b connect $n6 + set i3_o [$i3 findITerm "o"] + $i3_o connect $n7 + + set P1 [odb::dbBPin_create $IN1] + set P2 [odb::dbBPin_create $IN2] + set P3 [odb::dbBPin_create $IN3] + set P4 [odb::dbBPin_create $IN4] + set P5 [odb::dbBPin_create $OUT] + + return $block +} + +# +----- +# |in1 \ +# out| +# |in2 / +# +----- +proc createMaster2X1 {lib name width height in1 in2 out} { + set master [odb::dbMaster_create $lib $name] + $master setWidth $width + $master setHeight $height + $master setType "CORE" + odb::dbMTerm_create $master $in1 "INPUT" + odb::dbMTerm_create $master $in2 "INPUT" + odb::dbMTerm_create $master $out "OUTPUT" + $master setFrozen + return $master +} + +proc createMaster3X1 {lib name width height in1 in2 in3 out} { + set master [odb::dbMaster_create $lib $name] + $master setWidth $width + $master setHeight $height + $master setType "CORE" + odb::dbMTerm_create $master $in1 "INPUT" + odb::dbMTerm_create $master $in2 "INPUT" + odb::dbMTerm_create $master $in3 "INPUT" + odb::dbMTerm_create $master $out "OUTPUT" + $master setFrozen + return $master +} + +# +# Assertion helper +# +proc assert { condition { message "assertion failed" } } { + # Try to evaluate the condition as an expression. + # This will work for numeric comparisons (e.g., $x == 5) + if {![catch {uplevel 1 expr $condition}]} { + # If the expression evaluates successfully and returns false, raise an error + if {![uplevel 1 expr $condition]} { + error $message + } + } else { + # If the condition involves string comparison, use string equal or eq. + if {[string equal $condition ""]} { + error $message + } + } +} + +# +# List comparison helper, since struct::list isn't available +# returns true if two lists are the same +# +proc lequal {l1 l2} { + foreach elem $l1 { + if { $elem ni $l2 } { + return false + } + } + foreach elem $l2 { + if { $elem ni $l1 } { + return false + } + } + return true +} diff --git a/src/odb/test/test_block.tcl b/src/odb/test/test_block.tcl new file mode 100644 index 00000000000..979d3be0f40 --- /dev/null +++ b/src/odb/test/test_block.tcl @@ -0,0 +1,156 @@ +#package require control +#control::control assert enabled 1 +# +# Converted from test_block.py +# TclTest isn't available so just calling tests sequentially +# +source "helper.tcl" + +proc placeInst {inst x y} { + $inst setLocation $x $y + $inst setPlacementStatus "PLACED" +} + +proc placeBPin {bpin layer x1 y1 x2 y2} { + odb::dbBox_create $bpin $layer $x1 $y1 $x2 $y2 + $bpin setPlacementStatus "PLACED" +} + +# Set up data +proc setUp {} { + lassign [createSimpleDB] db lib + set parentBlock [odb::dbBlock_create [$db getChip] "Parent"] + set block [create2LevelBlock $db $lib $parentBlock] + $block setCornerCount 4 + set extcornerblock [$block createExtCornerBlock 1] + odb::dbTechNonDefaultRule_create $block "non_default_1" + set parentRegion [odb::dbRegion_create $block "parentRegion"] + return [list $db $lib $block $parentBlock] +} + +proc tearDown {db} { + odb::dbDatabase_destroy $db +} + +proc test_find {} { + lassign [setUp] db lib block parentBlock + # bterm + assert {[[$block findBTerm "IN1"] getName] == "IN1"} + assert {[$block findBTerm "in1"] == "NULL"} + # child + assert {[[$parentBlock findChild "2LevelBlock"] getName] == "2LevelBlock"} + assert {[$parentBlock findChild "1LevelBlock"] == "NULL"} + # inst + assert {[[$block findInst "i3"] getName] == "i3"} + assert {[$parentBlock findInst "i3"] == "NULL"} + # net + assert {[[$block findNet "n2"] getName] == "n2"} + assert {[$block findNet "a"] == "NULL"} + # iterm + set iterm [$block findITerm "i1o"] + assert {[[$iterm getInst] getName] == "i1"} + assert {[[$iterm getMTerm] getName] == "o"} + assert {[$block findITerm "i1\o"] == "NULL"} + # extcornerblock + assert {[[$block findExtCornerBlock 1] getName] == "extCornerBlock__1"} + assert {[$block findExtCornerBlock 0] == "NULL"} + # nondefaultrule + assert {[[$block findNonDefaultRule "non_default_1"] getName] == "non_default_1"} + assert {[$block findNonDefaultRule "non_default_2"] == "NULL"} + # region + assert {[[$block findRegion "parentRegion"] getName] == "parentRegion"} + tearDown $db +} + +proc check_box_rect {block min_x min_y max_x max_y} { + set box [$block getBBox] + assert {[$box xMin] == $min_x} [format "bbox xMin doesn't match: %d %d" [$box xMin] $min_x] + assert {[$box xMax] == $max_x} [format "bbox xMax doesn't match: %d %d" [$box xMax] $max_x] + assert {[$box yMin] == $min_y} [format "bbox yMin doesn't match: %d %d" [$box yMin] $min_y] + assert {[$box yMax] == $max_y} [format "bbox yMax doesn't match: %d %d" [$box yMax] $max_y] +} + +proc block_placement {block lib test_num flag} { + if {($flag && $test_num == 1) || (!$flag && $test_num >= 1)} { + if {$flag} { + puts "here" + } + placeInst [$block findInst "i1"] 0 3000 + placeInst [$block findInst "i2"] -1000 0 + placeInst [$block findInst "i3"] 2000 -1000 + } + if {($flag && $test_num == 2) || (!$flag && $test_num >= 2)} { + placeBPin [lindex [[$block findBTerm "OUT"] getBPins] 0] \ + [[$lib getTech] findLayer "L1"] 2500 -1000 2550 -950 + } + if {($flag && $test_num == 3) || (!$flag && $test_num >= 3)} { + odb::dbObstruction_create $block [[$lib getTech] findLayer "L1"] \ + -1500 0 -1580 50 + } + if {($flag && $test_num == 4) || (!$flag && $test_num >= 4)} { + set n_s [odb::dbNet_create $block "n_s"] + set swire [odb::dbSWire_create $n_s "NONE"] + odb::dbSBox_create $swire [[$lib getTech] findLayer "L1"] \ + 0 4000 100 4100 "NONE" + } + if {($flag && $test_num == 5) || (!$flag && $test_num >= 5)} { + # TODO ADD WIRE + } +} + +proc test_bbox0 {} { + lassign [setUp] db lib block parentBlock + set box [$block getBBox] + check_box_rect $block 0 0 0 0 + tearDown $db +} + +proc test_bbox1 {} { + lassign [setUp] db lib block parentBlock + set box [$block getBBox] + block_placement $block $lib 1 false + check_box_rect $block -1000 -1000 2500 4000 + tearDown $db +} + +proc test_bbox2 {} { + lassign [setUp] db lib block parentBlock + set box [$block getBBox] + block_placement $block $lib 2 false + check_box_rect $block -1000 -1000 2550 4000 + tearDown $db +} + +proc test_bbox3 {} { + lassign [setUp] db lib block parentBlock + # block_placement $block 2 false + # set box [$block getBBox] + # block_placement $block 3 true + set layer [[$lib getTech] findLayer "L1"] + placeInst [$block findInst "i1"] 0 3000 + placeInst [$block findInst "i2"] -1000 0 + placeInst [$block findInst "i3"] 2000 -1000 + placeBPin [lindex [[$block findBTerm "OUT"] getBPins] 0] \ + $layer 2500 -1000 2550 -950 + set box [$block getBBox] + odb::dbObstruction_create $block $layer -1500 0 -1580 50 + check_box_rect $block -1580 -1000 2550 4000 + tearDown $db +} + +proc test_bbox4 {} { + lassign [setUp] db lib block parentBlock + set box [$block getBBox] + block_placement $block $lib 4 false + check_box_rect $block -1580 -1000 2550 4100 + tearDown $db +} + +test_find +test_bbox0 +test_bbox1 +test_bbox2 +test_bbox3 +test_bbox4 +puts "pass" +exit 0 diff --git a/src/odb/test/test_bterm.tcl b/src/odb/test/test_bterm.tcl new file mode 100644 index 00000000000..abc3810d59b --- /dev/null +++ b/src/odb/test/test_bterm.tcl @@ -0,0 +1,60 @@ +#package require control +#control::control assert enabled 1 +# +# Converted from test_bterm.py +# TclTest isn't available so just calling tests sequentially +# + +source "helper.tcl" + +proc setUp {} { + lassign [createSimpleDB] db lib + set blockName "1LevelBlock" + set block [odb::dbBlock_create [$db getChip] blockName] + set and2 [$lib findMaster "and2"] + set inst [odb::dbInst_create $block $and2 "inst"] + set iterm_a [$inst findITerm "a"] + set n_a [odb::dbNet_create $block "na"] + set n_b [odb::dbNet_create $block "nb"] + set bterm_a [odb::dbBTerm_create $n_a "IN_a"] + return [list $db $bterm_a $n_a $n_b] +} + +proc tearDown {db} { + odb::dbDatabase_destroy $db +} + +proc test_idle {} { + lassign [setUp] db bterm_a n_a n_b + assert {[[$bterm_a getNet] getName] == "na"} + assert {[$n_a getBTermCount] == 1} + assert {[[lindex [$n_a getBTerms] 0] getName] == "IN_a"} + assert {[$n_b getBTermCount] == 0} + tearDown $db +} + +proc test_connect {} { + lassign [setUp] db bterm_a n_a n_b + $bterm_a connect $n_b + assert {[[$bterm_a getNet] getName] == "nb"} + assert {[$n_a getBTermCount] == 0} + assert {[lequal [$n_a getBTerms] []]} + assert {[$n_b getBTermCount] == 1} + assert {[[lindex [$n_b getBTerms] 0] getName()] == "IN_a"} + tearDown $db +} + +proc test_disconnect {} { + lassign [setUp] db bterm_a n_a n_b + $bterm_a disconnect + assert {[$bterm_a getNet] == "NULL"} + assert {[$n_a getBTermCount()] == 0} + assert {[lequal [$n_a getBTerms] []]} + tearDown $db +} + +test_idle +test_connect +test_disconnect +puts "pass" +exit 0 diff --git a/src/odb/test/test_destroy.tcl b/src/odb/test/test_destroy.tcl new file mode 100644 index 00000000000..32bae0ed4ff --- /dev/null +++ b/src/odb/test/test_destroy.tcl @@ -0,0 +1,245 @@ +#package require control +#control::control assert enabled 1 +# +# Converted from test_destroy.py +# TclTest isn't available so just calling tests sequentially +# + +# destroying dbInst, dbNet, dbBTerm, dbBlock, dbBPin, dbWire, dbCapNode, +# dbCcSeg, dbLib, dbSWire, dbObstruction, dbRegion +# TODO dbRSeg, dbRCSeg, dbRow, dbTarget, dbTech + +source "helper.tcl" + +proc setup_regions {block} { + set parentRegion [odb::dbRegion_create $block "parentRegion"] + return $parentRegion +} + +proc setUp {} { + lassign [createSimpleDB] db lib + set parentBlock [odb::dbBlock_create [$db getChip] "Parent"] + set block [create2LevelBlock $db $lib $parentBlock] + set i1 [$block findInst "i1"] + set i2 [$block findInst "i2"] + set i3 [$block findInst "i3"] + set n1 [[$i1 findITerm "a"] getNet] + set n2 [[$i1 findITerm "b"] getNet] + set n3 [[$i2 findITerm "a"] getNet] + set n4 [[$i2 findITerm "b"] getNet] + set n5 [[$i3 findITerm "a"] getNet] + set n6 [[$i3 findITerm "b"] getNet] + set n7 [[$i3 findITerm "o"] getNet] + return [list $db $block $parentBlock $i1 $n1 $n2 $n4 $n5 $n7] +} + +proc tearDown {db} { + odb::dbDatabase_destroy $db +} + +proc test_destroy_net {} { + lassign [setUp] db block parentBlock i1 n1 n2 n4 n5 n7 + odb::dbNet_destroy $n1 + # check for Inst + assert {[[$i1 findITerm "a"] getNet] == "NULL"} "inst term i1/a has non null net" + # check for Iterms + foreach iterm [$block getITerms] { + if {[$iterm getNet] == "NULL"} { + assert {[[$iterm getInst] getName] == "i1"} + assert {[[$iterm getMTerm] getName] == "a"} + } else { + assert {[[$iterm getNet] getName] != "n1"} + } + } + # check for block and BTerms + set nets [$block getNets] + foreach net $nets { + assert {[$net getName] != "n1"} "found net n1" + } + set bterms [$block getBTerms] + assert {[llength $bterms] == 4} [format "Found more than four bterms: " [llength $bterms]] + foreach bterm $bterms { + assert {[$bterm getName] != "IN1"} + assert {[[$bterm getNet] getName] != "n1"} + } + assert {[$block findBTerm "IN1"] == "NULL"} "Bterm IN1 was found" + assert {[$block findNet "n1"] == "NULL"} "Net n1 was found" + tearDown $db +} + +proc test_destroy_inst {} { + lassign [setUp] db block parentBlock i1 n1 n2 n4 n5 n7 + odb::dbInst_destroy $i1 + # check for block + assert {[$block findInst "i1"] == "NULL"} + foreach inst [$block getInsts] { + assert {[$inst getName] != "i1"} + } + assert {[llength [$block getITerms]] == 6} [format "Inst term count is not 6: %d" [llength [$block getITerms]]] + # check for Iterms + foreach iterm [$block getITerms] { + assert {[lsearch ["n1" "n2"] [[$iterm getNet] getName]] == -1} + assert {[[$iterm getInst] getName] != "i1"} + } + # check for BTERMS + set IN1 [$block findBTerm "IN1"] + assert {[$IN1 getITerm] == "NULL"} "Bterm IN1's inst term isn't null" + set IN2 [$block findBTerm "IN2"] + assert {[$IN2 getITerm] == "NULL"} "Bterm IN2's inst term isn't null" + # check for nets + assert {[$n1 getITermCount] == 0} [format "Net %s inst term count is not 0: %d" [$n1 getName] [$n1 getITermCount]] + assert {[$n2 getITermCount] == 0} [format "Net %s inst term count is not 0: %d" [$n2 getName] [$n2 getITermCount]] + assert {[$n5 getITermCount] == 1} [format "Net %s inst term count is not 1: %d" [$n5 getName] [$n5 getITermCount]] + assert {[[[lindex [$n5 getITerms] 0] getInst] getName] != "i1"} + tearDown $db +} + +proc test_destroy_bterm {} { + lassign [setUp] db block parentBlock i1 n1 n2 n4 n5 n7 + set IN1 [$block findBTerm "IN1"] + odb::dbBTerm_destroy $IN1 + # check for block and BTerms + assert {[$block findBTerm "IN1"] == "NULL"} + set bterms [$block getBTerms] + assert {[llength $bterms] == 4} + foreach bterm $bterms { + assert {[$bterm getName] != "IN1"} + } + # check for n1 + assert {[$n1 getBTermCount] == 0} + assert {[lequal [$n1 getBTerms] []]} + tearDown $db +} + +proc test_destroy_block {} { + # creating a child block to parent block + lassign [setUp] db block parentBlock i1 n1 n2 n4 n5 n7 + set other_block [create1LevelBlock $db [lindex [$db getLibs] 0] $parentBlock] + assert {[llength [$parentBlock getChildren]] == 2} + odb::dbBlock_destroy $other_block + assert {[llength [$parentBlock getChildren]] == 1} + odb::dbBlock_destroy $parentBlock + tearDown $db +} + +proc test_destroy_bpin {} { + lassign [setUp] db block parentBlock i1 n1 n2 n4 n5 n7 + set IN1 [$block findBTerm "IN1"] + assert {[llength [$IN1 getBPins]] == 1} + set P1 [lindex [$IN1 getBPins] 0] + odb::dbBPin_destroy $P1 + assert {[llength [$IN1 getBPins]] == 0} + tearDown $db +} + +proc test_create_destroy_wire {} { + lassign [setUp] db block parentBlock i1 n1 n2 n4 n5 n7 + set w [odb::dbWire_create $n7] + assert {[$n7 getWire] != "NULL"} + odb::dbWire_destroy $w + assert {[$n7 getWire] == "NULL"} + tearDown $db +} + +proc test_destroy_capnode {} { + lassign [setUp] db block parentBlock i1 n1 n2 n4 n5 n7 + set node2 [odb::dbCapNode_create $n2 0 false] + set node1 [odb::dbCapNode_create $n1 1 false] + set seg [odb::dbCCSeg_create $node1 $node2] + assert {[$n1 getCapNodeCount] == 1} + assert {[$n1 getCcCount] == 1} + odb::dbCapNode_destroy $node1 + assert {[$n1 getCapNodeCount] == 0} + assert {[$n1 getCcCount] == 0} + tearDown $db +} + +proc test_destroy_ccseg {} { + lassign [setUp] db block parentBlock i1 n1 n2 n4 n5 n7 + set node2 [odb::dbCapNode_create $n2 0 false] + set node1 [odb::dbCapNode_create $n1 1 false] + set ccseg [odb::dbCCSeg_create $node1 $node2] + assert {[llength [$node1 getCCSegs]] == 1} + assert {[llength [$block getCCSegs]] == 1} + assert {[$n1 getCcCount == 1]} + odb::dbCCSeg_destroy $ccseg + assert {[lequal [$node1 getCCSegs] []]} + assert {[lequal [$block getCCSegs] []]} + assert {[$n1 getCcCount] == 0} + tearDown $db +} + +proc test_destroy_lib {} { + lassign [setUp] db block parentBlock i1 n1 n2 n4 n5 n7 + set lib [lindex [$db getLibs] 0] + odb::dbLib_destroy $lib + assert {[llength [$db getLibs]] == 0} + tearDown $db +} + +proc test_destroy_swire {} { + lassign [setUp] db block parentBlock i1 n1 n2 n4 n5 n7 + set swire [odb::dbSWire_create $n4 "ROUTED"] + assert {[llength [$n4 getSWires]] == 1} "swire wasn't created" + assert {[[$swire getNet] getName] == [$n4 getName]} [format "swire nets don't have same name: %s %s" [[$swire getNet] getName] [$n4 getName]] + odb::dbSWire_destroy $swire + assert {[lequal [$n4 getSWires] []])} "swire wasn't destroyed" + tearDown $db +} + +proc test_destroy_obstruction {} { + lassign [setUp] db block parentBlock i1 n1 n2 n4 n5 n7 + set tech [[lindex [$db getLibs] 0] getTech] + set L1 [lindex [$tech getLayers] 0] + set obst [odb::dbObstruction_create $block $L1 0 0 1000 1000] + assert {[llength [$block getObstructions]] == 1} + odb::dbObstruction_destroy $obst + assert {[llength [$block getObstructions]] == 0} + tearDown $db +} + +proc test_create_regions {} { + lassign [setUp] db block parentBlock i1 n1 n2 n4 n5 n7 + set parentRegion [setup_regions $block] + assert {[$i1 getRegion] != "NULL"} + set region_list [$block getRegions] + assert {[llength $region_list] == 1} + assert {[[lindex region_list 0] getName] == [$parentRegion getName]} + tearDown $db +} + +proc test_destroy_region_parent {} { + lassign [setUp] db block parentBlock i1 n1 n2 n4 n5 n7 + set parentRegion [setup_regions $block] + odb::dbRegion_destroy $parentRegion + assert {[llength [$block getRegions] == 0} + tearDown $db +} + +proc test_destroy_trackgrid {} { + lassign [setUp] db block parentBlock i1 n1 n2 n4 n5 n7 + set tech [[lindex [$db getLibs] 0] getTech] + set L1 [$tech findLayer "L1"] + set grid [odb::dbTrackGrid_create $block $L1] + assert {[odb::dbTrackGrid_create $block $L1] == "NULL"} + odb::dbTrackGrid_destroy $grid + assert {[odb::dbTrackGrid_create $block $L1] != "NULL"} + tearDown $db +} + +test_destroy_net +test_destroy_inst +test_destroy_bterm +test_destroy_block +test_destroy_bpin +test_create_destroy_wire +test_destroy_capnode +test_destroy_ccseg +test_destroy_lib +test_destroy_swire +test_destroy_obstruction +test_create_regions +test_destroy_region_parent +test_destroy_trackgrid +puts "pass" +exit 0 diff --git a/src/odb/test/test_group.tcl b/src/odb/test/test_group.tcl new file mode 100644 index 00000000000..bbdfd633e83 --- /dev/null +++ b/src/odb/test/test_group.tcl @@ -0,0 +1,62 @@ +#package require control +#control::control assert enabled 1 +# +# Converted from test_group.py +# TclTest isn't available so just calling tests sequentially +# +source "helper.tcl" + +proc setUp {} { + lassign [createSimpleDB] db lib + set block [create1LevelBlock $db $lib [$db getChip]] + set group [odb::dbGroup_create $block "group"] + set domain [odb::dbRegion_create $block "domain"] + odb::dbBox_create $domain 0 0 100 100 + set child [odb::dbGroup_create $block "child"] + set master_mod [odb::dbModule_create $block "master_mod"] + set parent_mod [odb::dbModule_create $block "parent_mod"] + set i1 [odb::dbModInst_create $parent_mod $master_mod "i1"] + set inst1 [$block findInst "inst"] + set n1 [$block findNet "n1"] + return [list $db $block $group $domain $i1 $inst1 $child $n1] +} + +proc tearDown {db} { + odb::dbDatabase_destroy $db +} + +proc test_default {} { + lassign [setUp] db block group domain i1 inst1 child n1 + assert {[$group getName] == "group"} + assert {[[$block findGroup "group"] getName] == "group"} + assert {[llength [$block getGroups]] == 2} + assert {[llength [$block getRegions]] == 1} + set region_boundaries [$domain getBoundaries] + assert {[llength region_boundaries] == 1} + assert {[[lindex $region_boundaries 0] xMax] == 100} + $group addModInst $i1 + assert {[[lindex [$group getModInsts] 0] getName] == "i1"} + assert {[[$i1 getGroup] getName] == "group"} + $group removeModInst $i1 + $group addInst $inst1 + assert {[[lindex [$group getInsts] 0] getName] == "inst"} + assert {[[$inst1 getGroup] getName] == "group"} + $group removeInst $inst1 + $group addGroup $child + assert {[[lindex [$group getGroups] 0] getName] == "child"} + assert {[[$child getParentGroup] getName] == "group"} + $group removeGroup $child + $group addPowerNet $n1 + assert {[[lindex [$group getPowerNets] 0] getName] == "n1"} + $group addGroundNet $n1 + assert {[[lindex [$group getGroundNets] 0] getName] == "n1"} + $group removeNet $n1 + assert {[$group getType] == "PHYSICAL_CLUSTER"} + $group setType "VOLTAGE_DOMAIN" + odb::dbGroup_destroy $group + tearDown $db +} + +test_default +puts "pass" +exit 0 diff --git a/src/odb/test/test_inst.py b/src/odb/test/test_inst.py index ebd4d790927..994681a7ad7 100644 --- a/src/odb/test/test_inst.py +++ b/src/odb/test/test_inst.py @@ -21,7 +21,7 @@ def test_swap_master(self): self.assertNotEqual(self.i1.getMaster().getName(), "_g2") for iterm in self.i1.getITerms(): self.assertNotIn(iterm.getMTerm().getName(), ["_a", "_b", "_o"]) - # testing with a gate with different mterms number - shuld fail + # testing with a gate with different mterms number - should fail gate = helper.createMaster3X1(self.lib, "_g3", 800, 800, "_a", "_b", "_c", "_o") self.assertFalse(self.i1.swapMaster(gate)) self.assertNotEqual(self.i1.getMaster().getName(), "_g3") diff --git a/src/odb/test/test_inst.tcl b/src/odb/test/test_inst.tcl new file mode 100644 index 00000000000..2290fccf8e9 --- /dev/null +++ b/src/odb/test/test_inst.tcl @@ -0,0 +1,52 @@ +#package require control +#control::control assert enabled 1 +# +# Converted from test_inst.py +# TclTest isn't available so just calling tests sequentially +# +source "helper.tcl" + +proc setUp {{use_default_db 0}} { + lassign [createSimpleDB $use_default_db] db lib + set block [create2LevelBlock $db $lib [$db getChip]] + set i1 [$block findInst "i1"] + return [list $db $lib $block $i1] +} + +proc tearDown {db} { + odb::dbDatabase_destroy $db +} + +# +# This test calls setUp with use_default_db since we need the logger to be +# defined for this DB (the negative tests result in warnings being logged). +# +proc test_swap_master {} { + lassign [setUp 1] db lib block i1 + assert {[[$i1 getMaster] getName] == "and2"} + # testing with a gate with different mterm names - should fail + set gate [createMaster2X1 $lib "_g2" 800 800 "_a" "_b" "_o"] + assert {[$i1 swapMaster gate] == 0} + assert {[[$i1 getMaster] getName] != "_g2"} + foreach iterm [$i1 getITerms] { + assert {[lsearch ["_a" "_b" "_o"] [[$iterm getMTerm] getName]] == -1} + } + # testing with a gate with different mterms number - should fail + set gate [createMaster3X1 $lib "_g3" 800 800 "_a" "_b" "_c" "_o"] + assert {[$i1 swapMaster $gate] == 0} + assert {[[$i1 getMaster] getName] != "_g3"} + foreach iterm [$i1 getITerms] { + assert {[lsearch ["_a" "_b" "_c" "_o"] [[$iterm getMTerm] getName]] == -1} + } + # testing with a gate with same mterm names - should succeed + set gate [createMaster2X1 $lib "g2" 800 800 "a" "b" "o"] + assert {[$i1 swapMaster $gate] == 1} + assert {[[$i1 getMaster] getName] == "g2"} + assert {[[$i1 getMaster] getWidth] == p800} + assert {[[$i1 etMaster] getHeight] == 800} + # don't tear down DB since we are using the default DB +} + +test_swap_master +puts "pass" +exit 0 diff --git a/src/odb/test/test_iterm.tcl b/src/odb/test/test_iterm.tcl new file mode 100644 index 00000000000..497a0ca0704 --- /dev/null +++ b/src/odb/test/test_iterm.tcl @@ -0,0 +1,128 @@ +#package require control +#control::control assert enabled 1 +# +# Converted from test_iterm.py +# TclTest isn't available so just calling tests sequentially +# + +source "helper.tcl" + +proc setUp {{use_default_db 0}} { + lassign [createSimpleDB $use_default_db] db lib + set blockName "1LevelBlock" + set block [odb::dbBlock_create [$db getChip] blockName] + set and2 [$lib findMaster "and2"] + set inst [odb::dbInst_create $block $and2 "inst"] + set iterm_a [$inst findITerm "a"] + return [list $db $lib $block $iterm_a $and2 $inst] +} + +proc tearDown {db} { + #odb::dbDatabase_destroy $db +} + +proc test_idle {} { + lassign [setUp] db lib block iterm_a and2 inst + assert {[$iterm_a getNet] == "NULL"} + tearDown $db +} + +proc test_connection_from_iterm {} { + lassign [setUp] db lib block iterm_a and2 inst + # Create net and Connect + set n [odb::dbNet_create $block "n1"] + assert {[$n getITermCount] == 0} + assert {[lequal [$n getITerms] []]} + $iterm_a connect $n + $iterm_a setConnected + assert {[[$iterm_a getNet] getName] == "n1"} + assert {[$n getITermCount] == 1} + assert {[[[lindex [$n getITerms] 0] getMTerm] getName] == "a"} + assert {[$iterm_a isConnected] == 1} + # disconnect + $iterm_a disconnect + $iterm_a clearConnected + assert {[$n getITermCount] == 0} + assert {[lequal [$n getITerms] []]} + assert {[$iterm_a getNet] == "NULL"} + assert {[$iterm_a isConnected] == 0} + tearDown $db +} + +proc test_connection_from_inst {} { + lassign [setUp] db lib block iterm_a and2 inst + # Create net and Connect + set n [odb::dbNet_create $block "n1"] + assert {[$n getITermCount] == 0} + assert {[lequal [$n getITerms] []]} + $iterm_a connect $n + $iterm_a setConnected + assert {[[$iterm_a getNet] getName] == "n1"} + assert {[$n getITermCount] == 1} + assert {[[[lindex [$n getITerms] 0] getMTerm] getName] == "a"} + assert {[$iterm_a isConnected] == 1} + # disconnect + $iterm_a disconnect + $iterm_a clearConnected + assert {[$n getITermCount] == 0} + assert {[lequal [$n getITerms] []]} + assert {[$iterm_a getNet] == "NULL"} + assert {[$iterm_a isConnected] == 0} + tearDown $db +} + +# +# This test calls setUp with use_default_db since we need the logger to be +# defined for this DB (the negative tests result in warnings being logged). +# +proc test_avgxy_R0 {} { + lassign [setUp 1] db lib block iterm_a and2 inst + # no mpin to work on - fails + lassign [$iterm_a getAvgXY] result x y + assert {$result == 0} "Result with no mpin was true" + set mterm_a [$and2 findMTerm "a"] + set mpin_a [odb::dbMPin_create $mterm_a] + # no boxes to work on - fails + lassign [$iterm_a getAvgXY] result x y + assert {result == 0} "Result with no boxes was true" + set layer [lindex [[$lib getTech] getLayers] 0] + set geo_box_a_1 [odb::dbBox_create $mpin_a $layer 0 0 50 50] + lassign [$iterm_a getAvgXY] result x y + assert {result == 1} "Result with geo_box_a_1 was false" + set expected_size [expr 50 / 2] + assert {$x == $expected_size} [format "geo_box_a_1 x's didn't match: %d %d" $x $expected_size] + assert {$y == $expected_size} [format "geo_box_a_1 y's didn't match: %d %d" $y $expected_size] + set geo_box_a_2 [odb::dbBox_create $mpin_a $layer 5 10 100 100] + lassign [$iterm_a getAvgXY] result x y + assert {result == 1} "Result with geo_box_a_2 was false" + set expected_x_size [expr ((0 + 50) + (5 + 100)) / 4] + set expected_y_size [expr ((0 + 50) + (10 + 100)) / 4] + assert {$x == $expected_x_size} [format "geo_box_a_2 x's didn't match: %d %d" $x $expected_x_size] + assert {$y == $expected_y_size} [format "geo_box_a_2 y's didn't match: %d %d" $y $expected_y_size] + # don't tear down DB since we are using the default DB +} + +proc test_avgxy_R90 {} { + lassign [setUp] db lib block iterm_a and2 inst + set mterm_a [$and2 findMTerm "a"] + set mpin_a [odb::dbMPin_create $mterm_a] + set layer [lindex [[$lib getTech] getLayers] 0] + set geo_box_a_1 [odb::dbBox_create $mpin_a $layer 0 0 50 50] + set geo_box_a_2 [odb::dbBox_create $mpin_a $layer 0 0 100 100] + $inst setOrient "R90" + lassign [$iterm_a getAvgXY] result x y + assert {result == 1} + set expected_x_size [expr (((0 + 50) + (0 + 100)) / 4) * -1] + set expected_y_size [expr ((0 + 50) + (0 + 100)) / 4] + assert {$x == $expected_x_size} + assert {$y == $expected_y_size} + tearDown $db +} + +test_idle +test_connection_from_iterm +test_connection_from_inst +test_avgxy_R0 +test_avgxy_R90 +puts "pass" +exit 0 diff --git a/src/odb/test/test_module.tcl b/src/odb/test/test_module.tcl new file mode 100644 index 00000000000..95ff5c88fe1 --- /dev/null +++ b/src/odb/test/test_module.tcl @@ -0,0 +1,46 @@ +#package require control +#control::control assert enabled 1 +# +# Converted from test_module.py +# TclTest isn't available so just calling tests sequentially +# +source "helper.tcl" + +proc setUp {} { + lassign [createSimpleDB] db lib + set block [create1LevelBlock $db $lib [$db getChip]] + set master_mod [odb::dbModule_create $block "master_mod"] + set parent_mod [odb::dbModule_create $block "parent_mod"] + set i1 [odb::dbModInst_create $parent_mod $master_mod "i1"] + set inst1 [$block findInst "inst"] + return [list $db $lib $i1 $master_mod $parent_mod $inst1] +} + +proc tearDown {db} { + odb::dbDatabase_destroy $db +} + +proc test_default {} { + lassign [setUp] db block i1 master_mod parent_mod inst1 + assert {[$master_mod getName] == "master_mod"} + assert {[[$block findModule "parent_mod"] getName] == "parent_mod"} + assert {[$i1 getName] == "i1"} + assert {[[$i1 getParent] getName] == "parent_mod"} + assert {[[$i1 getMaster] getName] == "master_mod"} + assert {[[$master_mod getModInst] getName] == "i1"} + assert {[[lindex [$parent_mod getChildren] 0] getName] == "i1"} + assert {[[lindex [$block getModInsts] 0] getName] == "i1"} + $parent_mod addInst $inst1 + assert {[[lindex [$parent_mod getInsts] 0] getName] == "inst"} + assert {[[$inst1 getModule] getName] == "parent_mod"} + odb::dbInst_destroy $inst1 + assert {[$parent_mod findModInst "inst"] == "NULL"} + assert {[[$parent_mod findModInst "i1"] getName] == "i1"} + odb::dbModInst_destroy $i1 + odb::dbModule_destroy $parent_mod + tearDown $db +} + +test_default +puts "pass" +exit 0 diff --git a/src/odb/test/test_net.tcl b/src/odb/test/test_net.tcl new file mode 100644 index 00000000000..800ec0c4c59 --- /dev/null +++ b/src/odb/test/test_net.tcl @@ -0,0 +1,82 @@ +#package require control +#control::control assert enabled 1 +# +# Converted from test_net.py +# TclTest isn't available so just calling tests sequentially +# +source "helper.tcl" + +proc changeAndTest { obj SetterName GetterName expectedVal args } { + $obj $SetterName $args + if {[string is ascii $expectedVal]} { + assert {[string equal [$obj $GetterName] $expectedVal]} [format "%s/%s failed: %s %s" $SetterName $GetterName [$obj $GetterName] $expectedVal] + } else { + assert {[$obj $GetterName] == $expectedVal} [format "%s/%s failed: %g %g" $SetterName $GetterName [$obj $GetterName] $expectedVal] + } +} + +# Set up data +proc setUp {} { + lassign [createSimpleDB] db lib + set block [create1LevelBlock $db $lib [$db getChip]] + set inst [lindex [$block getInsts] 0] + set n1 [[$inst findITerm "a"] getNet] + set n2 [[$inst findITerm "b"] getNet] + set n3 [[$inst findITerm "o"] getNet] + return [list $db $n1 $n2 $n3] +} + +proc tearDown {db} { + odb::dbDatabase_destroy $db +} + +proc test_naming {} { + lassign [setUp] db n1 n2 n3 + changeAndTest $n1 "rename" "getName" "_n1" "_n1" + assert {[string equal [$n1 getConstName] "_n1"]} [format "getConstName failed: %s _n1" [$n1 getConstName]] + assert {[$n1 rename "n2"] == 0} [format "rename failed: %s" [$n1 getName]] + tearDown $db +} + +proc test_dbSetterAndGetter {} { + lassign [setUp] db n1 n2 n3 + changeAndTest $n1 "setRCDisconnected" "isRCDisconnected" 0 0 + changeAndTest $n1 "setRCDisconnected" "isRCDisconnected" 1 1 + changeAndTest $n1 "setWeight" "getWeight" 2 2 + changeAndTest $n1 "setSourceType" "getSourceType" "NETLIST" "NETLIST" + changeAndTest $n1 "setXTalkClass" "getXTalkClass" 1 1 + changeAndTest $n1 "setCcAdjustFactor" "getCcAdjustFactor" 1.0 1.0 + changeAndTest $n1 "setSigType" "getSigType" "RESET" "RESET" + tearDown $db +} + +proc test_dbCc {} { + lassign [setUp] db n1 n2 n3 + changeAndTest $n1 "setDbCc" "getDbCc" 2.0 2.0 + changeAndTest $n1 "addDbCc" "getDbCc" 5.0 3.0 + tearDown $db +} + +proc test_cc {} { + lassign [setUp] db n1 n2 n3 + set node2 [odb::dbCapNode_create $n2 0 false] + assert {[string length $node2] != 0} [format "node2 from %s is null" [$n2 getName]] + set node1 [odb::dbCapNode_create $n1 1 false] + assert {[string length $node1] != 0} [format "node1 from %s is null" [$n1 getName]] + $node1 setInternalFlag + set ccseg [odb::dbCCSeg_create $node1 $node2] + $n1 calibrateCouplingCap + assert {[$n1 maxInternalCapNum] == 1} + assert {[$n1 groundCC 1] == 1} + assert {[$n2 groundCC 1] == 0} + assert {[$n1 getCcCount] == 1} + tearDown $db +} + +test_naming +test_dbSetterAndGetter +test_dbCc +test_cc + +puts "pass" +exit 0 diff --git a/src/odb/test/unitTestsPython/TestWireCodec.py b/src/odb/test/test_wire_codec.py similarity index 63% rename from src/odb/test/unitTestsPython/TestWireCodec.py rename to src/odb/test/test_wire_codec.py index 01b746d49a7..9cfd72d6d1d 100644 --- a/src/odb/test/unitTestsPython/TestWireCodec.py +++ b/src/odb/test/test_wire_codec.py @@ -1,6 +1,7 @@ -import opendbpy as odb +import odb import helper import odbUnitTest +import unittest class TestWireCodec(odbUnitTest.TestCase): @@ -66,122 +67,122 @@ def test_decoder(self): # Encoding started with a path nextOp = decoder.next() - assert nextOp == odb.dbWireDecoder.PATH + self.assertEqual(nextOp, odb.dbWireDecoder.PATH) # Check first point nextOp = decoder.next() - assert nextOp == odb.dbWireDecoder.POINT + self.assertEqual(nextOp, odb.dbWireDecoder.POINT) point = decoder.getPoint() - assert point == [2000, 2000] + self.assertEqual(point, [2000, 2000]) # Check second point nextOp = decoder.next() - assert nextOp == odb.dbWireDecoder.POINT + self.assertEqual(nextOp, odb.dbWireDecoder.POINT) point = decoder.getPoint() - assert point == [10000, 2000] + self.assertEqual(point, [10000, 2000]) # Check third point nextOp = decoder.next() - assert nextOp == odb.dbWireDecoder.POINT + self.assertEqual(nextOp, odb.dbWireDecoder.POINT) point = decoder.getPoint() - assert point == [18000, 2000] + self.assertEqual(point, [18000, 2000]) # Check first junction id nextOp = decoder.next() - assert nextOp == odb.dbWireDecoder.JUNCTION + self.assertEqual(nextOp, odb.dbWireDecoder.JUNCTION) jid = decoder.getJunctionValue() - assert jid == j1 + self.assertEqual(jid, j1) # Check junction point nextOp = decoder.next() - assert nextOp == odb.dbWireDecoder.POINT + self.assertEqual(nextOp, odb.dbWireDecoder.POINT) point = decoder.getPoint() - assert point == [10000, 2000] + self.assertEqual(point, [10000, 2000]) # Check tech via nextOp = decoder.next() - assert nextOp == odb.dbWireDecoder.TECH_VIA + self.assertEqual(nextOp, odb.dbWireDecoder.TECH_VIA) tchVia = decoder.getTechVia() - assert tchVia.getName() == self.v12.getName() + self.assertEqual(tchVia.getName(), self.v12.getName()) # Check next point nextOp = decoder.next() - assert nextOp == odb.dbWireDecoder.POINT + self.assertEqual(nextOp, odb.dbWireDecoder.POINT) point = decoder.getPoint() - assert point == [10000, 10000] + self.assertEqual(point, [10000, 10000]) # Check next point nextOp = decoder.next() - assert nextOp == odb.dbWireDecoder.POINT + self.assertEqual(nextOp, odb.dbWireDecoder.POINT) point = decoder.getPoint() - assert point == [10000, 18000] + self.assertEqual(point, [10000, 18000]) # Check second junction id nextOp = decoder.next() - assert nextOp == odb.dbWireDecoder.JUNCTION + self.assertEqual(nextOp, odb.dbWireDecoder.JUNCTION) jid = decoder.getJunctionValue() - assert jid == j2 + self.assertEqual(jid, j2) # Check junction point nextOp = decoder.next() - assert nextOp == odb.dbWireDecoder.POINT + self.assertEqual(nextOp, odb.dbWireDecoder.POINT) point = decoder.getPoint() - assert point == [10000, 10000] + self.assertEqual(point, [10000, 10000]) # Check tech via nextOp = decoder.next() - assert nextOp == odb.dbWireDecoder.TECH_VIA + self.assertEqual(nextOp, odb.dbWireDecoder.TECH_VIA) tchVia = decoder.getTechVia() - assert tchVia.getName() == self.v12.getName() + self.assertEqual(tchVia.getName(), self.v12.getName()) # Check next point nextOp = decoder.next() - assert nextOp == odb.dbWireDecoder.POINT_EXT + self.assertEqual(nextOp, odb.dbWireDecoder.POINT_EXT) point = decoder.getPoint_ext() - assert point == [23000, 10000, 4000] + self.assertEqual(point, [23000, 10000, 4000]) # Check third junction id nextOp = decoder.next() - assert nextOp == odb.dbWireDecoder.JUNCTION + self.assertEqual(nextOp, odb.dbWireDecoder.JUNCTION) jid = decoder.getJunctionValue() - assert jid == j3 + self.assertEqual(jid, j3) # Check junction point nextOp = decoder.next() - assert nextOp == odb.dbWireDecoder.POINT + self.assertEqual(nextOp, odb.dbWireDecoder.POINT) point = decoder.getPoint() - assert point == [10000, 10000] + self.assertEqual(point, [10000, 10000]) # Check next point nextOp = decoder.next() - assert nextOp == odb.dbWireDecoder.POINT + self.assertEqual(nextOp, odb.dbWireDecoder.POINT) point = decoder.getPoint() - assert point == [3000, 10000] + self.assertEqual(point, [3000, 10000]) # Check tech via nextOp = decoder.next() - assert nextOp == odb.dbWireDecoder.TECH_VIA + self.assertEqual(nextOp, odb.dbWireDecoder.TECH_VIA) tchVia = decoder.getTechVia() - assert tchVia.getName() == self.v12.getName() + self.assertEqual(tchVia.getName(), self.v12.getName()) # Check tech via nextOp = decoder.next() - assert nextOp == odb.dbWireDecoder.TECH_VIA + self.assertEqual(nextOp, odb.dbWireDecoder.TECH_VIA) tchVia = decoder.getTechVia() - assert tchVia.getName() == self.v23.getName() + self.assertEqual(tchVia.getName(), self.v23.getName()) # Check next point nextOp = decoder.next() - assert nextOp == odb.dbWireDecoder.POINT_EXT + self.assertEqual(nextOp, odb.dbWireDecoder.POINT_EXT) point = decoder.getPoint_ext() - assert point == [3000, 10000, 4000] + self.assertEqual(point, [3000, 10000, 4000]) # Check next point nextOp = decoder.next() - assert nextOp == odb.dbWireDecoder.POINT_EXT + self.assertEqual(nextOp, odb.dbWireDecoder.POINT_EXT) point = decoder.getPoint_ext() - assert point == [3000, 18000, 6000] + self.assertEqual(point, [3000, 18000, 6000]) if __name__ == "__main__": - odbUnitTest.mainParallel(TestWireCodec) + unittest.main() diff --git a/src/odb/test/test_wire_codec.tcl b/src/odb/test/test_wire_codec.tcl new file mode 100644 index 00000000000..9162edf4605 --- /dev/null +++ b/src/odb/test/test_wire_codec.tcl @@ -0,0 +1,159 @@ +#package require control +#control::control assert enabled 1 +# +# Converted from test_wire_codec.py +# +source "helper.tcl" + +# Set up data +lassign [createMultiLayerDB] db tech m1 m2 m3 v12 v23 +set chip [odb::dbChip_create $db] +set block [odb::dbBlock_create $chip "chip"] +set net [odb::dbNet_create $block "net"] +set wire [odb::dbWire_create $net] + +set encoder [odb::dbWireEncoder] +$encoder begin $wire +$encoder newPath $m1 "ROUTED" +$encoder addPoint 2000 2000 +set j1 [$encoder addPoint 10000 2000] +$encoder addPoint 18000 2000 +$encoder newPath $j1 +$encoder addTechVia $v12 +set j2 [$encoder addPoint 10000 10000] +$encoder addPoint 10000 18000 +$encoder newPath $j2 +set j3 [$encoder addTechVia $v12] +$encoder addPoint 23000 10000 4000 +$encoder newPath $j3 +$encoder addPoint 3000 10000 +$encoder addTechVia $v12 +$encoder addTechVia $v23 +$encoder addPoint 3000 10000 4000 +$encoder addPoint 3000 18000 6000 +$encoder end + +# Start decoding process +set decoder [odb::dbWireDecoder] +$decoder begin $wire + +# Encoding started with a path +set nextOp [$decoder next] +assert {$nextOp == $odb::dbWireDecoder_PATH} [format "nextop isn't path: %d" $nextOp] + +# Check first point +set nextOp [$decoder next] +assert {$nextOp == $odb::dbWireDecoder_POINT} [format "nextop isn't point: %d" $nextOp] +set point [$decoder getPoint] +assert {[lequal $point [list 2000 2000]]} "point list doesn't match" + +# Check second point +set nextOp [$decoder next] +assert {$nextOp == $odb::dbWireDecoder_POINT} [format "nextop isn't point: %d" $nextOp] +set point [$decoder getPoint] +assert {[lequal $point [list 10000 2000]]} "point list doesn't match" + +# Check third point +set nextOp [$decoder next] +assert {$nextOp == $odb::dbWireDecoder_POINT} [format "nextop isn't point: %d" $nextOp] +set point [$decoder getPoint] +assert {[lequal $point [list 18000 2000]]} "point list doesn't match" + +# Check first junction id +set nextOp [$decoder next] +assert {$nextOp == $odb::dbWireDecoder_JUNCTION} [format "nextop isn't jun: %d" $nextOp] +set jid [$decoder getJunctionValue] +assert {$jid == $j1} "jun value doesn't match" + +# Check junction point +set nextOp [$decoder next] +assert {$nextOp == $odb::dbWireDecoder_POINT} [format "nextop isn't point: %d" $nextOp] +set point [$decoder getPoint] +assert {[lequal $point [list 10000 2000]]} "point list doesn't match" + +# Check tech via +set nextOp [$decoder next] +assert {$nextOp == $odb::dbWireDecoder_TECH_VIA} [format "nextop isn't via: %d" $nextOp] +set tchVia [$decoder getTechVia] +assert {[string equal [$tchVia getName] [$v12 getName]]} [format "techvia name doesn't match: %s %s" [$tchVia getName] [$v12 getName]] + +# Check next point +set nextOp [$decoder next] +assert {$nextOp == $odb::dbWireDecoder_POINT} [format "nextop isn't point: %d" $nextOp] +set point [$decoder getPoint] +assert {[lequal $point [list 10000 10000]]} "point list doesn't match" + +# Check next point +set nextOp [$decoder next] +assert {$nextOp == $odb::dbWireDecoder_POINT} [format "nextop isn't point: %d" $nextOp] +set point [$decoder getPoint] +assert {[lequal $point [list 10000 18000]]} "point list doesn't match" + +# Check second junction id +set nextOp [$decoder next] +assert {$nextOp == $odb::dbWireDecoder_JUNCTION} [format "nextop isn't jun: %d" $nextOp] +set jid [$decoder getJunctionValue] +assert {$jid == $j2} "jun value doesn't match" + +# Check junction point +set nextOp [$decoder next] +assert {$nextOp == $odb::dbWireDecoder_POINT} [format "nextop isn't point: %d" $nextOp] +set point [$decoder getPoint] +assert {[lequal $point [list 10000 10000]]} "point list doesn't match" + +# Check tech via +set nextOp [$decoder next] +assert {$nextOp == $odb::dbWireDecoder_TECH_VIA} [format "nextop isn't via: %d" $nextOp] +set tchVia [$decoder getTechVia] +assert {[string equal [$tchVia getName] [$v12 getName]]} [format "techvia name doesn't match: %s %s" [$tchVia getName] [$v12 getName]] + +# Check next point +set nextOp [$decoder next] +assert {$nextOp == $odb::dbWireDecoder_POINT_EXT} [format "nextop isn't point_ext: %d" $nextOp] +set point [$decoder getPoint_ext] +assert {[lequal $point [list 23000 10000 4000]]} "point list doesn't match" + +# Check third junction id +set nextOp [$decoder next] +assert {$nextOp == $odb::dbWireDecoder_JUNCTION} [format "nextop isn't jun: %d" $nextOp] +set jid [$decoder getJunctionValue] +assert {$jid == $j3} "jun value doesn't match" + +# Check junction point +set nextOp [$decoder next] +assert {$nextOp == $odb::dbWireDecoder_POINT} [format "nextop isn't point: %d" $nextOp] +set point [$decoder getPoint] +assert {[lequal $point [list 10000 10000]]} "point list doesn't match" + +# Check next point +set nextOp [$decoder next] +assert {$nextOp == $odb::dbWireDecoder_POINT} [format "nextop isn't point: %d" $nextOp] +set point [$decoder getPoint] +assert {[lequal $point [list 3000 10000]]} "point list doesn't match" + +# Check tech via +set nextOp [$decoder next] +assert {$nextOp == $odb::dbWireDecoder_TECH_VIA} [format "nextop isn't via: %d" $nextOp] +set tchVia [$decoder getTechVia] +assert {[string equal [$tchVia getName] [$v12 getName]]} [format "techvia name doesn't match: %s %s" [$tchVia getName] [$v12 getName]] + +# Check tech via +set nextOp [$decoder next] +assert {$nextOp == $odb::dbWireDecoder_TECH_VIA} [format "nextop isn't via: %d" $nextOp] +set tchVia [$decoder getTechVia] +assert {[string equal [$tchVia getName] [$v23 getName]]} [format "techvia name doesn't match: %s %s" [$tchVia getName] [$v23 getName]] + +# Check next point +set nextOp [$decoder next] +assert {$nextOp == $odb::dbWireDecoder_POINT_EXT} [format "nextop isn't point_ext: %d" $nextOp] +set point [$decoder getPoint_ext] +assert {[lequal $point [list 3000 10000 4000]]} "point list doesn't match" + +# Check next point +set nextOp [$decoder next] +assert {$nextOp == $odb::dbWireDecoder_POINT_EXT} [format "nextop isn't point_ext: %d" $nextOp] +set point [$decoder getPoint_ext] +assert {[lequal $point [list 3000 18000 6000]]} "point list doesn't match" + +puts "pass" +exit 0