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 // This only measures, and unoptimized MSVC needs 20 minutes to do so
86#ifdef DEBUG
87 BOOST_TEST_MESSAGE( "Skipping creepage performance measurement in a debug build" );
88 return;
89#endif
90
91 // Load the test board with custom creepage rules
92 KI_TEST::LoadBoard( m_settingsManager, "issue21482/issue21482", m_board );
93
94 BOOST_REQUIRE_MESSAGE( m_board, "Failed to load board issue21482" );
95
96 // Count board elements for reporting
97 int trackCount = m_board->Tracks().size();
98 int padCount = 0;
99 for( FOOTPRINT* fp : m_board->Footprints() )
100 padCount += fp->Pads().size();
101
102 BOOST_TEST_MESSAGE( wxString::Format( "Board has %d tracks and %d pads", trackCount, padCount ) );
103
104 std::vector<DRC_ITEM> violations;
105 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
106
107 BOOST_REQUIRE_MESSAGE( bds.m_DRCEngine, "DRC engine not initialized" );
108
109 // Disable all DRC tests except creepage
110 for( int ii = DRCE_FIRST; ii <= DRCE_LAST; ++ii )
112
114
116 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
117 const std::function<void( PCB_MARKER* )>& aPathGenerator )
118 {
119 if( bds.GetSeverity( aItem->GetErrorCode() ) == SEVERITY::RPT_SEVERITY_ERROR )
120 violations.push_back( *aItem );
121 } );
122
123 BOOST_TEST_CHECKPOINT( "Running creepage DRC" );
124
125 // Time the DRC run
126 auto start = std::chrono::high_resolution_clock::now();
127
128 try
129 {
130 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
131 }
132 catch( const std::exception& e )
133 {
134 BOOST_ERROR( wxString::Format( "DRC creepage exception: %s", e.what() ) );
135 return;
136 }
137
138 auto end = std::chrono::high_resolution_clock::now();
139 double elapsedSeconds = std::chrono::duration<double>( end - start ).count();
140
141 BOOST_TEST_MESSAGE( wxString::Format( "DRC creepage completed in %.2f seconds", elapsedSeconds ) );
142 BOOST_TEST_MESSAGE( wxString::Format( "Found %d creepage violations", (int) violations.size() ) );
143
144 // Clear the violation handler
146
147 // Check if running on GitLab CI
148 bool onGitLabCI = std::getenv( "GITLAB_CI" ) != nullptr;
149
150 // Check if running on Launchpad/Debian build (DEB_BUILD_OPTIONS contains "nocheck")
151 bool onDebianBuild = false;
152 const char* debBuildOpts = std::getenv( "DEB_BUILD_OPTIONS" );
153
154 if( debBuildOpts && std::string( debBuildOpts ).find( "nocheck" ) != std::string::npos )
155 onDebianBuild = true;
156
157 if( onGitLabCI || onDebianBuild )
158 {
159 // On CI systems, write metrics to a file for collection as an artifact.
160 // The timeout varies too much between runners, so we only record the time
161 // without asserting on it.
162 std::ofstream metricsFile( "creepage_perf_metrics.txt" );
163
164 if( metricsFile.is_open() )
165 {
166 metricsFile << "creepage_drc_seconds " << elapsedSeconds << "\n";
167 metricsFile << "creepage_violations " << violations.size() << "\n";
168 metricsFile.close();
169 BOOST_TEST_MESSAGE( "Metrics written to creepage_perf_metrics.txt" );
170 }
171 }
172 else if( std::getenv( "KICAD_ENABLE_DRC_PERFORMANCE_QA" ) != nullptr )
173 {
174 // On local machines, enforce the timeout constraint
175 BOOST_CHECK_MESSAGE( elapsedSeconds < 20.0,
176 wxString::Format( "Creepage DRC too slow: %.2f seconds (target: <20s)",
177 elapsedSeconds ) );
178 }
179
180 // Performance tier feedback
181 if( elapsedSeconds < 5.0 )
182 {
183 BOOST_TEST_MESSAGE( "Excellent performance: <5 seconds" );
184 }
185 else if( elapsedSeconds < 10.0 )
186 {
187 BOOST_TEST_MESSAGE( "Good performance: <10 seconds" );
188 }
189 else if( elapsedSeconds < 15.0 )
190 {
191 BOOST_TEST_MESSAGE( "Acceptable performance: <15 seconds" );
192 }
193}
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.
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:53
@ DRCE_FIRST
Definition drc_item.h:47
@ DRCE_LAST
Definition drc_item.h:145
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
BOOST_REQUIRE_MESSAGE(dc.CacheTableInfo(table, { "part_id", "val" }), dc.GetLastError())
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:708