KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_stacked_pin_netlist.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 (C) 2024 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 2
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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <boost/test/unit_test.hpp>
25
27#include <lib_id.h>
28#include <board.h>
29#include <footprint.h>
30#include <pad.h>
32#include <project.h>
34#include <wx/log.h>
36#include <reporter.h>
37
38BOOST_AUTO_TEST_SUITE( StackedPinNetlist )
39
40
41
45BOOST_AUTO_TEST_CASE( TestStackedPinNetMatch )
46{
47 // Create a component with a stacked pin notation
48 LIB_ID fpid( wxT( "TestLib" ), wxT( "TestFootprint" ) );
49 wxString reference = wxT( "U1" );
50 wxString value = wxT( "TestIC" );
52 std::vector<KIID> kiids;
53
54 COMPONENT component( fpid, reference, value, path, kiids );
55
56 // Add a net with stacked pin notation [8,9,10]
57 component.AddNet( wxT( "[8,9,10]" ), wxT( "DATA_BUS" ), wxT( "bidirectional" ), wxT( "bidirectional" ) );
58
59 // Test that individual pins within the stack are found
60 const COMPONENT_NET& net8 = component.GetNet( wxT( "8" ) );
61 const COMPONENT_NET& net9 = component.GetNet( wxT( "9" ) );
62 const COMPONENT_NET& net10 = component.GetNet( wxT( "10" ) );
63
64 BOOST_CHECK( net8.IsValid() );
65 BOOST_CHECK( net9.IsValid() );
66 BOOST_CHECK( net10.IsValid() );
67
68 BOOST_CHECK_EQUAL( net8.GetNetName(), wxString( "DATA_BUS" ) );
69 BOOST_CHECK_EQUAL( net9.GetNetName(), wxString( "DATA_BUS" ) );
70 BOOST_CHECK_EQUAL( net10.GetNetName(), wxString( "DATA_BUS" ) );
71
72 // Test that pins outside the stack are not found
73 const COMPONENT_NET& net7 = component.GetNet( wxT( "7" ) );
74 const COMPONENT_NET& net11 = component.GetNet( wxT( "11" ) );
75
76 BOOST_CHECK( !net7.IsValid() );
77 BOOST_CHECK( !net11.IsValid() );
78}
79
80
84BOOST_AUTO_TEST_CASE( TestStackedPinRangeMatch )
85{
86 LIB_ID fpid( wxT( "TestLib" ), wxT( "TestFootprint" ) );
87 wxString reference = wxT( "U2" );
88 wxString value = wxT( "TestIC" );
90 std::vector<KIID> kiids;
91
92 COMPONENT component( fpid, reference, value, path, kiids );
93
94 // Add a net with range notation [1-4]
95 component.AddNet( wxT( "[1-4]" ), wxT( "POWER_BUS" ), wxT( "power_in" ), wxT( "power_in" ) );
96
97 // Test that all pins in the range are found
98 for( int i = 1; i <= 4; i++ )
99 {
100 const COMPONENT_NET& net = component.GetNet( wxString::Format( wxT( "%d" ), i ) );
101 BOOST_CHECK( net.IsValid() );
102 BOOST_CHECK_EQUAL( net.GetNetName(), wxString( "POWER_BUS" ) );
103 }
104
105 // Test pins outside the range
106 const COMPONENT_NET& net0 = component.GetNet( wxT( "0" ) );
107 const COMPONENT_NET& net5 = component.GetNet( wxT( "5" ) );
108
109 BOOST_CHECK( !net0.IsValid() );
110 BOOST_CHECK( !net5.IsValid() );
111}
112
113
117BOOST_AUTO_TEST_CASE( TestStackedPinMixedMatch )
118{
119 LIB_ID fpid( wxT( "TestLib" ), wxT( "TestFootprint" ) );
120 wxString reference = wxT( "U3" );
121 wxString value = wxT( "TestIC" );
123 std::vector<KIID> kiids;
124
125 COMPONENT component( fpid, reference, value, path, kiids );
126
127 // Add a net with mixed notation [1,3,5-7]
128 component.AddNet( wxT( "[1,3,5-7]" ), wxT( "CONTROL_BUS" ), wxT( "output" ), wxT( "output" ) );
129
130 // Test individual pins and ranges
131 std::vector<int> expectedPins = { 1, 3, 5, 6, 7 };
132 for( int pin : expectedPins )
133 {
134 const COMPONENT_NET& net = component.GetNet( wxString::Format( wxT( "%d" ), pin ) );
135 BOOST_CHECK( net.IsValid() );
136 BOOST_CHECK_EQUAL( net.GetNetName(), wxString( "CONTROL_BUS" ) );
137 }
138
139 // Test pins that should not be found
140 std::vector<int> unexpectedPins = { 2, 4, 8 };
141 for( int pin : unexpectedPins )
142 {
143 const COMPONENT_NET& net = component.GetNet( wxString::Format( wxT( "%d" ), pin ) );
144 BOOST_CHECK( !net.IsValid() );
145 }
146}
147
148
152BOOST_AUTO_TEST_CASE( TestRegularPinMatch )
153{
154 LIB_ID fpid( wxT( "TestLib" ), wxT( "TestFootprint" ) );
155 wxString reference = wxT( "R1" );
156 wxString value = wxT( "1k" );
158 std::vector<KIID> kiids;
159
160 COMPONENT component( fpid, reference, value, path, kiids );
161
162 // Add regular pins
163 component.AddNet( wxT( "1" ), wxT( "VCC" ), wxT( "passive" ), wxT( "passive" ) );
164 component.AddNet( wxT( "2" ), wxT( "GND" ), wxT( "passive" ), wxT( "passive" ) );
165
166 const COMPONENT_NET& net1 = component.GetNet( wxT( "1" ) );
167 const COMPONENT_NET& net2 = component.GetNet( wxT( "2" ) );
168
169 BOOST_CHECK( net1.IsValid() );
170 BOOST_CHECK( net2.IsValid() );
171 BOOST_CHECK_EQUAL( net1.GetNetName(), wxString( "VCC" ) );
172 BOOST_CHECK_EQUAL( net2.GetNetName(), wxString( "GND" ) );
173}
174
175
180BOOST_AUTO_TEST_CASE( TestStackedProjectNetlistUpdate )
181{
182 BOOST_TEST_MESSAGE( "Testing stacked pin project netlist functionality" );
183
184 // Create a component that matches the R1 component from the stacked project
185 LIB_ID fpid( wxT( "Connector" ), wxT( "Tag-Connect_TC2050-IDC-FP_2x05_P1.27mm_Vertical" ) );
186 wxString reference = wxT( "R1" );
187 wxString value = wxT( "R" );
189 std::vector<KIID> kiids;
190
191 COMPONENT component( fpid, reference, value, path, kiids );
192
193 // Add nets matching the stacked project
194 // The schematic has two stacked pin groups: [1-5] and [6,7,9-11]
195 component.AddNet( wxT( "[1-5]" ), wxT( "Net-(R1-Pad1)" ), wxT( "passive" ), wxT( "passive" ) );
196 component.AddNet( wxT( "[6,7,9-11]" ), wxT( "Net-(R1-Pad6)" ), wxT( "passive" ), wxT( "passive" ) );
197
198 BOOST_TEST_MESSAGE( "Created R1 component with stacked pins [1-5] and [6,7,9-11]" );
199
200 // Log all nets for the component
201 BOOST_TEST_MESSAGE( "R1 component nets:" );
202 for( unsigned i = 0; i < component.GetNetCount(); i++ )
203 {
204 const COMPONENT_NET& net = component.GetNet( i );
205 BOOST_TEST_MESSAGE( " Pin: " + net.GetPinName() + " -> Net: " + net.GetNetName() );
206 }
207
208 // Test individual pin lookups
209 // Pins 1-5 should be found (they're in the [1-5] stacked group)
210 for( int pin = 1; pin <= 5; pin++ )
211 {
212 wxString pinStr = wxString::Format( wxT( "%d" ), pin );
213 const COMPONENT_NET& net = component.GetNet( pinStr );
214
215 BOOST_CHECK_MESSAGE( net.IsValid(),
216 "Pin " + pinStr + " should be found in stacked group [1-5]" );
217
218 if( net.IsValid() )
219 {
220 BOOST_CHECK_EQUAL( net.GetNetName(), wxString( "Net-(R1-Pad1)" ) );
221 BOOST_TEST_MESSAGE( "Pin " + pinStr + " found with net: " + net.GetNetName() );
222 }
223 else
224 {
225 BOOST_TEST_MESSAGE( "Pin " + pinStr + " NOT found (should be in [1-5])" );
226 }
227 }
228
229 // Pins 6,7,9,10,11 should be found (they're in the [6,7,9-11] stacked group)
230 std::vector<int> groupTwoPins = { 6, 7, 9, 10, 11 };
231 for( int pin : groupTwoPins )
232 {
233 wxString pinStr = wxString::Format( wxT( "%d" ), pin );
234 const COMPONENT_NET& net = component.GetNet( pinStr );
235
236 BOOST_CHECK_MESSAGE( net.IsValid(),
237 "Pin " + pinStr + " should be found in stacked group [6,7,9-11]" );
238
239 if( net.IsValid() )
240 {
241 BOOST_CHECK_EQUAL( net.GetNetName(), wxString( "Net-(R1-Pad6)" ) );
242 BOOST_TEST_MESSAGE( "Pin " + pinStr + " found with net: " + net.GetNetName() );
243 }
244 else
245 {
246 BOOST_TEST_MESSAGE( "Pin " + pinStr + " NOT found (should be in [6,7,9-11])" );
247 }
248 }
249
250 // Pin 8 should NOT be found (it's not in either stacked group)
251 const COMPONENT_NET& net8 = component.GetNet( wxT( "8" ) );
252 BOOST_CHECK_MESSAGE( !net8.IsValid(),
253 "Pin 8 should NOT be found (not in any stacked group)" );
254
255 if( net8.IsValid() )
256 {
257 BOOST_TEST_MESSAGE( "Pin 8 unexpectedly found with net: " + net8.GetNetName() );
258 }
259 else
260 {
261 BOOST_TEST_MESSAGE( "Pin 8 correctly NOT found (expected behavior)" );
262 }
263}
264
265
Used to store the component pin name to net name (and pin function) associations stored in a netlist.
Definition pcb_netlist.h:47
const wxString & GetNetName() const
Definition pcb_netlist.h:61
bool IsValid() const
Definition pcb_netlist.h:65
const wxString & GetPinName() const
Definition pcb_netlist.h:60
Store all of the related footprint information found in a netlist.
const COMPONENT_NET & GetNet(unsigned aIndex) const
void AddNet(const wxString &aPinName, const wxString &aNetName, const wxString &aPinFunction, const wxString &aPinType)
unsigned GetNetCount() const
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:49
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
BOOST_AUTO_TEST_CASE(TestStackedPinNetMatch)
Test that COMPONENT::GetNet properly handles stacked pin notation like [8,9,10] and finds individual ...
BOOST_CHECK_EQUAL(result, "25.4")