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
40{
42
44 std::unique_ptr<SCHEMATIC> m_schematic;
45};
46
47
49{
51 auto& enabled = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() ).m_ConnectivityEngine;
52 SCOPED_SET_RESET restore( enabled, enabled );
53
54 std::vector<std::pair<wxString, int>> tests = { { "erc_multiple_pin_to_pin", 2 } };
55
56 for( bool useEngine : { false, true } )
57 {
58 enabled = useEngine;
59
60 for( const std::pair<wxString, int>& test : tests )
61 {
62 BOOST_TEST_CONTEXT( test.first.ToStdString() << " engine=" << useEngine )
63 {
64 KI_TEST::LoadSchematic( m_settingsManager, test.first, m_schematic );
65
66 const SCH_SHEET_PATH root = m_schematic->Hierarchy().front();
67 std::set<wxString> connectors;
68 size_t powerSymbols = 0;
69
70 for( SCH_ITEM* item : root.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
71 {
72 const auto* symbol = static_cast<SCH_SYMBOL*>( item );
73 const auto pins = symbol->GetPins( &root );
74 BOOST_REQUIRE_EQUAL( pins.size(), 1 );
75
76 if( symbol->IsPower() )
77 ++powerSymbols;
78 else
79 {
80 BOOST_CHECK( pins.front()->GetType() == ELECTRICAL_PINTYPE::PT_UNSPECIFIED );
81 connectors.insert( symbol->GetRef( &root ) );
82 }
83 }
84
85 BOOST_REQUIRE_EQUAL( powerSymbols, 14 );
86 const std::set<wxString> expectedConnectors{ "J1", "J2" };
87 BOOST_REQUIRE( connectors == expectedConnectors );
88
89 ERC_SETTINGS& settings = m_schematic->ErcSettings();
90 SHEETLIST_ERC_ITEMS_PROVIDER errors( m_schematic.get() );
91
92 // Skip the "Modified symbol" warning
95
96 m_schematic->ConnectionGraph()->RunERC();
97
98 ERC_TESTER tester( m_schematic.get() );
101 tester.TestNoConnectPins();
102 tester.TestPinToPin();
103 tester.TestSimilarLabels();
104
106
107 ERC_REPORT reportWriter( m_schematic.get(), EDA_UNITS::MM );
108
109 BOOST_CHECK_MESSAGE( errors.GetCount() == test.second,
110 "Expected " << test.second << " errors in " << test.first.ToStdString()
111 << " but got " << errors.GetCount() << "\n"
112 << reportWriter.GetTextReport() );
113 }
114 }
115 }
116}
117
118
119BOOST_FIXTURE_TEST_CASE( ERCPinConflictsUsePublishedNets, ERC_REGRESSION_TEST_FIXTURE )
120{
121 LOCALE_IO locale;
122 auto& enabled = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() ).m_ConnectivityEngine;
123 SCOPED_SET_RESET restore( enabled, enabled );
124 using DIAGNOSTIC = std::tuple<int, KIID, KIID, KIID_PATH>;
125 using CHECK = int ( ERC_TESTER::* )();
126 const std::vector<std::pair<wxString, CHECK>> cases = {
127 { "issue1768/issue1768", &ERC_TESTER::TestMultUnitPinConflicts },
128 { "similar_labels", &ERC_TESTER::TestSimilarLabels },
129 { "same_local_global_label", &ERC_TESTER::TestSameLocalGlobalLabel }
130 };
131
132 for( const auto& [fixture, check] : cases )
133 {
134 BOOST_TEST_CONTEXT( fixture )
135 {
136 std::multiset<DIAGNOSTIC> expected;
137
138 for( bool published : { false, true } )
139 {
140 enabled = published;
141 KI_TEST::LoadSchematic( m_settingsManager, fixture, m_schematic );
142 m_schematic->ErcSettings().m_ERCSeverities[ERCE_SAME_LOCAL_GLOBAL_LABEL] = RPT_SEVERITY_ERROR;
143 m_schematic->RebuildConnectivity();
144
145 if( published )
146 m_schematic->ConnectionGraph()->Reset();
147
148 ERC_TESTER tester( m_schematic.get() );
149 ( tester.*check )();
150 SHEETLIST_ERC_ITEMS_PROVIDER errors( m_schematic.get() );
152 std::multiset<DIAGNOSTIC> actual;
153
154 for( size_t i = 0; i < errors.GetCount(); ++i )
155 {
156 const auto item = std::static_pointer_cast<ERC_ITEM>( errors.GetItem( i ) );
157 actual.emplace( item->GetErrorCode(), item->GetMainItemID(), item->GetAuxItemID(),
158 item->IsSheetSpecific() ? item->GetSpecificSheetPath().Path() : KIID_PATH() );
159 }
160
161 if( !published )
162 {
163 BOOST_REQUIRE( !actual.empty() );
165 }
166 else
167 {
168 ERC_REPORT report( m_schematic.get(), EDA_UNITS::MM );
169 BOOST_CHECK_MESSAGE( actual == expected,
170 "Published diagnostics: " << actual.size() << ", legacy: " << expected.size()
171 << "\n" << report.GetTextReport() );
172 }
173 }
174 }
175 }
176}
177
178
179BOOST_FIXTURE_TEST_CASE( ERCPublishedNetsRespectNoConnectFlags, ERC_REGRESSION_TEST_FIXTURE )
180{
181 LOCALE_IO locale;
182 auto& enabled = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() ).m_ConnectivityEngine;
183 SCOPED_SET_RESET restore( enabled, enabled );
184
185 for( bool published : { false, true } )
186 {
187 BOOST_TEST_CONTEXT( "Published connectivity: " << published )
188 {
189 enabled = published;
190 KI_TEST::LoadSchematic( m_settingsManager, "NoConnectOnLine", m_schematic );
191 const SCH_SHEET_PATH path = m_schematic->Hierarchy().front();
192 SCH_SCREEN* screen = path.LastScreen();
193 std::vector<SCH_PIN*> pins;
194 std::vector<SCH_ITEM*> flags;
195
196 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
197 {
198 for( SCH_PIN* pin : static_cast<SCH_SYMBOL*>( item )->GetPins( &path ) )
199 pins.push_back( pin );
200 }
201
202 for( SCH_ITEM* item : screen->Items().OfType( SCH_NO_CONNECT_T ) )
203 flags.push_back( item );
204
205 BOOST_REQUIRE_EQUAL( pins.size(), 1 );
206 BOOST_REQUIRE_EQUAL( flags.size(), 1 );
207 pins.front()->SetType( ELECTRICAL_PINTYPE::PT_INPUT );
208
209 for( bool flagged : { true, false } )
210 {
211 if( !flagged )
212 screen->DeleteItem( flags.front() );
213
214 m_schematic->RebuildConnectivity();
215
216 if( published )
217 m_schematic->ConnectionGraph()->Reset();
218
219 ERC_TESTER tester( m_schematic.get() );
220 BOOST_CHECK_EQUAL( tester.TestPinToPin(), flagged ? 0 : 1 );
221 SHEETLIST_ERC_ITEMS_PROVIDER errors( m_schematic.get() );
223 BOOST_REQUIRE_EQUAL( errors.GetCount(), flagged ? 0 : 1 );
224
225 if( !flagged )
227 }
228 }
229 }
230}
231
232
233BOOST_FIXTURE_TEST_CASE( ERCDuplicatePinNumbersJoinOnlyWhenJumpered, ERC_REGRESSION_TEST_FIXTURE )
234{
235 LOCALE_IO locale;
236 auto& enabled = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() ).m_ConnectivityEngine;
237 SCOPED_SET_RESET restore( enabled, enabled );
238 KI_TEST::LoadSchematic( m_settingsManager, "ground_pin_test_error", m_schematic );
239 const SCH_SHEET_PATH path = m_schematic->Hierarchy().front();
240 SCH_SCREEN* screen = path.LastScreen();
241 SCH_SYMBOL* symbol = nullptr;
242
243 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
244 {
245 auto* candidate = static_cast<SCH_SYMBOL*>( item );
246
247 if( candidate->GetRef( &path ) == wxS( "U1" ) )
248 symbol = candidate;
249 }
250
251 BOOST_REQUIRE( symbol );
252 const auto pins = symbol->GetPins( &path );
253 BOOST_REQUIRE_EQUAL( pins.size(), 2 );
254 pins[1]->SetNumber( pins[0]->GetNumber() );
255
256 for( bool backend : { false, true } )
257 {
258 for( bool jumpered : { false, true } )
259 {
260 BOOST_TEST_CONTEXT( "engine=" << backend << ", jumpered=" << jumpered )
261 {
262 enabled = backend;
264 m_schematic->RebuildConnectivity();
265 ERC_TESTER tester( m_schematic.get() );
266 BOOST_CHECK_EQUAL( tester.TestDuplicatePinNets(), jumpered ? 0 : 1 );
267 SCH_SCREENS( m_schematic->Root() ).DeleteAllMarkers( MARKER_BASE::MARKER_ERC, true );
268 }
269 }
270 }
271}
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:1709
int TestSimilarLabels()
Checks for labels that differ only in capitalization.
Definition erc.cpp:2696
int TestSameLocalGlobalLabel()
Checks for global and local labels with the same name.
Definition erc.cpp:2655
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 TestDuplicatePinNets()
Checks if duplicate pin numbers within a symbol are connected to different nets.
Definition erc.cpp:2446
int TestMultiunitFootprints()
Test if all units of each multiunit symbol have the same footprint assigned.
Definition erc.cpp:923
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:158
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:818
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:73
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:182
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
std::unique_ptr< SCHEMATIC > m_schematic
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