KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_issue23868.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 2
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 here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
26
27#include <functional>
28#include <memory>
29#include <utility>
30#include <vector>
31
32#include <board.h>
34#include <board_loader.h>
35#include <drc/drc_engine.h>
36#include <drc/drc_item.h>
37#include <drc/drc_rule.h>
38#include <pcb_io/pcb_io_mgr.h>
39#include <project.h>
41#include <wx/filename.h>
42
43
45{
47
49 {
50 wxFileName projectFile( wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir() )
51 + "issue23868/issue23868.kicad_pro" );
52
53 m_settingsManager.LoadProject( projectFile.GetFullPath() );
54
55 PROJECT* project = m_settingsManager.GetProject( projectFile.GetFullPath() );
56 BOOST_REQUIRE_MESSAGE( project, "Could not load project" );
57 return project;
58 }
59
60 wxString boardPath() const
61 {
62 return wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir() )
63 + "issue23868/issue23868.kicad_pcb";
64 }
65};
66
67
68// Regression test for https://gitlab.com/kicad/code/kicad/-/issues/23868
69//
70// Length-domain DRC rules expressed in propagation delay (e.g. "min 85ps") would spuriously fire
71// when run through kicad-cli pcb drc because BOARD_LOADER::Load skipped the tuning-profile cache
72// rebuild that PCB_EDIT_FRAME::OpenProjectFiles performs. Without the cache, the matched-length
73// provider sees every track's propagation delay as 0 ps and reports it as below the rule minimum.
74//
75// IMPORTANT: this test must use BOARD_LOADER::Load directly, NOT KI_TEST::LoadBoard.
76// KI_TEST::LoadBoard calls SynchronizeTuningProfileProperties itself, which would mask the bug.
77BOOST_FIXTURE_TEST_CASE( DRCIssue23868PropagationDelayCacheAfterLoad, DRC_ISSUE_23868_FIXTURE )
78{
79 PROJECT* project = loadProject();
80
81 std::unique_ptr<BOARD> board = BOARD_LOADER::Load( boardPath(), PCB_IO_MGR::KICAD_SEXP,
82 project );
83
84 BOOST_REQUIRE( board );
85
86 BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings();
87
89 BOOST_REQUIRE_MESSAGE( bds.m_DRCEngine->RulesValid(),
90 "BOARD_LOADER did not parse the .kicad_dru file" );
91
92 for( int code = DRCE_FIRST; code <= DRCE_LAST; ++code )
94
96
97 std::vector<std::pair<wxString, wxString>> violations;
98
100 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I&, int,
101 const std::function<void( PCB_MARKER* )>& )
102 {
103 wxString ruleName;
104
105 if( aItem->GetViolatingRule() )
106 ruleName = aItem->GetViolatingRule()->m_Name;
107
108 violations.emplace_back( ruleName, aItem->GetErrorMessage( false ) );
109 } );
110
111 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
112
113 BOOST_TEST_MESSAGE( "Total violations: " << violations.size() );
114
115 for( const auto& [rule, msg] : violations )
116 BOOST_TEST_MESSAGE( "Violation rule='" << rule.ToStdString()
117 << "' msg='" << msg.ToStdString() << "'" );
118
119 // The reproduction board routes its DIFF_100 pairs to lengths whose propagation delay is well
120 // inside the 85 ps .. 1020 ps window defined by the diff_propagation_delay rule. The GUI
121 // confirms zero length-out-of-range violations. Before the fix, BOARD_LOADER::Load returned a
122 // board whose tuning-profile cache was empty, so every routed pair reported 0 ps and tripped
123 // the min-length check.
124 for( const auto& [rule, msg] : violations )
125 {
126 BOOST_CHECK_MESSAGE( rule != wxT( "diff_propagation_delay" ),
127 "diff_propagation_delay reported a spurious violation: "
128 << msg.ToStdString() );
129 }
130}
General utilities for PCB file IO for QA programs.
Container for design settings for a BOARD object.
std::map< int, SEVERITY > m_DRCSeverities
std::shared_ptr< DRC_ENGINE > m_DRCEngine
static std::unique_ptr< BOARD > Load(const wxString &aFileName, PCB_IO_MGR::PCB_FILE_T aFormat, PROJECT *aProject, const OPTIONS &aOptions)
void RunTests(EDA_UNITS aUnits, bool aReportAllTrackErrors, bool aTestFootprints, BOARD_COMMIT *aCommit=nullptr)
Run the DRC tests.
void SetViolationHandler(DRC_VIOLATION_HANDLER aHandler)
Set an optional DRC violation handler (receives DRC_ITEMs and positions).
Definition drc_engine.h:168
bool RulesValid()
Definition drc_engine.h:278
@ KICAD_SEXP
S-expression Pcbnew file format.
Definition pcb_io_mgr.h:58
Container for project specific data.
Definition project.h:66
@ DRCE_FIRST
Definition drc_item.h:39
@ DRCE_LENGTH_OUT_OF_RANGE
Definition drc_item.h:104
@ DRCE_LAST
Definition drc_item.h:124
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
BOOST_FIXTURE_TEST_CASE(DRCIssue23868PropagationDelayCacheAfterLoad, DRC_ISSUE_23868_FIXTURE)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_TEST_MESSAGE("\n=== Real-World Polygon PIP Benchmark ===\n"<< formatTable(table))
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687