KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_erc_marker_deduplication.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 <base_units.h>
24#include <connection_graph.h>
25#include <schematic.h>
26#include <sch_marker.h>
27#include <erc/erc_settings.h>
28#include <erc/erc.h>
29#include <erc/erc_report.h>
30#include <erc/erc_item.h>
32#include <locale_io.h>
33
34
43
44
45// Regression test for issue 23672. SHEETLIST_ERC_ITEMS_PROVIDER::visitMarkers
46// collects markers into a std::set keyed by marker position. The position
47// comparator formerly fell through to VECTOR2::operator<, which compared by
48// squared magnitude. Two markers at mirrored coordinates (a, b) and (b, a)
49// have the same squared magnitude and were therefore treated as duplicates,
50// silently dropping one marker. The multinetclasses schematic triggers this
51// exact collision: an isolated_pin_label at (121.92, 77.47) and a
52// pin_not_connected at (77.47, 121.92) share squared magnitude 21394.9153.
53BOOST_FIXTURE_TEST_CASE( ERCMarkerDeduplicationMultinetclasses, ERC_MARKER_DEDUP_FIXTURE )
54{
56
57 KI_TEST::LoadSchematic( m_settingsManager, wxS( "netlists/multinetclasses/multinetclasses" ),
58 m_schematic );
59
60 ERC_SETTINGS& settings = m_schematic->ErcSettings();
61 SHEETLIST_ERC_ITEMS_PROVIDER errors( m_schematic.get() );
62
65
66 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
67 m_schematic->ConnectionGraph()->Recalculate( sheets, true );
68 m_schematic->ConnectionGraph()->RunERC();
69
70 ERC_TESTER tester( m_schematic.get() );
73 tester.TestNoConnectPins();
74 tester.TestPinToPin();
75 tester.TestSimilarLabels();
76
78
79 // The mirrored positions that triggered the squared-magnitude collision.
80 const VECTOR2I expectedPinNotConnected( schIUScale.mmToIU( 77.47 ),
81 schIUScale.mmToIU( 121.92 ) );
82 const VECTOR2I expectedIsolatedLabel( schIUScale.mmToIU( 121.92 ),
83 schIUScale.mmToIU( 77.47 ) );
84
85 int pinNotConnected = 0;
86 int isolatedPinLabel = 0;
87 bool sawExpectedPinNotConnected = false;
88 bool sawExpectedIsolatedLabel = false;
89
90 for( int ii = 0; ii < errors.GetCount(); ++ii )
91 {
92 std::shared_ptr<RC_ITEM> item = errors.GetItem( ii );
93 SCH_MARKER* marker = static_cast<SCH_MARKER*>( item->GetParent() );
94 int errorCode = item->GetErrorCode();
95
96 BOOST_REQUIRE( marker );
97
98 if( errorCode == ERCE_PIN_NOT_CONNECTED )
99 {
100 pinNotConnected++;
101 sawExpectedPinNotConnected |= marker->GetPosition() == expectedPinNotConnected;
102 }
103 else if( errorCode == ERCE_LABEL_SINGLE_PIN )
104 {
105 isolatedPinLabel++;
106 sawExpectedIsolatedLabel |= marker->GetPosition() == expectedIsolatedLabel;
107 }
108 }
109
110 ERC_REPORT reportWriter( m_schematic.get(), EDA_UNITS::MM );
111
112 // Before the fix, one pin_not_connected marker (R7 Pad1) was dropped
113 // because its position collided with an isolated_pin_label marker.
114 BOOST_CHECK_MESSAGE( pinNotConnected == 12,
115 "Expected 12 pin_not_connected violations but got " << pinNotConnected
116 << "\n"
117 << reportWriter.GetTextReport() );
118
119 BOOST_CHECK_MESSAGE( isolatedPinLabel >= 1,
120 "Expected at least 1 isolated_pin_label violation but got "
121 << isolatedPinLabel << "\n"
122 << reportWriter.GetTextReport() );
123
124 // The two specific markers from the bug report must both be present.
125 BOOST_CHECK_MESSAGE( sawExpectedPinNotConnected,
126 "Expected pin_not_connected marker at (77.47, 121.92) mm was missing\n"
127 << reportWriter.GetTextReport() );
128
129 BOOST_CHECK_MESSAGE( sawExpectedIsolatedLabel,
130 "Expected isolated_pin_label marker at (121.92, 77.47) mm was missing\n"
131 << reportWriter.GetTextReport() );
132}
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:123
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
int TestPinToPin()
Checks the full netlist against the pin-to-pin connectivity requirements.
Definition erc.cpp:980
int TestSimilarLabels()
Checks for labels that differ only in capitalization.
Definition erc.cpp:1747
int TestMultUnitPinConflicts()
Checks if shared pins on multi-unit symbols have been connected to different nets.
Definition erc.cpp:1426
int TestNoConnectPins()
In KiCad 5 and earlier, you could connect stuff up to pins with NC electrical type.
Definition erc.cpp:889
int TestMultiunitFootprints()
Test if all units of each multiunit symbol have the same footprint assigned.
Definition erc.cpp:507
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
VECTOR2I GetPosition() const override
Definition sch_marker.h:98
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
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.
@ ERCE_LABEL_SINGLE_PIN
A label is connected only to a single pin.
@ ERCE_PIN_NOT_CONNECTED
Pin not connected and not no connect symbol.
@ ERCE_LIB_SYMBOL_MISMATCH
Symbol doesn't match copy in library.
@ ERCE_LIB_SYMBOL_ISSUES
Symbol not found in active libraries.
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
@ 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(ERCMarkerDeduplicationMultinetclasses, ERC_MARKER_DEDUP_FIXTURE)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683