KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_tracks_cleaner.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
21#include <boost/test/data/test_case.hpp>
22
24#include <board.h>
25#include <board_commit.h>
27#include <drc/drc_engine.h>
29#include <tracks_cleaner.h>
30#include <lset.h>
32#include <cleanup_item.h>
33#include <drc/drc_engine.h>
34#include <drc/drc_item.h>
36#include <tool/tool_manager.h>
37
38namespace
39{
40struct TRACK_CLEANER_TEST_FIXTURE
41{
42 TRACK_CLEANER_TEST_FIXTURE()
43 { }
44
45 SETTINGS_MANAGER m_settingsManager;
46 std::unique_ptr<BOARD> m_board;
47};
48
49
50struct TEST_DESCRIPTION
51{
52 wxString m_File;
53 bool m_Shorts;
54 bool m_RedundantVias;
55 bool m_RedundantTracks;
56 bool m_DanglingTracks;
57 bool m_TracksInPads;
58 bool m_DanglingVias;
59 int m_Expected;
60
61 friend std::ostream& operator<<( std::ostream& os, const TEST_DESCRIPTION& aDesc )
62 {
63 os << aDesc.m_File;
64 return os;
65 }
66};
67
68/*
69* This one ensures that certain cleanup items are indeed found and marked for cleanup.
70*/
71std::vector<TEST_DESCRIPTION> FailedToCleanRegressionTests_tests =
72{
73 // short redundant redundant dangling tracks dangling
74 // circuits vias tracks tracks in pads vias expected
75 { "issue2904", false, false, false, true, false, false, 9 },
76 { "issue5093", false, false, false, false, true, false, 117 },
77 { "issue7004", false, true, false, false, false, true, 25 },
78 { "issue8883", true, true, true, true, false, true, 81 },
79 { "issue10916", false, false, true, false, false, false, 0 },
80 { "issue19574", false, false, true, false, false, false, 2 },
81};
82
83} // namespace
84
85
86BOOST_DATA_TEST_CASE_F( TRACK_CLEANER_TEST_FIXTURE, FailedToCleanRegressionTests,
87 boost::unit_test::data::make( FailedToCleanRegressionTests_tests ), entry )
88{
89 KI_TEST::LoadBoard( m_settingsManager, entry.m_File, m_board );
90 KI_TEST::FillZones( m_board.get() );
91 m_board->GetConnectivity()->RecalculateRatsnest();
92 m_board->UpdateRatsnestExclusions();
93
94 TOOL_MANAGER toolMgr;
95 toolMgr.SetEnvironment( m_board.get(), nullptr, nullptr, nullptr, nullptr );
96
98 toolMgr.RegisterTool( dummyTool );
99
100 BOARD_COMMIT commit( dummyTool );
101 TRACKS_CLEANER cleaner( m_board.get(), commit );
102 std::vector< std::shared_ptr<CLEANUP_ITEM> > dryRunItems;
103 std::vector< std::shared_ptr<CLEANUP_ITEM> > realRunItems;
104
105 cleaner.CleanupBoard( true, &dryRunItems, entry.m_Shorts,
106 entry.m_RedundantVias,
107 entry.m_RedundantTracks,
108 entry.m_DanglingTracks,
109 entry.m_TracksInPads,
110 entry.m_DanglingVias );
111
112 cleaner.CleanupBoard( true, &realRunItems, entry.m_Shorts,
113 entry.m_RedundantVias,
114 entry.m_RedundantTracks,
115 entry.m_DanglingTracks,
116 entry.m_TracksInPads,
117 entry.m_DanglingVias );
118
119 if( dryRunItems.size() == entry.m_Expected && realRunItems.size() == entry.m_Expected )
120 {
121 BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
122 BOOST_TEST_MESSAGE( wxString::Format( "Track cleaner regression: %s, passed",
123 entry.m_File ) );
124 }
125 else
126 {
127 BOOST_CHECK_EQUAL( dryRunItems.size(), entry.m_Expected );
128 BOOST_CHECK_EQUAL( realRunItems.size(), entry.m_Expected );
129
130 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::INCH );
131
132 BOARD_RC_ITEM_RESOLVER resolver( *m_board );
133
134 for( const std::shared_ptr<CLEANUP_ITEM>& item : realRunItems )
135 {
136 BOOST_TEST_MESSAGE( item->ShowReport( &unitsProvider, RPT_SEVERITY_ERROR,
137 resolver ) );
138 }
139
140 BOOST_ERROR( wxString::Format( "Track cleaner regression: %s, failed",
141 entry.m_File ) );
142 }
143}
144
145namespace
146{
147
148std::vector<wxString> TrackCleanerRegressionTests_tests = {
149 //"issue832",
150 "issue4257",
151 //"issue8909"
152};
153
154} // namespace
155
156/*
157 * This one just makes sure that the dry-run counts agree with the "real" counts, and that
158 * the cleaning doesn't produce any connectivity changes.
159 */
160BOOST_DATA_TEST_CASE_F( TRACK_CLEANER_TEST_FIXTURE, TrackCleanerRegressionTests,
161 boost::unit_test::data::make( TrackCleanerRegressionTests_tests ), relPath )
162{
163 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
164 KI_TEST::FillZones( m_board.get() );
165 m_board->GetConnectivity()->RecalculateRatsnest();
166 m_board->UpdateRatsnestExclusions();
167
168 TOOL_MANAGER toolMgr;
169 toolMgr.SetEnvironment( m_board.get(), nullptr, nullptr, nullptr, nullptr );
170
171 KI_TEST::DUMMY_TOOL* dummyTool = new KI_TEST::DUMMY_TOOL();
172 toolMgr.RegisterTool( dummyTool );
173
174 BOARD_COMMIT commit( dummyTool );
175 TRACKS_CLEANER cleaner( m_board.get(), commit );
176 std::vector< std::shared_ptr<CLEANUP_ITEM> > dryRunItems;
177 std::vector< std::shared_ptr<CLEANUP_ITEM> > realRunItems;
178
179 cleaner.CleanupBoard( true, &dryRunItems, true, // short circuits
180 true, // redundant vias
181 true, // redundant tracks
182 true, // dangling tracks
183 true, // tracks in pads
184 true ); // dangling vias
185
186 cleaner.CleanupBoard( true, &realRunItems, true, // short circuits
187 true, // redundant vias
188 true, // redundant tracks
189 true, // dangling tracks
190 true, // tracks in pads
191 true ); // dangling vias
192
193 BOOST_CHECK_EQUAL( dryRunItems.size(), realRunItems.size() );
194
195 std::vector<DRC_ITEM> violations;
196 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
197
198 // Disable some DRC tests not useful in this testcase
203 // Also disable this test: for some reason it generate an exception inside this QA
204 // test ans it is useless
206
208 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
209 const std::function<void( PCB_MARKER* )>& aPathGenerator )
210 {
211 if( aItem->GetErrorCode() == DRCE_UNCONNECTED_ITEMS )
212 violations.push_back( *aItem );
213 } );
214
215 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
216
217 if( violations.empty() )
218 {
219 BOOST_TEST_MESSAGE( wxString::Format( "Track cleaner regression: %s, passed", relPath ) );
220 }
221 else
222 {
223 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::INCH );
224
225 BOARD_RC_ITEM_RESOLVER resolver( *m_board );
226
227 for( const DRC_ITEM& item : violations )
228 BOOST_TEST_MESSAGE( item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, resolver ) );
229
230 BOOST_ERROR( wxString::Format( "Track cleaner regression: %s, failed", relPath ) );
231 }
232}
233
234
235// A stack dropped under a BGA before anything is routed to it connects only to itself, which is
236// what the dangling-via test looks for. The cleaner must not eat it.
237BOOST_FIXTURE_TEST_CASE( CleanupKeepsAnUnlandedMicroviaStack, TRACK_CLEANER_TEST_FIXTURE )
238{
239 m_board = std::make_unique<BOARD>();
240 m_board->SetCopperLayerCount( 4 );
241 m_board->SetEnabledLayers( LSET::AllCuMask( 4 ) | LSET::AllTechMask() );
242
243 PCB_VIA_STACK* stack = new PCB_VIA_STACK( m_board.get(), F_Cu );
244 stack->SetStartLayer( F_Cu );
245 stack->SetEndLayer( In2_Cu );
246 stack->SetViaSize( 300000 );
247 stack->SetViaDrill( 150000 );
248 stack->SetPosition( VECTOR2I( 10000000, 10000000 ) );
249 m_board->Add( stack );
250 stack->Regenerate( m_board.get(), nullptr );
251
252 const size_t hops = stack->GetBoardItems().size();
253 BOOST_REQUIRE_EQUAL( hops, 2u );
254
255 m_board->BuildConnectivity();
256
257 TOOL_MANAGER toolMgr;
258 toolMgr.SetEnvironment( m_board.get(), nullptr, nullptr, nullptr, nullptr );
259
260 KI_TEST::DUMMY_TOOL* dummyTool = new KI_TEST::DUMMY_TOOL();
261 toolMgr.RegisterTool( dummyTool );
262
263 BOARD_COMMIT commit( dummyTool );
264 TRACKS_CLEANER cleaner( m_board.get(), commit );
265 std::vector<std::shared_ptr<CLEANUP_ITEM>> items;
266
267 cleaner.CleanupBoard( false, &items, false, false, false, false, false, true );
268
269 BOOST_CHECK_MESSAGE( stack->GetBoardItems().size() == hops,
270 "cleanup deleted hops of a stack nothing has been routed to yet" );
271 BOOST_CHECK_EQUAL( m_board->Tracks().size(), hops );
272}
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
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 const LSET & AllTechMask()
Return a mask holding all technical layers (no CU layer) on both side.
Definition lset.cpp:672
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:595
void SetPosition(const VECTOR2I &aPos) override
std::unordered_set< BOARD_ITEM * > GetBoardItems() const
A microvia stack: several single hop microvias, plus connecting traces for staggered stacks,...
void Regenerate(BOARD *aBoard, BOARD_COMMIT *aCommit)
Rebuild the member vias (and, for a staggered stack, the connecting traces) from the current stack se...
void SetStartLayer(PCB_LAYER_ID aLayer)
void SetViaSize(int aSize)
void SetViaDrill(int aDrill)
void SetEndLayer(PCB_LAYER_ID aLayer)
Master controller class:
void RegisterTool(TOOL_BASE *aTool)
Add a tool to the manager set and sets it up.
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, APP_SETTINGS_BASE *aSettings, TOOLS_HOLDER *aFrame)
Set the work environment (model, view, view controls and the parent window).
void CleanupBoard(bool aDryRun, std::vector< std::shared_ptr< CLEANUP_ITEM > > *aItemsList, bool aCleanVias, bool aRemoveMisConnected, bool aMergeSegments, bool aDeleteUnconnected, bool aDeleteTracksinPad, bool aDeleteDanglingVias, REPORTER *aReporter=nullptr)
the cleanup function.
@ DRCE_UNCONNECTED_ITEMS
Definition drc_item.h:48
@ DRCE_LIB_FOOTPRINT_ISSUES
Definition drc_item.h:96
@ DRCE_STARVED_THERMAL
Definition drc_item.h:58
@ DRCE_COPPER_SLIVER
Definition drc_item.h:107
@ DRCE_SOLDERMASK_BRIDGE
Definition drc_item.h:108
@ DRCE_LIB_FOOTPRINT_MISMATCH
Definition drc_item.h:97
std::ostream & operator<<(std::ostream &aStream, const EDA_TEXT &aText)
@ In2_Cu
Definition layer_ids.h:63
@ F_Cu
Definition layer_ids.h:60
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_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
BOOST_CHECK_EQUAL(result, "25.4")
BOOST_DATA_TEST_CASE_F(TRACK_CLEANER_TEST_FIXTURE, FailedToCleanRegressionTests, boost::unit_test::data::make(FailedToCleanRegressionTests_tests), entry)
BOOST_FIXTURE_TEST_CASE(CleanupKeepsAnUnlandedMicroviaStack, TRACK_CLEANER_TEST_FIXTURE)
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708