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