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
41namespace
42{
43struct DRC_REGRESSION_TEST_FIXTURE
44{
45 DRC_REGRESSION_TEST_FIXTURE()
46 { }
47
48 ~DRC_REGRESSION_TEST_FIXTURE()
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
63 SETTINGS_MANAGER m_settingsManager;
64 std::unique_ptr<BOARD> m_board;
65};
66} // namespace
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
81BOOST_DATA_TEST_CASE_F( DRC_REGRESSION_TEST_FIXTURE, DRCCopperSliver,
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 BOARD_RC_ITEM_RESOLVER resolver( *m_board );
153
154 // Report violations with bounds checking
155 for( size_t i = 0; i < violations.size() && i < 100; ++i ) // Limit output to prevent excessive logging
156 {
157 try
158 {
159 const DRC_ITEM& item = violations[i];
160 BOOST_TEST_MESSAGE( item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, resolver ) );
161 }
162 catch( const std::exception& e )
163 {
164 BOOST_TEST_MESSAGE( wxString::Format( "Error reporting violation %zu: %s", i, e.what() ) );
165 }
166 catch( ... )
167 {
168 BOOST_TEST_MESSAGE( wxString::Format( "Unknown error reporting violation %zu", i ) );
169 }
170 }
171
172 BOOST_ERROR( wxString::Format( "DRC copper sliver: %s, failed (violations found %d "
173 "expected %d)",
174 test.first,
175 (int) violations.size(),
176 test.second ) );
177 }
178}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
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) const
Return the severity of a given DRC error code.
Implements the RC_ITEM_RESOLVER interface to resolve PCB items by their KIID.
Definition drc_item.h:349
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 RC_ITEM_RESOLVER &aResolver) const
Translate this object into a text string suitable for saving to disk in a report.
Definition rc_item.cpp:104
@ DRCE_COPPER_SLIVER
Definition drc_item.h:107
@ DRCE_FIRST
Definition drc_item.h:47
@ DRCE_LAST
Definition drc_item.h:144
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:708