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