KiCad PCB EDA Suite
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 (C) 2021-2022 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, 118 },
71 { "issue7004", false, true, false, false, false, true, 25 },
72 { "issue8883", true, true, true, true, false, true, 80 },
73 { "issue10916", false, false, true, false, false, false, 0 }
74 };
75
76 for( const TEST_DESCRIPTION& entry : tests )
77 {
78 KI_TEST::LoadBoard( m_settingsManager, entry.m_File, m_board );
79 KI_TEST::FillZones( m_board.get() );
80 m_board->GetConnectivity()->RecalculateRatsnest();
81 m_board->UpdateRatsnestExclusions();
82
83 TOOL_MANAGER toolMgr;
84 toolMgr.SetEnvironment( m_board.get(), nullptr, nullptr, nullptr, nullptr );
85
86 BOARD_COMMIT commit( &toolMgr );
87 TRACKS_CLEANER cleaner( m_board.get(), commit );
88 std::vector< std::shared_ptr<CLEANUP_ITEM> > dryRunItems;
89 std::vector< std::shared_ptr<CLEANUP_ITEM> > realRunItems;
90
91 cleaner.CleanupBoard( true, &dryRunItems, entry.m_Shorts,
92 entry.m_RedundantVias,
93 entry.m_RedundantTracks,
94 entry.m_DanglingTracks,
95 entry.m_TracksInPads,
96 entry.m_DanglingVias );
97
98 cleaner.CleanupBoard( true, &realRunItems, entry.m_Shorts,
99 entry.m_RedundantVias,
100 entry.m_RedundantTracks,
101 entry.m_DanglingTracks,
102 entry.m_TracksInPads,
103 entry.m_DanglingVias );
104
105 if( dryRunItems.size() == entry.m_Expected && realRunItems.size() == entry.m_Expected )
106 {
107 BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
108 BOOST_TEST_MESSAGE( wxString::Format( "Track cleaner regression: %s, passed",
109 entry.m_File ) );
110 }
111 else
112 {
113 BOOST_CHECK_EQUAL( dryRunItems.size(), entry.m_Expected );
114 BOOST_CHECK_EQUAL( realRunItems.size(), entry.m_Expected );
115
117
118 std::map<KIID, EDA_ITEM*> itemMap;
119 m_board->FillItemMap( itemMap );
120
121 for( const std::shared_ptr<CLEANUP_ITEM>& item : realRunItems )
122 {
123 BOOST_TEST_MESSAGE( item->ShowReport( &unitsProvider, RPT_SEVERITY_ERROR,
124 itemMap ) );
125 }
126
127 BOOST_ERROR( wxString::Format( "Track cleaner regression: %s, failed",
128 entry.m_File ) );
129 }
130 }
131}
132
133
135{
136 /*
137 * This one just makes sure that the dry-run counts agree with the "real" counts, and that
138 * the cleaning doesn't produce any connectivity changes.
139 */
140 std::vector<wxString> tests = { "issue832",
141 "issue4257",
142 "issue8909"
143 };
144
145 for( const wxString& relPath : tests )
146 {
147 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
148 KI_TEST::FillZones( m_board.get() );
149 m_board->GetConnectivity()->RecalculateRatsnest();
150 m_board->UpdateRatsnestExclusions();
151
152 TOOL_MANAGER toolMgr;
153 toolMgr.SetEnvironment( m_board.get(), nullptr, nullptr, nullptr, nullptr );
154
155 BOARD_COMMIT commit( &toolMgr );
156 TRACKS_CLEANER cleaner( m_board.get(), commit );
157 std::vector< std::shared_ptr<CLEANUP_ITEM> > dryRunItems;
158 std::vector< std::shared_ptr<CLEANUP_ITEM> > realRunItems;
159
160 cleaner.CleanupBoard( true, &dryRunItems, true, // short circuits
161 true, // redundant vias
162 true, // redundant tracks
163 true, // dangling tracks
164 true, // tracks in pads
165 true ); // dangling vias
166
167 cleaner.CleanupBoard( true, &realRunItems, 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 BOOST_CHECK_EQUAL( dryRunItems.size(), realRunItems.size() );
175
176 std::vector<DRC_ITEM> violations;
177 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
178
179 // Disable some DRC tests not useful in this testcase
184
185 bds.m_DRCEngine->SetViolationHandler(
186 [&]( const std::shared_ptr<DRC_ITEM>& aItem, VECTOR2I aPos, int aLayer )
187 {
188 if( aItem->GetErrorCode() == DRCE_UNCONNECTED_ITEMS )
189 violations.push_back( *aItem );
190 } );
191
192 bds.m_DRCEngine->RunTests( EDA_UNITS::MILLIMETRES, true, false );
193
194 if( violations.empty() )
195 {
196 BOOST_TEST_MESSAGE( wxString::Format( "Track cleaner regression: %s, passed",
197 relPath ) );
198 }
199 else
200 {
202
203 std::map<KIID, EDA_ITEM*> itemMap;
204 m_board->FillItemMap( itemMap );
205
206 for( const DRC_ITEM& item : violations )
207 {
208 BOOST_TEST_MESSAGE( item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR,
209 itemMap ) );
210 }
211
212 BOOST_ERROR( wxString::Format( "Track cleaner regression: %s, failed",
213 relPath ) );
214 }
215 }
216}
217
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:109
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:55
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:39
@ DRCE_LIB_FOOTPRINT_ISSUES
Definition: drc_item.h:76
@ DRCE_STARVED_THERMAL
Definition: drc_item.h:48
@ DRCE_COPPER_SLIVER
Definition: drc_item.h:84
@ DRCE_LIB_FOOTPRINT_MISMATCH
Definition: drc_item.h:77
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
void FillZones(BOARD *m_board)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
std::unique_ptr< BOARD > m_board
BOOST_FIXTURE_TEST_CASE(FailedToCleanRegressionTests, TRACK_CLEANER_TEST_FIXTURE)