KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_erc_bus_member_label_local_pins.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 at
18 * http://www.gnu.org/licenses/
19 */
20
23
24#include <connection_graph.h>
25#include <schematic.h>
26#include <erc/erc_settings.h>
27#include <erc/erc.h>
28#include <erc/erc_report.h>
30#include <locale_io.h>
31
32
40
41
43{
45
46 // Test case for https://gitlab.com/kicad/code/kicad/-/issues/19646
47 //
48 // When a hierarchical bus connects sheets, local labels that are bus members may only connect
49 // to pins through the hierarchy (in other sheets). Previously, ERC counted pins from all sheets
50 // connected through the hierarchy, which masked labels that lacked local connections.
51 //
52 // The fix tracks local pin count separately for bus member labels. If a bus member label has no
53 // local pin connections, it is flagged as unconnected even if the net has pins in other sheets
54 // through the hierarchical bus.
55 //
56 // Test data has 5 bus member labels (RES.EXC, RES.PWM, RES.SIN, RES.COS, RES.EN) in the MCU
57 // sheet that only connect to pins through the hierarchical bus to the Resolver sheet. All 5
58 // should be flagged as unconnected.
59
60 KI_TEST::LoadSchematic( m_settingsManager, "issue19646/issue19646", m_schematic );
61
62 ERC_SETTINGS& settings = m_schematic->ErcSettings();
63 SHEETLIST_ERC_ITEMS_PROVIDER errors( m_schematic.get() );
64
67
68 m_schematic->ConnectionGraph()->RunERC();
69
70 ERC_TESTER tester( m_schematic.get() );
73 tester.TestNoConnectPins();
74 tester.TestPinToPin();
75 tester.TestSimilarLabels();
76 tester.TestTextVars( nullptr );
77
79
80 ERC_REPORT reportWriter( m_schematic.get(), EDA_UNITS::MM );
81
82 // Count ERCE_LABEL_NOT_CONNECTED errors specifically
83 int labelNotConnectedCount = 0;
84
85 for( int i = 0; i < errors.GetCount(); i++ )
86 {
87 std::shared_ptr<ERC_ITEM> ercItem =
88 std::static_pointer_cast<ERC_ITEM>( errors.GetItem( i ) );
89
90 if( ercItem->GetErrorCode() == ERCE_LABEL_NOT_CONNECTED )
91 labelNotConnectedCount++;
92 }
93
94 BOOST_CHECK_MESSAGE( labelNotConnectedCount == 5,
95 "Expected 5 ERCE_LABEL_NOT_CONNECTED errors for bus member labels "
96 "without local pin connections, but got " << labelNotConnectedCount
97 << "\n" << reportWriter.GetTextReport() );
98}
wxString GetTextReport()
Returns the ERC report in "text" (human readable) format in the C-locale.
Container for ERC settings.
std::map< int, SEVERITY > m_ERCSeverities
void TestTextVars(DS_PROXY_VIEW_ITEM *aDrawingSheet)
Check for any unresolved text variable references.
Definition erc.cpp:185
int TestPinToPin()
Checks the full netlist against the pin-to-pin connectivity requirements.
Definition erc.cpp:913
int TestSimilarLabels()
Checks for labels that differ only in capitalization.
Definition erc.cpp:1382
int TestMultUnitPinConflicts()
Checks if shared pins on multi-unit symbols have been connected to different nets.
Definition erc.cpp:1173
int TestNoConnectPins()
In KiCad 5 and earlier, you could connect stuff up to pins with NC electrical type.
Definition erc.cpp:822
int TestMultiunitFootprints()
Test if all units of each multiunit symbol have the same footprint assigned.
Definition erc.cpp:440
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:41
An implementation of the RC_ITEM_LIST interface which uses the global SHEETLIST to fulfill the contra...
int GetCount(int aSeverity=-1) const override
void SetSeverities(int aSeverities) override
std::shared_ptr< RC_ITEM > GetItem(int aIndex) const override
Retrieve a RC_ITEM by index.
@ ERCE_LABEL_NOT_CONNECTED
Label not connected to any pins.
@ ERCE_LIB_SYMBOL_MISMATCH
Symbol doesn't match copy in library.
@ ERCE_LIB_SYMBOL_ISSUES
Symbol not found in active libraries.
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
@ RPT_SEVERITY_WARNING
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
std::vector< FAB_LAYER_COLOR > dummy
BOOST_FIXTURE_TEST_CASE(ERCBusMemberLabelLocalPins, ERC_BUS_MEMBER_LABEL_TEST_FIXTURE)