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, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <boost/test/unit_test.hpp>
21
23#include <lib_id.h>
24#include <board.h>
25#include <footprint.h>
26#include <pad.h>
28#include <project.h>
30#include <wx/log.h>
32#include <reporter.h>
33
34BOOST_AUTO_TEST_SUITE( StackedPinNetlist )
35
36
37
41BOOST_AUTO_TEST_CASE( TestStackedPinNetMatch )
42{
43 // Create a component with a stacked pin notation
44 LIB_ID fpid( wxT( "TestLib" ), wxT( "TestFootprint" ) );
45 wxString reference = wxT( "U1" );
46 wxString value = wxT( "TestIC" );
48 std::vector<KIID> kiids;
49
50 COMPONENT component( fpid, reference, value, path, kiids );
51
52 // Add a net with stacked pin notation [8,9,10]
53 component.AddNet( wxT( "[8,9,10]" ), wxT( "DATA_BUS" ), wxT( "bidirectional" ), wxT( "bidirectional" ) );
54
55 // Test that individual pins within the stack are found
56 const COMPONENT_NET& net8 = component.GetNet( wxT( "8" ) );
57 const COMPONENT_NET& net9 = component.GetNet( wxT( "9" ) );
58 const COMPONENT_NET& net10 = component.GetNet( wxT( "10" ) );
59
60 BOOST_CHECK( net8.IsValid() );
61 BOOST_CHECK( net9.IsValid() );
62 BOOST_CHECK( net10.IsValid() );
63
64 BOOST_CHECK_EQUAL( net8.GetNetName(), wxString( "DATA_BUS" ) );
65 BOOST_CHECK_EQUAL( net9.GetNetName(), wxString( "DATA_BUS" ) );
66 BOOST_CHECK_EQUAL( net10.GetNetName(), wxString( "DATA_BUS" ) );
67
68 // Test that pins outside the stack are not found
69 const COMPONENT_NET& net7 = component.GetNet( wxT( "7" ) );
70 const COMPONENT_NET& net11 = component.GetNet( wxT( "11" ) );
71
72 BOOST_CHECK( !net7.IsValid() );
73 BOOST_CHECK( !net11.IsValid() );
74}
75
76
80BOOST_AUTO_TEST_CASE( TestStackedPinRangeMatch )
81{
82 LIB_ID fpid( wxT( "TestLib" ), wxT( "TestFootprint" ) );
83 wxString reference = wxT( "U2" );
84 wxString value = wxT( "TestIC" );
86 std::vector<KIID> kiids;
87
88 COMPONENT component( fpid, reference, value, path, kiids );
89
90 // Add a net with range notation [1-4]
91 component.AddNet( wxT( "[1-4]" ), wxT( "POWER_BUS" ), wxT( "power_in" ), wxT( "power_in" ) );
92
93 // Test that all pins in the range are found
94 for( int i = 1; i <= 4; i++ )
95 {
96 const COMPONENT_NET& net = component.GetNet( wxString::Format( wxT( "%d" ), i ) );
97 BOOST_CHECK( net.IsValid() );
98 BOOST_CHECK_EQUAL( net.GetNetName(), wxString( "POWER_BUS" ) );
99 }
100
101 // Test pins outside the range
102 const COMPONENT_NET& net0 = component.GetNet( wxT( "0" ) );
103 const COMPONENT_NET& net5 = component.GetNet( wxT( "5" ) );
104
105 BOOST_CHECK( !net0.IsValid() );
106 BOOST_CHECK( !net5.IsValid() );
107}
108
109
113BOOST_AUTO_TEST_CASE( TestStackedPinMixedMatch )
114{
115 LIB_ID fpid( wxT( "TestLib" ), wxT( "TestFootprint" ) );
116 wxString reference = wxT( "U3" );
117 wxString value = wxT( "TestIC" );
119 std::vector<KIID> kiids;
120
121 COMPONENT component( fpid, reference, value, path, kiids );
122
123 // Add a net with mixed notation [1,3,5-7]
124 component.AddNet( wxT( "[1,3,5-7]" ), wxT( "CONTROL_BUS" ), wxT( "output" ), wxT( "output" ) );
125
126 // Test individual pins and ranges
127 std::vector<int> expectedPins = { 1, 3, 5, 6, 7 };
128 for( int pin : expectedPins )
129 {
130 const COMPONENT_NET& net = component.GetNet( wxString::Format( wxT( "%d" ), pin ) );
131 BOOST_CHECK( net.IsValid() );
132 BOOST_CHECK_EQUAL( net.GetNetName(), wxString( "CONTROL_BUS" ) );
133 }
134
135 // Test pins that should not be found
136 std::vector<int> unexpectedPins = { 2, 4, 8 };
137 for( int pin : unexpectedPins )
138 {
139 const COMPONENT_NET& net = component.GetNet( wxString::Format( wxT( "%d" ), pin ) );
140 BOOST_CHECK( !net.IsValid() );
141 }
142}
143
144
148BOOST_AUTO_TEST_CASE( TestRegularPinMatch )
149{
150 LIB_ID fpid( wxT( "TestLib" ), wxT( "TestFootprint" ) );
151 wxString reference = wxT( "R1" );
152 wxString value = wxT( "1k" );
154 std::vector<KIID> kiids;
155
156 COMPONENT component( fpid, reference, value, path, kiids );
157
158 // Add regular pins
159 component.AddNet( wxT( "1" ), wxT( "VCC" ), wxT( "passive" ), wxT( "passive" ) );
160 component.AddNet( wxT( "2" ), wxT( "GND" ), wxT( "passive" ), wxT( "passive" ) );
161
162 const COMPONENT_NET& net1 = component.GetNet( wxT( "1" ) );
163 const COMPONENT_NET& net2 = component.GetNet( wxT( "2" ) );
164
165 BOOST_CHECK( net1.IsValid() );
166 BOOST_CHECK( net2.IsValid() );
167 BOOST_CHECK_EQUAL( net1.GetNetName(), wxString( "VCC" ) );
168 BOOST_CHECK_EQUAL( net2.GetNetName(), wxString( "GND" ) );
169}
170
171
176BOOST_AUTO_TEST_CASE( TestStackedProjectNetlistUpdate )
177{
178 BOOST_TEST_MESSAGE( "Testing stacked pin project netlist functionality" );
179
180 // Create a component that matches the R1 component from the stacked project
181 LIB_ID fpid( wxT( "Connector" ), wxT( "Tag-Connect_TC2050-IDC-FP_2x05_P1.27mm_Vertical" ) );
182 wxString reference = wxT( "R1" );
183 wxString value = wxT( "R" );
185 std::vector<KIID> kiids;
186
187 COMPONENT component( fpid, reference, value, path, kiids );
188
189 // Add nets matching the stacked project
190 // The schematic has two stacked pin groups: [1-5] and [6,7,9-11]
191 component.AddNet( wxT( "[1-5]" ), wxT( "Net-(R1-Pad1)" ), wxT( "passive" ), wxT( "passive" ) );
192 component.AddNet( wxT( "[6,7,9-11]" ), wxT( "Net-(R1-Pad6)" ), wxT( "passive" ), wxT( "passive" ) );
193
194 BOOST_TEST_MESSAGE( "Created R1 component with stacked pins [1-5] and [6,7,9-11]" );
195
196 // Log all nets for the component
197 BOOST_TEST_MESSAGE( "R1 component nets:" );
198 for( unsigned i = 0; i < component.GetNetCount(); i++ )
199 {
200 const COMPONENT_NET& net = component.GetNet( i );
201 BOOST_TEST_MESSAGE( " Pin: " + net.GetPinName() + " -> Net: " + net.GetNetName() );
202 }
203
204 // Test individual pin lookups
205 // Pins 1-5 should be found (they're in the [1-5] stacked group)
206 for( int pin = 1; pin <= 5; pin++ )
207 {
208 wxString pinStr = wxString::Format( wxT( "%d" ), pin );
209 const COMPONENT_NET& net = component.GetNet( pinStr );
210
212 "Pin " + pinStr + " should be found in stacked group [1-5]" );
213
214 if( net.IsValid() )
215 {
216 BOOST_CHECK_EQUAL( net.GetNetName(), wxString( "Net-(R1-Pad1)" ) );
217 BOOST_TEST_MESSAGE( "Pin " + pinStr + " found with net: " + net.GetNetName() );
218 }
219 else
220 {
221 BOOST_TEST_MESSAGE( "Pin " + pinStr + " NOT found (should be in [1-5])" );
222 }
223 }
224
225 // Pins 6,7,9,10,11 should be found (they're in the [6,7,9-11] stacked group)
226 std::vector<int> groupTwoPins = { 6, 7, 9, 10, 11 };
227 for( int pin : groupTwoPins )
228 {
229 wxString pinStr = wxString::Format( wxT( "%d" ), pin );
230 const COMPONENT_NET& net = component.GetNet( pinStr );
231
233 "Pin " + pinStr + " should be found in stacked group [6,7,9-11]" );
234
235 if( net.IsValid() )
236 {
237 BOOST_CHECK_EQUAL( net.GetNetName(), wxString( "Net-(R1-Pad6)" ) );
238 BOOST_TEST_MESSAGE( "Pin " + pinStr + " found with net: " + net.GetNetName() );
239 }
240 else
241 {
242 BOOST_TEST_MESSAGE( "Pin " + pinStr + " NOT found (should be in [6,7,9-11])" );
243 }
244 }
245
246 // Pin 8 should NOT be found (it's not in either stacked group)
247 const COMPONENT_NET& net8 = component.GetNet( wxT( "8" ) );
249 "Pin 8 should NOT be found (not in any stacked group)" );
250
251 if( net8.IsValid() )
252 {
253 BOOST_TEST_MESSAGE( "Pin 8 unexpectedly found with net: " + net8.GetNetName() );
254 }
255 else
256 {
257 BOOST_TEST_MESSAGE( "Pin 8 correctly NOT found (expected behavior)" );
258 }
259}
260
261
Used to store the component pin name to net name (and pin function) associations stored in a netlist.
const wxString & GetNetName() const
const wxString & GetPinName() const
Store all of the related component 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:45
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
std::string path
KIBIS_PIN * pin
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_TEST_MESSAGE("\n=== Real-World Polygon PIP Benchmark ===\n"<< formatTable(table))
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")