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, see <https://www.gnu.org/licenses/>.
18 */
19
27
30#include <board.h>
31#include <footprint.h>
32#include <pad.h>
33#include <pcb_track.h>
37
38
46
47
52BOOST_FIXTURE_TEST_CASE( LengthCalculationIncludesAllWidths, TUNER_DRC_TEST_FIXTURE )
53{
54 // Load a board that has tracks with different widths on the same net
55 KI_TEST::LoadBoard( m_settingsManager, "issue18045/test_proj", m_board );
56
57 LENGTH_DELAY_CALCULATION* lengthCalc = m_board->GetLengthCalculation();
58
59 // Find a net that has tracks with different widths
60 NETINFO_ITEM* testNet = m_board->FindNet( "/TEST1_P" );
61 BOOST_REQUIRE( testNet != nullptr );
62
63 // Collect all tracks on this net and verify they have multiple widths
64 std::vector<LENGTH_DELAY_CALCULATION_ITEM> lengthItems;
65 std::set<int> widths;
66
67 for( PCB_TRACK* track : m_board->Tracks() )
68 {
69 if( track->GetNetCode() != testNet->GetNetCode() )
70 continue;
71
72 if( track->Type() == PCB_TRACE_T )
73 widths.insert( track->GetWidth() );
74
76
77 if( item.Type() != LENGTH_DELAY_CALCULATION_ITEM::TYPE::UNKNOWN )
78 lengthItems.emplace_back( item );
79 }
80
81 BOOST_TEST_MESSAGE( wxString::Format( "Found %zu different track widths on net /TEST1_P", widths.size() ) );
82
83 // The test board should have at least 2 different widths to be a valid test case
84 BOOST_REQUIRE_GE( widths.size(), 2 );
85
86 // Calculate total length including all track widths
87 constexpr PATH_OPTIMISATIONS opts = {
88 .OptimiseVias = true, .MergeTracks = true, .OptimiseTracesInPads = true, .InferViaInPad = false
89 };
90 LENGTH_DELAY_STATS stats = lengthCalc->CalculateLengthDetails( lengthItems, opts, nullptr, nullptr,
93
94 BOOST_TEST_MESSAGE( wxString::Format( "Total track length: %lld nm", stats.TrackLength ) );
95 BOOST_CHECK_GT( stats.TrackLength, 0 );
96
97 // Verify that all track segments contributed to the length
98 BOOST_CHECK_GT( lengthItems.size(), 0 );
99}
100
101
111{
112 KI_TEST::LoadBoard( m_settingsManager, "issue23690_via_in_pad", m_board );
113
114 LENGTH_DELAY_CALCULATION* lengthCalc = m_board->GetLengthCalculation();
115
116 NETINFO_ITEM* testNet = m_board->FindNet( "/ABC" );
117 BOOST_REQUIRE( testNet != nullptr );
118
119 // Collect every connectivity item on the test net: tracks, vias, and pads.
120 // This mirrors what PCB_NET_INSPECTOR_PANEL::calculateNets feeds into
121 // CalculateLengthDetails, so the test exercises the same code path the
122 // user actually sees in the Net Inspector.
123 std::vector<LENGTH_DELAY_CALCULATION_ITEM> lengthItems;
124
125 int viaCount = 0;
126 int padCount = 0;
127
128 for( PCB_TRACK* track : m_board->Tracks() )
129 {
130 if( track->GetNetCode() != testNet->GetNetCode() )
131 continue;
132
134
135 if( item.Type() == LENGTH_DELAY_CALCULATION_ITEM::TYPE::VIA )
136 viaCount++;
137
138 if( item.Type() != LENGTH_DELAY_CALCULATION_ITEM::TYPE::UNKNOWN )
139 lengthItems.emplace_back( std::move( item ) );
140 }
141
142 for( FOOTPRINT* fp : m_board->Footprints() )
143 {
144 for( PAD* pad : fp->Pads() )
145 {
146 if( pad->GetNetCode() != testNet->GetNetCode() )
147 continue;
148
150
151 if( item.Type() != LENGTH_DELAY_CALCULATION_ITEM::TYPE::UNKNOWN )
152 {
153 lengthItems.emplace_back( std::move( item ) );
154 padCount++;
155 }
156 }
157 }
158
159 BOOST_TEST_MESSAGE( wxString::Format( "TEST_NET has %d vias, %d pads, %zu total length items", viaCount, padCount,
160 lengthItems.size() ) );
161
162
163 constexpr PATH_OPTIMISATIONS opts = {
164 .OptimiseVias = true, .MergeTracks = true, .OptimiseTracesInPads = true, .InferViaInPad = false
165 };
166
167 LENGTH_DELAY_STATS stats = lengthCalc->CalculateLengthDetails( lengthItems, opts, nullptr, nullptr,
170
171 BOOST_TEST_MESSAGE( wxString::Format( "Via length: %d nm (from %d vias), track length: %lld nm", stats.ViaLength,
172 stats.NumVias, stats.TrackLength ) );
173
174 BOOST_CHECK_EQUAL( stats.NumVias, 2 );
175
176 BOOST_CHECK_GT( stats.ViaLength, 0 );
177
178 const int expectedHeight = 2 * lengthCalc->StackupHeight( F_Cu, In1_Cu );
179 BOOST_CHECK_EQUAL( stats.ViaLength, expectedHeight );
180}
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_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, LENGTH_DELAY_ITEM_DETAILS *aPerItemLengthDelays=nullptr) const
Calculates the electrical length of the given items.
LENGTH_DELAY_CALCULATION_ITEM GetLengthCalculationItem(const BOARD_CONNECTED_ITEM *aBoardItem) const
Return a LENGTH_CALCULATION_ITEM constructed from the given BOARD_CONNECTED_ITEM.
Handle the data for a net.
Definition netinfo.h:46
int GetNetCode() const
Definition netinfo.h:94
Definition pad.h:61
@ In1_Cu
Definition layer_ids.h:62
@ F_Cu
Definition layer_ids.h:60
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:89