KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_erc_multiple_pin_to_pin.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 <connection_graph.h>
24#include <schematic.h>
25#include <erc/erc_settings.h>
26#include <erc/erc.h>
27#include <erc/erc_report.h>
29#include <locale_io.h>
30#include <advanced_config.h>
31#include <scoped_set_reset.h>
32#include <erc/erc_item.h>
33#include <sch_symbol.h>
34#include <lib_symbol.h>
35#include <set>
36#include <tuple>
37
38
39namespace
40{
41struct ERC_REGRESSION_TEST_FIXTURE
42{
43 ERC_REGRESSION_TEST_FIXTURE() {}
44
45 SETTINGS_MANAGER m_settingsManager;
46 std::unique_ptr<SCHEMATIC> m_schematic;
47};
48} // namespace
49
50
51BOOST_FIXTURE_TEST_CASE( ERCMultiplePinToPin, ERC_REGRESSION_TEST_FIXTURE )
52{
54 auto& enabled = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() ).m_ConnectivityEngine;
55 SCOPED_SET_RESET restore( enabled, enabled );
56
57 std::vector<std::pair<wxString, int>> tests = { { "erc_multiple_pin_to_pin", 2 } };
58
59 for( bool useEngine : { false, true } )
60 {
61 enabled = useEngine;
62
63 for( const std::pair<wxString, int>& test : tests )
64 {
65 BOOST_TEST_CONTEXT( test.first.ToStdString() << " engine=" << useEngine )
66 {
67 KI_TEST::LoadSchematic( m_settingsManager, test.first, m_schematic );
68
69 const SCH_SHEET_PATH root = m_schematic->Hierarchy().front();
70 std::set<wxString> connectors;
71 size_t powerSymbols = 0;
72
73 for( SCH_ITEM* item : root.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
74 {
75 const auto* symbol = static_cast<SCH_SYMBOL*>( item );
76 const auto pins = symbol->GetPins( &root );
77 BOOST_REQUIRE_EQUAL( pins.size(), 1 );
78
79 if( symbol->IsPower() )
80 ++powerSymbols;
81 else
82 {
83 BOOST_CHECK( pins.front()->GetType() == ELECTRICAL_PINTYPE::PT_UNSPECIFIED );
84 connectors.insert( symbol->GetRef( &root ) );
85 }
86 }
87
88 BOOST_REQUIRE_EQUAL( powerSymbols, 14 );
89 const std::set<wxString> expectedConnectors{ "J1", "J2" };
90 BOOST_REQUIRE( connectors == expectedConnectors );
91
92 ERC_SETTINGS& settings = m_schematic->ErcSettings();
93 SHEETLIST_ERC_ITEMS_PROVIDER errors( m_schematic.get() );
94
95 // Skip the "Modified symbol" warning
98
99 m_schematic->ConnectionGraph()->RunERC();
100
101 ERC_TESTER tester( m_schematic.get() );
104 tester.TestNoConnectPins();
105 tester.TestPinToPin();
106 tester.TestSimilarLabels();
107
109
110 ERC_REPORT reportWriter( m_schematic.get(), EDA_UNITS::MM );
111
112 BOOST_CHECK_MESSAGE( errors.GetCount() == test.second,
113 "Expected " << test.second << " errors in " << test.first.ToStdString()
114 << " but got " << errors.GetCount() << "\n"
115 << reportWriter.GetTextReport() );
116 }
117 }
118 }
119}
120
121
122BOOST_FIXTURE_TEST_CASE( ERCPinConflictsUsePublishedNets, ERC_REGRESSION_TEST_FIXTURE )
123{
124 LOCALE_IO locale;
125 auto& enabled = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() ).m_ConnectivityEngine;
126 SCOPED_SET_RESET restore( enabled, enabled );
127 using DIAGNOSTIC = std::tuple<int, KIID, KIID, KIID_PATH>;
128 using CHECK = int ( ERC_TESTER::* )();
129 const std::vector<std::pair<wxString, CHECK>> cases = {
130 { "issue1768/issue1768", &ERC_TESTER::TestMultUnitPinConflicts },
131 { "similar_labels", &ERC_TESTER::TestSimilarLabels },
132 { "same_local_global_label", &ERC_TESTER::TestSameLocalGlobalLabel }
133 };
134
135 for( const auto& [fixture, check] : cases )
136 {
137 BOOST_TEST_CONTEXT( fixture )
138 {
139 std::multiset<DIAGNOSTIC> expected;
140
141 for( bool published : { false, true } )
142 {
143 enabled = published;
144 KI_TEST::LoadSchematic( m_settingsManager, fixture, m_schematic );
145 m_schematic->ErcSettings().m_ERCSeverities[ERCE_SAME_LOCAL_GLOBAL_LABEL] = RPT_SEVERITY_ERROR;
146 m_schematic->RebuildConnectivity();
147
148 if( published )
149 m_schematic->ConnectionGraph()->Reset();
150
151 ERC_TESTER tester( m_schematic.get() );
152 ( tester.*check )();
153 SHEETLIST_ERC_ITEMS_PROVIDER errors( m_schematic.get() );
155 std::multiset<DIAGNOSTIC> actual;
156
157 for( size_t i = 0; i < errors.GetCount(); ++i )
158 {
159 const auto item = std::static_pointer_cast<ERC_ITEM>( errors.GetItem( i ) );
160 actual.emplace( item->GetErrorCode(), item->GetMainItemID(), item->GetAuxItemID(),
161 item->IsSheetSpecific() ? item->GetSpecificSheetPath().Path() : KIID_PATH() );
162 }
163
164 if( !published )
165 {
166 BOOST_REQUIRE( !actual.empty() );
168 }
169 else
170 {
171 ERC_REPORT report( m_schematic.get(), EDA_UNITS::MM );
172 BOOST_CHECK_MESSAGE( actual == expected,
173 "Published diagnostics: " << actual.size() << ", legacy: " << expected.size()
174 << "\n" << report.GetTextReport() );
175 }
176 }
177 }
178 }
179}
180
181
182BOOST_FIXTURE_TEST_CASE( ERCPublishedNetsRespectNoConnectFlags, ERC_REGRESSION_TEST_FIXTURE )
183{
184 LOCALE_IO locale;
185 auto& enabled = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() ).m_ConnectivityEngine;
186 SCOPED_SET_RESET restore( enabled, enabled );
187
188 for( bool published : { false, true } )
189 {
190 BOOST_TEST_CONTEXT( "Published connectivity: " << published )
191 {
192 enabled = published;
193 KI_TEST::LoadSchematic( m_settingsManager, "NoConnectOnLine", m_schematic );
194 const SCH_SHEET_PATH path = m_schematic->Hierarchy().front();
195 SCH_SCREEN* screen = path.LastScreen();
196 std::vector<SCH_PIN*> pins;
197 std::vector<SCH_ITEM*> flags;
198
199 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
200 {
201 for( SCH_PIN* pin : static_cast<SCH_SYMBOL*>( item )->GetPins( &path ) )
202 pins.push_back( pin );
203 }
204
205 for( SCH_ITEM* item : screen->Items().OfType( SCH_NO_CONNECT_T ) )
206 flags.push_back( item );
207
208 BOOST_REQUIRE_EQUAL( pins.size(), 1 );
209 BOOST_REQUIRE_EQUAL( flags.size(), 1 );
210 pins.front()->SetType( ELECTRICAL_PINTYPE::PT_INPUT );
211
212 for( bool flagged : { true, false } )
213 {
214 if( !flagged )
215 screen->DeleteItem( flags.front() );
216
217 m_schematic->RebuildConnectivity();
218
219 if( published )
220 m_schematic->ConnectionGraph()->Reset();
221
222 ERC_TESTER tester( m_schematic.get() );
223 BOOST_CHECK_EQUAL( tester.TestPinToPin(), flagged ? 0 : 1 );
224 SHEETLIST_ERC_ITEMS_PROVIDER errors( m_schematic.get() );
226 BOOST_REQUIRE_EQUAL( errors.GetCount(), flagged ? 0 : 1 );
227
228 if( !flagged )
230 }
231 }
232 }
233}
234
235
236BOOST_FIXTURE_TEST_CASE( ERCDuplicatePinNumbersJoinOnlyWhenJumpered, ERC_REGRESSION_TEST_FIXTURE )
237{
238 LOCALE_IO locale;
239 auto& enabled = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() ).m_ConnectivityEngine;
240 SCOPED_SET_RESET restore( enabled, enabled );
241 KI_TEST::LoadSchematic( m_settingsManager, "ground_pin_test_error", m_schematic );
242 const SCH_SHEET_PATH path = m_schematic->Hierarchy().front();
243 SCH_SCREEN* screen = path.LastScreen();
244 SCH_SYMBOL* symbol = nullptr;
245
246 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
247 {
248 auto* candidate = static_cast<SCH_SYMBOL*>( item );
249
250 if( candidate->GetRef( &path ) == wxS( "U1" ) )
251 symbol = candidate;
252 }
253
254 BOOST_REQUIRE( symbol );
255 const auto pins = symbol->GetPins( &path );
256 BOOST_REQUIRE_EQUAL( pins.size(), 2 );
257 pins[1]->SetNumber( pins[0]->GetNumber() );
258
259 for( bool backend : { false, true } )
260 {
261 for( bool jumpered : { false, true } )
262 {
263 BOOST_TEST_CONTEXT( "engine=" << backend << ", jumpered=" << jumpered )
264 {
265 enabled = backend;
267 m_schematic->RebuildConnectivity();
268 ERC_TESTER tester( m_schematic.get() );
269 BOOST_CHECK_EQUAL( tester.TestDuplicatePinNets(), jumpered ? 0 : 1 );
270 SCH_SCREENS( m_schematic->Root() ).DeleteAllMarkers( MARKER_BASE::MARKER_ERC, true );
271 }
272 }
273 }
274}
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:248
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:1764
int TestSimilarLabels()
Checks for labels that differ only in capitalization.
Definition erc.cpp:2753
int TestSameLocalGlobalLabel()
Checks for global and local labels with the same name.
Definition erc.cpp:2712
int TestMultUnitPinConflicts()
Checks if shared pins on multi-unit symbols have been connected to different nets.
Definition erc.cpp:2200
int TestNoConnectPins()
In KiCad 5 and earlier, you could connect stuff up to pins with NC electrical type.
Definition erc.cpp:1343
int TestDuplicatePinNets()
Checks if duplicate pin numbers within a symbol are connected to different nets.
Definition erc.cpp:2503
int TestMultiunitFootprints()
Test if all units of each multiunit symbol have the same footprint assigned.
Definition erc.cpp:978
void SetDuplicatePinNumbersAreJumpers(bool aEnabled)
Definition lib_symbol.h:885
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
int GetErrorCode() const
Definition rc_item.h:213
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition sch_screen.h:826
void DeleteAllMarkers(enum MARKER_BASE::MARKER_T aMarkerType, bool aIncludeExclusions)
Delete all electronic rules check markers of aMarkerType from all the screens in the list.
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:122
void DeleteItem(SCH_ITEM *aItem)
Remove aItem from the linked list and deletes the object.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SCREEN * LastScreen()
Schematic symbol object.
Definition sch_symbol.h:75
std::vector< const SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition sch_symbol.h:184
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.
#define CHECK(x)
@ ERCE_SAME_LOCAL_GLOBAL_LABEL
2 labels are equal for case insensitive comparisons.
@ ERCE_LIB_SYMBOL_MISMATCH
Symbol doesn't match copy in library.
@ ERCE_PIN_NOT_DRIVEN
Pin connected to some others pins but no pin to drive it.
@ ERCE_LIB_SYMBOL_ISSUES
Symbol not found in active libraries.
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
@ PT_INPUT
usual pin input: must be connected
Definition pin_type.h:33
@ PT_UNSPECIFIED
unknown electrical properties: creates always a warning when connected
Definition pin_type.h:41
@ RPT_SEVERITY_WARNING
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
std::vector< FAB_LAYER_COLOR > dummy
BOOST_FIXTURE_TEST_CASE(ERCMultiplePinToPin, ERC_REGRESSION_TEST_FIXTURE)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
std::string path
KIBIS_PIN * pin
VECTOR3I expected(15, 30, 45)
BOOST_TEST_CONTEXT("Test Clearance")
int actual
BOOST_CHECK_EQUAL(result, "25.4")
@ SCH_NO_CONNECT_T
Definition typeinfo.h:156
@ SCH_SYMBOL_T
Definition typeinfo.h:168