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, see <https://www.gnu.org/licenses/>.
18 */
19
22
23#include <advanced_config.h>
24#include <connection_graph.h>
26#include <scoped_set_reset.h>
27#include <schematic.h>
28#include <erc/erc_settings.h>
29#include <erc/erc.h>
30#include <erc/erc_report.h>
32#include <locale_io.h>
33
34
42
43
45{
47
48 // Test case for https://gitlab.com/kicad/code/kicad/-/issues/19646
49 //
50 // When a hierarchical bus connects sheets, local labels that are bus members may only connect
51 // to pins through the hierarchy (in other sheets). Previously, ERC counted pins from all sheets
52 // connected through the hierarchy, which masked labels that lacked local connections.
53 //
54 // The fix tracks local pin count separately for bus member labels. If a bus member label has no
55 // local pin connections, it is flagged as unconnected even if the net has pins in other sheets
56 // through the hierarchical bus.
57 //
58 // Test data has 5 bus member labels (RES.EXC, RES.PWM, RES.SIN, RES.COS, RES.EN) in the MCU
59 // sheet that only connect to pins through the hierarchical bus to the Resolver sheet. All 5
60 // should be flagged as unconnected.
61
62 auto& enabled = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() ).m_ConnectivityEngine;
63 SCOPED_SET_RESET restore( enabled, enabled );
64
65 for( bool useEngine : { false, true } )
66 {
67 BOOST_TEST_CONTEXT( "engine=" << useEngine )
68 {
69 enabled = useEngine;
70 KI_TEST::LoadSchematic( m_settingsManager, "issue19646/issue19646", m_schematic );
71
72 ERC_SETTINGS& settings = m_schematic->ErcSettings();
73 SHEETLIST_ERC_ITEMS_PROVIDER errors( m_schematic.get() );
74
77
78 if( useEngine )
79 {
80 m_schematic->RebuildConnectivity();
81 m_schematic->Connectivity().PrepareTextChecks( *m_schematic );
82 }
83
84 m_schematic->ConnectionGraph()->RunERC();
85
86 ERC_TESTER tester( m_schematic.get() );
89 tester.TestNoConnectPins();
90 tester.TestPinToPin();
91 tester.TestSimilarLabels();
92 tester.TestTextVars( nullptr );
93
95
96 ERC_REPORT reportWriter( m_schematic.get(), EDA_UNITS::MM );
97
98 // Count ERCE_LABEL_NOT_CONNECTED errors specifically
99 int labelNotConnectedCount = 0;
100
101 for( int i = 0; i < errors.GetCount(); i++ )
102 {
103 std::shared_ptr<ERC_ITEM> ercItem =
104 std::static_pointer_cast<ERC_ITEM>( errors.GetItem( i ) );
105
106 if( ercItem->GetErrorCode() == ERCE_LABEL_NOT_CONNECTED )
107 labelNotConnectedCount++;
108 }
109
110 BOOST_CHECK_MESSAGE( labelNotConnectedCount == 5,
111 "Expected 5 ERCE_LABEL_NOT_CONNECTED errors for bus member labels "
112 "without local pin connections, but got " << labelNotConnectedCount
113 << "\n" << reportWriter.GetTextReport() );
114 }
115 }
116}
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
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
Runs the electrical rules checks and adds a SCH_MARKER for each violation.
Definition erc.h:60
void TestTextVars(DS_PROXY_VIEW_ITEM *aDrawingSheet)
Check for any unresolved text variable references.
Definition erc.cpp:648
int TestPinToPin()
Checks the full netlist against the pin-to-pin connectivity requirements.
Definition erc.cpp:1709
int TestSimilarLabels()
Checks for labels that differ only in capitalization.
Definition erc.cpp:2696
int TestMultUnitPinConflicts()
Checks if shared pins on multi-unit symbols have been connected to different nets.
Definition erc.cpp:2145
int TestNoConnectPins()
In KiCad 5 and earlier, you could connect stuff up to pins with NC electrical type.
Definition erc.cpp:1288
int TestMultiunitFootprints()
Test if all units of each multiunit symbol have the same footprint assigned.
Definition erc.cpp:923
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
RAII class that sets an value at construction and resets it to the original value at destruction.
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)
BOOST_TEST_CONTEXT("Test Clearance")