# encoding: UTF-8 # 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 if !$:.member?(File::dirname($0)) $:.push(File::dirname($0)) end load("test_prologue.rb") class DBLayoutToNetlist_TestClass < TestBase def test_1_Basic ly = RBA::Layout::new ly.read(File.join($ut_testsrc, "testdata", "algo", "device_extract_l1.gds")) l2n = RBA::LayoutToNetlist::new(RBA::RecursiveShapeIterator::new(ly, ly.top_cell, [])) l2n.threads = 17 l2n.max_vertex_count = 42 l2n.area_ratio = 7.5 assert_equal(l2n.threads, 17) assert_equal(l2n.max_vertex_count, 42) assert_equal(l2n.area_ratio, 7.5) r = l2n.make_layer(ly.layer(6, 0)) assert_not_equal(l2n.internal_layout.object_id, ly.object_id) assert_equal(l2n.internal_layout.top_cell.name, ly.top_cell.name) assert_equal(l2n.internal_top_cell.name, ly.top_cell.name) assert_not_equal(l2n.layer_of(r), ly.layer(6, 0)) # would be a strange coincidence ... cm = l2n.const_cell_mapping_into(ly, ly.top_cell) (0 .. l2n.internal_layout.cells - 1).each do |ci| assert_equal(l2n.internal_layout.cell(ci).name, ly.cell(cm.cell_mapping(ci)).name) end ly2 = RBA::Layout::new ly2.create_cell(ly.top_cell.name) cm = l2n.cell_mapping_into(ly2, ly2.top_cell) assert_equal(ly2.cells, ly.cells) (0 .. l2n.internal_layout.cells - 1).each do |ci| assert_equal(l2n.internal_layout.cell(ci).name, ly2.cell(cm.cell_mapping(ci)).name) end rmetal1 = l2n.make_polygon_layer( ly.layer(6, 0), "metal1" ) bulk_id = l2n.connect_global(rmetal1, "BULK") assert_equal(l2n.global_net_name(bulk_id), "BULK") end def test_2_ShapesFromNet ly = RBA::Layout::new ly.read(File.join($ut_testsrc, "testdata", "algo", "device_extract_l1.gds")) l2n = RBA::LayoutToNetlist::new(RBA::RecursiveShapeIterator::new(ly, ly.top_cell, [])) # only plain backend connectivity rmetal1 = l2n.make_polygon_layer( ly.layer(6, 0), "metal1" ) rmetal1_lbl = l2n.make_text_layer( ly.layer(6, 1), "metal1_lbl" ) rvia1 = l2n.make_polygon_layer( ly.layer(7, 0), "via1" ) rmetal2 = l2n.make_polygon_layer( ly.layer(8, 0), "metal2" ) rmetal2_lbl = l2n.make_text_layer( ly.layer(8, 1), "metal2_lbl" ) # Intra-layer l2n.connect(rmetal1) l2n.connect(rvia1) l2n.connect(rmetal2) # Inter-layer l2n.connect(rmetal1, rvia1) l2n.connect(rvia1, rmetal2) l2n.connect(rmetal1, rmetal1_lbl) # attaches labels l2n.connect(rmetal2, rmetal2_lbl) # attaches labels # Perform netlist extraction l2n.extract_netlist assert_equal(l2n.netlist.to_s, < rpsd, "G" => rpgate, "P" => rpoly }) # NMOS transistor device extraction nmos_ex = RBA::DeviceExtractorMOS3Transistor::new("NMOS") l2n.extract_devices(nmos_ex, { "SD" => rnsd, "G" => rngate, "P" => rpoly }) # Define connectivity for netlist extraction l2n.register(rpsd, "psd") l2n.register(rnsd, "nsd") # Intra-layer l2n.connect(rpsd) l2n.connect(rnsd) l2n.connect(rpoly) l2n.connect(rdiff_cont) l2n.connect(rpoly_cont) l2n.connect(rmetal1) l2n.connect(rvia1) l2n.connect(rmetal2) # Inter-layer l2n.connect(rpsd, rdiff_cont) l2n.connect(rnsd, rdiff_cont) l2n.connect(rpoly, rpoly_cont) l2n.connect(rpoly_cont, rmetal1) l2n.connect(rdiff_cont, rmetal1) l2n.connect(rmetal1, rvia1) l2n.connect(rvia1, rmetal2) l2n.connect(rpoly, rpoly_lbl) # attaches labels l2n.connect(rmetal1, rmetal1_lbl) # attaches labels l2n.connect(rmetal2, rmetal2_lbl) # attaches labels # Perform netlist extraction l2n.extract_netlist assert_equal(l2n.netlist.to_s, < rpsd, "G" => rpgate, "P" => rpoly, "W" => rnwell }) # NMOS transistor device extraction nmos_ex = RBA::DeviceExtractorMOS4Transistor::new("NMOS") l2n.extract_devices(nmos_ex, { "SD" => rnsd, "G" => rngate, "P" => rpoly, "W" => rbulk }) # Define connectivity for netlist extraction l2n.register(rpsd, "psd") l2n.register(rnsd, "nsd") l2n.register(rptie, "ptie") l2n.register(rntie, "ntie") # Intra-layer l2n.connect(rpsd) l2n.connect(rnsd) l2n.connect(rnwell) l2n.connect(rpoly) l2n.connect(rdiff_cont) l2n.connect(rpoly_cont) l2n.connect(rmetal1) l2n.connect(rvia1) l2n.connect(rmetal2) l2n.connect(rptie) l2n.connect(rntie) # Inter-layer l2n.connect(rpsd, rdiff_cont) l2n.connect(rnsd, rdiff_cont) l2n.connect(rpoly, rpoly_cont) l2n.connect(rpoly_cont, rmetal1) l2n.connect(rdiff_cont, rmetal1) l2n.connect(rdiff_cont, rntie) l2n.connect(rdiff_cont, rptie) l2n.connect(rnwell, rntie) l2n.connect(rmetal1, rvia1) l2n.connect(rvia1, rmetal2) l2n.connect(rpoly, rpoly_lbl) # attaches labels l2n.connect(rmetal1, rmetal1_lbl) # attaches labels l2n.connect(rmetal2, rmetal2_lbl) # attaches labels # Global connections l2n.connect_global(rptie, "BULK") l2n.connect_global(rbulk, "BULK") # Perform netlist extraction l2n.extract_netlist assert_equal(l2n.netlist.to_s, <