KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_creepage_issue21482.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
34
37
38#include <board.h>
40#include <footprint.h>
41#include <pcb_track.h>
42#include <pcb_marker.h>
43#include <drc/drc_item.h>
44#include <drc/drc_engine.h>
47
48#include <chrono>
49#include <cstdlib>
50#include <fstream>
51
52
54{
57
59 {
60 if( m_board && m_board->GetDesignSettings().m_DRCEngine )
61 {
62 m_board->GetDesignSettings().m_DRCEngine->ClearViolationHandler();
63 }
64
65 if( m_board )
66 {
67 m_board->SetProject( nullptr );
68 m_board = nullptr;
69 }
70 }
71
73 std::unique_ptr<BOARD> m_board;
74};
75
76
88{
89 // Load the test board with custom creepage rules
90 KI_TEST::LoadBoard( m_settingsManager, "issue21482/issue21482", m_board );
91
92 BOOST_REQUIRE_MESSAGE( m_board, "Failed to load board issue21482" );
93
94 // Count board elements for reporting
95 int trackCount = m_board->Tracks().size();
96 int padCount = 0;
97 for( FOOTPRINT* fp : m_board->Footprints() )
98 padCount += fp->Pads().size();
99
100 BOOST_TEST_MESSAGE( wxString::Format( "Board has %d tracks and %d pads", trackCount, padCount ) );
101
102 std::vector<DRC_ITEM> violations;
103 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
104
105 BOOST_REQUIRE_MESSAGE( bds.m_DRCEngine, "DRC engine not initialized" );
106
107 // Disable all DRC tests except creepage
108 for( int ii = DRCE_FIRST; ii <= DRCE_LAST; ++ii )
110
112
114 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
115 const std::function<void( PCB_MARKER* )>& aPathGenerator )
116 {
117 if( bds.GetSeverity( aItem->GetErrorCode() ) == SEVERITY::RPT_SEVERITY_ERROR )
118 violations.push_back( *aItem );
119 } );
120
121 BOOST_TEST_CHECKPOINT( "Running creepage DRC" );
122
123 // Time the DRC run
124 auto start = std::chrono::high_resolution_clock::now();
125
126 try
127 {
128 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
129 }
130 catch( const std::exception& e )
131 {
132 BOOST_ERROR( wxString::Format( "DRC creepage exception: %s", e.what() ) );
133 return;
134 }
135
136 auto end = std::chrono::high_resolution_clock::now();
137 double elapsedSeconds = std::chrono::duration<double>( end - start ).count();
138
139 BOOST_TEST_MESSAGE( wxString::Format( "DRC creepage completed in %.2f seconds", elapsedSeconds ) );
140 BOOST_TEST_MESSAGE( wxString::Format( "Found %d creepage violations", (int) violations.size() ) );
141
142 // Clear the violation handler
144
145 // Check if running on GitLab CI
146 bool onGitLabCI = std::getenv( "GITLAB_CI" ) != nullptr;
147
148 if( onGitLabCI )
149 {
150 // On GitLab CI, write metrics to a file for collection as an artifact.
151 // The timeout varies too much between runners, so we only record the time
152 // without asserting on it.
153 std::ofstream metricsFile( "creepage_perf_metrics.txt" );
154
155 if( metricsFile.is_open() )
156 {
157 metricsFile << "creepage_drc_seconds " << elapsedSeconds << "\n";
158 metricsFile << "creepage_violations " << violations.size() << "\n";
159 metricsFile.close();
160 BOOST_TEST_MESSAGE( "Metrics written to creepage_perf_metrics.txt" );
161 }
162 }
163 else
164 {
165 // On local machines, enforce the timeout constraint
166 BOOST_CHECK_MESSAGE( elapsedSeconds < 20.0,
167 wxString::Format( "Creepage DRC too slow: %.2f seconds (target: <20s)",
168 elapsedSeconds ) );
169 }
170
171 // Performance tier feedback
172 if( elapsedSeconds < 5.0 )
173 {
174 BOOST_TEST_MESSAGE( "Excellent performance: <5 seconds" );
175 }
176 else if( elapsedSeconds < 10.0 )
177 {
178 BOOST_TEST_MESSAGE( "Good performance: <10 seconds" );
179 }
180 else if( elapsedSeconds < 15.0 )
181 {
182 BOOST_TEST_MESSAGE( "Acceptable performance: <15 seconds" );
183 }
184}
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:152
void ClearViolationHandler()
Definition drc_engine.h:157
@ DRCE_CREEPAGE
Definition drc_item.h:45
@ 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)
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
BOOST_FIXTURE_TEST_CASE(CreepagePerformanceIssue21482, DRC_CREEPAGE_PERF_TEST_FIXTURE)
Test that creepage DRC check completes in a reasonable time.
VECTOR2I end
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695