File: dbNetlistCrossReference.rb

package info (click to toggle)
klayout 0.30.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 292,204 kB
  • sloc: cpp: 2,068,428; ruby: 47,823; xml: 26,924; python: 14,404; sh: 1,812; tcl: 212; perl: 170; makefile: 112; ansic: 42
file content (180 lines) | stat: -rw-r--r-- 5,678 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180

# encoding: UTF-8

# KLayout Layout Viewer
# Copyright (C) 2006-2025 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 DBNetlistCrossReference_TestClass < TestBase

  def test_1_Basic

    xref = RBA::NetlistCrossReference::new

    lvs = RBA::LayoutVsSchematic::new
    input = File.join($ut_testsrc, "testdata", "algo", "lvsdb_read_test.lvsdb")
    lvs.read(input)

    reader = RBA::NetlistSpiceReader::new
    nl = RBA::Netlist::new
    nl.read(File.join($ut_testsrc, "testdata", "algo", "lvs_test_1.spi"), reader)

    assert_equal(xref.circuit_count, 0)

    # A NetlistCrossReference object can act as a receiver for a netlist comparer
    comp = RBA::NetlistComparer::new
    comp.compare(lvs.netlist, nl, xref)

    assert_equal(xref.circuit_count, 3)

    xref.clear
    assert_equal(xref.circuit_count, 0)

  end

  def test_2_CircuitPairs

    lvs = RBA::LayoutVsSchematic::new
    input = File.join($ut_testsrc, "testdata", "algo", "lvsdb_read_test2.lvsdb")
    lvs.read(input)

    xref = lvs.xref
    assert_equal(xref.circuit_count, 4)

    info = []
    xref.each_circuit_pair do |cp|
      info << [ cp.first, cp.second ].collect { |s| s ? s.name : "(nil)" }.join("/") + ":" + cp.status.to_s
    end
    assert_equal(info.join(","), "(nil)/INV2PAIRX:Mismatch,INV2/INV2:Match,INV2PAIR/INV2PAIR:NoMatch,RINGO/RINGO:Skipped")

    cp_inv2 = nil
    xref.each_circuit_pair do |cp|
      if cp.first && cp.first.name == "INV2"
        cp_inv2 = cp
      end
    end

    assert_equal(cp_inv2 != nil, true)

    info = []
    xref.each_pin_pair(cp_inv2) do |p|
      info << [ p.first, p.second ].collect { |s| s ? s.name : "(nil)" }.join("/") + ":" + p.status.to_s
    end
    assert_equal(info.join(","), "/1:Match,BULK/6:Match,IN/2:Match,OUT/3:Match,VDD/5:Match,VSS/4:Match")
      
    info = []
    xref.each_net_pair(cp_inv2) do |p|
      info << [ p.first, p.second ].collect { |s| s ? s.name : "(nil)" }.join("/") + ":" + p.status.to_s
    end
    assert_equal(info.join(","), "/1:Match,BULK/6:Match,IN/2:Match,OUT/3:Match,VDD/5:Match,VSS/4:Match")

    netp_bulk = nil
    xref.each_net_pair(cp_inv2) do |p|
      if p.first.name == "BULK"
        netp_bulk = p
      end
    end
      
    info = []
    xref.each_net_terminal_pair(netp_bulk) do |p|
      info << [ p.first, p.second ].collect { |s| s ? s.terminal_def.name : "(nil)" }.join("/")
    end
    assert_equal(info.join(","), "B/B")

    info = []
    xref.each_net_pin_pair(netp_bulk) do |p|
      info << [ p.first, p.second ].collect { |s| s ? s.pin.name : "(nil)" }.join("/")
    end
    assert_equal(info.join(","), "BULK/6")

    info = []
    xref.each_net_subcircuit_pin_pair(netp_bulk) do |p|
      info << [ p.first, p.second ].collect { |s| s ? s.pin.name : "(nil)" }.join("/")
    end
    assert_equal(info.join(","), "")

    info = []
    xref.each_device_pair(cp_inv2) do |p|
      info << [ p.first, p.second ].collect { |s| s ? s.name : "(nil)" }.join("/") + ":" + p.status.to_s
    end
    assert_equal(info.join(","), "/$1:Match,/$3:Match")
      
    info = []
    xref.each_subcircuit_pair(cp_inv2) do |p|
      info << [ p.first, p.second ].collect { |s| s ? s.name : "(nil)" }.join("/") + ":" + p.status.to_s
    end
    assert_equal(info.join(","), "")
      
    cp_inv2pair = nil
    xref.each_circuit_pair do |cp|
      if cp.first && cp.first.name == "INV2PAIR"
        cp_inv2pair = cp
      end
    end

    assert_equal(cp_inv2pair != nil, true)

    info = []
    xref.each_pin_pair(cp_inv2pair) do |p|
      info << [ p.first, p.second ].collect { |s| s ? s.name : "(nil)" }.join("/") + ":" + p.status.to_s
    end
    assert_equal(info.join(","), "(nil)/5:Mismatch,/(nil):Mismatch,/2:Match,/3:Match,/4:Match,/6:Match,/7:Match,BULK/1:Match")
      
    info = []
    xref.each_net_pair(cp_inv2pair) do |p|
      info << [ p.first, p.second ].collect { |s| s ? s.name : "(nil)" }.join("/") + ":" + p.status.to_s
    end
    assert_equal(info.join(","), "/(nil):Mismatch,/2:Mismatch,/3:Mismatch,/4:Match,/6:Match,/7:Mismatch,BULK/1:Mismatch")
      
    info = []
    xref.each_device_pair(cp_inv2pair) do |p|
      info << [ p.first, p.second ].collect { |s| s ? s.name : "(nil)" }.join("/") + ":" + p.status.to_s
    end
    assert_equal(info.join(","), "")
      
    info = []
    xref.each_subcircuit_pair(cp_inv2pair) do |p|
      info << [ p.first, p.second ].collect { |s| s ? s.name : "(nil)" }.join("/") + ":" + p.status.to_s
    end
    assert_equal(info.join(","), "(nil)/$2:Mismatch,/(nil):Mismatch,/(nil):Mismatch")

  end

  def test_3_StatusEnums

    st = RBA::NetlistCrossReference::Status::new
    assert_equal(st.to_i, 0)
    assert_equal(st.to_s, "None")
  
    st = RBA::NetlistCrossReference::Status::Match
    assert_equal(st.to_s, "Match")

    st = RBA::NetlistCrossReference::Skipped
    assert_equal(st.to_s, "Skipped")

  end

end

load("test_epilogue.rb")