KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_pin_map_erc.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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
21
22#include <memory>
23
24#include <pin_map.h>
25#include <jumper_group.h>
26#include <lib_symbol.h>
27#include <sch_pin.h>
28#include <sch_symbol.h>
29#include <sch_screen.h>
30#include <sch_sheet.h>
31#include <sch_sheet_path.h>
32#include <schematic.h>
34#include <erc/erc.h>
35
36
38{
40 {
41 m_settingsManager.LoadProject( "" );
42 m_schematic = std::make_unique<SCHEMATIC>( &m_settingsManager.Prj() );
43 m_schematic->Reset();
44
45 SCH_SHEET* defaultSheet = m_schematic->GetTopLevelSheet( 0 );
46 SCH_SHEET* root = new SCH_SHEET( m_schematic.get() );
47 SCH_SCREEN* screen = new SCH_SCREEN( m_schematic.get() );
48 root->SetScreen( screen );
49
50 m_schematic->AddTopLevelSheet( root );
51 m_schematic->RemoveTopLevelSheet( defaultSheet );
52 delete defaultSheet;
53 }
54
56 void placeSymbol( PIN_MAP aMap, const std::set<wxString>& aJumperGroup = {} )
57 {
59 path.push_back( &m_schematic->Root() );
60
61 m_libSym = std::make_unique<LIB_SYMBOL>( "DUT", nullptr );
62
63 for( const wxString& number : { wxString( "1" ), wxString( "2" ) } )
64 {
65 SCH_PIN* pin = new SCH_PIN( m_libSym.get() );
66 pin->SetNumber( number );
68 m_libSym->AddDrawItem( pin );
69 }
70
71 m_libSym->PinMaps().AddOrReplace( std::move( aMap ) );
72
73 if( std::optional<JUMPER_GROUP> group = JUMPER_GROUP::Make( aJumperGroup ) )
74 m_libSym->JumperPinGroups().Add( std::move( *group ) );
75
76 SCH_SYMBOL* sym = new SCH_SYMBOL( *m_libSym, m_libSym->GetLibId(), &path, 0, 0,
77 VECTOR2I( 0, 0 ) );
78 sym->UpdatePins();
79 m_schematic->RootScreen()->Append( sym );
80 }
81
83 {
84 // ERC_TESTER::RunTests() always recalculates first, and the engine reads only published facts
85 m_schematic->RebuildConnectivity();
86 return ERC_TESTER( m_schematic.get() ).TestPinMap( nullptr, nullptr );
87 }
88
90 std::unique_ptr<SCHEMATIC> m_schematic;
91 std::unique_ptr<LIB_SYMBOL> m_libSym;
92};
93
94
95BOOST_FIXTURE_TEST_SUITE( PinMapErc, PIN_MAP_ERC_FIXTURE )
96
97
98BOOST_AUTO_TEST_CASE( StalePinReferenceFires )
99{
100 PIN_MAP map( wxS( "M" ) );
101 map.SetEntry( wxS( "1" ), wxS( "1" ) );
102 map.SetEntry( wxS( "9" ), wxS( "9" ) ); // pin 9 does not exist on the symbol
103
104 placeSymbol( std::move( map ) );
105
106 BOOST_CHECK_EQUAL( runPinMapErc(), 1 );
107}
108
109
110BOOST_AUTO_TEST_CASE( DuplicatePadFires )
111{
112 PIN_MAP map( wxS( "M" ) );
113 map.SetEntry( wxS( "1" ), wxS( "5" ) );
114 map.SetEntry( wxS( "2" ), wxS( "5" ) ); // two different pins -> same pad
115
116 placeSymbol( std::move( map ) );
117
118 BOOST_CHECK_EQUAL( runPinMapErc(), 1 );
119}
120
121
122BOOST_AUTO_TEST_CASE( CleanMapStaysQuiet )
123{
124 PIN_MAP map( wxS( "M" ) );
125 map.SetEntry( wxS( "1" ), wxS( "1" ) );
126 map.SetEntry( wxS( "2" ), wxS( "2" ) );
127
128 placeSymbol( std::move( map ) );
129
130 BOOST_CHECK_EQUAL( runPinMapErc(), 0 );
131}
132
133
134BOOST_AUTO_TEST_CASE( JumperedDuplicateStaysQuiet )
135{
136 // Two pins deliberately jumpered (internally connected) may share a pad.
137 PIN_MAP map( wxS( "M" ) );
138 map.SetEntry( wxS( "1" ), wxS( "5" ) );
139 map.SetEntry( wxS( "2" ), wxS( "5" ) );
140
141 placeSymbol( std::move( map ), { wxS( "1" ), wxS( "2" ) } );
142
143 BOOST_CHECK_EQUAL( runPinMapErc(), 0 );
144}
145
146
147BOOST_AUTO_TEST_CASE( StackedSamePinStaysQuiet )
148{
149 // One pin mapped to several pads (stacked) is not a duplicate-target collision.
150 PIN_MAP map( wxS( "M" ) );
151 map.SetEntry( wxS( "1" ), wxS( "[4,9]" ) );
152 map.SetEntry( wxS( "2" ), wxS( "2" ) );
153
154 placeSymbol( std::move( map ) );
155
156 BOOST_CHECK_EQUAL( runPinMapErc(), 0 );
157}
158
159
Runs the electrical rules checks and adds a SCH_MARKER for each violation.
Definition erc.h:60
int TestPinMap(KIFACE *aCvPcb, PROJECT *aProject)
Check pin-to-pad maps (issue #2282): stale pin references, duplicate pad targets, bad pads and unmapp...
Definition erc.cpp:417
static std::optional< JUMPER_GROUP > Make(std::set< wxString > aNames)
Factory method to create a JUMPER_GROUP from a set of names.
A named pin map.
Definition pin_map.h:65
void SetEntry(const wxString &aPinNumber, const wxString &aPadNumber)
Set the pad number for a symbol pin.
Definition pin_map.cpp:59
SCH_SHEET & Root() const
Definition schematic.h:200
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:48
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
void UpdatePins()
Updates the cache of SCH_PIN objects for each pin.
@ SCH_SYMBOL
one item stream of a Schematic Symbol Library
@ PT_PASSIVE
pin for passive symbols: must be connected, and can be connected to any pin.
Definition pin_type.h:39
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
std::unique_ptr< SCHEMATIC > m_schematic
SETTINGS_MANAGER m_settingsManager
std::unique_ptr< LIB_SYMBOL > m_libSym
void placeSymbol(PIN_MAP aMap, const std::set< wxString > &aJumperGroup={})
Build a two-pin symbol carrying aMap (+ optional symbol jumper group) and place it.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE_END()
std::string path
KIBIS_PIN * pin
BOOST_AUTO_TEST_CASE(StalePinReferenceFires)
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708