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, see <https://www.gnu.org/licenses/>.
18 */
19
22#include <board.h>
24#include <drc/drc_engine.h>
25#include <pad.h>
26#include <pcb_track.h>
27#include <pcb_marker.h>
28#include <footprint.h>
29#include <drc/drc_engine.h>
30#include <drc/drc_item.h>
33
34
35namespace
36{
37struct DRC_REGRESSION_TEST_FIXTURE
38{
39 DRC_REGRESSION_TEST_FIXTURE()
40 { }
41
42 SETTINGS_MANAGER m_settingsManager;
43 std::unique_ptr<BOARD> m_board;
44};
45} // namespace
46
47
48BOOST_FIXTURE_TEST_CASE( DRCFalsePositiveRegressions, DRC_REGRESSION_TEST_FIXTURE )
49{
50 // These documents at one time flagged DRC errors that they shouldn't have.
51
52 std::vector<wxString> tests = {
53 "issue4139", // DRC fails wrongly with minimally-spaced pads at 45 degree
54 "issue4774", // Shape collisions missing SH_POLY_SET
55 "issue5978", // Hole clearance violation with non-copper pad
56 "issue5990", // DRC flags a board edge clearance violation although the clearance is respected
57 "issue6443", // Wrong DRC and rendering of THT pads with selective inner copper layers
58 "issue7567", // DRC constraint to disallow holes gets SMD pads also
59 "issue7975", // Differential pair gap out of range fault by DRC
60 "issue8407", // PCBNEW: Arc for diff pair has clearance DRC error
61 "issue10906", // Soldermask bridge for only one object
62 "issue12609", // Arc collison edge case
63 "issue14412", // Solder mask bridge between pads in a net-tie pad group
64 "issue15280", // Very wide spokes mis-counted as being single spoke
65 "issue14008", // Net-tie clearance error
66 "issue17967/issue17967", // Arc dp coupling
67 "issue18203", // DRC error due to colliding arc and circle
68 "issue18839", // False positive board edge clearance between concentric arcs
69 "unconnected-netnames/unconnected-netnames", // Raised false schematic partity error
70 "net_tie_drc", // Net tie bridging soldermask DRC test
71 "issue24974", // Net-tie graphic copper on last pad, UUID-order-independent exemption
72 "diff_pair_uncoupled_tuning_drc" // Tuning pattern length wrongly counted as uncoupled
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 BOARD_RC_ITEM_RESOLVER resolver( *m_board );
114
115 for( const DRC_ITEM& item : violations )
116 report += item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, resolver );
117
118 BOOST_ERROR( wxString::Format( "DRC regression: %s\n"
119 "%d violations found (expected 0)\n"
120 "%s",
121 relPath,
122 (int) violations.size(),
123 report ) );
124 }
125 }
126}
127
128
129BOOST_FIXTURE_TEST_CASE( DRCFalseNegativeRegressions, DRC_REGRESSION_TEST_FIXTURE )
130{
131 // These documents at one time failed to catch DRC errors that they should have
132
133 std::map<int, SEVERITY> issue19325_ignore, issue22102_ignore, issue18142_ignore;
138
139 std::vector<std::tuple<wxString, int, decltype( BOARD_DESIGN_SETTINGS::m_DRCSeverities )>> tests = {
140 { "issue1358", 2, {} },
141 { "issue2512", 5, {} },
142 { "issue2528", 1, {} },
143 { "issue5750", 4, {} }, // Shorting zone fills pass DRC in some cases
144 { "issue5854", 3, {} },
145 { "issue6879", 6, {} },
146 { "issue6945", 2, {} },
147 { "issue7241", 1, {} },
148 { "issue7267", 6, {} }, // One track sits wholly inside a footprint slot
149 { "issue7325", 2, {} },
150 { "issue8003", 2, {} },
151 { "issue9081", 2, {} },
152 { "issue12109", 8, {} }, // Pads fail annular width test
153 { "issue14334", 2, {} }, // Thermal spoke to otherwise unconnected island
154 { "issue16566", 6, {} }, // Pad_Shape vs Shape property
155 { "issue18142", 1, issue18142_ignore }, // blind/buried via to micro-via hole-to-hole
156 { "reverse_via", 3, {} }, // Via/track ordering
157 { "intersectingzones", 1, {} }, // zones are too close to each other
158 { "fill_bad", 1, {} }, // zone max BBox was too small
159 { "issue18878", 12, {} }, // Updated: fix reports all cross-net mask bridge pairs
160 { "issue19325/issue19325", 4, issue19325_ignore }, // Overlapping pad annular ring calculation
161 { "issue22102", 2, issue22102_ignore }, // arc-to-rect collision; colocated arcs collision
162 { "issue11814", 2, {} }, // Teardrop clearance to pad
163 };
164
165 for( const auto& [testName, expectedErrors, customSeverities] : tests )
166 {
167 KI_TEST::LoadBoard( m_settingsManager, testName, m_board );
168 // Do not refill zones here because this is testing the DRC engine, not the zone filler
169
170 std::vector<PCB_MARKER> markers;
171 std::vector<DRC_ITEM> violations;
172 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
173
174 // Disable DRC tests not useful in this testcase
179
180 for(const auto [test, severity] : customSeverities)
181 bds.m_DRCSeverities[test] = severity;
182
184 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
185 const std::function<void( PCB_MARKER* )>& aPathGenerator )
186 {
187 markers.emplace_back( PCB_MARKER( aItem, aPos ) );
188
189 if( bds.m_DrcExclusions.find( DRC_EXCLUSION::FromMarker( markers.back() ) )
190 == bds.m_DrcExclusions.end() )
191 {
192 violations.push_back( *aItem );
193 }
194 } );
195
196 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
197
198 if( violations.size() == expectedErrors )
199 {
200 BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
201 BOOST_TEST_MESSAGE( wxString::Format( "DRC regression: %s, passed", testName ) );
202 }
203 else
204 {
205 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::INCH );
206
207 wxString report;
208 BOARD_RC_ITEM_RESOLVER resolver( *m_board );
209
210 for( const DRC_ITEM& item : violations )
211 report += item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, resolver );
212
213 BOOST_ERROR( wxString::Format( "DRC regression: %s\n"
214 "%d violations found (expected %d)\n"
215 "%s",
216 testName,
217 (int) violations.size(),
218 expectedErrors,
219 report ) );
220 }
221 }
222}
223
224
225BOOST_FIXTURE_TEST_CASE( DRCZoneFalsePositiveRegressions, DRC_REGRESSION_TEST_FIXTURE )
226{
227 // These documents at one time flagged DRC errors that they shouldn't have.
228 // These tests require zone filling to properly test the DRC checks.
229
230 std::vector<wxString> tests =
231 {
232 "issue19090/issue19090", // Copper graphic shapes count as thermal spoke connections
233 "issue23467/issue23467", // Zones must respect clearance from NPTH pads with no copper layers
234 };
235
236 for( const wxString& relPath : tests )
237 {
238 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
239 KI_TEST::FillZones( m_board.get() );
240
241 std::vector<DRC_ITEM> violations;
242 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
243
244 // Disable DRC tests not useful or not handled in this testcase
250
251 // Ensure starved thermal is enabled for this test
253
255 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
256 const std::function<void( PCB_MARKER* )>& aPathGenerator )
257 {
258 if( bds.GetSeverity( aItem->GetErrorCode() ) == SEVERITY::RPT_SEVERITY_ERROR )
259 violations.push_back( *aItem );
260 } );
261
262 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
263
264 if( violations.empty() )
265 {
266 BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
267 BOOST_TEST_MESSAGE( wxString::Format( "DRC zone regression: %s, passed", relPath ) );
268 }
269 else
270 {
271 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::INCH );
272
273 wxString report;
274 BOARD_RC_ITEM_RESOLVER resolver( *m_board );
275
276 for( const DRC_ITEM& item : violations )
277 report += item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, resolver );
278
279 BOOST_ERROR( wxString::Format( "DRC zone regression: %s\n"
280 "%d violations found (expected 0)\n"
281 "%s",
282 relPath,
283 (int) violations.size(),
284 report ) );
285 }
286 }
287}
288
289
290BOOST_FIXTURE_TEST_CASE( DRCTeardropOverCopperField, DRC_REGRESSION_TEST_FIXTURE )
291{
292 // A knockout footprint reference designator on a copper layer fills as real copper, so a
293 // teardrop zone of another net overlapping it bridges the two nets. Footprint fields live in
294 // their own list rather than the graphical-items list, so the copper clearance test must reach
295 // them. The board also carries a hidden knockout field bridging the same two zones; hidden
296 // fields render no copper and must not produce a short.
297 // See https://gitlab.com/kicad/code/kicad/-/issues/24649
298
299 KI_TEST::LoadBoard( m_settingsManager, "issue24649", m_board );
300 KI_TEST::FillZones( m_board.get() );
301
302 std::vector<DRC_ITEM> violations;
303 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
304
305 // The bare test board has unconnected fills by design; suppress checks unrelated to the
306 // short under test.
312
314 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I&, int,
315 const std::function<void( PCB_MARKER* )>& )
316 {
317 violations.push_back( *aItem );
318 } );
319
320 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
321
322 BOARD_RC_ITEM_RESOLVER resolver( *m_board );
323
324 auto involvesCopperField =
325 [&]( const DRC_ITEM& aItem )
326 {
327 for( const KIID& id : { aItem.GetMainItemID(), aItem.GetAuxItemID() } )
328 {
329 const EDA_ITEM* resolved = resolver.ResolveItemById( id );
330
331 if( resolved && resolved->Type() == PCB_FIELD_T )
332 return true;
333 }
334
335 return false;
336 };
337
338 int fieldShorts = 0;
339
340 for( const DRC_ITEM& item : violations )
341 {
342 if( item.GetErrorCode() == DRCE_SHORTING_ITEMS && involvesCopperField( item ) )
343 fieldShorts++;
344 }
345
346 if( fieldShorts != 1 )
347 {
348 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::MM );
349
350 for( const DRC_ITEM& item : violations )
351 BOOST_TEST_MESSAGE( item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, resolver ) );
352 }
353
354 // Exactly one short: the visible field bridges the two nets; the hidden field does not.
355 BOOST_CHECK_MESSAGE( fieldShorts == 1,
356 "Expected exactly one shorting-items violation involving a visible "
357 "knockout copper reference field; found "
358 << fieldShorts );
359}
360
361
362BOOST_FIXTURE_TEST_CASE( DRCHoleToHoleReportsRuleValue, DRC_REGRESSION_TEST_FIXTURE )
363{
364 // The hole-to-hole test relaxes its comparison by the DRC epsilon, but it also reported that
365 // relaxed value as the rule minimum, so the violation quoted a different number than the one
366 // entered in Board Setup.
367 // See https://gitlab.com/kicad/code/kicad/-/issues/22267
368
369 KI_TEST::LoadBoard( m_settingsManager, "issue22267", m_board );
370
371 std::vector<DRC_ITEM> violations;
372 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
373
377
379 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I&, int,
380 const std::function<void( PCB_MARKER* )>& )
381 {
382 if( aItem->GetErrorCode() == DRCE_DRILLED_HOLES_TOO_CLOSE )
383 violations.push_back( *aItem );
384 } );
385
386 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
387
388 BOOST_REQUIRE_MESSAGE( !violations.empty(), "Expected at least one hole-to-hole violation" );
389
390 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::MM );
391 wxString ruleValue = unitsProvider.MessageTextFromValue( bds.m_HoleToHoleMin );
392 wxString relaxedValue = unitsProvider.MessageTextFromValue( bds.m_HoleToHoleMin
393 - bds.GetDRCEpsilon() );
394
395 BOOST_REQUIRE( ruleValue != relaxedValue );
396
397 // Match on the values alone; the surrounding detail text is translated at format time
398 for( const DRC_ITEM& item : violations )
399 {
400 wxString msg = item.GetErrorMessage( false );
401
402 BOOST_CHECK_MESSAGE( msg.Contains( ruleValue ),
403 wxString::Format( "Expected the configured minimum '%s' but got: %s",
404 ruleValue, msg ) );
405
406 BOOST_CHECK_MESSAGE( !msg.Contains( relaxedValue ),
407 wxString::Format( "Reported the epsilon-relaxed minimum '%s': %s",
408 relaxedValue, msg ) );
409 }
410}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
Container for design settings for a BOARD object.
std::map< int, SEVERITY > m_DRCSeverities
std::shared_ptr< DRC_ENGINE > m_DRCEngine
SEVERITY GetSeverity(int aDRCErrorCode) const
Return the severity of a given DRC error code.
int GetDRCEpsilon() const
Return an epsilon which accounts for rounding errors, etc.
std::set< DRC_EXCLUSION, DRC_EXCLUSION_COMPARE > m_DrcExclusions
Implements the RC_ITEM_RESOLVER interface to resolve PCB items by their KIID.
Definition drc_item.h:349
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:164
static DRC_EXCLUSION FromMarker(const PCB_MARKER &aMarker)
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
Definition kiid.h:46
EDA_ITEM * ResolveItemById(const KIID &aKiid) const
Resolve an item by its KIID.
Definition rc_item.h:98
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
@ DRCE_UNCONNECTED_ITEMS
Definition drc_item.h:48
@ DRCE_LIB_FOOTPRINT_ISSUES
Definition drc_item.h:96
@ DRCE_MICROVIA_CROSSES_CORE
Definition drc_item.h:78
@ DRCE_INVALID_OUTLINE
Definition drc_item.h:86
@ DRCE_STARVED_THERMAL
Definition drc_item.h:58
@ DRCE_TRACK_NOT_CENTERED_ON_VIA
Definition drc_item.h:135
@ DRCE_ISOLATED_COPPER
Definition drc_item.h:57
@ DRCE_DRILLED_HOLES_TOO_CLOSE
Definition drc_item.h:61
@ DRCE_COPPER_SLIVER
Definition drc_item.h:107
@ DRCE_SHORTING_ITEMS
Definition drc_item.h:49
@ DRCE_DANGLING_TRACK
Definition drc_item.h:60
@ DRCE_LIB_FOOTPRINT_MISMATCH
Definition drc_item.h:97
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_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
BOOST_CHECK_EQUAL(result, "25.4")
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
Definition typeinfo.h:82
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708