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
36{
39
41 std::unique_ptr<BOARD> m_board;
42};
43
44
46{
47 // These documents at one time flagged DRC errors that they shouldn't have.
48
49 std::vector<wxString> tests = {
50 "issue4139", // DRC fails wrongly with minimally-spaced pads at 45 degree
51 "issue4774", // Shape collisions missing SH_POLY_SET
52 "issue5978", // Hole clearance violation with non-copper pad
53 "issue5990", // DRC flags a board edge clearance violation although the clearance is respected
54 "issue6443", // Wrong DRC and rendering of THT pads with selective inner copper layers
55 "issue7567", // DRC constraint to disallow holes gets SMD pads also
56 "issue7975", // Differential pair gap out of range fault by DRC
57 "issue8407", // PCBNEW: Arc for diff pair has clearance DRC error
58 "issue10906", // Soldermask bridge for only one object
59 "issue12609", // Arc collison edge case
60 "issue14412", // Solder mask bridge between pads in a net-tie pad group
61 "issue15280", // Very wide spokes mis-counted as being single spoke
62 "issue14008", // Net-tie clearance error
63 "issue17967/issue17967", // Arc dp coupling
64 "issue18203", // DRC error due to colliding arc and circle
65 "issue18839", // False positive board edge clearance between concentric arcs
66 "unconnected-netnames/unconnected-netnames", // Raised false schematic partity error
67 "net_tie_drc", // Net tie bridging soldermask DRC test
68 "diff_pair_uncoupled_tuning_drc" // Tuning pattern length wrongly counted as uncoupled
69 };
70
71 for( const wxString& relPath : tests )
72 {
73 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
74 // Do not refill zones here because this is testing the DRC engine, not the zone filler
75
76 std::vector<DRC_ITEM> violations;
77 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
78
79 // Disable DRC tests not useful or not handled in this testcase
84 // These DRC tests are not useful and do not work because they need a footprint library
85 // associated to the board
88
90 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
91 const std::function<void( PCB_MARKER* )>& aPathGenerator )
92 {
93 if( bds.GetSeverity( aItem->GetErrorCode() ) == SEVERITY::RPT_SEVERITY_ERROR )
94 violations.push_back( *aItem );
95 } );
96
97 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
98
99 if( violations.empty() )
100 {
101 BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
102 BOOST_TEST_MESSAGE( wxString::Format( "DRC regression: %s, passed", relPath ) );
103 }
104 else
105 {
106 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::INCH );
107
108 wxString report;
109 std::map<KIID, EDA_ITEM*> itemMap;
110 m_board->FillItemMap( itemMap );
111
112 for( const DRC_ITEM& item : violations )
113 report += item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, itemMap );
114
115 BOOST_ERROR( wxString::Format( "DRC regression: %s\n"
116 "%d violations found (expected 0)\n"
117 "%s",
118 relPath,
119 (int) violations.size(),
120 report ) );
121 }
122 }
123}
124
125
127{
128 // These documents at one time failed to catch DRC errors that they should have
129
130 std::map<int, SEVERITY> issue19325_ignore, issue22102_ignore;
134
135 std::vector<std::tuple<wxString, int, decltype(BOARD_DESIGN_SETTINGS::m_DRCSeverities)>> tests =
136 {
137 { "issue1358", 2, {} },
138 { "issue2512", 5, {} },
139 { "issue2528", 1, {} },
140 { "issue5750", 4, {} }, // Shorting zone fills pass DRC in some cases
141 { "issue5854", 3, {} },
142 { "issue6879", 6, {} },
143 { "issue6945", 2, {} },
144 { "issue7241", 1, {} },
145 { "issue7267", 5, {} },
146 { "issue7325", 2, {} },
147 { "issue8003", 2, {} },
148 { "issue9081", 2, {} },
149 { "issue12109", 8, {} }, // Pads fail annular width test
150 { "issue14334", 2, {} }, // Thermal spoke to otherwise unconnected island
151 { "issue16566", 6, {} }, // Pad_Shape vs Shape property
152 { "issue18142", 1, {} }, // blind/buried via to micro-via hole-to-hole
153 { "reverse_via", 3, {} }, // Via/track ordering
154 { "intersectingzones", 1, {} }, // zones are too close to each other
155 { "fill_bad", 1, {} }, // zone max BBox was too small
156 { "issue18878", 12, {} }, // Updated: fix reports all cross-net mask bridge pairs
157 { "issue19325/issue19325", 4, issue19325_ignore }, // Overlapping pad annular ring calculation
158 { "issue22102", 2, issue22102_ignore }, // arc-to-rect collision; colocated arcs collision
159 { "issue11814", 2, {} }, // Teardrop clearance to pad
160 };
161
162 for( const auto& [testName, expectedErrors, customSeverities] : tests )
163 {
164 KI_TEST::LoadBoard( m_settingsManager, testName, m_board );
165 // Do not refill zones here because this is testing the DRC engine, not the zone filler
166
167 std::vector<PCB_MARKER> markers;
168 std::vector<DRC_ITEM> violations;
169 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
170
171 // Disable DRC tests not useful in this testcase
176
177 for(const auto [test, severity] : customSeverities)
178 bds.m_DRCSeverities[test] = severity;
179
181 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
182 const std::function<void( PCB_MARKER* )>& aPathGenerator )
183 {
184 markers.emplace_back( PCB_MARKER( aItem, aPos ) );
185
186 if( bds.m_DrcExclusions.find( markers.back().SerializeToString() )
187 == bds.m_DrcExclusions.end() )
188 {
189 violations.push_back( *aItem );
190 }
191 } );
192
193 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
194
195 if( violations.size() == expectedErrors )
196 {
197 BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
198 BOOST_TEST_MESSAGE( wxString::Format( "DRC regression: %s, passed", testName ) );
199 }
200 else
201 {
202 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::INCH );
203
204 wxString report;
205 std::map<KIID, EDA_ITEM*> itemMap;
206 m_board->FillItemMap( itemMap );
207
208 for( const DRC_ITEM& item : violations )
209 report += item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, itemMap );
210
211 BOOST_ERROR( wxString::Format( "DRC regression: %s\n"
212 "%d violations found (expected %d)\n"
213 "%s",
214 testName,
215 (int) violations.size(),
216 expectedErrors,
217 report ) );
218 }
219 }
220}
221
222
223BOOST_FIXTURE_TEST_CASE( DRCZoneFalsePositiveRegressions, DRC_REGRESSION_TEST_FIXTURE )
224{
225 // These documents at one time flagged DRC errors that they shouldn't have.
226 // These tests require zone filling to properly test the DRC checks.
227
228 std::vector<wxString> tests =
229 {
230 "issue19090/issue19090", // Copper graphic shapes count as thermal spoke connections
231 "issue23467/issue23467", // Zones must respect clearance from NPTH pads with no copper layers
232 };
233
234 for( const wxString& relPath : tests )
235 {
236 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
237 KI_TEST::FillZones( m_board.get() );
238
239 std::vector<DRC_ITEM> violations;
240 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
241
242 // Disable DRC tests not useful or not handled in this testcase
248
249 // Ensure starved thermal is enabled for this test
251
253 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
254 const std::function<void( PCB_MARKER* )>& aPathGenerator )
255 {
256 if( bds.GetSeverity( aItem->GetErrorCode() ) == SEVERITY::RPT_SEVERITY_ERROR )
257 violations.push_back( *aItem );
258 } );
259
260 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
261
262 if( violations.empty() )
263 {
264 BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
265 BOOST_TEST_MESSAGE( wxString::Format( "DRC zone regression: %s, passed", relPath ) );
266 }
267 else
268 {
269 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::INCH );
270
271 wxString report;
272 std::map<KIID, EDA_ITEM*> itemMap;
273 m_board->FillItemMap( itemMap );
274
275 for( const DRC_ITEM& item : violations )
276 report += item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, itemMap );
277
278 BOOST_ERROR( wxString::Format( "DRC zone regression: %s\n"
279 "%d violations found (expected 0)\n"
280 "%s",
281 relPath,
282 (int) violations.size(),
283 report ) );
284 }
285 }
286}
287
288
290{
291 // A knockout footprint reference designator on a copper layer fills as real copper, so a
292 // teardrop zone of another net overlapping it bridges the two nets. Footprint fields live in
293 // their own list rather than the graphical-items list, so the copper clearance test must reach
294 // them. The board also carries a hidden knockout field bridging the same two zones; hidden
295 // fields render no copper and must not produce a short.
296 // See https://gitlab.com/kicad/code/kicad/-/issues/24649
297
298 KI_TEST::LoadBoard( m_settingsManager, "issue24649", m_board );
299 KI_TEST::FillZones( m_board.get() );
300
301 std::vector<DRC_ITEM> violations;
302 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
303
304 // The bare test board has unconnected fills by design; suppress checks unrelated to the
305 // short under test.
311
313 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I&, int,
314 const std::function<void( PCB_MARKER* )>& )
315 {
316 violations.push_back( *aItem );
317 } );
318
319 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
320
321 std::map<KIID, EDA_ITEM*> itemMap;
322 m_board->FillItemMap( itemMap );
323
324 auto involvesCopperField =
325 [&]( const DRC_ITEM& aItem )
326 {
327 for( const KIID& id : { aItem.GetMainItemID(), aItem.GetAuxItemID() } )
328 {
329 auto it = itemMap.find( id );
330
331 if( it != itemMap.end() && it->second->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, itemMap ) );
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}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
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:164
Definition kiid.h:44
@ DRCE_UNCONNECTED_ITEMS
Definition drc_item.h:36
@ DRCE_LIB_FOOTPRINT_ISSUES
Definition drc_item.h:79
@ DRCE_INVALID_OUTLINE
Definition drc_item.h:69
@ DRCE_STARVED_THERMAL
Definition drc_item.h:46
@ DRCE_TRACK_NOT_CENTERED_ON_VIA
Definition drc_item.h:117
@ DRCE_ISOLATED_COPPER
Definition drc_item.h:45
@ DRCE_DRILLED_HOLES_TOO_CLOSE
Definition drc_item.h:49
@ DRCE_COPPER_SLIVER
Definition drc_item.h:90
@ DRCE_SHORTING_ITEMS
Definition drc_item.h:37
@ DRCE_DANGLING_TRACK
Definition drc_item.h:48
@ DRCE_LIB_FOOTPRINT_MISMATCH
Definition drc_item.h:80
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_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_TEST_MESSAGE("\n=== Real-World Polygon PIP Benchmark ===\n"<< formatTable(table))
BOOST_CHECK_EQUAL(result, "25.4")
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
Definition typeinfo.h:83
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683