|
| 1 | +#include <iostream> |
| 2 | +#include <string> |
| 3 | + |
| 4 | +#include "gtest/gtest.h" |
| 5 | +#include "odb/3dblox.h" |
| 6 | +#include "odb/db.h" |
| 7 | +#include "odb/geom.h" |
| 8 | +#include "tst/fixture.h" |
| 9 | + |
| 10 | +namespace odb { |
| 11 | +namespace { |
| 12 | + |
| 13 | +class CheckerFixture : public tst::Fixture |
| 14 | +{ |
| 15 | + protected: |
| 16 | + CheckerFixture() |
| 17 | + { |
| 18 | + tech_ = dbTech::create(db_.get(), "tech"); |
| 19 | + // Create a top chip |
| 20 | + top_chip_ |
| 21 | + = dbChip::create(db_.get(), nullptr, "TopChip", dbChip::ChipType::HIER); |
| 22 | + top_chip_->setWidth(10000); |
| 23 | + top_chip_->setHeight(10000); |
| 24 | + top_chip_->setThickness(1000); |
| 25 | + // Create master chips |
| 26 | + chip1_ = dbChip::create(db_.get(), tech_, "Chip1", dbChip::ChipType::DIE); |
| 27 | + chip1_->setWidth(2000); |
| 28 | + chip1_->setHeight(2000); |
| 29 | + chip1_->setThickness(500); |
| 30 | + |
| 31 | + chip2_ = dbChip::create(db_.get(), tech_, "Chip2", dbChip::ChipType::DIE); |
| 32 | + chip2_->setWidth(1500); |
| 33 | + chip2_->setHeight(1500); |
| 34 | + chip2_->setThickness(500); |
| 35 | + |
| 36 | + chip3_ = dbChip::create(db_.get(), tech_, "Chip3", dbChip::ChipType::DIE); |
| 37 | + chip3_->setWidth(1000); |
| 38 | + chip3_->setHeight(1000); |
| 39 | + chip3_->setThickness(500); |
| 40 | + } |
| 41 | + |
| 42 | + dbTech* tech_; |
| 43 | + dbChip* top_chip_; |
| 44 | + dbChip* chip1_; |
| 45 | + dbChip* chip2_; |
| 46 | + dbChip* chip3_; |
| 47 | +}; |
| 48 | + |
| 49 | +TEST_F(CheckerFixture, test_overlapping_chips) |
| 50 | +{ |
| 51 | + // Create two overlapping chip instances |
| 52 | + auto inst1 = dbChipInst::create(top_chip_, chip1_, "inst1"); |
| 53 | + inst1->setLoc(Point3D(0, 0, 0)); |
| 54 | + inst1->setOrient(dbOrientType3D(dbOrientType::R0, false)); |
| 55 | + |
| 56 | + auto inst2 = dbChipInst::create(top_chip_, chip2_, "inst2"); |
| 57 | + // Place inst2 overlapping with inst1 |
| 58 | + inst2->setLoc(Point3D(1000, 1000, 0)); // Overlaps with inst1 |
| 59 | + inst2->setOrient(dbOrientType3D(dbOrientType::R0, false)); |
| 60 | + |
| 61 | + // Run checker |
| 62 | + ThreeDBlox three_dblox(&logger_, db_.get()); |
| 63 | + three_dblox.check(); |
| 64 | + |
| 65 | + // Verify markers were created |
| 66 | + auto category = top_chip_->findMarkerCategory("3DBlox"); |
| 67 | + ASSERT_NE(category, nullptr); |
| 68 | + |
| 69 | + auto overlapping_category = category->findMarkerCategory("Overlapping chips"); |
| 70 | + ASSERT_NE(overlapping_category, nullptr); |
| 71 | + |
| 72 | + auto markers = overlapping_category->getMarkers(); |
| 73 | + EXPECT_EQ(markers.size(), 1); |
| 74 | + |
| 75 | + if (markers.size() > 0) { |
| 76 | + auto marker = *markers.begin(); |
| 77 | + auto sources = marker->getSources(); |
| 78 | + EXPECT_EQ(sources.size(), 2); |
| 79 | + EXPECT_EQ(marker->getBBox(), odb::Rect(1000, 1000, 2000, 2000)); |
| 80 | + // Verify both chip instances are in the sources |
| 81 | + bool found_inst1 = false; |
| 82 | + bool found_inst2 = false; |
| 83 | + for (auto src : sources) { |
| 84 | + if (src->getObjectType() == dbObjectType::dbChipInstObj) { |
| 85 | + auto chip_inst = static_cast<dbChipInst*>(src); |
| 86 | + if (chip_inst->getName() == "inst1") { |
| 87 | + found_inst1 = true; |
| 88 | + } |
| 89 | + if (chip_inst->getName() == "inst2") { |
| 90 | + found_inst2 = true; |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + EXPECT_TRUE(found_inst1); |
| 95 | + EXPECT_TRUE(found_inst2); |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +TEST_F(CheckerFixture, test_floating_chips) |
| 100 | +{ |
| 101 | + // Create three chip instances: two connected, one floating |
| 102 | + auto inst1 = dbChipInst::create(top_chip_, chip1_, "inst1"); |
| 103 | + inst1->setLoc(Point3D(0, 0, 0)); |
| 104 | + inst1->setOrient(dbOrientType3D(dbOrientType::R0, false)); |
| 105 | + |
| 106 | + auto inst2 = dbChipInst::create(top_chip_, chip2_, "inst2"); |
| 107 | + // Place inst2 touching inst1 (connected) |
| 108 | + inst2->setLoc(Point3D(0, 0, 500)); // Stacked on top of inst1 |
| 109 | + inst2->setOrient(dbOrientType3D(dbOrientType::R0, false)); |
| 110 | + |
| 111 | + auto inst3 = dbChipInst::create(top_chip_, chip3_, "inst3"); |
| 112 | + // Place inst3 far away (floating) |
| 113 | + inst3->setLoc(Point3D(5000, 5000, 0)); |
| 114 | + inst3->setOrient(dbOrientType3D(dbOrientType::R0, false)); |
| 115 | + |
| 116 | + // Run checker |
| 117 | + ThreeDBlox three_dblox(&logger_, db_.get()); |
| 118 | + three_dblox.check(); |
| 119 | + |
| 120 | + // Verify markers were created |
| 121 | + auto category = top_chip_->findMarkerCategory("3DBlox"); |
| 122 | + ASSERT_NE(category, nullptr); |
| 123 | + |
| 124 | + auto floating_category = category->findMarkerCategory("Floating chips"); |
| 125 | + ASSERT_NE(floating_category, nullptr); |
| 126 | + |
| 127 | + auto markers = floating_category->getMarkers(); |
| 128 | + EXPECT_EQ(markers.size(), 1); |
| 129 | + |
| 130 | + if (markers.size() > 0) { |
| 131 | + auto marker = *markers.begin(); |
| 132 | + auto sources = marker->getSources(); |
| 133 | + EXPECT_EQ(sources.size(), 1); |
| 134 | + // Verify the floating chip is inst3 |
| 135 | + if (sources.size() > 0) { |
| 136 | + auto src = *sources.begin(); |
| 137 | + EXPECT_EQ(src->getObjectType(), dbObjectType::dbChipInstObj); |
| 138 | + auto chip_inst = static_cast<dbChipInst*>(src); |
| 139 | + EXPECT_EQ(chip_inst->getName(), "inst3"); |
| 140 | + } |
| 141 | + } |
| 142 | +} |
| 143 | + |
| 144 | +TEST_F(CheckerFixture, test_no_violations) |
| 145 | +{ |
| 146 | + // Create two non-overlapping, connected chip instances |
| 147 | + auto inst1 = dbChipInst::create(top_chip_, chip1_, "inst1"); |
| 148 | + inst1->setLoc(Point3D(0, 0, 0)); |
| 149 | + inst1->setOrient(dbOrientType3D(dbOrientType::R0, false)); |
| 150 | + |
| 151 | + auto inst2 = dbChipInst::create(top_chip_, chip2_, "inst2"); |
| 152 | + // Place inst2 touching but not overlapping inst1 |
| 153 | + inst2->setLoc(Point3D(0, 0, 500)); // Stacked on top |
| 154 | + inst2->setOrient(dbOrientType3D(dbOrientType::R0, false)); |
| 155 | + |
| 156 | + // Run checker |
| 157 | + ThreeDBlox three_dblox(&logger_, db_.get()); |
| 158 | + three_dblox.check(); |
| 159 | + |
| 160 | + // Verify no violation markers were created |
| 161 | + auto category = top_chip_->findMarkerCategory("3DBlox"); |
| 162 | + ASSERT_NE(category, nullptr); |
| 163 | + |
| 164 | + auto overlapping_category = category->findMarkerCategory("Overlapping chips"); |
| 165 | + if (overlapping_category != nullptr) { |
| 166 | + auto markers = overlapping_category->getMarkers(); |
| 167 | + EXPECT_EQ(markers.size(), 0); |
| 168 | + } |
| 169 | + |
| 170 | + auto floating_category = category->findMarkerCategory("Floating chips"); |
| 171 | + if (floating_category != nullptr) { |
| 172 | + auto markers = floating_category->getMarkers(); |
| 173 | + EXPECT_EQ(markers.size(), 0); |
| 174 | + } |
| 175 | +} |
| 176 | + |
| 177 | +TEST_F(CheckerFixture, test_multiple_violations) |
| 178 | +{ |
| 179 | + // Create a complex scenario with both overlapping and floating chips |
| 180 | + auto inst1 = dbChipInst::create(top_chip_, chip1_, "inst1"); |
| 181 | + inst1->setLoc(Point3D(0, 0, 0)); |
| 182 | + inst1->setOrient(dbOrientType3D(dbOrientType::R0, false)); |
| 183 | + |
| 184 | + auto inst2 = dbChipInst::create(top_chip_, chip2_, "inst2"); |
| 185 | + // Overlapping with inst1 |
| 186 | + inst2->setLoc(Point3D(500, 500, 0)); |
| 187 | + inst2->setOrient(dbOrientType3D(dbOrientType::R0, false)); |
| 188 | + |
| 189 | + auto inst3 = dbChipInst::create(top_chip_, chip3_, "inst3"); |
| 190 | + // Also overlapping with inst1 |
| 191 | + inst3->setLoc(Point3D(1000, 1000, 0)); |
| 192 | + inst3->setOrient(dbOrientType3D(dbOrientType::R0, false)); |
| 193 | + |
| 194 | + auto inst4 = dbChipInst::create(top_chip_, chip3_, "inst4"); |
| 195 | + // Floating chip |
| 196 | + inst4->setLoc(Point3D(7000, 7000, 0)); |
| 197 | + inst4->setOrient(dbOrientType3D(dbOrientType::R0, false)); |
| 198 | + |
| 199 | + // Run checker |
| 200 | + ThreeDBlox three_dblox(&logger_, db_.get()); |
| 201 | + three_dblox.check(); |
| 202 | + |
| 203 | + // Verify markers were created |
| 204 | + auto category = top_chip_->findMarkerCategory("3DBlox"); |
| 205 | + ASSERT_NE(category, nullptr); |
| 206 | + |
| 207 | + // Check overlapping chips |
| 208 | + auto overlapping_category = category->findMarkerCategory("Overlapping chips"); |
| 209 | + ASSERT_NE(overlapping_category, nullptr); |
| 210 | + auto overlapping_markers = overlapping_category->getMarkers(); |
| 211 | + EXPECT_GT(overlapping_markers.size(), 0); |
| 212 | + |
| 213 | + // Check floating chips |
| 214 | + auto floating_category = category->findMarkerCategory("Floating chips"); |
| 215 | + ASSERT_NE(floating_category, nullptr); |
| 216 | + auto floating_markers = floating_category->getMarkers(); |
| 217 | + EXPECT_EQ(floating_markers.size(), 1); |
| 218 | +} |
| 219 | + |
| 220 | +} // namespace |
| 221 | +} // namespace odb |
0 commit comments