KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_skew_arc.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
28
31#include <board.h>
32#include <footprint.h>
33#include <pad.h>
34#include <pcb_track.h>
38
39
41{
43 std::unique_ptr<BOARD> m_board;
44
45 int64_t netLength( const wxString& aNet, const PATH_OPTIMISATIONS& aOpts )
46 {
47 LENGTH_DELAY_CALCULATION* calc = m_board->GetLengthCalculation();
48 NETINFO_ITEM* net = m_board->FindNet( aNet );
49 BOOST_REQUIRE_MESSAGE( net != nullptr, "net not found: " << aNet.ToStdString() );
50
51 std::vector<LENGTH_DELAY_CALCULATION_ITEM> items;
52
53 for( PCB_TRACK* track : m_board->Tracks() )
54 {
55 if( track->GetNetCode() != net->GetNetCode() )
56 continue;
57
59
60 if( item.Type() != LENGTH_DELAY_CALCULATION_ITEM::TYPE::UNKNOWN )
61 items.emplace_back( std::move( item ) );
62 }
63
64 for( FOOTPRINT* fp : m_board->Footprints() )
65 {
66 for( PAD* pad : fp->Pads() )
67 {
68 if( pad->GetNetCode() != net->GetNetCode() )
69 continue;
70
72
73 if( item.Type() != LENGTH_DELAY_CALCULATION_ITEM::TYPE::UNKNOWN )
74 items.emplace_back( std::move( item ) );
75 }
76 }
77
78 return calc->CalculateLength( items, aOpts, nullptr, nullptr );
79 }
80};
81
82
83// DRC (clip and merge on) must agree with the tuner (clip and merge off) for
84// every diff pair. Before the fix net2_P was inflated by about 223 um, over the
85// 0.1 mm rule.
87{
88 KI_TEST::LoadBoard( m_settingsManager, "drc_skew/drc_skew", m_board );
89
90 constexpr PATH_OPTIMISATIONS drcOpts = {
91 .OptimiseVias = true, .MergeTracks = true, .OptimiseTracesInPads = true, .InferViaInPad = false
92 };
93 constexpr PATH_OPTIMISATIONS tunerOpts = {
94 .OptimiseVias = false, .MergeTracks = false, .OptimiseTracesInPads = false, .InferViaInPad = true
95 };
96
97 const int64_t skewLimit = 100000; // 0.1 mm rule in the board
98
99 for( const wxString& pair : { wxString( "net1" ), wxString( "net2" ), wxString( "net3" ) } )
100 {
101 const wxString p = "/" + pair + "_P";
102 const wxString n = "/" + pair + "_N";
103
104 const int64_t drcSkew = std::llabs( netLength( p, drcOpts ) - netLength( n, drcOpts ) );
105 const int64_t tunSkew = std::llabs( netLength( p, tunerOpts ) - netLength( n, tunerOpts ) );
106
107 BOOST_TEST_MESSAGE( pair.ToStdString() << ": DRC skew = " << drcSkew / 1000.0
108 << " um, tuner skew = " << tunSkew / 1000.0 << " um" );
109
110 BOOST_CHECK_MESSAGE( std::llabs( drcSkew - tunSkew ) < skewLimit,
111 pair.ToStdString() << ": DRC and tuner skew disagree by "
112 << std::llabs( drcSkew - tunSkew ) / 1000.0 << " um" );
113 }
114}
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.
int64_t CalculateLength(std::vector< LENGTH_DELAY_CALCULATION_ITEM > &aItems, PATH_OPTIMISATIONS aOptimisations, const PAD *aStartPad=nullptr, const PAD *aEndPad=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
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
int64_t netLength(const wxString &aNet, const PATH_OPTIMISATIONS &aOpts)
SETTINGS_MANAGER m_settingsManager
std::unique_ptr< BOARD > m_board
Struct to control which optimisations the length calculation code runs on the given path objects.
BOOST_FIXTURE_TEST_CASE(DrcSkewArc_TunerVsDrc, DRC_SKEW_ARC_FIXTURE)
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))