File size: 4,151 Bytes
5cdf637 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | // SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2026, The OpenROAD Authors
#include "gtest/gtest.h"
#include "helper.h"
#include "odb/db.h"
namespace odb {
namespace {
class TestGCellTileSize : public SimpleDbFixture
{
protected:
void SetUp() override { createSimpleDB(); }
dbTech* tech() { return db_->getTech(); }
dbBlock* block() { return db_->getChip()->getBlock(); }
// Creates a frontside ROUTING layer with a track grid of the given pitch.
dbTechLayer* makeRoutingLayer(const char* name, int pitch)
{
dbTechLayer* layer
= dbTechLayer::create(tech(), name, dbTechLayerType::ROUTING);
layer->setDirection(dbTechLayerDir::HORIZONTAL);
dbTrackGrid* track = dbTrackGrid::create(block(), layer);
track->addGridPatternY(0, 1000, pitch);
return layer;
}
// Creates a backside ROUTING layer with no track grid -- getGCellTileSize
// never needs a backside layer's track grid, only its presence in the raw
// getRoutingLevel() numbering.
dbTechLayer* makeBacksideLayer(const char* name)
{
dbTechLayer* layer
= dbTechLayer::create(tech(), name, dbTechLayerType::ROUTING);
layer->setBackside(true);
return layer;
}
// Creates a frontside ROUTING layer with no track grid at all.
dbTechLayer* makeUntrackedRoutingLayer(const char* name)
{
dbTechLayer* layer
= dbTechLayer::create(tech(), name, dbTechLayerType::ROUTING);
layer->setDirection(dbTechLayerDir::HORIZONTAL);
return layer;
}
};
// Reproduces a null-pointer dereference in getGCellTileSize()'s
// getAverageTrackSpacing() lambda: it counts frontside (non-backside)
// ROUTING layers to find the Nth one, but the baseline call site
// unconditionally asks for the 2nd/3rd/4th frontside layer regardless of
// how many frontside layers actually exist once max_routing_layer_ is at
// least 4 in the tech's raw (backside-inclusive) numbering. On a
// technology whose leading routing layers are backside (e.g. a BSPDN
// stack), that lookup can fail to find a layer at all, leaving the local
// tech_layer pointer null. The unguarded error-message call then
// dereferences it (tech_layer->getName()) even though the surrounding
// null check already proved it might be null -- crashing on the
// error-reporting path itself rather than raising a proper error.
//
// Here, 4 backside layers precede a single frontside layer (M1), so
// getRoutingLevel() puts M1 at raw level 5 -- past the early-return
// threshold (< 4), so getGCellTileSize() takes the baseline path and asks
// for the 2nd frontside layer, which doesn't exist.
TEST_F(TestGCellTileSize, ErrorsRatherThanCrashesWithTooFewFrontsideLayers)
{
makeBacksideLayer("BPR");
makeBacksideLayer("BM1");
makeBacksideLayer("BM2");
makeBacksideLayer("BRDL");
dbTechLayer* m1 = makeRoutingLayer("M1", 56);
ASSERT_EQ(m1->getRoutingLevel(), 5); // 4 backside + M1
block()->setMaxRoutingLayer(5);
// Confirm the specific new error fires (ODB-1219, "no such frontside
// layer"), not just that some runtime_error is thrown -- a bug in the
// split could silently fall through to the pre-existing ODB-0358
// ("track grid not found") instead and this would still vacuously
// pass without checking the message.
try {
block()->getGCellTileSize();
FAIL() << "Expected ODB-1219";
} catch (const std::exception& e) {
EXPECT_STREQ(e.what(), "ODB-1219");
} catch (...) {
FAIL() << "Unexpected exception (other than ODB-1219)";
}
}
// The split's other error path: tech_layer is found (so it's guaranteed
// non-null when findTrackGrid()/getName() are called), but that layer
// has no track grid built yet. Must raise the pre-existing ODB-0358,
// distinct from ODB-1219 above.
TEST_F(TestGCellTileSize, ErrorsOnFoundLayerWithNoTrackGrid)
{
makeUntrackedRoutingLayer("M1");
block()->setMaxRoutingLayer(1);
try {
block()->getGCellTileSize();
FAIL() << "Expected ODB-0358";
} catch (const std::exception& e) {
EXPECT_STREQ(e.what(), "ODB-0358");
} catch (...) {
FAIL() << "Unexpected exception (other than ODB-0358)";
}
}
} // namespace
} // namespace odb
|