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 (C) 2021-2023 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, 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
87 toolMgr.RegisterTool( dummyTool );
88
89 BOARD_COMMIT commit( dummyTool );
90 TRACKS_CLEANER cleaner( m_board.get(), commit );
91 std::vector< std::shared_ptr<CLEANUP_ITEM> > dryRunItems;
92 std::vector< std::shared_ptr<CLEANUP_ITEM> > realRunItems;
93
94 cleaner.CleanupBoard( true, &dryRunItems, entry.m_Shorts,
95 entry.m_RedundantVias,
96 entry.m_RedundantTracks,
97 entry.m_DanglingTracks,
98 entry.m_TracksInPads,
99 entry.m_DanglingVias );
100
101 cleaner.CleanupBoard( true, &realRunItems, entry.m_Shorts,
102 entry.m_RedundantVias,
103 entry.m_RedundantTracks,
104 entry.m_DanglingTracks,
105 entry.m_TracksInPads,
106 entry.m_DanglingVias );
107
108 if( dryRunItems.size() == entry.m_Expected && realRunItems.size() == entry.m_Expected )
109 {
110 BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
111 BOOST_TEST_MESSAGE( wxString::Format( "Track cleaner regression: %s, passed",
112 entry.m_File ) );
113 }
114 else
115 {
116 BOOST_CHECK_EQUAL( dryRunItems.size(), entry.m_Expected );
117 BOOST_CHECK_EQUAL( realRunItems.size(), entry.m_Expected );
118
120
121 std::map<KIID, EDA_ITEM*> itemMap;
122 m_board->FillItemMap( itemMap );
123
124 for( const std::shared_ptr<CLEANUP_ITEM>& item : realRunItems )
125 {
126 BOOST_TEST_MESSAGE( item->ShowReport( &unitsProvider, RPT_SEVERITY_ERROR,
127 itemMap ) );
128 }
129
130 BOOST_ERROR( wxString::Format( "Track cleaner regression: %s, failed",
131 entry.m_File ) );
132 }
133 }
134}
135
136
138{
139 /*
140 * This one just makes sure that the dry-run counts agree with the "real" counts, and that
141 * the cleaning doesn't produce any connectivity changes.
142 */
143 std::vector<wxString> tests = { "issue832",
144 "issue4257",
145 "issue8909"
146 };
147
148 for( const wxString& relPath : tests )
149 {
150 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
151 KI_TEST::FillZones( m_board.get() );
152 m_board->GetConnectivity()->RecalculateRatsnest();
153 m_board->UpdateRatsnestExclusions();
154
155 TOOL_MANAGER toolMgr;
156 toolMgr.SetEnvironment( m_board.get(), nullptr, nullptr, nullptr, nullptr );
157
158 KI_TEST::DUMMY_TOOL* dummyTool = new KI_TEST::DUMMY_TOOL();
159 toolMgr.RegisterTool( dummyTool );
160
161 BOARD_COMMIT commit( dummyTool );
162 TRACKS_CLEANER cleaner( m_board.get(), commit );
163 std::vector< std::shared_ptr<CLEANUP_ITEM> > dryRunItems;
164 std::vector< std::shared_ptr<CLEANUP_ITEM> > realRunItems;
165
166 cleaner.CleanupBoard( true, &dryRunItems, true, // short circuits
167 true, // redundant vias
168 true, // redundant tracks
169 true, // dangling tracks
170 true, // tracks in pads
171 true ); // dangling vias
172
173 cleaner.CleanupBoard( true, &realRunItems, true, // short circuits
174 true, // redundant vias
175 true, // redundant tracks
176 true, // dangling tracks
177 true, // tracks in pads
178 true ); // dangling vias
179
180 BOOST_CHECK_EQUAL( dryRunItems.size(), realRunItems.size() );
181
182 std::vector<DRC_ITEM> violations;
183 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
184
185 // Disable some DRC tests not useful in this testcase
190 // Also disable this test: for some reason it generate an exception inside this QA
191 // test ans it is useless
193
194 bds.m_DRCEngine->SetViolationHandler(
195 [&]( const std::shared_ptr<DRC_ITEM>& aItem, VECTOR2I aPos, int aLayer )
196 {
197 if( aItem->GetErrorCode() == DRCE_UNCONNECTED_ITEMS )
198 violations.push_back( *aItem );
199 } );
200
201 bds.m_DRCEngine->RunTests( EDA_UNITS::MILLIMETRES, true, false );
202
203 if( violations.empty() )
204 {
205 BOOST_TEST_MESSAGE( wxString::Format( "Track cleaner regression: %s, passed",
206 relPath ) );
207 }
208 else
209 {
211
212 std::map<KIID, EDA_ITEM*> itemMap;
213 m_board->FillItemMap( itemMap );
214
215 for( const DRC_ITEM& item : violations )
216 {
217 BOOST_TEST_MESSAGE( item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR,
218 itemMap ) );
219 }
220
221 BOOST_ERROR( wxString::Format( "Track cleaner regression: %s, failed",
222 relPath ) );
223 }
224 }
225}
226
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.
@ DRCE_UNCONNECTED_ITEMS
Definition: drc_item.h:39
@ DRCE_LIB_FOOTPRINT_ISSUES
Definition: drc_item.h:77
@ DRCE_STARVED_THERMAL
Definition: drc_item.h:48
@ DRCE_COPPER_SLIVER
Definition: drc_item.h:85
@ DRCE_SOLDERMASK_BRIDGE
Definition: drc_item.h:86
@ DRCE_LIB_FOOTPRINT_MISMATCH
Definition: drc_item.h:78
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)