KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_tuner_agreement.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
31
34#include <board.h>
35#include <footprint.h>
36#include <pad.h>
37#include <pcb_track.h>
41
42
50
51
56BOOST_FIXTURE_TEST_CASE( LengthCalculationIncludesAllWidths, TUNER_DRC_TEST_FIXTURE )
57{
58 // Load a board that has tracks with different widths on the same net
59 KI_TEST::LoadBoard( m_settingsManager, "issue18045/test_proj", m_board );
60
61 LENGTH_DELAY_CALCULATION* lengthCalc = m_board->GetLengthCalculation();
62
63 // Find a net that has tracks with different widths
64 NETINFO_ITEM* testNet = m_board->FindNet( "/TEST1_P" );
65 BOOST_REQUIRE( testNet != nullptr );
66
67 // Collect all tracks on this net and verify they have multiple widths
68 std::vector<LENGTH_DELAY_CALCULATION_ITEM> lengthItems;
69 std::set<int> widths;
70
71 for( PCB_TRACK* track : m_board->Tracks() )
72 {
73 if( track->GetNetCode() != testNet->GetNetCode() )
74 continue;
75
76 if( track->Type() == PCB_TRACE_T )
77 widths.insert( track->GetWidth() );
78
80
81 if( item.Type() != LENGTH_DELAY_CALCULATION_ITEM::TYPE::UNKNOWN )
82 lengthItems.emplace_back( item );
83 }
84
85 BOOST_TEST_MESSAGE( wxString::Format( "Found %zu different track widths on net /TEST1_P", widths.size() ) );
86
87 // The test board should have at least 2 different widths to be a valid test case
88 BOOST_REQUIRE_GE( widths.size(), 2 );
89
90 // Calculate total length including all track widths
91 constexpr PATH_OPTIMISATIONS opts = {
92 .OptimiseVias = true, .MergeTracks = true, .OptimiseTracesInPads = true, .InferViaInPad = false
93 };
94 LENGTH_DELAY_STATS stats = lengthCalc->CalculateLengthDetails( lengthItems, opts, nullptr, nullptr,
97
98 BOOST_TEST_MESSAGE( wxString::Format( "Total track length: %lld nm", stats.TrackLength ) );
99 BOOST_CHECK_GT( stats.TrackLength, 0 );
100
101 // Verify that all track segments contributed to the length
102 BOOST_CHECK_GT( lengthItems.size(), 0 );
103}
104
105
115{
116 KI_TEST::LoadBoard( m_settingsManager, "issue23690_via_in_pad", m_board );
117
118 LENGTH_DELAY_CALCULATION* lengthCalc = m_board->GetLengthCalculation();
119
120 NETINFO_ITEM* testNet = m_board->FindNet( "/ABC" );
121 BOOST_REQUIRE( testNet != nullptr );
122
123 // Collect every connectivity item on the test net: tracks, vias, and pads.
124 // This mirrors what PCB_NET_INSPECTOR_PANEL::calculateNets feeds into
125 // CalculateLengthDetails, so the test exercises the same code path the
126 // user actually sees in the Net Inspector.
127 std::vector<LENGTH_DELAY_CALCULATION_ITEM> lengthItems;
128
129 int viaCount = 0;
130 int padCount = 0;
131
132 for( PCB_TRACK* track : m_board->Tracks() )
133 {
134 if( track->GetNetCode() != testNet->GetNetCode() )
135 continue;
136
138
139 if( item.Type() == LENGTH_DELAY_CALCULATION_ITEM::TYPE::VIA )
140 viaCount++;
141
142 if( item.Type() != LENGTH_DELAY_CALCULATION_ITEM::TYPE::UNKNOWN )
143 lengthItems.emplace_back( std::move( item ) );
144 }
145
146 for( FOOTPRINT* fp : m_board->Footprints() )
147 {
148 for( PAD* pad : fp->Pads() )
149 {
150 if( pad->GetNetCode() != testNet->GetNetCode() )
151 continue;
152
154
155 if( item.Type() != LENGTH_DELAY_CALCULATION_ITEM::TYPE::UNKNOWN )
156 {
157 lengthItems.emplace_back( std::move( item ) );
158 padCount++;
159 }
160 }
161 }
162
163 BOOST_TEST_MESSAGE( wxString::Format( "TEST_NET has %d vias, %d pads, %zu total length items", viaCount, padCount,
164 lengthItems.size() ) );
165
166
167 constexpr PATH_OPTIMISATIONS opts = {
168 .OptimiseVias = true, .MergeTracks = true, .OptimiseTracesInPads = true, .InferViaInPad = false
169 };
170
171 LENGTH_DELAY_STATS stats = lengthCalc->CalculateLengthDetails( lengthItems, opts, nullptr, nullptr,
174
175 BOOST_TEST_MESSAGE( wxString::Format( "Via length: %d nm (from %d vias), track length: %lld nm", stats.ViaLength,
176 stats.NumVias, stats.TrackLength ) );
177
178 BOOST_CHECK_EQUAL( stats.NumVias, 2 );
179
180 BOOST_CHECK_GT( stats.ViaLength, 0 );
181
182 const int expectedHeight = 2 * lengthCalc->StackupHeight( F_Cu, In1_Cu );
183 BOOST_CHECK_EQUAL( stats.ViaLength, expectedHeight );
184}
Lightweight class which holds a pad, via, or a routed trace outline.
TYPE Type() const
Gets the routing item type.
Class which calculates lengths (and associated routing statistics) in a BOARD context.
int StackupHeight(PCB_LAYER_ID aFirstLayer, PCB_LAYER_ID aSecondLayer) const
Returns the stackup distance between the two given layers.
LENGTH_DELAY_CALCULATION_ITEM GetLengthCalculationItem(const BOARD_CONNECTED_ITEM *aBoardItem) const
Return a LENGTH_CALCULATION_ITEM constructed from the given BOARD_CONNECTED_ITEM.
LENGTH_DELAY_STATS CalculateLengthDetails(std::vector< LENGTH_DELAY_CALCULATION_ITEM > &aItems, PATH_OPTIMISATIONS aOptimisations, const PAD *aStartPad=nullptr, const PAD *aEndPad=nullptr, LENGTH_DELAY_LAYER_OPT aLayerOpt=LENGTH_DELAY_LAYER_OPT::NO_LAYER_DETAIL, LENGTH_DELAY_DOMAIN_OPT aDomain=LENGTH_DELAY_DOMAIN_OPT::NO_DELAY_DETAIL) const
Calculates the electrical length of the given items.
Handle the data for a net.
Definition netinfo.h:50
int GetNetCode() const
Definition netinfo.h:97
Definition pad.h:55
@ In1_Cu
Definition layer_ids.h:66
@ F_Cu
Definition layer_ids.h:64
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
Holds length measurement result details and statistics.
Struct to control which optimisations the length calculation code runs on the given path objects.
std::unique_ptr< BOARD > m_board
BOOST_FIXTURE_TEST_CASE(LengthCalculationIncludesAllWidths, TUNER_DRC_TEST_FIXTURE)
Verify that length calculation includes all segments regardless of track width.
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_TEST_MESSAGE("\n=== Real-World Polygon PIP Benchmark ===\n"<< formatTable(table))
BOOST_CHECK_EQUAL(result, "25.4")
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:93