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