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 std::map<KIID, EDA_ITEM*> itemMap;
133 m_board->FillItemMap( itemMap );
134
135 for( const std::shared_ptr<CLEANUP_ITEM>& item : realRunItems )
136 {
137 BOOST_TEST_MESSAGE( item->ShowReport( &unitsProvider, RPT_SEVERITY_ERROR,
138 itemMap ) );
139 }
140
141 BOOST_ERROR( wxString::Format( "Track cleaner regression: %s, failed",
142 entry.m_File ) );
143 }
144}
145
146namespace
147{
148
149std::vector<wxString> TrackCleanerRegressionTests_tests = {
150 //"issue832",
151 "issue4257",
152 //"issue8909"
153};
154
155} // namespace
156
157/*
158 * This one just makes sure that the dry-run counts agree with the "real" counts, and that
159 * the cleaning doesn't produce any connectivity changes.
160 */
161BOOST_DATA_TEST_CASE_F( TRACK_CLEANER_TEST_FIXTURE, TrackCleanerRegressionTests,
162 boost::unit_test::data::make( TrackCleanerRegressionTests_tests ), relPath )
163{
164 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
165 KI_TEST::FillZones( m_board.get() );
166 m_board->GetConnectivity()->RecalculateRatsnest();
167 m_board->UpdateRatsnestExclusions();
168
169 TOOL_MANAGER toolMgr;
170 toolMgr.SetEnvironment( m_board.get(), nullptr, nullptr, nullptr, nullptr );
171
172 KI_TEST::DUMMY_TOOL* dummyTool = new KI_TEST::DUMMY_TOOL();
173 toolMgr.RegisterTool( dummyTool );
174
175 BOARD_COMMIT commit( dummyTool );
176 TRACKS_CLEANER cleaner( m_board.get(), commit );
177 std::vector< std::shared_ptr<CLEANUP_ITEM> > dryRunItems;
178 std::vector< std::shared_ptr<CLEANUP_ITEM> > realRunItems;
179
180 cleaner.CleanupBoard( true, &dryRunItems, true, // short circuits
181 true, // redundant vias
182 true, // redundant tracks
183 true, // dangling tracks
184 true, // tracks in pads
185 true ); // dangling vias
186
187 cleaner.CleanupBoard( true, &realRunItems, true, // short circuits
188 true, // redundant vias
189 true, // redundant tracks
190 true, // dangling tracks
191 true, // tracks in pads
192 true ); // dangling vias
193
194 BOOST_CHECK_EQUAL( dryRunItems.size(), realRunItems.size() );
195
196 std::vector<DRC_ITEM> violations;
197 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
198
199 // Disable some DRC tests not useful in this testcase
204 // Also disable this test: for some reason it generate an exception inside this QA
205 // test ans it is useless
207
209 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
210 const std::function<void( PCB_MARKER* )>& aPathGenerator )
211 {
212 if( aItem->GetErrorCode() == DRCE_UNCONNECTED_ITEMS )
213 violations.push_back( *aItem );
214 } );
215
216 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
217
218 if( violations.empty() )
219 {
220 BOOST_TEST_MESSAGE( wxString::Format( "Track cleaner regression: %s, passed", relPath ) );
221 }
222 else
223 {
224 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::INCH );
225
226 std::map<KIID, EDA_ITEM*> itemMap;
227 m_board->FillItemMap( itemMap );
228
229 for( const DRC_ITEM& item : violations )
230 BOOST_TEST_MESSAGE( item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, itemMap ) );
231
232 BOOST_ERROR( wxString::Format( "Track cleaner regression: %s, failed", relPath ) );
233 }
234}
235
236
237// A stack dropped under a BGA before anything is routed to it connects only to itself, which is
238// what the dangling-via test looks for. The cleaner must not eat it.
239BOOST_FIXTURE_TEST_CASE( CleanupKeepsAnUnlandedMicroviaStack, TRACK_CLEANER_TEST_FIXTURE )
240{
241 m_board = std::make_unique<BOARD>();
242 m_board->SetCopperLayerCount( 4 );
243 m_board->SetEnabledLayers( LSET::AllCuMask( 4 ) | LSET::AllTechMask() );
244
245 PCB_VIA_STACK* stack = new PCB_VIA_STACK( m_board.get(), F_Cu );
246 stack->SetStartLayer( F_Cu );
247 stack->SetEndLayer( In2_Cu );
248 stack->SetViaSize( 300000 );
249 stack->SetViaDrill( 150000 );
250 stack->SetPosition( VECTOR2I( 10000000, 10000000 ) );
251 m_board->Add( stack );
252 stack->Regenerate( m_board.get(), nullptr );
253
254 const size_t hops = stack->GetBoardItems().size();
255 BOOST_REQUIRE_EQUAL( hops, 2u );
256
257 m_board->BuildConnectivity();
258
259 TOOL_MANAGER toolMgr;
260 toolMgr.SetEnvironment( m_board.get(), nullptr, nullptr, nullptr, nullptr );
261
262 KI_TEST::DUMMY_TOOL* dummyTool = new KI_TEST::DUMMY_TOOL();
263 toolMgr.RegisterTool( dummyTool );
264
265 BOARD_COMMIT commit( dummyTool );
266 TRACKS_CLEANER cleaner( m_board.get(), commit );
267 std::vector<std::shared_ptr<CLEANUP_ITEM>> items;
268
269 cleaner.CleanupBoard( false, &items, false, false, false, false, false, true );
270
271 BOOST_CHECK_MESSAGE( stack->GetBoardItems().size() == hops,
272 "cleanup deleted hops of a stack nothing has been routed to yet" );
273 BOOST_CHECK_EQUAL( m_board->Tracks().size(), hops );
274}
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
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:37
@ DRCE_LIB_FOOTPRINT_ISSUES
Definition drc_item.h:85
@ DRCE_STARVED_THERMAL
Definition drc_item.h:47
@ DRCE_COPPER_SLIVER
Definition drc_item.h:96
@ DRCE_SOLDERMASK_BRIDGE
Definition drc_item.h:97
@ DRCE_LIB_FOOTPRINT_MISMATCH
Definition drc_item.h:86
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:683