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, you may find one at
18 * http://www.gnu.org/licenses/
19 */
20
23
24#include <base_units.h>
25#include <connection_graph.h>
26#include <schematic.h>
27#include <sch_marker.h>
28#include <erc/erc_settings.h>
29#include <erc/erc.h>
30#include <erc/erc_report.h>
31#include <erc/erc_item.h>
33#include <locale_io.h>
34
35
44
45
46// Regression test for issue 23672. SHEETLIST_ERC_ITEMS_PROVIDER::visitMarkers
47// collects markers into a std::set keyed by marker position. The position
48// comparator formerly fell through to VECTOR2::operator<, which compared by
49// squared magnitude. Two markers at mirrored coordinates (a, b) and (b, a)
50// have the same squared magnitude and were therefore treated as duplicates,
51// silently dropping one marker. The multinetclasses schematic triggers this
52// exact collision: an isolated_pin_label at (121.92, 77.47) and a
53// pin_not_connected at (77.47, 121.92) share squared magnitude 21394.9153.
54BOOST_FIXTURE_TEST_CASE( ERCMarkerDeduplicationMultinetclasses, ERC_MARKER_DEDUP_FIXTURE )
55{
57
58 KI_TEST::LoadSchematic( m_settingsManager, wxS( "netlists/multinetclasses/multinetclasses" ),
59 m_schematic );
60
61 ERC_SETTINGS& settings = m_schematic->ErcSettings();
62 SHEETLIST_ERC_ITEMS_PROVIDER errors( m_schematic.get() );
63
66
67 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
68 m_schematic->ConnectionGraph()->Recalculate( sheets, true );
69 m_schematic->ConnectionGraph()->RunERC();
70
71 ERC_TESTER tester( m_schematic.get() );
74 tester.TestNoConnectPins();
75 tester.TestPinToPin();
76 tester.TestSimilarLabels();
77
79
80 // The mirrored positions that triggered the squared-magnitude collision.
81 const VECTOR2I expectedPinNotConnected( schIUScale.mmToIU( 77.47 ),
82 schIUScale.mmToIU( 121.92 ) );
83 const VECTOR2I expectedIsolatedLabel( schIUScale.mmToIU( 121.92 ),
84 schIUScale.mmToIU( 77.47 ) );
85
86 int pinNotConnected = 0;
87 int isolatedPinLabel = 0;
88 bool sawExpectedPinNotConnected = false;
89 bool sawExpectedIsolatedLabel = false;
90
91 for( int ii = 0; ii < errors.GetCount(); ++ii )
92 {
93 std::shared_ptr<RC_ITEM> item = errors.GetItem( ii );
94 SCH_MARKER* marker = static_cast<SCH_MARKER*>( item->GetParent() );
95 int errorCode = item->GetErrorCode();
96
97 BOOST_REQUIRE( marker );
98
99 if( errorCode == ERCE_PIN_NOT_CONNECTED )
100 {
101 pinNotConnected++;
102 sawExpectedPinNotConnected |= marker->GetPosition() == expectedPinNotConnected;
103 }
104 else if( errorCode == ERCE_LABEL_SINGLE_PIN )
105 {
106 isolatedPinLabel++;
107 sawExpectedIsolatedLabel |= marker->GetPosition() == expectedIsolatedLabel;
108 }
109 }
110
111 ERC_REPORT reportWriter( m_schematic.get(), EDA_UNITS::MM );
112
113 // Before the fix, one pin_not_connected marker (R7 Pad1) was dropped
114 // because its position collided with an isolated_pin_label marker.
115 BOOST_CHECK_MESSAGE( pinNotConnected == 12,
116 "Expected 12 pin_not_connected violations but got " << pinNotConnected
117 << "\n"
118 << reportWriter.GetTextReport() );
119
120 BOOST_CHECK_MESSAGE( isolatedPinLabel >= 1,
121 "Expected at least 1 isolated_pin_label violation but got "
122 << isolatedPinLabel << "\n"
123 << reportWriter.GetTextReport() );
124
125 // The two specific markers from the bug report must both be present.
126 BOOST_CHECK_MESSAGE( sawExpectedPinNotConnected,
127 "Expected pin_not_connected marker at (77.47, 121.92) mm was missing\n"
128 << reportWriter.GetTextReport() );
129
130 BOOST_CHECK_MESSAGE( sawExpectedIsolatedLabel,
131 "Expected isolated_pin_label marker at (121.92, 77.47) mm was missing\n"
132 << reportWriter.GetTextReport() );
133}
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:127
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:983
int TestSimilarLabels()
Checks for labels that differ only in capitalization.
Definition erc.cpp:1561
int TestMultUnitPinConflicts()
Checks if shared pins on multi-unit symbols have been connected to different nets.
Definition erc.cpp:1243
int TestNoConnectPins()
In KiCad 5 and earlier, you could connect stuff up to pins with NC electrical type.
Definition erc.cpp:892
int TestMultiunitFootprints()
Test if all units of each multiunit symbol have the same footprint assigned.
Definition erc.cpp:510
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:41
VECTOR2I GetPosition() const override
Definition sch_marker.h:102
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:687