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, see <https://www.gnu.org/licenses/>.
18 */
19
30
33
34#include <board.h>
36#include <footprint.h>
37#include <pcb_track.h>
38#include <pcb_marker.h>
39#include <drc/drc_item.h>
40#include <drc/drc_engine.h>
43
44#include <chrono>
45#include <cstdlib>
46#include <fstream>
47
48
50{
53
55 {
56 if( m_board && m_board->GetDesignSettings().m_DRCEngine )
57 {
58 m_board->GetDesignSettings().m_DRCEngine->ClearViolationHandler();
59 }
60
61 if( m_board )
62 {
63 m_board->SetProject( nullptr );
64 m_board = nullptr;
65 }
66 }
67
69 std::unique_ptr<BOARD> m_board;
70};
71
72
84{
85 // Load the test board with custom creepage rules
86 KI_TEST::LoadBoard( m_settingsManager, "issue21482/issue21482", m_board );
87
88 BOOST_REQUIRE_MESSAGE( m_board, "Failed to load board issue21482" );
89
90 // Count board elements for reporting
91 int trackCount = m_board->Tracks().size();
92 int padCount = 0;
93 for( FOOTPRINT* fp : m_board->Footprints() )
94 padCount += fp->Pads().size();
95
96 BOOST_TEST_MESSAGE( wxString::Format( "Board has %d tracks and %d pads", trackCount, padCount ) );
97
98 std::vector<DRC_ITEM> violations;
99 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
100
101 BOOST_REQUIRE_MESSAGE( bds.m_DRCEngine, "DRC engine not initialized" );
102
103 // Disable all DRC tests except creepage
104 for( int ii = DRCE_FIRST; ii <= DRCE_LAST; ++ii )
106
108
110 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
111 const std::function<void( PCB_MARKER* )>& aPathGenerator )
112 {
113 if( bds.GetSeverity( aItem->GetErrorCode() ) == SEVERITY::RPT_SEVERITY_ERROR )
114 violations.push_back( *aItem );
115 } );
116
117 BOOST_TEST_CHECKPOINT( "Running creepage DRC" );
118
119 // Time the DRC run
120 auto start = std::chrono::high_resolution_clock::now();
121
122 try
123 {
124 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
125 }
126 catch( const std::exception& e )
127 {
128 BOOST_ERROR( wxString::Format( "DRC creepage exception: %s", e.what() ) );
129 return;
130 }
131
132 auto end = std::chrono::high_resolution_clock::now();
133 double elapsedSeconds = std::chrono::duration<double>( end - start ).count();
134
135 BOOST_TEST_MESSAGE( wxString::Format( "DRC creepage completed in %.2f seconds", elapsedSeconds ) );
136 BOOST_TEST_MESSAGE( wxString::Format( "Found %d creepage violations", (int) violations.size() ) );
137
138 // Clear the violation handler
140
141 // Check if running on GitLab CI
142 bool onGitLabCI = std::getenv( "GITLAB_CI" ) != nullptr;
143
144 // Check if running on Launchpad/Debian build (DEB_BUILD_OPTIONS contains "nocheck")
145 bool onDebianBuild = false;
146 const char* debBuildOpts = std::getenv( "DEB_BUILD_OPTIONS" );
147
148 if( debBuildOpts && std::string( debBuildOpts ).find( "nocheck" ) != std::string::npos )
149 onDebianBuild = true;
150
151 if( onGitLabCI || onDebianBuild )
152 {
153 // On CI systems, write metrics to a file for collection as an artifact.
154 // The timeout varies too much between runners, so we only record the time
155 // without asserting on it.
156 std::ofstream metricsFile( "creepage_perf_metrics.txt" );
157
158 if( metricsFile.is_open() )
159 {
160 metricsFile << "creepage_drc_seconds " << elapsedSeconds << "\n";
161 metricsFile << "creepage_violations " << violations.size() << "\n";
162 metricsFile.close();
163 BOOST_TEST_MESSAGE( "Metrics written to creepage_perf_metrics.txt" );
164 }
165 }
166 else if( std::getenv( "KICAD_ENABLE_DRC_PERFORMANCE_QA" ) != nullptr )
167 {
168 // On local machines, enforce the timeout constraint
169 BOOST_CHECK_MESSAGE( elapsedSeconds < 20.0,
170 wxString::Format( "Creepage DRC too slow: %.2f seconds (target: <20s)",
171 elapsedSeconds ) );
172 }
173
174 // Performance tier feedback
175 if( elapsedSeconds < 5.0 )
176 {
177 BOOST_TEST_MESSAGE( "Excellent performance: <5 seconds" );
178 }
179 else if( elapsedSeconds < 10.0 )
180 {
181 BOOST_TEST_MESSAGE( "Good performance: <10 seconds" );
182 }
183 else if( elapsedSeconds < 15.0 )
184 {
185 BOOST_TEST_MESSAGE( "Acceptable performance: <15 seconds" );
186 }
187}
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
@ DRCE_CREEPAGE
Definition drc_item.h:41
@ 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)
@ 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.
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_TEST_MESSAGE("\n=== Real-World Polygon PIP Benchmark ===\n"<< formatTable(table))
VECTOR2I end
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683