Coverage for tests/klayout/netlist_reducer_test.py: 100%

33 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-17 17:24 +0000

1# 

2# -------------------------------------------------------------------------------- 

3# SPDX-FileCopyrightText: 2024 Martin Jan Köhler and Harald Pretl 

4# Johannes Kepler University, Institute for Integrated Circuits. 

5# 

6# This file is part of KPEX  

7# (see https://github.com/martinjankoehler/klayout-pex). 

8# 

9# This program is free software: you can redistribute it and/or modify 

10# it under the terms of the GNU General Public License as published by 

11# the Free Software Foundation, either version 3 of the License, or 

12# (at your option) any later version. 

13# 

14# This program is distributed in the hope that it will be useful, 

15# but WITHOUT ANY WARRANTY; without even the implied warranty of 

16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

17# GNU General Public License for more details. 

18# 

19# You should have received a copy of the GNU General Public License 

20# along with this program. If not, see <http://www.gnu.org/licenses/>. 

21# SPDX-License-Identifier: GPL-3.0-or-later 

22# -------------------------------------------------------------------------------- 

23# 

24import allure 

25import os 

26import tempfile 

27import unittest 

28 

29import klayout.db as kdb 

30 

31from klayout_pex.log import ( 

32 LogLevel, 

33 set_log_level, 

34) 

35from klayout_pex.klayout.netlist_reducer import NetlistReducer 

36 

37 

38@allure.parent_suite("Unit Tests") 

39@allure.tag("Netlist", "Netlist Reduction") 

40class Test(unittest.TestCase): 

41 @classmethod 

42 def setUpClass(cls): 

43 set_log_level(LogLevel.DEBUG) 

44 

45 @property 

46 def klayout_testdata_dir(self) -> str: 

47 return os.path.realpath(os.path.join(__file__, '..', '..', '..', 

48 'testdata', 'klayout', 'netlists')) 

49 

50 def _test_netlist_reduction(self, netlist_path: str, cell_name: str): 

51 netlist = kdb.Netlist() 

52 reader = kdb.NetlistSpiceReader() 

53 netlist.read(netlist_path, reader) 

54 

55 reducer = NetlistReducer() 

56 reduced_netlist = reducer.reduce(netlist=netlist, top_cell_name=cell_name) 

57 

58 out_path = tempfile.mktemp(prefix=f"{cell_name}_Reduced_Netlist_", suffix=".cir") 

59 spice_writer = kdb.NetlistSpiceWriter() 

60 reduced_netlist.write(out_path, spice_writer) 

61 print(f"Wrote reduced netlist to: {out_path}") 

62 allure.attach.file(out_path, attachment_type=allure.attachment_type.TEXT) 

63 

64 def test_netlist_reduction_1(self): 

65 netlist_path = os.path.join(self.klayout_testdata_dir, 'nmos_diode2_Expanded_Netlist.cir') 

66 self._test_netlist_reduction(netlist_path=netlist_path, cell_name='nmos_diode2') 

67 

68 def test_netlist_reduction_2(self): 

69 netlist_path = os.path.join(self.klayout_testdata_dir, 'cap_vpp_Expanded_Netlist.cir') 

70 self._test_netlist_reduction(netlist_path=netlist_path, cell_name='TOP')