KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue18119_bus_hierarchy.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 3
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
41
44
45#include <connection_graph.h>
46#include <schematic.h>
47#include <sch_sheet.h>
48#include <sch_screen.h>
49#include <sch_symbol.h>
50#include <sch_pin.h>
52#include <locale_io.h>
53
55{
58
60 std::unique_ptr<SCHEMATIC> m_schematic;
61};
62
63
77{
79
80 KI_TEST::LoadSchematic( m_settingsManager, "issue18119/issue18119", m_schematic );
81
82 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
83 CONNECTION_GRAPH* graph = m_schematic->ConnectionGraph();
84
85 // Find connectors and power symbols and their net codes
86 std::map<wxString, int> connectorNetCodes; // Reference -> net code
87 std::map<wxString, int> resistorPinNetCodes; // R1.1, R1.2 -> net code
88
89 for( const auto& [key, subgraphs] : graph->GetNetMap() )
90 {
91 for( CONNECTION_SUBGRAPH* subgraph : subgraphs )
92 {
93 for( SCH_ITEM* item : subgraph->GetItems() )
94 {
95 if( item->Type() == SCH_PIN_T )
96 {
97 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
98 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( pin->GetParentSymbol() );
99
100 if( symbol )
101 {
102 wxString ref = symbol->GetRef( &subgraph->GetSheet() );
103
104 // Track connectors J1-J4 and power symbols
105 if( ref == "J1" || ref == "J2" || ref == "J3" || ref == "J4" ||
106 ref == "#PWR01" || ref == "#PWR02" || ref == "#PWR03" || ref == "#PWR04" )
107 {
108 connectorNetCodes[ref] = key.Netcode;
109 }
110
111 // Track R1 pins
112 if( ref == "R1" )
113 {
114 wxString pinKey = ref + "." + pin->GetNumber();
115 resistorPinNetCodes[pinKey] = key.Netcode;
116 }
117 }
118 }
119 }
120 }
121 }
122
123 // Verify we found all expected components
124 BOOST_REQUIRE_MESSAGE( connectorNetCodes.count( "J1" ), "J1 (VCC connector) should be found" );
125 BOOST_REQUIRE_MESSAGE( connectorNetCodes.count( "J2" ), "J2 (GND connector) should be found" );
126 BOOST_REQUIRE_MESSAGE( connectorNetCodes.count( "J3" ), "J3 (BUS0) should be found" );
127 BOOST_REQUIRE_MESSAGE( connectorNetCodes.count( "J4" ), "J4 (BUS1) should be found" );
128 BOOST_REQUIRE_MESSAGE( connectorNetCodes.count( "#PWR02" ), "GND power symbol should be found" );
129
130 // J1 should be on VCC net (through direct wire connection)
131 BOOST_REQUIRE_MESSAGE( connectorNetCodes.count( "#PWR01" ), "VCC power symbol should be found" );
132 BOOST_CHECK_MESSAGE( connectorNetCodes["J1"] == connectorNetCodes["#PWR01"],
133 "J1 should be on the same net as VCC" );
134
135 // J2 should be on GND net (through direct wire connection)
136 BOOST_CHECK_MESSAGE( connectorNetCodes["J2"] == connectorNetCodes["#PWR02"],
137 "J2 should be on the same net as GND" );
138
139 // J3 (BUS0) should be on the same net as R1 pin 1 (through OUT_0)
140 // Note: R1 separates the OUT_0 net from the VCC net, so J3 is NOT on VCC net
141 BOOST_REQUIRE_MESSAGE( resistorPinNetCodes.count( "R1.1" ), "R1 pin 1 should be found" );
142 BOOST_CHECK_MESSAGE( connectorNetCodes["J3"] == resistorPinNetCodes["R1.1"],
143 "J3 (BUS0) should be on the same net as R1.1 (via OUT_0)" );
144
145 // J4 (BUS1) should be on GND net (through OUT_1 -> GND)
146 // This tests that BUS1 properly connects through BUS[0..1] -> SUB_BUS[0..1] -> SUB_BUS1 -> OUT_1
147 // This is the main bug - BUS1 does not connect to GND
148 BOOST_CHECK_MESSAGE( connectorNetCodes["J4"] == connectorNetCodes["#PWR02"],
149 "J4 (BUS1) should be on the same net as GND (via OUT_1)" );
150}
Calculate the connectivity of a schematic and generates netlists.
const NET_MAP & GetNetMap() const
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:162
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Schematic symbol object.
Definition sch_symbol.h:69
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
std::unique_ptr< SCHEMATIC > m_schematic
BOOST_FIXTURE_TEST_CASE(Issue18119BusHierarchy, ISSUE18119_FIXTURE)
Test that bus member connections propagate correctly through hierarchy when wire names differ on each...
KIBIS_PIN * pin
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
@ SCH_PIN_T
Definition typeinfo.h:150