KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_erc_rule_areas.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 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 <connection_graph.h>
25#include <schematic.h>
26#include <erc/erc_settings.h>
27#include <erc/erc.h>
28#include <erc/erc_report.h>
29#include <sch_rule_area.h>
31#include <locale_io.h>
32
33
35{
36 ERC_REGRESSION_TEST_FIXTURE() : m_settingsManager( true /* headless */ ) {}
37
39 std::unique_ptr<SCHEMATIC> m_schematic;
40};
41
42
43BOOST_FIXTURE_TEST_CASE( ERCRuleAreaNetClasseDirectives, ERC_REGRESSION_TEST_FIXTURE )
44{
46
47 // Check for Errors when using rule area netclass directives
48 std::vector<std::pair<wxString, int>> tests = { { "RuleAreaOneNetclassDirective", 0 },
49 { "RuleAreaTwoNetclassDirectives", 1 },
50 { "RuleAreaThreeNetclassDirectives", 2 },
51 { "RuleAreaNetclassConflictOnWire_1", 1 },
52 { "RuleAreaNetclassConflictOnWire_2", 1 } };
53
54 for( const std::pair<wxString, int>& test : tests )
55 {
56 KI_TEST::LoadSchematic( m_settingsManager, test.first, m_schematic );
57
58 ERC_SETTINGS& settings = m_schematic->ErcSettings();
59 SHEETLIST_ERC_ITEMS_PROVIDER errors( m_schematic.get() );
60
61 // Skip the "Modified symbol" warning
64
65 // Configure the rules under test
67
68 std::unordered_set<SCH_SCREEN*> allScreens;
69 SCH_SCREENS screens( m_schematic->Root() );
71
72 for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr;
73 screen = screens.GetNext() )
74 allScreens.insert( screen );
75
76 SCH_RULE_AREA::UpdateRuleAreasInScreens( allScreens, nullptr );
77 m_schematic->ConnectionGraph()->Recalculate( m_schematic->GetSheets(), true );
78 m_schematic->ConnectionGraph()->RunERC();
79
81
82 ERC_REPORT reportWriter( m_schematic.get(), EDA_UNITS::MILLIMETRES );
83
84 BOOST_CHECK_MESSAGE( errors.GetCount() == test.second,
85 "Expected " << test.second << " errors in " << test.first.ToStdString()
86 << " but got " << errors.GetCount() << "\n"
87 << reportWriter.GetTextReport() );
88 }
89}
90
91
93{
95
96 // Check for Errors when using rule area netclass directives
97 std::vector<std::pair<wxString, int>> tests = { { "RuleAreaNoOverlap", 0 },
98 { "RuleAreaOneOverlap", 1 },
99 { "RuleAreaOneOverlapTwice", 2 },
100 { "RuleAreaTwoOverlaps", 2 } };
101
102 for( const std::pair<wxString, int>& test : tests )
103 {
104 KI_TEST::LoadSchematic( m_settingsManager, test.first, m_schematic );
105
106 ERC_SETTINGS& settings = m_schematic->ErcSettings();
107 SHEETLIST_ERC_ITEMS_PROVIDER errors( m_schematic.get() );
108
109 // Skip the "Modified symbol" warning
112
113 // Configure the rules under test
115
116 std::unordered_set<SCH_SCREEN*> allScreens;
117 SCH_SCREENS screens( m_schematic->Root() );
118 screens.BuildClientSheetPathList();
119
120 for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr;
121 screen = screens.GetNext() )
122 allScreens.insert( screen );
123
124 SCH_RULE_AREA::UpdateRuleAreasInScreens( allScreens, nullptr );
125 m_schematic->ConnectionGraph()->Recalculate( m_schematic->GetSheets(), true );
126
127 ERC_TESTER tester( m_schematic.get() );
128 tester.RunRuleAreaERC();
129
131
132 ERC_REPORT reportWriter( m_schematic.get(), EDA_UNITS::MILLIMETRES );
133
134 BOOST_CHECK_MESSAGE( errors.GetCount() == test.second,
135 "Expected " << test.second << " errors in " << test.first.ToStdString()
136 << " but got " << errors.GetCount() << "\n"
137 << reportWriter.GetTextReport() );
138 }
139}
wxString GetTextReport()
Returns the ERC report in "text" (human readable) format.
Definition: erc_report.cpp:44
Container for ERC settings.
Definition: erc_settings.h:121
std::map< int, SEVERITY > m_ERCSeverities
Definition: erc_settings.h:180
Definition: erc.h:50
int RunRuleAreaERC()
Tests for rule area ERC issues.
Definition: erc.cpp:1287
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:49
static std::vector< std::pair< SCH_RULE_AREA *, SCH_SCREEN * > > UpdateRuleAreasInScreens(std::unordered_set< SCH_SCREEN * > &screens, KIGFX::SCH_VIEW *view)
Updates all rule area connectvity / caches in the given sheet paths.
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:704
SCH_SCREEN * GetNext()
SCH_SCREEN * GetFirst()
void BuildClientSheetPathList()
built the list of sheet paths sharing a screen for each screen in use
An implementation of the RC_ITEM_LIST interface which uses the global SHEETLIST to fulfill the contra...
Definition: erc_settings.h:199
int GetCount(int aSeverity=-1) const override
void SetSeverities(int aSeverities) override
@ ERCE_OVERLAPPING_RULE_AREAS
Rule areas are overlapping.
Definition: erc_settings.h:70
@ ERCE_NETCLASS_CONFLICT
Multiple labels assign different netclasses to same net.
Definition: erc_settings.h:69
@ ERCE_LIB_SYMBOL_MISMATCH
Symbol doesn't match copy in library.
Definition: erc_settings.h:77
@ ERCE_LIB_SYMBOL_ISSUES
Symbol not found in active libraries.
Definition: erc_settings.h:76
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(ERCRuleAreaNetClasseDirectives, ERC_REGRESSION_TEST_FIXTURE)