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