KiCad PCB EDA Suite
test_netlists.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) 2020-2021 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#include "eeschema_test_utils.h"
22
23
25{
26public:
27 void CompareNetlists() override
28 {
29 NETLIST golden;
31
32 {
33 std::unique_ptr<NETLIST_READER> netlistReader( NETLIST_READER::GetNetlistReader(
34 &golden, getNetlistFileName(), wxEmptyString ) );
35
36 BOOST_REQUIRE_NO_THROW( netlistReader->LoadNetlist() );
37 }
38
39 {
40 std::unique_ptr<NETLIST_READER> netlistReader( NETLIST_READER::GetNetlistReader(
41 &test, getNetlistFileName( true ), wxEmptyString ) );
42
43 BOOST_REQUIRE_NO_THROW( netlistReader->LoadNetlist() );
44 }
45
46 // Number of components should match
47 BOOST_REQUIRE_EQUAL( golden.GetCount(), test.GetCount() );
48
49 for( unsigned i = 0; i < golden.GetCount(); i++ )
50 {
51 COMPONENT* goldenComp = golden.GetComponent( i );
52 COMPONENT* refComp = test.GetComponentByReference( goldenComp->GetReference() );
53
54 // Retrieval by reference
55 BOOST_REQUIRE_NE( refComp, nullptr );
56
57 // Retrieval by KIID
58 KIID_PATH path = goldenComp->GetPath();
59
60 BOOST_REQUIRE( !goldenComp->GetKIIDs().empty() );
61
62 path.push_back( goldenComp->GetKIIDs().front() );
63
64 COMPONENT* pathComp = test.GetComponentByPath( path );
65 BOOST_REQUIRE_NE( pathComp, nullptr );
66
67 // We should have found the same component
68 BOOST_REQUIRE_EQUAL( refComp->GetReference(), pathComp->GetReference() );
69
70 // And that component should have the same number of attached nets
71 BOOST_REQUIRE_EQUAL( goldenComp->GetNetCount(), refComp->GetNetCount() );
72
73 for( unsigned net = 0; net < goldenComp->GetNetCount(); net++ )
74 {
75 const COMPONENT_NET& goldenNet = goldenComp->GetNet( net );
76 const COMPONENT_NET& testNet = refComp->GetNet( net );
77
78 // The video test has a bunch of unconnected RESERVED pins which cause duplicate
79 // auto-generated netnames. The connectivity algo disambiguates these with "_n"
80 // suffixes, but since the algorithm is multi-threaded, which ones get which suffix
81 // is not deterministic. So skip these.
82 if( testNet.GetPinFunction().Contains( "RESERVED" ) )
83 continue;
84
85 // The two nets at the same index should be identical
86 BOOST_REQUIRE_EQUAL( goldenNet.GetNetName(), testNet.GetNetName() );
87 BOOST_REQUIRE_EQUAL( goldenNet.GetPinName(), testNet.GetPinName() );
88 }
89 }
90 }
91};
92
93
94BOOST_FIXTURE_TEST_SUITE( Netlists, TEST_NETLIST_EXPORTER_KICAD_FIXTURE )
95
96
98{
99 BOOST_CHECK_NE( m_pi, nullptr );
100}
101
102
103BOOST_AUTO_TEST_CASE( GlobalPromotion )
104{
105 doNetlistTest( "test_global_promotion" );
106}
107
108
109BOOST_AUTO_TEST_CASE( GlobalPromotion2 )
110{
111 doNetlistTest( "test_global_promotion_2" );
112}
113
114
116{
117 doNetlistTest( "video" );
118}
119
120
121BOOST_AUTO_TEST_CASE( ComplexHierarchy )
122{
123 doNetlistTest( "complex_hierarchy" );
124}
125
126
127BOOST_AUTO_TEST_CASE( WeakVectorBusDisambiguation )
128{
129 doNetlistTest( "weak_vector_bus_disambiguation" );
130}
131
132
133BOOST_AUTO_TEST_CASE( BusJunctions )
134{
135 doNetlistTest( "bus_junctions" );
136}
137
138
139BOOST_AUTO_TEST_CASE( HierRenaming )
140{
141 doNetlistTest( "test_hier_renaming" );
142}
143
144
146{
147 doNetlistTest( "noconnects" );
148}
149
150
151BOOST_AUTO_TEST_CASE( PrefixBusAlias )
152{
153 doNetlistTest( "prefix_bus_alias" );
154}
155
156
157BOOST_AUTO_TEST_CASE( GroupBusMatching )
158{
159 doNetlistTest( "group_bus_matching" );
160}
161
162
163BOOST_AUTO_TEST_CASE( TopLevelHierPins )
164{
165 doNetlistTest( "top_level_hier_pins" );
166}
167
168
170{
171 doNetlistTest( "bus_entries" );
172}
173
174BOOST_AUTO_TEST_SUITE_END()
Used to store the component pin name to net name (and pin function) associations stored in a netlist.
Definition: pcb_netlist.h:44
const wxString & GetNetName() const
Definition: pcb_netlist.h:58
const wxString & GetPinFunction() const
Definition: pcb_netlist.h:59
const wxString & GetPinName() const
Definition: pcb_netlist.h:57
Store all of the related footprint information found in a netlist.
Definition: pcb_netlist.h:85
const COMPONENT_NET & GetNet(unsigned aIndex) const
Definition: pcb_netlist.h:111
const KIID_PATH & GetPath() const
Definition: pcb_netlist.h:143
const wxString & GetReference() const
Definition: pcb_netlist.h:126
const std::vector< KIID > & GetKIIDs() const
Definition: pcb_netlist.h:145
unsigned GetNetCount() const
Definition: pcb_netlist.h:109
static NETLIST_READER * GetNetlistReader(NETLIST *aNetlist, const wxString &aNetlistFileName, const wxString &aCompFootprintFileName=wxEmptyString)
Attempt to determine the net list file type of aNetlistFileName and return the appropriate NETLIST_RE...
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
Definition: pcb_netlist.h:213
unsigned GetCount() const
Definition: pcb_netlist.h:234
COMPONENT * GetComponent(unsigned aIndex)
Return the COMPONENT at aIndex.
Definition: pcb_netlist.h:242
BOOST_AUTO_TEST_CASE(FindPlugin)