/ test / unit / design / library.py
library.py
  1  # SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-or-later OR CERN-OHL-S-2.0+ OR Apache-2.0
  2  # type: ignore
  3  import unittest
  4  
  5  from pdkmaster.technology import primitive as _prm
  6  from pdkmaster.design import cell as _cell, routinggauge as _rg, library as _lbry, factory as _fab
  7  
  8  from ..dummy import dummy_tech, dummy_cktfab, dummy_layoutfab, dummy_lib, dummy_fab
  9  dummy_prims = dummy_tech.primitives
 10  
 11  
 12  class LibraryTest(unittest.TestCase):
 13      def test_property(self):
 14          # Can't assign to .cells
 15          with self.assertRaises(AttributeError):
 16              dummy_lib.cells = _cell._Cells()
 17  
 18          self.assertEqual(dummy_lib.tech, dummy_tech)
 19          self.assertEqual(dummy_fab.cktfab, dummy_cktfab)
 20          self.assertEqual(dummy_fab.layoutfab, dummy_layoutfab)
 21  
 22      def test___init__(self):
 23          # code coverage
 24          tuple(dummy_lib.sorted_cells)
 25  
 26          lib = _lbry.Library(name="test", tech=dummy_tech)
 27          fab = _fab.BaseCellFactory(lib=lib, cktfab=dummy_cktfab, layoutfab=dummy_layoutfab)
 28          cell = fab.new_cell(name="test")
 29          ckt = cell.new_circuit()
 30  
 31          cell2 = fab.new_cell(name="test2")
 32          ckt2 = cell2.new_circuit()
 33  
 34          # Instantiate in first created in order to try to trigger code
 35          # in sorted_cells.
 36          ckt.instantiate(cell2, name="cell2")
 37  
 38          tuple(lib.sorted_cells)
 39  
 40  
 41  class RoutingGaugeLibraryTest(unittest.TestCase):
 42      def test_routinggauge(self):
 43          mw = _prm.MetalWire(name="mw", min_width=1.0, min_space=1.0)
 44  
 45          with self.assertRaises(ValueError):
 46              # wrong bottom
 47              _rg.RoutingGauge(
 48                  tech=dummy_tech, bottom=mw, bottom_direction="horizontal",
 49                  top=dummy_prims.metal2,
 50                  pingrid_pitch=0.4, row_height=10.0,
 51              )
 52          with self.assertRaises(ValueError):
 53              # wrong top
 54              _rg.RoutingGauge(
 55                  tech=dummy_tech, bottom=dummy_prims.metal, bottom_direction="horizontal",
 56                  top=mw,
 57                  pingrid_pitch=0.4, row_height=10.0,
 58              )
 59          with self.assertRaises(ValueError):
 60              # top not above bottom
 61              _rg.RoutingGauge(
 62                  tech=dummy_tech, bottom=dummy_prims.metal2, bottom_direction="horizontal",
 63                  top=dummy_prims.metal,
 64                  pingrid_pitch=0.4, row_height=10.0,
 65              )
 66          with self.assertRaises(ValueError):
 67              # wrong direction
 68              _rg.RoutingGauge(
 69                  tech=dummy_tech, bottom=dummy_prims.metal, bottom_direction="error",
 70                  top=dummy_prims.metal2,
 71                  pingrid_pitch=0.4, row_height=10.0,
 72              )
 73          with self.assertRaises(ValueError):
 74              # wrong metalwire in pitches
 75              _rg.RoutingGauge(
 76                  tech=dummy_tech, bottom=dummy_prims.metal, bottom_direction="horizontal",
 77                  top=dummy_prims.metal2,
 78                  pitches={
 79                      mw: 2.0,
 80                      dummy_prims.metal2: 2.0,
 81                  },
 82                  offsets={
 83                      dummy_prims.metal: 0.0,
 84                      dummy_prims.metal2: 1.0,
 85                  },
 86                  pingrid_pitch=0.4, row_height=10.0,
 87              )
 88          with self.assertRaises(ValueError):
 89              # wrong metalwire in offsets
 90              _rg.RoutingGauge(
 91                  tech=dummy_tech, bottom=dummy_prims.metal, bottom_direction="horizontal",
 92                  top=dummy_prims.metal2,
 93                  pitches={
 94                      dummy_prims.metal: 2.0,
 95                      dummy_prims.metal2: 2.0,
 96                  },
 97                  offsets={
 98                      dummy_prims.metal: 0.0,
 99                      mw: 1.0,
100                  },
101                  pingrid_pitch=0.4, row_height=10.0,
102              )
103  
104      def test_stdcelllibrary(self):
105          rg = _rg.RoutingGauge(
106              tech=dummy_tech, bottom=dummy_prims.metal, bottom_direction="horizontal",
107              top=dummy_prims.metal2,
108              pitches={
109                  dummy_prims.metal: 2.0,
110                  dummy_prims.metal2: 2.0,
111              },
112              offsets={
113                  dummy_prims.metal: 0.0,
114                  dummy_prims.metal2: 1.0,
115              },
116              pingrid_pitch=0.4, row_height=10.0,
117          )
118          lib = _lbry.RoutingGaugeLibrary(
119              name="test", tech=dummy_tech, routinggauge=rg,
120          )
121  
122          self.assertEqual(rg.tech, dummy_tech)
123  
124          self.assertEqual(lib.routinggauge[0], rg)
125          self.assertAlmostEqual(lib.pingrid_pitch, 0.4)
126          self.assertAlmostEqual(lib.row_height, 10.0)