diff --git a/src/drc/drc/built-in-macros/_drc_complex_ops.rb b/src/drc/drc/built-in-macros/_drc_complex_ops.rb index 8569143f0..adf7b579f 100644 --- a/src/drc/drc/built-in-macros/_drc_complex_ops.rb +++ b/src/drc/drc/built-in-macros/_drc_complex_ops.rb @@ -1119,7 +1119,7 @@ class DRCOpNodeWithCompare < DRCOpNode end def _self_or_original - return self.original || self + return (self.original || self).dup end def ==(other) @@ -1505,7 +1505,6 @@ class DRCOpNodeCheck < DRCOpNodeWithCompare if self.gt || self.ge dmax = self.ge ? @engine._make_value(self.ge) : @engine._make_value(self.gt) + 1 max_check = RBA::CompoundRegionOperationNode::send(factory, dmax, *self.args + [ true ]) - res_max = RBA::CompoundRegionOperationNode::new_edge_pair_to_first_edges(max_check) if res if self.check == :width || self.check == :notch # Same polygon check - we need to take both edges of the result @@ -1513,9 +1512,10 @@ class DRCOpNodeCheck < DRCOpNodeWithCompare else and_with = RBA::CompoundRegionOperationNode::new_edge_pair_to_first_edges(res) end + res_max = RBA::CompoundRegionOperationNode::new_edge_pair_to_first_edges(max_check) res = RBA::CompoundRegionOperationNode::new_geometrical_boolean(RBA::CompoundRegionOperationNode::GeometricalOp::And, and_with, res_max) else - res = res_max + res = max_check end end diff --git a/src/drc/drc/built-in-macros/_drc_cop_integration.rb b/src/drc/drc/built-in-macros/_drc_cop_integration.rb index 2a76fa4df..f9f233857 100644 --- a/src/drc/drc/built-in-macros/_drc_cop_integration.rb +++ b/src/drc/drc/built-in-macros/_drc_cop_integration.rb @@ -76,8 +76,8 @@ module DRC def drc(op) @engine._context("drc") do requires_region - expr.is_a?(DRCOpNode) || raise("A DRC expression is required for the argument (got #{expr.inspect})") - return DRCLayer::new(@engine, self.data.complex_op(op.create_node({}))) + op.is_a?(DRCOpNode) || raise("A DRC expression is required for the argument (got #{op.inspect})") + DRCLayer::new(@engine, self.data.complex_op(op.create_node({}))) end end @@ -632,9 +632,13 @@ CODE # out = in.drc(0.1.um <= enclosing(other) < 0.2.um) # @/code # - # The result of the enclosing check are edge pairs forming the violation - # markers. With a lower limit, these markers are formed by two, identical but opposite edges attached to - # the primary shape. Without a lower limit, the first edge of the marker is attached to the + # The result of the enclosing check are edges or edge pairs forming the markers. + # These markers indicate the presence of the specified condition. + # + # With a lower and upper limit, the results are edges marking the positions on the + # primary shape where the condition is met. + # With a lower limit alone, these markers are formed by two, identical but opposite edges attached to + # the primary shape. Without an upper limit only, the first edge of the marker is attached to the # primary shape while the second edge is attached to the shape of the "other" layer. # %DRC% @@ -682,9 +686,10 @@ CODE # out = in.drc(0.1.um <= width < 0.2.um) # @/code # - # The result of the width check are edge pairs forming the violation - # markers. With a lower limit, these markers are formed by two, identical but opposite edges attached to - # the primary shape. Without a lower limit, both edges are attached to different sides of the primary + # With a lower and upper limit, the results are edges marking the positions on the + # primary shape where the condition is met. + # With a lower limit alone, these markers are formed by two, identical but opposite edges attached to + # the primary shape. Without an upper limit only, both edges are attached to different sides of the primary # shape. # %DRC% diff --git a/src/drc/unit_tests/drcGenericTests.cc b/src/drc/unit_tests/drcGenericTests.cc new file mode 100644 index 000000000..41b416b4e --- /dev/null +++ b/src/drc/unit_tests/drcGenericTests.cc @@ -0,0 +1,80 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2021 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 + +*/ + +#include "tlUnitTest.h" +#include "dbReader.h" +#include "dbTestSupport.h" +#include "dbNetlist.h" +#include "dbNetlistSpiceReader.h" +#include "lymMacro.h" +#include "tlFileUtils.h" + +static void runTest (tl::TestBase *_this, const std::string &number, bool deep) +{ + std::string rs = tl::testsrc (); + rs += "/testdata/drc/drcGenericTests_" + number + ".drc"; + + std::string input = tl::testsrc (); + input += "/testdata/drc/drcGenericTests_" + number + ".gds"; + + std::string au = tl::testsrc (); + au += "/testdata/drc/drcGenericTests_au" + number + std::string (deep ? "d" : "") + ".gds"; + + std::string output = _this->tmp_file ("tmp.gds"); + + { + // Set some variables + lym::Macro config; + config.set_text (tl::sprintf ( + "$drc_test_source = '%s'\n" + "$drc_test_target = '%s'\n" + "$drc_test_deep = %s\n" + , input, output, deep ? "true" : "false") + ); + config.set_interpreter (lym::Macro::Ruby); + EXPECT_EQ (config.run (), 0); + } + + lym::Macro drc; + drc.load_from (rs); + EXPECT_EQ (drc.run (), 0); + + db::Layout layout; + + { + tl::InputStream stream (output); + db::Reader reader (stream); + reader.read (layout); + } + + db::compare_layouts (_this, layout, au, db::NoNormalization); +} + +TEST(1) +{ + runTest (_this, "1", false); +} + +TEST(1d) +{ + runTest (_this, "1", true); +} diff --git a/src/drc/unit_tests/unit_tests.pro b/src/drc/unit_tests/unit_tests.pro index 1acc6688f..30b2d3db0 100644 --- a/src/drc/unit_tests/unit_tests.pro +++ b/src/drc/unit_tests/unit_tests.pro @@ -8,6 +8,7 @@ include($$PWD/../../lib_ut.pri) SOURCES = \ drcBasicTests.cc \ + drcGenericTests.cc \ drcSimpleTests.cc \ drcSuiteTests.cc \ diff --git a/testdata/drc/drcGenericTests_1.drc b/testdata/drc/drcGenericTests_1.drc new file mode 100644 index 000000000..3bbb96f4b --- /dev/null +++ b/testdata/drc/drcGenericTests_1.drc @@ -0,0 +1,30 @@ + +source $drc_test_source +target $drc_test_target + +if $drc_test_deep + deep +end + +l1 = input(1, 0) +l2 = input(2, 0) +l3 = input(3, 0) + +l1.output(1, 0) +l2.output(2, 0) +l3.output(3, 0) + +wcheck = width(projection) + +l1.drc(wcheck < 1.0).polygons.output(100, 0) +l1.drc(wcheck <= 0.5).polygons.output(101, 0) +l1.drc(1.0 > wcheck).polygons.output(102, 0) +l1.drc(0.5 >= wcheck).polygons.output(103, 0) +l1.drc(wcheck > 1.0).output(104, 0) +l1.drc(wcheck >= 1.5).output(105, 0) +l1.drc(1.0 < wcheck).output(106, 0) +l1.drc(1.5 <= wcheck).output(107, 0) +l1.drc(wcheck == 1.5).output(108, 0) +l1.drc(1.0 <= wcheck <= 1.5).output(109, 0) +l1.drc(1.0 < wcheck < 2.0).output(110, 0) + diff --git a/testdata/drc/drcGenericTests_1.gds b/testdata/drc/drcGenericTests_1.gds new file mode 100644 index 000000000..18c6261a1 Binary files /dev/null and b/testdata/drc/drcGenericTests_1.gds differ diff --git a/testdata/drc/drcGenericTests_au1.gds b/testdata/drc/drcGenericTests_au1.gds new file mode 100644 index 000000000..8b1e44020 Binary files /dev/null and b/testdata/drc/drcGenericTests_au1.gds differ diff --git a/testdata/drc/drcGenericTests_au1d.gds b/testdata/drc/drcGenericTests_au1d.gds new file mode 100644 index 000000000..3e467d9dd Binary files /dev/null and b/testdata/drc/drcGenericTests_au1d.gds differ