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 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
|
# 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")
def compare(a, b, flags = RBA::LayoutDiff::Verbose)
res = []
diff = RBA::LayoutDiff::new
diff.on_dbu_differs { |a,b| res << "on_dbu_differs #{'%.12g'%a} #{'%.12g'%b}" }
diff.on_layer_in_a_only { |a| res << "on_layer_in_a_only #{a}" }
diff.on_layer_in_b_only { |b| res << "on_layer_in_b_only #{b}" }
diff.on_layer_name_differs { |a,b| res << "on_layer_name_differs #{a} #{b}" }
diff.on_cell_name_differs { |a,b| res << "on_cell_name_differs #{a.name} #{b.name}" }
diff.on_cell_in_a_only { |a| res << "on_cell_in_a_only #{a.name}" }
diff.on_cell_in_b_only { |b| res << "on_cell_in_b_only #{b.name}" }
diff.on_bbox_differs { |a,b| res << "on_bbox_differs #{diff.cell_a.name}:#{a.to_s} #{diff.cell_b.name}:#{b.to_s}" }
diff.on_begin_cell { |a,b| res << "on_begin_cell #{a.name} #{b.name}" }
diff.on_begin_inst_differences { res << "on_begin_inst_differences" }
diff.on_instance_in_a_only { |i,p| res << "on_instance_in_a_only #{i.to_s} #{p.to_s}" }
diff.on_instance_in_b_only { |i,p| res << "on_instance_in_b_only #{i.to_s} #{p.to_s}" }
diff.on_end_inst_differences { res << "on_end_inst_differences" }
diff.on_begin_layer { |a,b| res << "on_begin_layer #{diff.layer_info_a.to_s}:#{a.to_s} #{diff.layer_info_b.to_s}:#{b.to_s}" }
diff.on_per_layer_bbox_differs { |a,b| res << "on_per_layer_bbox_differs #{diff.cell_a.name}@#{diff.layer_info_a.to_s}:#{a.to_s} #{diff.cell_b.name}@#{diff.layer_info_b.to_s}:#{b.to_s}" }
diff.on_begin_polygon_differences { res << "on_begin_polygon_differences" }
diff.on_polygon_in_a_only { |p| res << "polygon_in_a_only #{p.to_s}" }
diff.on_polygon_in_b_only { |p| res << "polygon_in_b_only #{p.to_s}" }
diff.on_end_polygon_differences { res << "on_end_polygon_differences" }
diff.on_begin_box_differences { res << "on_begin_box_differences" }
diff.on_box_in_a_only { |p| res << "box_in_a_only #{p.to_s}" }
diff.on_box_in_b_only { |p| res << "box_in_b_only #{p.to_s}" }
diff.on_end_box_differences { res << "on_end_box_differences" }
diff.on_begin_path_differences { res << "on_begin_path_differences" }
diff.on_path_in_a_only { |p| res << "path_in_a_only #{p.to_s}" }
diff.on_path_in_b_only { |p| res << "path_in_b_only #{p.to_s}" }
diff.on_end_path_differences { res << "on_end_path_differences" }
diff.on_begin_text_differences { res << "on_begin_text_differences" }
diff.on_text_in_a_only { |p| res << "text_in_a_only #{p.to_s}" }
diff.on_text_in_b_only { |p| res << "text_in_b_only #{p.to_s}" }
diff.on_end_text_differences { res << "on_end_text_differences" }
diff.on_begin_edge_differences { res << "on_begin_edge_differences" }
diff.on_edge_in_a_only { |p| res << "edge_in_a_only #{p.to_s}" }
diff.on_edge_in_b_only { |p| res << "edge_in_b_only #{p.to_s}" }
diff.on_end_edge_differences { res << "on_end_edge_differences" }
diff.on_end_layer { res << "on_end_layer" }
diff.on_end_cell { res << "on_end_cell" }
assert_equal(diff.compare(a, b, flags), false)
return res.join("\n") + "\n"
end
class DBLayoutDiff_TestClass < TestBase
def test_1
a = RBA::Layout::new
a.dbu = 0.1
b = RBA::Layout::new
b.dbu = 0.001
res = compare(a, b)
assert_equal(res, <<"END")
on_dbu_differs 0.1 0.001
END
end
def test_2
a = RBA::Layout::new
l1a = a.layer(1, 0)
c1a = a.create_cell("C1")
c1a.shapes(l1a).insert(RBA::Box::new(0, 0, 1000, 1000))
b = RBA::Layout::new
l1b = b.layer(1, 0)
l2b = b.layer(2, 0)
c1b = b.create_cell("C1")
c2b = b.create_cell("C2")
c1b.shapes(l1b).insert(RBA::Box::new(1, 0, 1000, 1001))
c1b.shapes(l1b).insert(RBA::Edge::new(1, 0, 1000, 1001))
c1b.shapes(l1b).insert(RBA::Polygon::new(RBA::Box::new(1, 0, 1000, 1001)))
c1b.shapes(l1b).insert(RBA::Path::new([RBA::Point::new(1, 0), RBA::Point::new(1000, 1001)], 0))
c1b.shapes(l1b).insert(RBA::Text::new("abc", RBA::Trans::new(1, 0)))
res = compare(a, b)
assert_equal(res, <<"END")
on_layer_in_b_only 2/0
on_cell_in_b_only C2
on_begin_cell C1 C1
on_begin_layer 1/0:1/0 1/0:0
on_begin_polygon_differences
polygon_in_b_only (1,0;1,1001;1000,1001;1000,0)
on_end_polygon_differences
on_begin_path_differences
path_in_b_only (1,0;1000,1001) w=0 bx=0 ex=0 r=false
on_end_path_differences
on_begin_text_differences
text_in_b_only ('abc',r0 1,0)
on_end_text_differences
on_begin_box_differences
box_in_a_only (0,0;1000,1000)
box_in_b_only (1,0;1000,1001)
on_end_box_differences
on_begin_edge_differences
edge_in_b_only (1,0;1000,1001)
on_end_edge_differences
on_end_layer
on_end_cell
END
res = compare(b, a)
assert_equal(res, <<"END")
on_layer_in_a_only 2/0
on_cell_in_a_only C2
on_begin_cell C1 C1
on_begin_layer 1/0:1/0 1/0:0
on_begin_polygon_differences
polygon_in_a_only (1,0;1,1001;1000,1001;1000,0)
on_end_polygon_differences
on_begin_path_differences
path_in_a_only (1,0;1000,1001) w=0 bx=0 ex=0 r=false
on_end_path_differences
on_begin_text_differences
text_in_a_only ('abc',r0 1,0)
on_end_text_differences
on_begin_box_differences
box_in_a_only (1,0;1000,1001)
box_in_b_only (0,0;1000,1000)
on_end_box_differences
on_begin_edge_differences
edge_in_a_only (1,0;1000,1001)
on_end_edge_differences
on_end_layer
on_end_cell
END
res = compare(a, b, 0)
assert_equal(res, <<"END")
on_layer_in_b_only 2/0
on_cell_in_b_only C2
on_begin_cell C1 C1
on_bbox_differs C1:(0,0;1000,1000) C1:(1,0;1000,1001)
on_begin_layer 1/0:1/0 1/0:0
on_per_layer_bbox_differs C1@1/0:(0,0;1000,1000) C1@1/0:(1,0;1000,1001)
on_begin_polygon_differences
on_end_polygon_differences
on_begin_path_differences
on_end_path_differences
on_begin_text_differences
on_end_text_differences
on_begin_box_differences
on_end_box_differences
on_begin_edge_differences
on_end_edge_differences
on_end_layer
on_end_cell
END
res = compare(b, a, 0)
assert_equal(res, <<"END")
on_layer_in_a_only 2/0
on_cell_in_a_only C2
on_begin_cell C1 C1
on_bbox_differs C1:(1,0;1000,1001) C1:(0,0;1000,1000)
on_begin_layer 1/0:1/0 1/0:0
on_per_layer_bbox_differs C1@1/0:(1,0;1000,1001) C1@1/0:(0,0;1000,1000)
on_begin_polygon_differences
on_end_polygon_differences
on_begin_path_differences
on_end_path_differences
on_begin_text_differences
on_end_text_differences
on_begin_box_differences
on_end_box_differences
on_begin_edge_differences
on_end_edge_differences
on_end_layer
on_end_cell
END
end
def test_3
a = RBA::Layout::new
l1a = a.layer(1, 0, "X")
b = RBA::Layout::new
l1b = b.layer(1, 0, "Y")
res = compare(a, b)
assert_equal(res, <<"END")
on_layer_name_differs X (1/0) Y (1/0)
END
end
def test_4
a = RBA::Layout::new
c1a = a.create_cell("C1")
c2a = a.create_cell("C2")
c1a.insert(RBA::CellInstArray::new(c2a.cell_index, RBA::Trans::new(10, 20)))
b = RBA::Layout::new
c1b = b.create_cell("C1")
c2b = b.create_cell("C2")
c1b.insert(RBA::CellInstArray::new(c2b.cell_index, RBA::Trans::new(11, 21)))
res = compare(a, b)
assert_equal(res, <<"END")
on_begin_cell C1 C1
on_begin_inst_differences
on_instance_in_a_only #1 r0 *1 10,20 0
on_instance_in_b_only #1 r0 *1 11,21 0
on_end_inst_differences
on_end_cell
on_begin_cell C2 C2
on_end_cell
END
res = compare(a, b, 0)
assert_equal(res, <<"END")
on_begin_cell C1 C1
on_begin_inst_differences
on_end_inst_differences
on_end_cell
on_begin_cell C2 C2
on_end_cell
END
end
def test_5
a = RBA::Layout::new
c1a = a.create_cell("C1")
c2a = a.create_cell("C2")
c1a.insert(RBA::CellInstArray::new(c2a.cell_index, RBA::Trans::new(10, 20)))
b = RBA::Layout::new
c1b = b.create_cell("C1")
c2b = b.create_cell("C2X")
c1b.insert(RBA::CellInstArray::new(c2b.cell_index, RBA::Trans::new(11, 21)))
res = compare(a, b)
assert_equal(res, <<"END")
on_cell_in_a_only C2
on_cell_in_b_only C2X
on_begin_cell C1 C1
on_begin_inst_differences
on_instance_in_a_only #1 r0 10,20 0
on_instance_in_b_only #1 r0 11,21 0
on_end_inst_differences
on_end_cell
END
end
def test_6
a = RBA::Layout::new
l1a = a.layer(1, 0)
c1a = a.create_cell("C1")
c2a = a.create_cell("C2")
c2a.shapes(l1a).insert(RBA::Box::new(0, 0, 100, 100))
c1a.insert(RBA::CellInstArray::new(c2a.cell_index, RBA::Trans::new(10, 20)))
b = RBA::Layout::new
l1b = b.layer(1, 0)
c1b = b.create_cell("C1")
c2b = b.create_cell("C2X")
c2b.shapes(l1b).insert(RBA::Box::new(0, 0, 100, 100))
c1b.insert(RBA::CellInstArray::new(c2b.cell_index, RBA::Trans::new(10, 20)))
res = compare(a.top_cell, b.top_cell, 0)
assert_equal(res, <<"END")
on_cell_in_a_only C2
on_cell_in_b_only C2X
on_begin_cell C1 C1
on_begin_inst_differences
on_end_inst_differences
on_begin_layer 1/0:1/0 1/0:0
on_end_layer
on_end_cell
END
res = compare(a.top_cell, b.top_cell, RBA::LayoutDiff::Verbose + RBA::LayoutDiff::SmartCellMapping)
assert_equal(res, <<"END")
on_cell_name_differs C2 C2X
on_begin_cell C1 C1
on_begin_layer 1/0:1/0 1/0:0
on_end_layer
on_end_cell
on_begin_cell C2 C2X
on_begin_layer 1/0:1/0 1/0:0
on_end_layer
on_end_cell
END
end
end
|