KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_copper_sliver.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
24
26#include <boost/test/data/test_case.hpp>
28
29#include <board.h>
31#include <pad.h>
32#include <pcb_track.h>
33#include <pcb_marker.h>
34#include <footprint.h>
35#include <drc/drc_item.h>
37
38#include <thread>
39#include <chrono>
40#include <exception>
41
42
44{
46 m_settingsManager( true /* headless */ )
47 { }
48
50 {
51 // Ensure proper cleanup
52 if( m_board && m_board->GetDesignSettings().m_DRCEngine )
53 {
54 m_board->GetDesignSettings().m_DRCEngine->ClearViolationHandler();
55 }
56
57 if( m_board )
58 {
59 m_board->SetProject( nullptr );
60 m_board = nullptr;
61 }
62 }
63
65 std::unique_ptr<BOARD> m_board;
66};
67
68
69// clang-format off
70static const std::vector<std::pair<wxString, int>> DRCCopperSliver_cases =
71{
72 { "sliver", 1 },
73 { "issue14449", 0 },
74 { "issue14549", 0 },
75 { "issue14549_2", 0 },
76 { "issue14559", 0 }
77};
78// clang-format on
79
80
82 boost::unit_test::data::make( DRCCopperSliver_cases ), test )
83{
84 // Check for minimum copper connection errors
85
86 KI_TEST::LoadBoard( m_settingsManager, test.first, m_board );
87
88 // Validate board was loaded successfully
89 BOOST_REQUIRE_MESSAGE( m_board, "Failed to load board for test: " + test.first.ToStdString() );
90
91 KI_TEST::FillZones( m_board.get() );
92
93 std::vector<DRC_ITEM> violations;
94 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
95
96 // Validate DRC engine is properly initialized
97 BOOST_REQUIRE_MESSAGE( bds.m_DRCEngine, "DRC engine not initialized for test: " + test.first.ToStdString() );
98
99 // Disable DRC tests not useful or not handled in this testcase
100 for( int ii = DRCE_FIRST; ii <= DRCE_LAST; ++ii )
102
103 // Ensure that our desired error is fired
105
107 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
108 const std::function<void( PCB_MARKER* )>& aPathGenerator )
109 {
110 if( bds.GetSeverity( aItem->GetErrorCode() ) == SEVERITY::RPT_SEVERITY_ERROR )
111 violations.push_back( *aItem );
112 } );
113
114 BOOST_TEST_CHECKPOINT( "Running copper sliver drc" );
115
116 // Add exception handling around DRC engine run to catch potential crashes
117 try
118 {
119 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
120
121 // Add a small delay to allow any background threads to complete
122 std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
123
124 BOOST_TEST_CHECKPOINT( "DRC engine run completed successfully" );
125 }
126 catch( const std::exception& e )
127 {
128 BOOST_ERROR( wxString::Format( "DRC copper sliver: %s, exception during RunTests: %s",
129 test.first, e.what() ) );
130 return;
131 }
132 catch( ... )
133 {
134 BOOST_ERROR( wxString::Format( "DRC copper sliver: %s, unknown exception during RunTests",
135 test.first ) );
136 return;
137 }
138
139 // Clear the violation handler to prevent any potential issues with cleanup
140 BOOST_TEST_CHECKPOINT( "Clearing violation handler" );
142
143 if( violations.size() == test.second )
144 {
145 BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
146 BOOST_TEST_MESSAGE( wxString::Format( "DRC copper sliver: %s, passed", test.first ) );
147 }
148 else
149 {
150 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::INCH );
151
152 std::map<KIID, EDA_ITEM*> itemMap;
153
154 // Safely build the item map with error handling
155 try
156 {
157 m_board->FillItemMap( itemMap );
158 }
159 catch( const std::exception& e )
160 {
161 BOOST_ERROR( wxString::Format( "DRC copper sliver: %s, exception in FillItemMap: %s",
162 test.first, e.what() ) );
163 return;
164 }
165 catch( ... )
166 {
167 BOOST_ERROR( wxString::Format( "DRC copper sliver: %s, unknown exception in FillItemMap",
168 test.first ) );
169 return;
170 }
171
172 // Safely report violations with bounds checking
173 for( size_t i = 0; i < violations.size() && i < 100; ++i ) // Limit output to prevent excessive logging
174 {
175 try
176 {
177 const DRC_ITEM& item = violations[i];
178 BOOST_TEST_MESSAGE( item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, itemMap ) );
179 }
180 catch( const std::exception& e )
181 {
182 BOOST_TEST_MESSAGE( wxString::Format( "Error reporting violation %zu: %s", i, e.what() ) );
183 }
184 catch( ... )
185 {
186 BOOST_TEST_MESSAGE( wxString::Format( "Unknown error reporting violation %zu", i ) );
187 }
188 }
189
190 BOOST_ERROR( wxString::Format( "DRC copper sliver: %s, failed (violations found %d "
191 "expected %d)",
192 test.first,
193 (int) violations.size(),
194 test.second ) );
195 }
196}
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
SEVERITY GetSeverity(int aDRCErrorCode)
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:118
void ClearViolationHandler()
Definition drc_engine.h:123
virtual wxString ShowReport(UNITS_PROVIDER *aUnitsProvider, SEVERITY aSeverity, const std::map< KIID, EDA_ITEM * > &aItemMap) const
Translate this object into a text string suitable for saving to disk in a report.
Definition rc_item.cpp:100
@ DRCE_COPPER_SLIVER
Definition drc_item.h:92
@ DRCE_FIRST
Definition drc_item.h:38
@ DRCE_LAST
Definition drc_item.h:112
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
void FillZones(BOARD *m_board)
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
static const std::vector< std::pair< wxString, int > > DRCCopperSliver_cases
BOOST_DATA_TEST_CASE_F(DRC_REGRESSION_TEST_FIXTURE, DRCCopperSliver, boost::unit_test::data::make(DRCCopperSliver_cases), test)
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695