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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
25#include <boost/test/data/test_case.hpp>
26
28#include <board.h>
29#include <board_commit.h>
32#include <tracks_cleaner.h>
33#include <cleanup_item.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 m_settingsManager( true /* headless */ )
44 { }
45
46 SETTINGS_MANAGER m_settingsManager;
47 std::unique_ptr<BOARD> m_board;
48};
49
50
51struct TEST_DESCRIPTION
52{
53 wxString m_File;
54 bool m_Shorts;
55 bool m_RedundantVias;
56 bool m_RedundantTracks;
57 bool m_DanglingTracks;
58 bool m_TracksInPads;
59 bool m_DanglingVias;
60 int m_Expected;
61
62 friend std::ostream& operator<<( std::ostream& os, const TEST_DESCRIPTION& aDesc )
63 {
64 os << aDesc.m_File;
65 return os;
66 }
67};
68
69/*
70* This one ensures that certain cleanup items are indeed found and marked for cleanup.
71*/
72std::vector<TEST_DESCRIPTION> FailedToCleanRegressionTests_tests =
73{
74 // short redundant redundant dangling tracks dangling
75 // circuits vias tracks tracks in pads vias expected
76 { "issue2904", false, false, false, true, false, false, 9 },
77 { "issue5093", false, false, false, false, true, false, 117 },
78 { "issue7004", false, true, false, false, false, true, 25 },
79 { "issue8883", true, true, true, true, false, true, 81 },
80 { "issue10916", false, false, true, false, false, false, 0 },
81 { "issue19574", false, false, true, false, false, false, 2 },
82};
83
84} // namespace
85
86
87BOOST_DATA_TEST_CASE_F( TRACK_CLEANER_TEST_FIXTURE, FailedToCleanRegressionTests,
88 boost::unit_test::data::make( FailedToCleanRegressionTests_tests ), entry )
89{
90 KI_TEST::LoadBoard( m_settingsManager, entry.m_File, m_board );
91 KI_TEST::FillZones( m_board.get() );
92 m_board->GetConnectivity()->RecalculateRatsnest();
93 m_board->UpdateRatsnestExclusions();
94
95 TOOL_MANAGER toolMgr;
96 toolMgr.SetEnvironment( m_board.get(), nullptr, nullptr, nullptr, nullptr );
97
99 toolMgr.RegisterTool( dummyTool );
100
101 BOARD_COMMIT commit( dummyTool );
102 TRACKS_CLEANER cleaner( m_board.get(), commit );
103 std::vector< std::shared_ptr<CLEANUP_ITEM> > dryRunItems;
104 std::vector< std::shared_ptr<CLEANUP_ITEM> > realRunItems;
105
106 cleaner.CleanupBoard( true, &dryRunItems, entry.m_Shorts,
107 entry.m_RedundantVias,
108 entry.m_RedundantTracks,
109 entry.m_DanglingTracks,
110 entry.m_TracksInPads,
111 entry.m_DanglingVias );
112
113 cleaner.CleanupBoard( true, &realRunItems, entry.m_Shorts,
114 entry.m_RedundantVias,
115 entry.m_RedundantTracks,
116 entry.m_DanglingTracks,
117 entry.m_TracksInPads,
118 entry.m_DanglingVias );
119
120 if( dryRunItems.size() == entry.m_Expected && realRunItems.size() == entry.m_Expected )
121 {
122 BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
123 BOOST_TEST_MESSAGE( wxString::Format( "Track cleaner regression: %s, passed",
124 entry.m_File ) );
125 }
126 else
127 {
128 BOOST_CHECK_EQUAL( dryRunItems.size(), entry.m_Expected );
129 BOOST_CHECK_EQUAL( realRunItems.size(), entry.m_Expected );
130
132
133 std::map<KIID, EDA_ITEM*> itemMap;
134 m_board->FillItemMap( itemMap );
135
136 for( const std::shared_ptr<CLEANUP_ITEM>& item : realRunItems )
137 {
138 BOOST_TEST_MESSAGE( item->ShowReport( &unitsProvider, RPT_SEVERITY_ERROR,
139 itemMap ) );
140 }
141
142 BOOST_ERROR( wxString::Format( "Track cleaner regression: %s, failed",
143 entry.m_File ) );
144 }
145}
146
147namespace
148{
149
150std::vector<wxString> TrackCleanerRegressionTests_tests = {
151 //"issue832",
152 "issue4257",
153 //"issue8909"
154};
155
156} // namespace
157
158/*
159 * This one just makes sure that the dry-run counts agree with the "real" counts, and that
160 * the cleaning doesn't produce any connectivity changes.
161 */
162BOOST_DATA_TEST_CASE_F( TRACK_CLEANER_TEST_FIXTURE, TrackCleanerRegressionTests,
163 boost::unit_test::data::make( TrackCleanerRegressionTests_tests ), relPath )
164{
165 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
166 KI_TEST::FillZones( m_board.get() );
167 m_board->GetConnectivity()->RecalculateRatsnest();
168 m_board->UpdateRatsnestExclusions();
169
170 TOOL_MANAGER toolMgr;
171 toolMgr.SetEnvironment( m_board.get(), nullptr, nullptr, nullptr, nullptr );
172
173 KI_TEST::DUMMY_TOOL* dummyTool = new KI_TEST::DUMMY_TOOL();
174 toolMgr.RegisterTool( dummyTool );
175
176 BOARD_COMMIT commit( dummyTool );
177 TRACKS_CLEANER cleaner( m_board.get(), commit );
178 std::vector< std::shared_ptr<CLEANUP_ITEM> > dryRunItems;
179 std::vector< std::shared_ptr<CLEANUP_ITEM> > realRunItems;
180
181 cleaner.CleanupBoard( true, &dryRunItems, true, // short circuits
182 true, // redundant vias
183 true, // redundant tracks
184 true, // dangling tracks
185 true, // tracks in pads
186 true ); // dangling vias
187
188 cleaner.CleanupBoard( true, &realRunItems, true, // short circuits
189 true, // redundant vias
190 true, // redundant tracks
191 true, // dangling tracks
192 true, // tracks in pads
193 true ); // dangling vias
194
195 BOOST_CHECK_EQUAL( dryRunItems.size(), realRunItems.size() );
196
197 std::vector<DRC_ITEM> violations;
198 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
199
200 // Disable some DRC tests not useful in this testcase
205 // Also disable this test: for some reason it generate an exception inside this QA
206 // test ans it is useless
208
209 bds.m_DRCEngine->SetViolationHandler(
210 [&]( const std::shared_ptr<DRC_ITEM>& aItem, VECTOR2I aPos, int aLayer,
211 DRC_CUSTOM_MARKER_HANDLER* aCustomHandler )
212 {
213 if( aItem->GetErrorCode() == DRCE_UNCONNECTED_ITEMS )
214 violations.push_back( *aItem );
215 } );
216
217 bds.m_DRCEngine->RunTests( EDA_UNITS::MILLIMETRES, true, false );
218
219 if( violations.empty() )
220 {
221 BOOST_TEST_MESSAGE( wxString::Format( "Track cleaner regression: %s, passed",
222 relPath ) );
223 }
224 else
225 {
227
228 std::map<KIID, EDA_ITEM*> itemMap;
229 m_board->FillItemMap( itemMap );
230
231 for( const DRC_ITEM& item : violations )
232 {
233 BOOST_TEST_MESSAGE( item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR,
234 itemMap ) );
235 }
236
237 BOOST_ERROR( wxString::Format( "Track cleaner regression: %s, failed",
238 relPath ) );
239 }
240}
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
Container for design settings for a BOARD object.
std::map< int, SEVERITY > m_DRCSeverities
std::shared_ptr< DRC_ENGINE > m_DRCEngine
Master controller class:
Definition: tool_manager.h:62
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.
std::function< void(PCB_MARKER *aMarker)> DRC_CUSTOM_MARKER_HANDLER
Definition: drc_engine.h:69
@ DRCE_UNCONNECTED_ITEMS
Definition: drc_item.h:39
@ DRCE_LIB_FOOTPRINT_ISSUES
Definition: drc_item.h:82
@ DRCE_STARVED_THERMAL
Definition: drc_item.h:49
@ DRCE_COPPER_SLIVER
Definition: drc_item.h:92
@ DRCE_SOLDERMASK_BRIDGE
Definition: drc_item.h:93
@ DRCE_LIB_FOOTPRINT_MISMATCH
Definition: drc_item.h:83
std::ostream & operator<<(std::ostream &aStream, const EDA_TEXT &aText)
Definition: eda_text.cpp:1307
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(ret, c.m_exp_result)
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
BOOST_DATA_TEST_CASE_F(TRACK_CLEANER_TEST_FIXTURE, FailedToCleanRegressionTests, boost::unit_test::data::make(FailedToCleanRegressionTests_tests), entry)