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 "net_tie_hole_clearance", // Net-tie hole clearance with layer-changing copper
72 "issue24974", // Net-tie graphic copper on last pad, UUID-order-independent exemption
73 "diff_pair_uncoupled_tuning_drc" // Tuning pattern length wrongly counted as uncoupled
74 };
75
76 for( const wxString& relPath : tests )
77 {
78 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
79 // Do not refill zones here because this is testing the DRC engine, not the zone filler
80
81 std::vector<DRC_ITEM> violations;
82 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
83
84 // Disable DRC tests not useful or not handled in this testcase
89 // These DRC tests are not useful and do not work because they need a footprint library
90 // associated to the board
93
95 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
96 const std::function<void( PCB_MARKER* )>& aPathGenerator )
97 {
98 if( bds.GetSeverity( aItem->GetErrorCode() ) == SEVERITY::RPT_SEVERITY_ERROR )
99 violations.push_back( *aItem );
100 } );
101
102 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
103
104 if( violations.empty() )
105 {
106 BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
107 BOOST_TEST_MESSAGE( wxString::Format( "DRC regression: %s, passed", relPath ) );
108 }
109 else
110 {
111 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::INCH );
112
113 wxString report;
114 BOARD_RC_ITEM_RESOLVER resolver( *m_board );
115
116 for( const DRC_ITEM& item : violations )
117 report += item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, resolver );
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
130BOOST_FIXTURE_TEST_CASE( DRCFalseNegativeRegressions, DRC_REGRESSION_TEST_FIXTURE )
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, issue18142_ignore;
140
141 std::vector<std::tuple<wxString, int, decltype( BOARD_DESIGN_SETTINGS::m_DRCSeverities )>> tests = {
142 { "issue1358", 2, {} },
143 { "issue2512", 5, {} },
144 { "issue2528", 1, {} },
145 { "issue5750", 4, {} }, // Shorting zone fills pass DRC in some cases
146 { "issue5854", 3, {} },
147 { "issue6879", 6, {} },
148 { "issue6945", 2, {} },
149 { "issue7241", 1, {} },
150 { "issue7267", 6, {} }, // One track sits wholly inside a footprint slot
151 { "issue7325", 2, {} },
152 { "issue8003", 2, {} },
153 { "issue9081", 2, {} },
154 { "issue12109", 8, {} }, // Pads fail annular width test
155 { "issue14334", 2, {} }, // Thermal spoke to otherwise unconnected island
156 { "issue16566", 6, {} }, // Pad_Shape vs Shape property
157 { "issue18142", 1, issue18142_ignore }, // blind/buried via to micro-via hole-to-hole
158 { "reverse_via", 3, {} }, // Via/track ordering
159 { "intersectingzones", 1, {} }, // zones are too close to each other
160 { "fill_bad", 1, {} }, // zone max BBox was too small
161 { "issue18878", 12, {} }, // Updated: fix reports all cross-net mask bridge pairs
162 { "issue19325/issue19325", 4, issue19325_ignore }, // Overlapping pad annular ring calculation
163 { "issue22102", 2, issue22102_ignore }, // arc-to-rect collision; colocated arcs collision
164 { "issue11814", 2, {} }, // Teardrop clearance to pad
165 };
166
167 for( const auto& [testName, expectedErrors, customSeverities] : tests )
168 {
169 KI_TEST::LoadBoard( m_settingsManager, testName, m_board );
170 // Do not refill zones here because this is testing the DRC engine, not the zone filler
171
172 std::vector<PCB_MARKER> markers;
173 std::vector<DRC_ITEM> violations;
174 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
175
176 // Disable DRC tests not useful in this testcase
181
182 for(const auto [test, severity] : customSeverities)
183 bds.m_DRCSeverities[test] = severity;
184
186 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
187 const std::function<void( PCB_MARKER* )>& aPathGenerator )
188 {
189 markers.emplace_back( PCB_MARKER( aItem, aPos ) );
190
191 if( bds.m_DrcExclusions.find( DRC_EXCLUSION::FromMarker( markers.back() ) )
192 == bds.m_DrcExclusions.end() )
193 {
194 violations.push_back( *aItem );
195 }
196 } );
197
198 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
199
200 if( violations.size() == expectedErrors )
201 {
202 BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
203 BOOST_TEST_MESSAGE( wxString::Format( "DRC regression: %s, passed", testName ) );
204 }
205 else
206 {
207 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::INCH );
208
209 wxString report;
210 BOARD_RC_ITEM_RESOLVER resolver( *m_board );
211
212 for( const DRC_ITEM& item : violations )
213 report += item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, resolver );
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 BOARD_RC_ITEM_RESOLVER resolver( *m_board );
277
278 for( const DRC_ITEM& item : violations )
279 report += item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, resolver );
280
281 BOOST_ERROR( wxString::Format( "DRC zone regression: %s\n"
282 "%d violations found (expected 0)\n"
283 "%s",
284 relPath,
285 (int) violations.size(),
286 report ) );
287 }
288 }
289}
290
291
292BOOST_FIXTURE_TEST_CASE( DRCTeardropOverCopperField, DRC_REGRESSION_TEST_FIXTURE )
293{
294 // A knockout footprint reference designator on a copper layer fills as real copper, so a
295 // teardrop zone of another net overlapping it bridges the two nets. Footprint fields live in
296 // their own list rather than the graphical-items list, so the copper clearance test must reach
297 // them. The board also carries a hidden knockout field bridging the same two zones; hidden
298 // fields render no copper and must not produce a short.
299 // See https://gitlab.com/kicad/code/kicad/-/issues/24649
300
301 KI_TEST::LoadBoard( m_settingsManager, "issue24649", m_board );
302 KI_TEST::FillZones( m_board.get() );
303
304 std::vector<DRC_ITEM> violations;
305 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
306
307 // The bare test board has unconnected fills by design; suppress checks unrelated to the
308 // short under test.
314
316 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I&, int,
317 const std::function<void( PCB_MARKER* )>& )
318 {
319 violations.push_back( *aItem );
320 } );
321
322 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
323
324 BOARD_RC_ITEM_RESOLVER resolver( *m_board );
325
326 auto involvesCopperField =
327 [&]( const DRC_ITEM& aItem )
328 {
329 for( const KIID& id : { aItem.GetMainItemID(), aItem.GetAuxItemID() } )
330 {
331 const EDA_ITEM* resolved = resolver.ResolveItemById( id );
332
333 if( resolved && resolved->Type() == PCB_FIELD_T )
334 return true;
335 }
336
337 return false;
338 };
339
340 int fieldShorts = 0;
341
342 for( const DRC_ITEM& item : violations )
343 {
344 if( item.GetErrorCode() == DRCE_SHORTING_ITEMS && involvesCopperField( item ) )
345 fieldShorts++;
346 }
347
348 if( fieldShorts != 1 )
349 {
350 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::MM );
351
352 for( const DRC_ITEM& item : violations )
353 BOOST_TEST_MESSAGE( item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, resolver ) );
354 }
355
356 // Exactly one short: the visible field bridges the two nets; the hidden field does not.
357 BOOST_CHECK_MESSAGE( fieldShorts == 1,
358 "Expected exactly one shorting-items violation involving a visible "
359 "knockout copper reference field; found "
360 << fieldShorts );
361}
362
363
364BOOST_FIXTURE_TEST_CASE( DRCHoleToHoleReportsRuleValue, DRC_REGRESSION_TEST_FIXTURE )
365{
366 // The hole-to-hole test relaxes its comparison by the DRC epsilon, but it also reported that
367 // relaxed value as the rule minimum, so the violation quoted a different number than the one
368 // entered in Board Setup.
369 // See https://gitlab.com/kicad/code/kicad/-/issues/22267
370
371 KI_TEST::LoadBoard( m_settingsManager, "issue22267", m_board );
372
373 std::vector<DRC_ITEM> violations;
374 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
375
379
381 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I&, int,
382 const std::function<void( PCB_MARKER* )>& )
383 {
384 if( aItem->GetErrorCode() == DRCE_DRILLED_HOLES_TOO_CLOSE )
385 violations.push_back( *aItem );
386 } );
387
388 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
389
390 BOOST_REQUIRE_MESSAGE( !violations.empty(), "Expected at least one hole-to-hole violation" );
391
392 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::MM );
393 wxString ruleValue = unitsProvider.MessageTextFromValue( bds.m_HoleToHoleMin );
394 wxString relaxedValue = unitsProvider.MessageTextFromValue( bds.m_HoleToHoleMin
395 - bds.GetDRCEpsilon() );
396
397 BOOST_REQUIRE( ruleValue != relaxedValue );
398
399 // Match on the values alone; the surrounding detail text is translated at format time
400 for( const DRC_ITEM& item : violations )
401 {
402 wxString msg = item.GetErrorMessage( false );
403
404 BOOST_CHECK_MESSAGE( msg.Contains( ruleValue ),
405 wxString::Format( "Expected the configured minimum '%s' but got: %s",
406 ruleValue, msg ) );
407
408 BOOST_CHECK_MESSAGE( !msg.Contains( relaxedValue ),
409 wxString::Format( "Reported the epsilon-relaxed minimum '%s': %s",
410 relaxedValue, msg ) );
411 }
412}
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:351
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:97
@ DRCE_MICROVIA_CROSSES_CORE
Definition drc_item.h:78
@ DRCE_INVALID_OUTLINE
Definition drc_item.h:87
@ DRCE_STARVED_THERMAL
Definition drc_item.h:58
@ DRCE_TRACK_NOT_CENTERED_ON_VIA
Definition drc_item.h:136
@ 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:108
@ DRCE_SHORTING_ITEMS
Definition drc_item.h:49
@ DRCE_DANGLING_TRACK
Definition drc_item.h:60
@ DRCE_LIB_FOOTPRINT_MISMATCH
Definition drc_item.h:98
@ DRCE_MICROVIA_SPANS_DIELECTRICS
Definition drc_item.h:79
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_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE_MESSAGE(dc.CacheTableInfo(table, { "part_id", "val" }), dc.GetLastError())
BOOST_REQUIRE(res.columns()==1)
BOOST_FIXTURE_TEST_CASE(DRCFalsePositiveRegressions, DRC_REGRESSION_TEST_FIXTURE)
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
Definition typeinfo.h:82
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708