KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue22938_local_power.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, you may find one here:
18 * https://www.gnu.org/licenses/gpl-3.0.en.html
19 * or you may search the http://www.gnu.org website for the version 32 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
35#include <connection_graph.h>
36#include <schematic.h>
37#include <sch_sheet.h>
38#include <sch_screen.h>
39#include <sch_symbol.h>
40#include <sch_pin.h>
42#include <locale_io.h>
43
51
52
53BOOST_FIXTURE_TEST_CASE( Issue22938_LocalPowerNotGlobal, LOCAL_POWER_TEST_FIXTURE )
54{
56
57 KI_TEST::LoadSchematic( m_settingsManager, "issue22938/issue22938", m_schematic );
58
59 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
60 CONNECTION_GRAPH* graph = m_schematic->ConnectionGraph();
61
62 // Map to track net codes for +48V local power pins on each sheet
63 // Key: sheet path human readable, Value: net code
64 std::map<wxString, int> localPower48VNetCodes;
65
66 for( const auto& [key, subgraphs] : graph->GetNetMap() )
67 {
68 for( CONNECTION_SUBGRAPH* subgraph : subgraphs )
69 {
70 for( SCH_ITEM* item : subgraph->GetItems() )
71 {
72 if( item->Type() == SCH_PIN_T )
73 {
74 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
75
76 if( pin->IsLocalPower() )
77 {
78 wxString netName = pin->GetDefaultNetName( subgraph->GetSheet() );
79
80 if( netName == "+48V" )
81 {
82 wxString sheetPath = subgraph->GetSheet().PathHumanReadable();
83 localPower48VNetCodes[sheetPath] = key.Netcode;
84 }
85 }
86 }
87 }
88 }
89 }
90
91 // We expect to find +48V local power pins on at least two different sheets
92 BOOST_REQUIRE_MESSAGE( localPower48VNetCodes.size() >= 2,
93 "Expected +48V local power pins on multiple sheets" );
94
95 // All local power pins with the same name but on DIFFERENT sheets
96 // should have DIFFERENT net codes (they should NOT be connected)
97 int firstNetCode = -1;
98 bool allSame = true;
99
100 for( const auto& [sheetPath, netCode] : localPower48VNetCodes )
101 {
102 if( firstNetCode == -1 )
103 {
104 firstNetCode = netCode;
105 }
106 else if( netCode != firstNetCode )
107 {
108 allSame = false;
109 break;
110 }
111 }
112
113 // The bug causes all local +48V nets to have the same net code
114 // After the fix, they should have different net codes
115 BOOST_CHECK_MESSAGE( !allSame,
116 "Local power ports +48V on different sheets should NOT be connected. "
117 "Each sheet should have its own isolated +48V net." );
118}
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:41
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:168
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
std::vector< FAB_LAYER_COLOR > dummy
Test for issue #22938: Local power port acts as global port.
LOCAL_POWER_TEST_FIXTURE()=default
std::unique_ptr< SCHEMATIC > m_schematic
BOOST_FIXTURE_TEST_CASE(Issue22938_LocalPowerNotGlobal, LOCAL_POWER_TEST_FIXTURE)
KIBIS_PIN * pin
@ SCH_PIN_T
Definition typeinfo.h:157