KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_hole_clearance_issue24355.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
59
62
63#include <board.h>
65#include <footprint.h>
66#include <pad.h>
67#include <drc/drc_item.h>
68#include <drc/drc_engine.h>
71
72
74{
76
78 {
79 if( m_board && m_board->GetDesignSettings().m_DRCEngine )
80 m_board->GetDesignSettings().m_DRCEngine->ClearViolationHandler();
81
82 if( m_board )
83 {
84 m_board->SetProject( nullptr );
85 m_board = nullptr;
86 }
87 }
88
90 std::unique_ptr<BOARD> m_board;
91};
92
93
95{
96 KI_TEST::LoadBoard( m_settingsManager, "issue24355/issue24355", m_board );
97
98 BOOST_REQUIRE_MESSAGE( m_board, "Failed to load board issue24355" );
99 BOOST_REQUIRE_EQUAL( m_board->Footprints().size(), 1 );
100
101 FOOTPRINT* fp = m_board->Footprints().front();
102 BOOST_REQUIRE_EQUAL( fp->Pads().size(), 2 );
103
104 // The bug is direction-sensitive; the fixture deliberately lists the
105 // NPTH pad first so the parser allocates it at the lower heap address.
106 // If a future allocator change flips this, the test may pass on buggy
107 // code by accident -- flag it so the failure mode is obvious.
108 PAD* first = fp->Pads()[0];
109 PAD* second = fp->Pads()[1];
110 BOOST_REQUIRE_MESSAGE( first->GetAttribute() == PAD_ATTRIB::NPTH,
111 "Fixture pad order changed: expected NPTH first." );
112 BOOST_REQUIRE_MESSAGE( second->GetAttribute() == PAD_ATTRIB::PTH,
113 "Fixture pad order changed: expected PTH second." );
114 BOOST_WARN_MESSAGE( static_cast<void*>( first ) < static_cast<void*>( second ),
115 "Heap put PTH below NPTH; the bug may not trigger in this run." );
116
117 int holeClearanceCount = 0;
118 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
119
120 BOOST_REQUIRE_MESSAGE( bds.m_DRCEngine, "DRC engine not initialized" );
121
122 for( int ii = DRCE_FIRST; ii <= DRCE_LAST; ++ii )
124
126
128 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& /*aPos*/, int /*aLayer*/,
129 const std::function<void( PCB_MARKER* )>& /*aPathGen*/ )
130 {
131 if( aItem->GetErrorCode() == DRCE_HOLE_CLEARANCE )
132 ++holeClearanceCount;
133 } );
134
135 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
136
138
139 BOOST_TEST_MESSAGE( wxString::Format( "Hole clearance violations: %d", holeClearanceCount ) );
140
141 // One violation per shared copper layer (F.Cu, B.Cu) for a 2-layer board.
142 BOOST_CHECK_EQUAL( holeClearanceCount, 2 );
143}
Container for design settings for a BOARD object.
std::map< int, SEVERITY > m_DRCSeverities
std::shared_ptr< DRC_ENGINE > m_DRCEngine
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
std::deque< PAD * > & Pads()
Definition footprint.h:375
Definition pad.h:61
PAD_ATTRIB GetAttribute() const
Definition pad.h:555
@ DRCE_HOLE_CLEARANCE
Definition drc_item.h:51
@ 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)
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition padstack.h:103
@ PTH
Plated through hole pad.
Definition padstack.h:98
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
DRC_HOLE_CLEARANCE_FIXTURE()=default
BOOST_FIXTURE_TEST_CASE(HoleClearanceIssue24355, DRC_HOLE_CLEARANCE_FIXTURE)
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