KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_erc_power_pin_marker_location.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
32
35
36#include <connection_graph.h>
37#include <schematic.h>
38#include <sch_marker.h>
39#include <sch_pin.h>
40#include <sch_sheet_path.h>
41#include <erc/erc_settings.h>
42#include <erc/erc.h>
43#include <erc/erc_item.h>
44#include <erc/erc_report.h>
46#include <locale_io.h>
47#include <advanced_config.h>
48#include <scoped_set_reset.h>
49
50
60
61
62BOOST_FIXTURE_TEST_CASE( ERCPowerPinNotDrivenMarkerOnPowerInputPin, ERC_POWER_PIN_MARKER_FIXTURE )
63{
65 auto& enabled = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() ).m_ConnectivityEngine;
66 SCOPED_SET_RESET restore( enabled, enabled );
67
68 for( bool useEngine : { false, true } )
69 {
70 BOOST_TEST_CONTEXT( "engine=" << useEngine )
71 {
72 enabled = useEngine;
73 KI_TEST::LoadSchematic( m_settingsManager, wxS( "issue24328/issue24328" ), m_schematic );
74
75 ERC_SETTINGS& settings = m_schematic->ErcSettings();
76 SHEETLIST_ERC_ITEMS_PROVIDER errors( m_schematic.get() );
77
82
83 m_schematic->ConnectionGraph()->RunERC();
84
85 ERC_TESTER tester( m_schematic.get() );
86 tester.TestPinToPin();
87
89
90 ERC_REPORT reportWriter( m_schematic.get(), EDA_UNITS::MM );
91
92 int powerPinErrors = 0;
93 bool allPowerInputAnchors = true;
94 std::vector<wxString> anchorDescriptions;
95
96 for( int ii = 0; ii < errors.GetCount(); ++ii )
97 {
98 std::shared_ptr<RC_ITEM> item = errors.GetItem( ii );
99
100 if( item->GetErrorCode() != ERCE_POWERPIN_NOT_DRIVEN )
101 continue;
102
103 powerPinErrors++;
104
105 SCH_SHEET_PATH sheetPath;
106 SCH_ITEM* mainItem = m_schematic->ResolveItem( item->GetMainItemID(),
107 &sheetPath, true );
108
109 BOOST_REQUIRE_MESSAGE( mainItem,
110 "ERCE_POWERPIN_NOT_DRIVEN marker has no main item" );
111 BOOST_REQUIRE_MESSAGE( mainItem->Type() == SCH_PIN_T,
112 "ERCE_POWERPIN_NOT_DRIVEN marker main item is not a pin" );
113
114 SCH_PIN* pin = static_cast<SCH_PIN*>( mainItem );
115
116 anchorDescriptions.push_back(
117 wxString::Format( "ref=%s pin=%s type=%s",
118 pin->GetParentSymbol()->GetRef( &sheetPath ),
119 pin->GetNumber(),
120 ElectricalPinTypeGetText( pin->GetType() ) ) );
121
122 if( pin->GetType() != ELECTRICAL_PINTYPE::PT_POWER_IN )
123 allPowerInputAnchors = false;
124 }
125
126 wxString anchorDump;
127
128 for( const wxString& s : anchorDescriptions )
129 anchorDump << s << wxS( "\n" );
130
131 BOOST_CHECK_MESSAGE( powerPinErrors >= 1,
132 "Expected at least 1 ERCE_POWERPIN_NOT_DRIVEN error\n"
133 << reportWriter.GetTextReport() );
134
135 BOOST_CHECK_MESSAGE( allPowerInputAnchors,
136 "At least one ERCE_POWERPIN_NOT_DRIVEN marker was anchored on a "
137 "non-PT_POWER_IN pin. The marker should refer to the pin the "
138 "error message is about.\nAnchors seen:\n"
139 << anchorDump.ToStdString()
140 << "\n"
141 << reportWriter.GetTextReport() );
142 }
143 }
144}
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
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
int TestPinToPin()
Checks the full netlist against the pin-to-pin connectivity requirements.
Definition erc.cpp:1709
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:170
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
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_UNANNOTATED
Symbol has not been annotated.
@ ERCE_POWERPIN_NOT_DRIVEN
Power input pin connected to some others pins but no power out pin to drive it.
@ 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)
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
Definition pin_type.h:42
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE)
Definition pin_type.cpp:203
@ RPT_SEVERITY_WARNING
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
std::vector< FAB_LAYER_COLOR > dummy
BOOST_FIXTURE_TEST_CASE(ERCPowerPinNotDrivenMarkerOnPowerInputPin, ERC_POWER_PIN_MARKER_FIXTURE)
KIBIS_PIN * pin
BOOST_TEST_CONTEXT("Test Clearance")
@ SCH_PIN_T
Definition typeinfo.h:149