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