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

37 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# 

24from __future__ import annotations 

25 

26import allure 

27import os 

28import tempfile 

29import unittest 

30 

31import klayout.db as kdb 

32 

33from klayout_pex.klayout.lvsdb_extractor import KLayoutExtractionContext 

34from klayout_pex.klayout.netlist_expander import NetlistExpander 

35from klayout_pex.log import ( 

36 debug, 

37) 

38from klayout_pex.common.capacitance_matrix import CapacitanceMatrix 

39from klayout_pex.tech_info import TechInfo 

40 

41 

42@allure.parent_suite("Unit Tests") 

43@allure.tag("Netlist", "Netlist Expansion") 

44class Test(unittest.TestCase): 

45 @property 

46 def klayout_testdata_dir(self) -> str: 

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

48 'testdata', 'fastercap')) 

49 

50 @property 

51 def tech_info_json_path(self) -> str: 

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

53 'build', 'sky130A_tech.pb.json')) 

54 

55 def test_netlist_expansion(self): 

56 exp = NetlistExpander() 

57 

58 cell_name = 'nmos_diode2' 

59 

60 lvsdb = kdb.LayoutVsSchematic() 

61 lvsdb_path = os.path.join(self.klayout_testdata_dir, f"{cell_name}.lvsdb.gz") 

62 lvsdb.read(lvsdb_path) 

63 

64 csv_path = os.path.join(self.klayout_testdata_dir, f"{cell_name}_FasterCap_Result_Matrix.csv") 

65 

66 cap_matrix = CapacitanceMatrix.parse_csv(csv_path, separator=';') 

67 

68 tech = TechInfo.from_json(self.tech_info_json_path, 

69 dielectric_filter=None) 

70 

71 pex_context = KLayoutExtractionContext.prepare_extraction(top_cell=cell_name, 

72 lvsdb=lvsdb, 

73 tech=tech, 

74 blackbox_devices=False) 

75 expanded_netlist = exp.expand(extracted_netlist=pex_context.lvsdb.netlist(), 

76 top_cell_name=pex_context.top_cell.name, 

77 cap_matrix=cap_matrix, 

78 blackbox_devices=False) 

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

80 spice_writer = kdb.NetlistSpiceWriter() 

81 expanded_netlist.write(out_path, spice_writer) 

82 debug(f"Wrote expanded netlist to: {out_path}") 

83 

84 allure.attach.file(csv_path, attachment_type=allure.attachment_type.CSV) 

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