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
78 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
79 m_schematic->ConnectionGraph()->Recalculate( sheets, true );
80 m_schematic->ConnectionGraph()->RunERC();
81
83
84 ERC_REPORT reportWriter( m_schematic.get(), EDA_UNITS::MILLIMETRES );
85
86 BOOST_CHECK_MESSAGE( errors.GetCount() == test.second,
87 "Expected " << test.second << " errors in " << test.first.ToStdString()
88 << " but got " << errors.GetCount() << "\n"
89 << reportWriter.GetTextReport() );
90 }
91}
92
93
95{
97
98 // Check for Errors when using rule area netclass directives
99 std::vector<std::pair<wxString, int>> tests = { { "RuleAreaNoOverlap", 0 },
100 { "RuleAreaOneOverlap", 1 },
101 { "RuleAreaOneOverlapTwice", 2 },
102 { "RuleAreaTwoOverlaps", 2 } };
103
104 for( const std::pair<wxString, int>& test : tests )
105 {
106 KI_TEST::LoadSchematic( m_settingsManager, test.first, m_schematic );
107
108 ERC_SETTINGS& settings = m_schematic->ErcSettings();
109 SHEETLIST_ERC_ITEMS_PROVIDER errors( m_schematic.get() );
110
111 // Skip the "Modified symbol" warning
114
115 // Configure the rules under test
117
118 std::unordered_set<SCH_SCREEN*> allScreens;
119 SCH_SCREENS screens( m_schematic->Root() );
120 screens.BuildClientSheetPathList();
121
122 for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
123 allScreens.insert( screen );
124
125 SCH_RULE_AREA::UpdateRuleAreasInScreens( allScreens, nullptr );
126
127 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
128 m_schematic->ConnectionGraph()->Recalculate( sheets, true );
129
130 ERC_TESTER tester( m_schematic.get() );
131 tester.RunRuleAreaERC();
132
134
135 ERC_REPORT reportWriter( m_schematic.get(), EDA_UNITS::MILLIMETRES );
136
137 BOOST_CHECK_MESSAGE( errors.GetCount() == test.second,
138 "Expected " << test.second << " errors in " << test.first.ToStdString()
139 << " but got " << errors.GetCount() << "\n"
140 << reportWriter.GetTextReport() );
141 }
142}
wxString GetTextReport()
Returns the ERC report in "text" (human readable) format.
Definition: erc_report.cpp:44
Container for ERC settings.
Definition: erc_settings.h:122
std::map< int, SEVERITY > m_ERCSeverities
Definition: erc_settings.h:181
Definition: erc.h:52
int RunRuleAreaERC()
Tests for rule area ERC issues.
Definition: erc.cpp:1296
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:703
SCH_SCREEN * GetNext()
SCH_SCREEN * GetFirst()
void BuildClientSheetPathList()
built the list of sheet paths sharing a screen for each screen in use
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...
Definition: erc_settings.h:200
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)