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, see <https://www.gnu.org/licenses/>.
18 */
19
27
30
31#include <connection_graph.h>
32#include <schematic.h>
33#include <sch_sheet.h>
34#include <sch_screen.h>
35#include <sch_symbol.h>
36#include <sch_pin.h>
38#include <locale_io.h>
39
47
48
49BOOST_FIXTURE_TEST_CASE( Issue22938_LocalPowerNotGlobal, LOCAL_POWER_TEST_FIXTURE )
50{
52
53 KI_TEST::LoadSchematic( m_settingsManager, "issue22938/issue22938", m_schematic );
54
55 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
56 CONNECTION_GRAPH* graph = m_schematic->ConnectionGraph();
57
58 // Map to track net codes for +48V local power pins on each sheet
59 // Key: sheet path human readable, Value: net code
60 std::map<wxString, int> localPower48VNetCodes;
61
62 for( const auto& [key, subgraphs] : graph->GetNetMap() )
63 {
64 for( CONNECTION_SUBGRAPH* subgraph : subgraphs )
65 {
66 for( SCH_ITEM* item : subgraph->GetItems() )
67 {
68 if( item->Type() == SCH_PIN_T )
69 {
70 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
71
72 if( pin->IsLocalPower() )
73 {
74 wxString netName = pin->GetDefaultNetName( subgraph->GetSheet() );
75
76 if( netName == "+48V" )
77 {
78 wxString sheetPath = subgraph->GetSheet().PathHumanReadable();
79 localPower48VNetCodes[sheetPath] = key.Netcode;
80 }
81 }
82 }
83 }
84 }
85 }
86
87 // We expect to find +48V local power pins on at least two different sheets
88 BOOST_REQUIRE_MESSAGE( localPower48VNetCodes.size() >= 2,
89 "Expected +48V local power pins on multiple sheets" );
90
91 // All local power pins with the same name but on DIFFERENT sheets
92 // should have DIFFERENT net codes (they should NOT be connected)
93 int firstNetCode = -1;
94 bool allSame = true;
95
96 for( const auto& [sheetPath, netCode] : localPower48VNetCodes )
97 {
98 if( firstNetCode == -1 )
99 {
100 firstNetCode = netCode;
101 }
102 else if( netCode != firstNetCode )
103 {
104 allSame = false;
105 break;
106 }
107 }
108
109 // The bug causes all local +48V nets to have the same net code
110 // After the fix, they should have different net codes
111 BOOST_CHECK_MESSAGE( !allSame,
112 "Local power ports +48V on different sheets should NOT be connected. "
113 "Each sheet should have its own isolated +48V net." );
114}
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.
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
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
@ SCH_PIN_T
Definition typeinfo.h:150