Some tests for Connectivity

This commit is contained in:
Matthias Koefferlein 2024-03-11 21:14:00 +01:00
parent 284a907ffb
commit fd8ca56caf
4 changed files with 200 additions and 0 deletions

View File

@ -26,22 +26,106 @@
namespace gsi namespace gsi
{ {
static std::string
l2s (db::Connectivity::layer_iterator b, db::Connectivity::layer_iterator e)
{
std::string s;
for (db::Connectivity::layer_iterator i = b; i != e; ++i) {
if (! s.empty ()) {
s += ",";
}
s += tl::to_string (i->first);
if (i->second < 0) {
s += "-S";
} else if (i->second > 0) {
s += "+S";
}
}
return s;
}
static std::string
gn2s (db::Connectivity::global_nets_iterator b, db::Connectivity::global_nets_iterator e)
{
std::string s;
for (db::Connectivity::global_nets_iterator i = b; i != e; ++i) {
if (! s.empty ()) {
s += ",";
}
s += tl::to_string (i->first);
if (i->second < 0) {
s += "-S";
} else if (i->second > 0) {
s += "+S";
}
}
return s;
}
static std::string
connectivity_to_string (const db::Connectivity *conn)
{
std::string res;
for (auto l = conn->begin_layers (); l != conn->end_layers (); ++l) {
if (conn->begin_connected (*l) != conn->end_connected (*l)) {
if (! res.empty ()) {
res += "\n";
}
res += tl::to_string (*l) + ":" + l2s (conn->begin_connected (*l), conn->end_connected (*l));
}
if (conn->begin_global_connections (*l) != conn->end_global_connections (*l)) {
if (! res.empty ()) {
res += "\n";
}
res += "G" + tl::to_string (*l) + ":" + gn2s (conn->begin_global_connections (*l), conn->end_global_connections (*l));
}
}
return res;
}
Class<db::Connectivity> decl_dbConnectivity ("db", "Connectivity", Class<db::Connectivity> decl_dbConnectivity ("db", "Connectivity",
gsi::method ("connect", (void (db::Connectivity::*) (unsigned int)) &db::Connectivity::connect, gsi::arg ("layer"), gsi::method ("connect", (void (db::Connectivity::*) (unsigned int)) &db::Connectivity::connect, gsi::arg ("layer"),
"@brief Specifies intra-layer connectivity.\n" "@brief Specifies intra-layer connectivity.\n"
"This method specifies a hard connection between shapes on the given layer. "
"Without specifying such a connection, shapes on that layer do not form connection regions."
) + ) +
gsi::method ("connect", (void (db::Connectivity::*) (unsigned int, unsigned int)) &db::Connectivity::connect, gsi::arg ("layer_a"), gsi::arg ("layer_b"), gsi::method ("connect", (void (db::Connectivity::*) (unsigned int, unsigned int)) &db::Connectivity::connect, gsi::arg ("layer_a"), gsi::arg ("layer_b"),
"@brief Specifies inter-layer connectivity.\n" "@brief Specifies inter-layer connectivity.\n"
"This method specifies a hard connection between shapes on layer_a and layer_b."
) +
gsi::method ("soft_connect", (void (db::Connectivity::*) (unsigned int, unsigned int)) &db::Connectivity::soft_connect, gsi::arg ("layer_a"), gsi::arg ("layer_b"),
"@brief Specifies a soft connection between layer_a and layer_b.\n"
"@param layer_a The 'upper' layer\n"
"@param layer_b The 'lower' layer\n"
"Soft connections are made between a lower and an upper layer. The lower layer conceptually is a high-ohmic "
"(i.e. substrate, diffusion) region that is not intended for signal wiring. The netlist extraction will check "
"that no routing happens over such regions.\n"
"\n"
"Soft connections have in introduced in version 0.29."
) + ) +
gsi::method ("connect_global", (size_t (db::Connectivity::*) (unsigned int, const std::string &)) &db::Connectivity::connect_global, gsi::arg ("layer"), gsi::arg ("global_net_name"), gsi::method ("connect_global", (size_t (db::Connectivity::*) (unsigned int, const std::string &)) &db::Connectivity::connect_global, gsi::arg ("layer"), gsi::arg ("global_net_name"),
"@brief Connects the given layer to the global net given by name.\n" "@brief Connects the given layer to the global net given by name.\n"
"Returns the ID of the global net." "Returns the ID of the global net."
) + ) +
gsi::method ("soft_connect_global", (size_t (db::Connectivity::*) (unsigned int, const std::string &)) &db::Connectivity::soft_connect_global, gsi::arg ("layer"), gsi::arg ("global_net_name"),
"@brief Soft-connects the given layer to the global net given by name.\n"
"Returns the ID of the global net.\n"
"See \\soft_connect for a description of the soft connection feature. The global net is always the "
"'lower' (i.e. high-ohmic, substrate) part of the soft connection.\n"
"\n"
"Soft connections have in introduced in version 0.29."
) +
gsi::method ("global_net_name", &db::Connectivity::global_net_name, gsi::arg ("global_net_id"), gsi::method ("global_net_name", &db::Connectivity::global_net_name, gsi::arg ("global_net_id"),
"@brief Gets the name for a given global net ID.\n" "@brief Gets the name for a given global net ID.\n"
) + ) +
gsi::method ("global_net_id", &db::Connectivity::global_net_id, gsi::arg ("global_net_name"), gsi::method ("global_net_id", &db::Connectivity::global_net_id, gsi::arg ("global_net_name"),
"@brief Gets the ID for a given global net name.\n" "@brief Gets the ID for a given global net name.\n"
) +
// provided for testing purposes mainly.
gsi::method_ext ("to_s", &connectivity_to_string,
"@hide\n"
), ),
"@brief This class specifies connections between different layers.\n" "@brief This class specifies connections between different layers.\n"
"Connections are build using \\connect. There are basically two flavours of connections: intra-layer and inter-layer.\n" "Connections are build using \\connect. There are basically two flavours of connections: intra-layer and inter-layer.\n"
@ -60,6 +144,10 @@ Class<db::Connectivity> decl_dbConnectivity ("db", "Connectivity",
"Global nets are defined by name and are managed through IDs. To get the name for a given ID, use " "Global nets are defined by name and are managed through IDs. To get the name for a given ID, use "
"\\global_net_name." "\\global_net_name."
"\n" "\n"
"Starting with version 0.29, soft connections are supported. Soft connections attach to high-ohmic substrate or diffusion "
"layers (the 'lower' layer) are upon netlist extraction it will be checked that no wiring is routed over such connections. "
"See \\soft_connect and \\soft_global_connect for details.\n"
"\n"
"This class has been introduced in version 0.26.\n" "This class has been introduced in version 0.26.\n"
); );

View File

@ -126,6 +126,60 @@ TEST(1_Connectivity)
EXPECT_EQ (conn2.global_net_name (1), "GLOBAL2"); EXPECT_EQ (conn2.global_net_name (1), "GLOBAL2");
} }
TEST(1_ConnectivitySoft)
{
db::Connectivity conn;
EXPECT_EQ (al2s (conn.begin_layers (), conn.end_layers ()), "");
conn.connect (0);
EXPECT_EQ (al2s (conn.begin_layers (), conn.end_layers ()), "0");
EXPECT_EQ (l2s (conn.begin_connected (0), conn.end_connected (0)), "0");
EXPECT_EQ (l2s (conn.begin_connected (1), conn.end_connected (1)), "");
conn.soft_connect (0, 1);
EXPECT_EQ (al2s (conn.begin_layers (), conn.end_layers ()), "0,1");
EXPECT_EQ (l2s (conn.begin_connected (0), conn.end_connected (0)), "0,1-S");
EXPECT_EQ (l2s (conn.begin_connected (1), conn.end_connected (1)), "0+S");
conn.connect (1);
EXPECT_EQ (l2s (conn.begin_connected (1), conn.end_connected (1)), "0+S,1");
conn.soft_connect (2, 0);
conn.connect (2);
EXPECT_EQ (l2s (conn.begin_connected (0), conn.end_connected (0)), "0,1-S,2+S");
EXPECT_EQ (l2s (conn.begin_connected (1), conn.end_connected (1)), "0+S,1");
EXPECT_EQ (l2s (conn.begin_connected (2), conn.end_connected (2)), "0-S,2");
conn.connect (2, 0);
EXPECT_EQ (l2s (conn.begin_connected (0), conn.end_connected (0)), "0,1-S,2");
EXPECT_EQ (l2s (conn.begin_connected (1), conn.end_connected (1)), "0+S,1");
EXPECT_EQ (l2s (conn.begin_connected (2), conn.end_connected (2)), "0,2");
EXPECT_EQ (conn.soft_connect_global (0, "GLOBAL"), size_t (0));
EXPECT_EQ (gn2s (conn.begin_global_connections (2), conn.end_global_connections (2)), "");
EXPECT_EQ (gn2s (conn.begin_global_connections (0), conn.end_global_connections (0)), "0-S");
EXPECT_EQ (conn.soft_connect_global (2, "GLOBAL2"), size_t (1));
EXPECT_EQ (gn2s (conn.begin_global_connections (2), conn.end_global_connections (2)), "1-S");
EXPECT_EQ (conn.connect_global (0, "GLOBAL2"), size_t (1));
EXPECT_EQ (gn2s (conn.begin_global_connections (0), conn.end_global_connections (0)), "0-S,1");
EXPECT_EQ (conn.global_net_name (0), "GLOBAL");
EXPECT_EQ (conn.global_net_name (1), "GLOBAL2");
db::Connectivity conn2 = conn;
EXPECT_EQ (l2s (conn2.begin_connected (0), conn2.end_connected (0)), "0,1-S,2");
EXPECT_EQ (l2s (conn2.begin_connected (1), conn2.end_connected (1)), "0+S,1");
EXPECT_EQ (l2s (conn2.begin_connected (2), conn2.end_connected (2)), "0,2");
EXPECT_EQ (gn2s (conn2.begin_global_connections (0), conn2.end_global_connections (0)), "0-S,1");
EXPECT_EQ (conn2.global_net_name (0), "GLOBAL");
EXPECT_EQ (conn2.global_net_name (1), "GLOBAL2");
}
TEST(2_ShapeInteractions) TEST(2_ShapeInteractions)
{ {
db::Connectivity conn; db::Connectivity conn;

View File

@ -102,6 +102,7 @@ RUBYTEST (dbEdgePairTest, "dbEdgePairTest.rb")
RUBYTEST (dbEdgesTest, "dbEdgesTest.rb") RUBYTEST (dbEdgesTest, "dbEdgesTest.rb")
RUBYTEST (dbEdgeTest, "dbEdgeTest.rb") RUBYTEST (dbEdgeTest, "dbEdgeTest.rb")
RUBYTEST (dbGlyphs, "dbGlyphs.rb") RUBYTEST (dbGlyphs, "dbGlyphs.rb")
RUBYTEST (dbHierNetworkProcessorTests, "dbHierNetworkProcessorTests.rb")
RUBYTEST (dbInstanceTest, "dbInstanceTest.rb") RUBYTEST (dbInstanceTest, "dbInstanceTest.rb")
RUBYTEST (dbInstElementTest, "dbInstElementTest.rb") RUBYTEST (dbInstElementTest, "dbInstElementTest.rb")
RUBYTEST (dbLayerMapping, "dbLayerMapping.rb") RUBYTEST (dbLayerMapping, "dbLayerMapping.rb")

View File

@ -0,0 +1,57 @@
# encoding: UTF-8
# KLayout Layout Viewer
# Copyright (C) 2006-2024 Matthias Koefferlein
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
if !$:.member?(File::dirname($0))
$:.push(File::dirname($0))
end
load("test_prologue.rb")
class DBHierNetworkProcessor_TestClass < TestBase
# Connectivity
def test_1_Connectivity
conn = RBA::Connectivity::new
assert_equal(conn.to_s, "")
conn.connect(1)
assert_equal(conn.to_s, "1:1")
conn.connect(0, 1)
assert_equal(conn.to_s, "0:1\n1:0,1")
conn.soft_connect(0, 2)
assert_equal(conn.to_s, "0:1,2-S\n1:0,1\n2:0+S")
gid1 = conn.connect_global(0, "GLOBAL1")
assert_equal(gid1, 0)
assert_equal(conn.global_net_name(gid1), "GLOBAL1")
assert_equal(conn.global_net_id("GLOBAL1"), 0)
assert_equal(conn.to_s, "0:1,2-S\nG0:0\n1:0,1\n2:0+S")
conn.soft_connect_global(1, "GLOBAL1")
assert_equal(conn.to_s, "0:1,2-S\nG0:0\n1:0,1\nG1:0-S\n2:0+S")
end
end
load("test_epilogue.rb")