2019-01-19 22:19:08 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
KLayout Layout Viewer
|
|
|
|
|
Copyright (C) 2006-2019 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
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "dbLayoutToNetlist.h"
|
|
|
|
|
#include "dbLayoutToNetlistReader.h"
|
|
|
|
|
#include "dbLayoutToNetlistWriter.h"
|
|
|
|
|
#include "dbStream.h"
|
|
|
|
|
#include "dbCommonReader.h"
|
|
|
|
|
#include "dbNetlistDeviceExtractorClasses.h"
|
2019-01-20 02:50:23 +01:00
|
|
|
#include "dbTestSupport.h"
|
2019-01-19 22:19:08 +01:00
|
|
|
|
|
|
|
|
#include "tlUnitTest.h"
|
|
|
|
|
#include "tlStream.h"
|
|
|
|
|
#include "tlFileUtils.h"
|
|
|
|
|
|
|
|
|
|
TEST(1_ReaderBasic)
|
|
|
|
|
{
|
2019-01-20 23:12:27 +01:00
|
|
|
db::LayoutToNetlist l2n;
|
2019-01-19 22:19:08 +01:00
|
|
|
|
|
|
|
|
std::string in_path = tl::combine_path (tl::combine_path (tl::combine_path (tl::testsrc (), "testdata"), "algo"), "l2n_writer_au.txt");
|
|
|
|
|
tl::InputStream is_in (in_path);
|
|
|
|
|
|
|
|
|
|
db::LayoutToNetlistStandardReader reader (is_in);
|
|
|
|
|
reader.read (&l2n);
|
|
|
|
|
|
|
|
|
|
// verify against the input
|
|
|
|
|
|
|
|
|
|
std::string path = tmp_file ("tmp_l2nreader_1.txt");
|
|
|
|
|
{
|
|
|
|
|
tl::OutputStream stream (path);
|
|
|
|
|
db::LayoutToNetlistStandardWriter writer (stream, false);
|
|
|
|
|
writer.write (&l2n);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string au_path = tl::combine_path (tl::combine_path (tl::combine_path (tl::testsrc (), "testdata"), "algo"), "l2n_writer_au.txt");
|
|
|
|
|
|
|
|
|
|
tl::InputStream is (path);
|
|
|
|
|
tl::InputStream is_au (au_path);
|
|
|
|
|
|
|
|
|
|
if (is.read_all () != is_au.read_all ()) {
|
|
|
|
|
_this->raise (tl::sprintf ("Compare failed - see\n actual: %s\n golden: %s",
|
|
|
|
|
tl::absolute_file_path (path),
|
|
|
|
|
tl::absolute_file_path (au_path)));
|
|
|
|
|
}
|
2019-01-19 23:00:19 +01:00
|
|
|
|
2019-01-20 02:50:23 +01:00
|
|
|
// test build_all_nets from read l2n
|
2019-01-19 23:00:19 +01:00
|
|
|
|
2019-01-20 02:50:23 +01:00
|
|
|
{
|
|
|
|
|
db::Layout ly2;
|
2019-01-20 23:12:27 +01:00
|
|
|
ly2.dbu (l2n.internal_layout ()->dbu ());
|
2019-01-20 02:50:23 +01:00
|
|
|
db::Cell &top2 = ly2.cell (ly2.add_cell ("TOP"));
|
|
|
|
|
|
|
|
|
|
db::CellMapping cm = l2n.cell_mapping_into (ly2, top2, true /*with device cells*/);
|
|
|
|
|
|
|
|
|
|
std::map<unsigned int, const db::Region *> lmap;
|
2019-01-20 23:12:27 +01:00
|
|
|
lmap [ly2.insert_layer (db::LayerProperties (10, 0))] = l2n.layer_by_name ("psd");
|
|
|
|
|
lmap [ly2.insert_layer (db::LayerProperties (11, 0))] = l2n.layer_by_name ("nsd");
|
|
|
|
|
lmap [ly2.insert_layer (db::LayerProperties (3, 0)) ] = l2n.layer_by_name ("poly");
|
|
|
|
|
lmap [ly2.insert_layer (db::LayerProperties (4, 0)) ] = l2n.layer_by_name ("diff_cont");
|
|
|
|
|
lmap [ly2.insert_layer (db::LayerProperties (5, 0)) ] = l2n.layer_by_name ("poly_cont");
|
|
|
|
|
lmap [ly2.insert_layer (db::LayerProperties (6, 0)) ] = l2n.layer_by_name ("metal1");
|
|
|
|
|
lmap [ly2.insert_layer (db::LayerProperties (7, 0)) ] = l2n.layer_by_name ("via1");
|
|
|
|
|
lmap [ly2.insert_layer (db::LayerProperties (8, 0)) ] = l2n.layer_by_name ("metal2");
|
2019-01-20 02:50:23 +01:00
|
|
|
|
|
|
|
|
l2n.build_all_nets (cm, ly2, lmap, "NET_", 0, "DEVICE_");
|
|
|
|
|
|
|
|
|
|
std::string au = tl::testsrc ();
|
|
|
|
|
au = tl::combine_path (au, "testdata");
|
|
|
|
|
au = tl::combine_path (au, "algo");
|
2019-01-20 17:31:58 +01:00
|
|
|
au = tl::combine_path (au, "l2n_reader_au.gds");
|
2019-01-20 02:50:23 +01:00
|
|
|
|
|
|
|
|
db::compare_layouts (_this, ly2, au);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-20 17:31:58 +01:00
|
|
|
TEST(1b_ReaderBasicShort)
|
2019-01-20 02:50:23 +01:00
|
|
|
{
|
2019-01-20 23:12:27 +01:00
|
|
|
db::LayoutToNetlist l2n;
|
2019-01-19 23:00:19 +01:00
|
|
|
|
2019-01-20 02:50:23 +01:00
|
|
|
std::string in_path = tl::combine_path (tl::combine_path (tl::combine_path (tl::testsrc (), "testdata"), "algo"), "l2n_writer_au_s.txt");
|
|
|
|
|
tl::InputStream is_in (in_path);
|
|
|
|
|
|
|
|
|
|
db::LayoutToNetlistStandardReader reader (is_in);
|
|
|
|
|
reader.read (&l2n);
|
|
|
|
|
|
|
|
|
|
// verify against the input
|
|
|
|
|
|
|
|
|
|
std::string path = tmp_file ("tmp_l2nreader_2.txt");
|
2019-01-19 23:00:19 +01:00
|
|
|
{
|
|
|
|
|
tl::OutputStream stream (path);
|
2019-01-20 02:50:23 +01:00
|
|
|
db::LayoutToNetlistStandardWriter writer (stream, true);
|
2019-01-19 23:00:19 +01:00
|
|
|
writer.write (&l2n);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-20 02:50:23 +01:00
|
|
|
std::string au_path = tl::combine_path (tl::combine_path (tl::combine_path (tl::testsrc (), "testdata"), "algo"), "l2n_writer_au_s.txt");
|
2019-01-19 23:00:19 +01:00
|
|
|
|
|
|
|
|
tl::InputStream is (path);
|
|
|
|
|
tl::InputStream is_au (au_path);
|
|
|
|
|
|
|
|
|
|
if (is.read_all () != is_au.read_all ()) {
|
|
|
|
|
_this->raise (tl::sprintf ("Compare failed - see\n actual: %s\n golden: %s",
|
|
|
|
|
tl::absolute_file_path (path),
|
|
|
|
|
tl::absolute_file_path (au_path)));
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-19 22:19:08 +01:00
|
|
|
}
|
2019-01-20 17:31:58 +01:00
|
|
|
|
|
|
|
|
TEST(2_ReaderWithGlobalNets)
|
|
|
|
|
{
|
2019-01-20 23:12:27 +01:00
|
|
|
db::LayoutToNetlist l2n;
|
2019-01-20 17:31:58 +01:00
|
|
|
|
|
|
|
|
std::string in_path = tl::combine_path (tl::combine_path (tl::combine_path (tl::testsrc (), "testdata"), "algo"), "l2n_writer_au_2.txt");
|
|
|
|
|
tl::InputStream is_in (in_path);
|
|
|
|
|
|
|
|
|
|
db::LayoutToNetlistStandardReader reader (is_in);
|
|
|
|
|
reader.read (&l2n);
|
|
|
|
|
|
|
|
|
|
// verify against the input
|
|
|
|
|
|
|
|
|
|
std::string path = tmp_file ("tmp_l2nreader_2.txt");
|
|
|
|
|
{
|
|
|
|
|
tl::OutputStream stream (path);
|
|
|
|
|
db::LayoutToNetlistStandardWriter writer (stream, false);
|
|
|
|
|
writer.write (&l2n);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string au_path = tl::combine_path (tl::combine_path (tl::combine_path (tl::testsrc (), "testdata"), "algo"), "l2n_writer_au_2.txt");
|
|
|
|
|
|
|
|
|
|
tl::InputStream is (path);
|
|
|
|
|
tl::InputStream is_au (au_path);
|
|
|
|
|
|
|
|
|
|
if (is.read_all () != is_au.read_all ()) {
|
|
|
|
|
_this->raise (tl::sprintf ("Compare failed - see\n actual: %s\n golden: %s",
|
|
|
|
|
tl::absolute_file_path (path),
|
|
|
|
|
tl::absolute_file_path (au_path)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// test build_all_nets from read l2n
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
db::Layout ly2;
|
2019-01-20 23:12:27 +01:00
|
|
|
ly2.dbu (l2n.internal_layout ()->dbu ());
|
2019-01-20 17:31:58 +01:00
|
|
|
db::Cell &top2 = ly2.cell (ly2.add_cell ("TOP"));
|
|
|
|
|
|
|
|
|
|
db::CellMapping cm = l2n.cell_mapping_into (ly2, top2, true /*with device cells*/);
|
|
|
|
|
|
|
|
|
|
std::map<unsigned int, const db::Region *> lmap;
|
2019-01-20 23:12:27 +01:00
|
|
|
lmap [ly2.insert_layer (db::LayerProperties (10, 0))] = l2n.layer_by_name ("psd");
|
|
|
|
|
lmap [ly2.insert_layer (db::LayerProperties (11, 0))] = l2n.layer_by_name ("nsd");
|
|
|
|
|
lmap [ly2.insert_layer (db::LayerProperties (12, 0))] = l2n.layer_by_name ("rbulk");
|
|
|
|
|
lmap [ly2.insert_layer (db::LayerProperties (13, 0))] = l2n.layer_by_name ("ptie");
|
|
|
|
|
lmap [ly2.insert_layer (db::LayerProperties (14, 0))] = l2n.layer_by_name ("ntie");
|
|
|
|
|
lmap [ly2.insert_layer (db::LayerProperties (1, 0)) ] = l2n.layer_by_name ("nwell");
|
|
|
|
|
lmap [ly2.insert_layer (db::LayerProperties (3, 0)) ] = l2n.layer_by_name ("poly");
|
|
|
|
|
lmap [ly2.insert_layer (db::LayerProperties (4, 0)) ] = l2n.layer_by_name ("diff_cont");
|
|
|
|
|
lmap [ly2.insert_layer (db::LayerProperties (5, 0)) ] = l2n.layer_by_name ("poly_cont");
|
|
|
|
|
lmap [ly2.insert_layer (db::LayerProperties (6, 0)) ] = l2n.layer_by_name ("metal1");
|
|
|
|
|
lmap [ly2.insert_layer (db::LayerProperties (7, 0)) ] = l2n.layer_by_name ("via1");
|
|
|
|
|
lmap [ly2.insert_layer (db::LayerProperties (8, 0)) ] = l2n.layer_by_name ("metal2");
|
2019-01-20 17:31:58 +01:00
|
|
|
|
|
|
|
|
l2n.build_all_nets (cm, ly2, lmap, "NET_", "CIRCUIT_", "DEVICE_");
|
|
|
|
|
|
|
|
|
|
std::string au = tl::testsrc ();
|
|
|
|
|
au = tl::combine_path (au, "testdata");
|
|
|
|
|
au = tl::combine_path (au, "algo");
|
|
|
|
|
au = tl::combine_path (au, "l2n_reader_au_2.gds");
|
|
|
|
|
|
|
|
|
|
db::compare_layouts (_this, ly2, au);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|