KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_regressions.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
26#include <board.h>
28#include <drc/drc_engine.h>
29#include <pad.h>
30#include <pcb_track.h>
31#include <pcb_marker.h>
32#include <footprint.h>
33#include <drc/drc_engine.h>
34#include <drc/drc_item.h>
37
38
40{
43
45 std::unique_ptr<BOARD> m_board;
46};
47
48
50{
51 // These documents at one time flagged DRC errors that they shouldn't have.
52
53 std::vector<wxString> tests =
54 {
55 "issue4139", // DRC fails wrongly with minimally-spaced pads at 45 degree
56 "issue4774", // Shape collisions missing SH_POLY_SET
57 "issue5978", // Hole clearance violation with non-copper pad
58 "issue5990", // DRC flags a board edge clearance violation although the clearance is respected
59 "issue6443", // Wrong DRC and rendering of THT pads with selective inner copper layers
60 "issue7567", // DRC constraint to disallow holes gets SMD pads also
61 "issue7975", // Differential pair gap out of range fault by DRC
62 "issue8407", // PCBNEW: Arc for diff pair has clearance DRC error
63 "issue10906", // Soldermask bridge for only one object
64 "issue12609", // Arc collison edge case
65 "issue14412", // Solder mask bridge between pads in a net-tie pad group
66 "issue15280", // Very wide spokes mis-counted as being single spoke
67 "issue14008", // Net-tie clearance error
68 "issue17967/issue17967", // Arc dp coupling
69 "issue18203", // DRC error due to colliding arc and circle
70 "issue18839", // False positive board edge clearance between concentric arcs
71 "unconnected-netnames/unconnected-netnames", // Raised false schematic partity error
72 "net_tie_drc" // Net tie bridging soldermask DRC test
73 };
74
75 for( const wxString& relPath : tests )
76 {
77 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
78 // Do not refill zones here because this is testing the DRC engine, not the zone filler
79
80 std::vector<DRC_ITEM> violations;
81 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
82
83 // Disable DRC tests not useful or not handled in this testcase
88 // These DRC tests are not useful and do not work because they need a footprint library
89 // associated to the board
92
94 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
95 const std::function<void( PCB_MARKER* )>& aPathGenerator )
96 {
97 if( bds.GetSeverity( aItem->GetErrorCode() ) == SEVERITY::RPT_SEVERITY_ERROR )
98 violations.push_back( *aItem );
99 } );
100
101 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
102
103 if( violations.empty() )
104 {
105 BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
106 BOOST_TEST_MESSAGE( wxString::Format( "DRC regression: %s, passed", relPath ) );
107 }
108 else
109 {
110 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::INCH );
111
112 wxString report;
113 std::map<KIID, EDA_ITEM*> itemMap;
114 m_board->FillItemMap( itemMap );
115
116 for( const DRC_ITEM& item : violations )
117 report += item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, itemMap );
118
119 BOOST_ERROR( wxString::Format( "DRC regression: %s\n"
120 "%d violations found (expected 0)\n"
121 "%s",
122 relPath,
123 (int) violations.size(),
124 report ) );
125 }
126 }
127}
128
129
131{
132 // These documents at one time failed to catch DRC errors that they should have
133
134 std::map<int, SEVERITY> issue19325_ignore, issue22102_ignore;
138
139 std::vector<std::tuple<wxString, int, decltype(BOARD_DESIGN_SETTINGS::m_DRCSeverities)>> tests =
140 {
141 { "issue1358", 2, {} },
142 { "issue2512", 5, {} },
143 { "issue2528", 1, {} },
144 { "issue5750", 4, {} }, // Shorting zone fills pass DRC in some cases
145 { "issue5854", 3, {} },
146 { "issue6879", 6, {} },
147 { "issue6945", 2, {} },
148 { "issue7241", 1, {} },
149 { "issue7267", 5, {} },
150 { "issue7325", 2, {} },
151 { "issue8003", 2, {} },
152 { "issue9081", 2, {} },
153 { "issue12109", 8, {} }, // Pads fail annular width test
154 { "issue14334", 2, {} }, // Thermal spoke to otherwise unconnected island
155 { "issue16566", 6, {} }, // Pad_Shape vs Shape property
156 { "issue18142", 1, {} }, // blind/buried via to micro-via hole-to-hole
157 { "reverse_via", 3, {} }, // Via/track ordering
158 { "intersectingzones", 1, {} }, // zones are too close to each other
159 { "fill_bad", 1, {} }, // zone max BBox was too small
160 { "issue18878", 12, {} }, // Updated: fix reports all cross-net mask bridge pairs
161 { "issue19325/issue19325", 4, issue19325_ignore }, // Overlapping pad annular ring calculation
162 { "issue22102", 2, issue22102_ignore }, // arc-to-rect collision; colocated arcs collision
163 { "issue11814", 2, {} }, // Teardrop clearance to pad
164 };
165
166 for( const auto& [testName, expectedErrors, customSeverities] : tests )
167 {
168 KI_TEST::LoadBoard( m_settingsManager, testName, m_board );
169 // Do not refill zones here because this is testing the DRC engine, not the zone filler
170
171 std::vector<PCB_MARKER> markers;
172 std::vector<DRC_ITEM> violations;
173 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
174
175 // Disable DRC tests not useful in this testcase
180
181 for(const auto [test, severity] : customSeverities)
182 bds.m_DRCSeverities[test] = severity;
183
185 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
186 const std::function<void( PCB_MARKER* )>& aPathGenerator )
187 {
188 markers.emplace_back( PCB_MARKER( aItem, aPos ) );
189
190 if( bds.m_DrcExclusions.find( markers.back().SerializeToString() )
191 == bds.m_DrcExclusions.end() )
192 {
193 violations.push_back( *aItem );
194 }
195 } );
196
197 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
198
199 if( violations.size() == expectedErrors )
200 {
201 BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
202 BOOST_TEST_MESSAGE( wxString::Format( "DRC regression: %s, passed", testName ) );
203 }
204 else
205 {
206 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::INCH );
207
208 wxString report;
209 std::map<KIID, EDA_ITEM*> itemMap;
210 m_board->FillItemMap( itemMap );
211
212 for( const DRC_ITEM& item : violations )
213 report += item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, itemMap );
214
215 BOOST_ERROR( wxString::Format( "DRC regression: %s\n"
216 "%d violations found (expected %d)\n"
217 "%s",
218 testName,
219 (int) violations.size(),
220 expectedErrors,
221 report ) );
222 }
223 }
224}
225
226
227BOOST_FIXTURE_TEST_CASE( DRCZoneFalsePositiveRegressions, DRC_REGRESSION_TEST_FIXTURE )
228{
229 // These documents at one time flagged DRC errors that they shouldn't have.
230 // These tests require zone filling to properly test the DRC checks.
231
232 std::vector<wxString> tests =
233 {
234 "issue19090/issue19090", // Copper graphic shapes count as thermal spoke connections
235 "issue23467/issue23467", // Zones must respect clearance from NPTH pads with no copper layers
236 };
237
238 for( const wxString& relPath : tests )
239 {
240 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
241 KI_TEST::FillZones( m_board.get() );
242
243 std::vector<DRC_ITEM> violations;
244 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
245
246 // Disable DRC tests not useful or not handled in this testcase
252
253 // Ensure starved thermal is enabled for this test
255
257 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
258 const std::function<void( PCB_MARKER* )>& aPathGenerator )
259 {
260 if( bds.GetSeverity( aItem->GetErrorCode() ) == SEVERITY::RPT_SEVERITY_ERROR )
261 violations.push_back( *aItem );
262 } );
263
264 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
265
266 if( violations.empty() )
267 {
268 BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
269 BOOST_TEST_MESSAGE( wxString::Format( "DRC zone regression: %s, passed", relPath ) );
270 }
271 else
272 {
273 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::INCH );
274
275 wxString report;
276 std::map<KIID, EDA_ITEM*> itemMap;
277 m_board->FillItemMap( itemMap );
278
279 for( const DRC_ITEM& item : violations )
280 report += item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, itemMap );
281
282 BOOST_ERROR( wxString::Format( "DRC zone regression: %s\n"
283 "%d violations found (expected 0)\n"
284 "%s",
285 relPath,
286 (int) violations.size(),
287 report ) );
288 }
289 }
290}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
Container for design settings for a BOARD object.
std::map< int, SEVERITY > m_DRCSeverities
std::shared_ptr< DRC_ENGINE > m_DRCEngine
std::set< wxString > m_DrcExclusions
SEVERITY GetSeverity(int aDRCErrorCode)
void RunTests(EDA_UNITS aUnits, bool aReportAllTrackErrors, bool aTestFootprints, BOARD_COMMIT *aCommit=nullptr)
Run the DRC tests.
void SetViolationHandler(DRC_VIOLATION_HANDLER aHandler)
Set an optional DRC violation handler (receives DRC_ITEMs and positions).
Definition drc_engine.h:168
@ DRCE_UNCONNECTED_ITEMS
Definition drc_item.h:40
@ DRCE_LIB_FOOTPRINT_ISSUES
Definition drc_item.h:83
@ DRCE_INVALID_OUTLINE
Definition drc_item.h:73
@ DRCE_STARVED_THERMAL
Definition drc_item.h:50
@ DRCE_TRACK_NOT_CENTERED_ON_VIA
Definition drc_item.h:118
@ DRCE_DRILLED_HOLES_TOO_CLOSE
Definition drc_item.h:53
@ DRCE_COPPER_SLIVER
Definition drc_item.h:93
@ DRCE_DANGLING_TRACK
Definition drc_item.h:52
@ DRCE_LIB_FOOTPRINT_MISMATCH
Definition drc_item.h:84
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
void FillZones(BOARD *m_board)
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
BOOST_FIXTURE_TEST_CASE(DRCFalsePositiveRegressions, DRC_REGRESSION_TEST_FIXTURE)
BOOST_TEST_MESSAGE("\n=== Real-World Polygon PIP Benchmark ===\n"<< formatTable(table))
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687