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>
31#include <drc/drc_engine.h>
33#include <tracks_cleaner.h>
34#include <cleanup_item.h>
35#include <drc/drc_engine.h>
36#include <drc/drc_item.h>
38#include <tool/tool_manager.h>
39
40namespace
41{
42struct TRACK_CLEANER_TEST_FIXTURE
43{
44 TRACK_CLEANER_TEST_FIXTURE()
45 { }
46
47 SETTINGS_MANAGER m_settingsManager;
48 std::unique_ptr<BOARD> m_board;
49};
50
51
52struct TEST_DESCRIPTION
53{
54 wxString m_File;
55 bool m_Shorts;
56 bool m_RedundantVias;
57 bool m_RedundantTracks;
58 bool m_DanglingTracks;
59 bool m_TracksInPads;
60 bool m_DanglingVias;
61 int m_Expected;
62
63 friend std::ostream& operator<<( std::ostream& os, const TEST_DESCRIPTION& aDesc )
64 {
65 os << aDesc.m_File;
66 return os;
67 }
68};
69
70/*
71* This one ensures that certain cleanup items are indeed found and marked for cleanup.
72*/
73std::vector<TEST_DESCRIPTION> FailedToCleanRegressionTests_tests =
74{
75 // short redundant redundant dangling tracks dangling
76 // circuits vias tracks tracks in pads vias expected
77 { "issue2904", false, false, false, true, false, false, 9 },
78 { "issue5093", false, false, false, false, true, false, 117 },
79 { "issue7004", false, true, false, false, false, true, 25 },
80 { "issue8883", true, true, true, true, false, true, 81 },
81 { "issue10916", false, false, true, false, false, false, 0 },
82 { "issue19574", false, false, true, false, false, false, 2 },
83};
84
85} // namespace
86
87
88BOOST_DATA_TEST_CASE_F( TRACK_CLEANER_TEST_FIXTURE, FailedToCleanRegressionTests,
89 boost::unit_test::data::make( FailedToCleanRegressionTests_tests ), entry )
90{
91 KI_TEST::LoadBoard( m_settingsManager, entry.m_File, m_board );
92 KI_TEST::FillZones( m_board.get() );
93 m_board->GetConnectivity()->RecalculateRatsnest();
94 m_board->UpdateRatsnestExclusions();
95
96 TOOL_MANAGER toolMgr;
97 toolMgr.SetEnvironment( m_board.get(), nullptr, nullptr, nullptr, nullptr );
98
100 toolMgr.RegisterTool( dummyTool );
101
102 BOARD_COMMIT commit( dummyTool );
103 TRACKS_CLEANER cleaner( m_board.get(), commit );
104 std::vector< std::shared_ptr<CLEANUP_ITEM> > dryRunItems;
105 std::vector< std::shared_ptr<CLEANUP_ITEM> > realRunItems;
106
107 cleaner.CleanupBoard( true, &dryRunItems, entry.m_Shorts,
108 entry.m_RedundantVias,
109 entry.m_RedundantTracks,
110 entry.m_DanglingTracks,
111 entry.m_TracksInPads,
112 entry.m_DanglingVias );
113
114 cleaner.CleanupBoard( true, &realRunItems, entry.m_Shorts,
115 entry.m_RedundantVias,
116 entry.m_RedundantTracks,
117 entry.m_DanglingTracks,
118 entry.m_TracksInPads,
119 entry.m_DanglingVias );
120
121 if( dryRunItems.size() == entry.m_Expected && realRunItems.size() == entry.m_Expected )
122 {
123 BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
124 BOOST_TEST_MESSAGE( wxString::Format( "Track cleaner regression: %s, passed",
125 entry.m_File ) );
126 }
127 else
128 {
129 BOOST_CHECK_EQUAL( dryRunItems.size(), entry.m_Expected );
130 BOOST_CHECK_EQUAL( realRunItems.size(), entry.m_Expected );
131
132 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::INCH );
133
134 std::map<KIID, EDA_ITEM*> itemMap;
135 m_board->FillItemMap( itemMap );
136
137 for( const std::shared_ptr<CLEANUP_ITEM>& item : realRunItems )
138 {
139 BOOST_TEST_MESSAGE( item->ShowReport( &unitsProvider, RPT_SEVERITY_ERROR,
140 itemMap ) );
141 }
142
143 BOOST_ERROR( wxString::Format( "Track cleaner regression: %s, failed",
144 entry.m_File ) );
145 }
146}
147
148namespace
149{
150
151std::vector<wxString> TrackCleanerRegressionTests_tests = {
152 //"issue832",
153 "issue4257",
154 //"issue8909"
155};
156
157} // namespace
158
159/*
160 * This one just makes sure that the dry-run counts agree with the "real" counts, and that
161 * the cleaning doesn't produce any connectivity changes.
162 */
163BOOST_DATA_TEST_CASE_F( TRACK_CLEANER_TEST_FIXTURE, TrackCleanerRegressionTests,
164 boost::unit_test::data::make( TrackCleanerRegressionTests_tests ), relPath )
165{
166 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
167 KI_TEST::FillZones( m_board.get() );
168 m_board->GetConnectivity()->RecalculateRatsnest();
169 m_board->UpdateRatsnestExclusions();
170
171 TOOL_MANAGER toolMgr;
172 toolMgr.SetEnvironment( m_board.get(), nullptr, nullptr, nullptr, nullptr );
173
174 KI_TEST::DUMMY_TOOL* dummyTool = new KI_TEST::DUMMY_TOOL();
175 toolMgr.RegisterTool( dummyTool );
176
177 BOARD_COMMIT commit( dummyTool );
178 TRACKS_CLEANER cleaner( m_board.get(), commit );
179 std::vector< std::shared_ptr<CLEANUP_ITEM> > dryRunItems;
180 std::vector< std::shared_ptr<CLEANUP_ITEM> > realRunItems;
181
182 cleaner.CleanupBoard( true, &dryRunItems, true, // short circuits
183 true, // redundant vias
184 true, // redundant tracks
185 true, // dangling tracks
186 true, // tracks in pads
187 true ); // dangling vias
188
189 cleaner.CleanupBoard( true, &realRunItems, true, // short circuits
190 true, // redundant vias
191 true, // redundant tracks
192 true, // dangling tracks
193 true, // tracks in pads
194 true ); // dangling vias
195
196 BOOST_CHECK_EQUAL( dryRunItems.size(), realRunItems.size() );
197
198 std::vector<DRC_ITEM> violations;
199 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
200
201 // Disable some DRC tests not useful in this testcase
206 // Also disable this test: for some reason it generate an exception inside this QA
207 // test ans it is useless
209
211 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
212 const std::function<void( PCB_MARKER* )>& aPathGenerator )
213 {
214 if( aItem->GetErrorCode() == DRCE_UNCONNECTED_ITEMS )
215 violations.push_back( *aItem );
216 } );
217
218 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
219
220 if( violations.empty() )
221 {
222 BOOST_TEST_MESSAGE( wxString::Format( "Track cleaner regression: %s, passed", relPath ) );
223 }
224 else
225 {
226 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::INCH );
227
228 std::map<KIID, EDA_ITEM*> itemMap;
229 m_board->FillItemMap( itemMap );
230
231 for( const DRC_ITEM& item : violations )
232 BOOST_TEST_MESSAGE( item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, itemMap ) );
233
234 BOOST_ERROR( wxString::Format( "Track cleaner regression: %s, failed", relPath ) );
235 }
236}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
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:167
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:40
@ DRCE_LIB_FOOTPRINT_ISSUES
Definition drc_item.h:83
@ DRCE_STARVED_THERMAL
Definition drc_item.h:50
@ DRCE_COPPER_SLIVER
Definition drc_item.h:93
@ DRCE_SOLDERMASK_BRIDGE
Definition drc_item.h:94
@ DRCE_LIB_FOOTPRINT_MISMATCH
Definition drc_item.h:84
std::ostream & operator<<(std::ostream &aStream, const EDA_TEXT &aText)
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)
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695