KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_hierarchy_driver_ranking.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
22
23#include <connection_graph.h>
24#include <locale_io.h>
25#include <sch_pin.h>
26#include <sch_symbol.h>
27#include <schematic.h>
29
30#include <map>
31
32
38
39
40// The hierarchy_driver_ranking schematic runs four independent nets through a four-sheet
41// hierarchy, each one setting up a different comparison between driver candidates:
42//
43// EXT_RST two global labels of equal rank and equal depth, EXT_RST in LeafB against
44// EXT_RSTIN in LeafA
45// +5V a global power pin in LeafA against the local label SUPPLY_LOCAL at the root
46// VBUS a global label in LeafB against the +3V3 power pin in LeafA
47// ZZZ_SHALLOW two global labels of equal rank at different depths, ZZZ_SHALLOW in Mid
48// against AAA_DEEP one sheet further down
49//
50// The subgraphs are collected in an unordered set, so a ranking rule that accepts a candidate
51// without comparing it against the incumbent resolves these by heap address instead of by rank.
53{
55
56 KI_TEST::LoadSchematic( m_settingsManager, "hierarchy_driver_ranking/hierarchy_driver_ranking",
57 m_schematic );
58
59 std::map<wxString, wxString> pinNets;
60
61 for( const auto& [key, subgraphs] : m_schematic->ConnectionGraph()->GetNetMap() )
62 {
63 for( CONNECTION_SUBGRAPH* subgraph : subgraphs )
64 {
65 for( SCH_ITEM* item : subgraph->GetItems() )
66 {
67 if( item->Type() != SCH_PIN_T )
68 continue;
69
70 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
71 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( pin->GetParentSymbol() );
72
73 if( !symbol )
74 continue;
75
76 wxString ref = symbol->GetRef( &subgraph->GetSheet() );
77 pinNets[ref + wxT( "-" ) + pin->GetNumber()] = key.Name;
78 }
79 }
80 }
81
82 const std::vector<std::pair<wxString, wxString>> expected = {
83 { wxT( "R1-1" ), wxT( "EXT_RST" ) },
84 { wxT( "R11-1" ), wxT( "EXT_RST" ) },
85 { wxT( "R21-1" ), wxT( "EXT_RST" ) },
86
87 { wxT( "R2-1" ), wxT( "+5V" ) },
88 { wxT( "R12-1" ), wxT( "+5V" ) },
89
90 { wxT( "R3-1" ), wxT( "VBUS" ) },
91 { wxT( "R13-1" ), wxT( "VBUS" ) },
92 { wxT( "R22-1" ), wxT( "VBUS" ) },
93
94 { wxT( "R4-1" ), wxT( "ZZZ_SHALLOW" ) },
95 { wxT( "R31-1" ), wxT( "ZZZ_SHALLOW" ) },
96 { wxT( "R41-1" ), wxT( "ZZZ_SHALLOW" ) },
97 };
98
99 for( const auto& [pin, netName] : expected )
100 {
101 auto it = pinNets.find( pin );
102
103 BOOST_REQUIRE_MESSAGE( it != pinNets.end(), pin + wxT( " is missing from the netlist" ) );
104 BOOST_CHECK_MESSAGE( it->second == netName,
105 pin + wxT( " resolved to " ) + it->second + wxT( " instead of " )
106 + netName );
107 }
108}
A subgraph is a set of items that are electrically connected on a single sheet.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:165
Schematic symbol object.
Definition sch_symbol.h:75
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
std::vector< FAB_LAYER_COLOR > dummy
BOOST_FIXTURE_TEST_CASE(HierarchyDriverRanking, HIERARCHY_DRIVER_RANKING_FIXTURE)
KIBIS_PIN * pin
VECTOR3I expected(15, 30, 45)
@ SCH_PIN_T
Definition typeinfo.h:149