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, see <https://www.gnu.org/licenses/>.
18 */
19
22
23#include <functional>
24#include <memory>
25#include <utility>
26#include <vector>
27
28#include <board.h>
30#include <board_loader.h>
31#include <drc/drc_engine.h>
32#include <drc/drc_item.h>
33#include <drc/drc_rule.h>
34#include <pcb_io/pcb_io_mgr.h>
35#include <project.h>
37#include <wx/filename.h>
38
39
41{
43
45 {
46 wxFileName projectFile( wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir() )
47 + "issue23868/issue23868.kicad_pro" );
48
49 m_settingsManager.LoadProject( projectFile.GetFullPath() );
50
51 PROJECT* project = m_settingsManager.GetProject( projectFile.GetFullPath() );
52 BOOST_REQUIRE_MESSAGE( project, "Could not load project" );
53 return project;
54 }
55
56 wxString boardPath() const
57 {
58 return wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir() )
59 + "issue23868/issue23868.kicad_pcb";
60 }
61};
62
63
64// Regression test for https://gitlab.com/kicad/code/kicad/-/issues/23868
65//
66// Length-domain DRC rules expressed in propagation delay (e.g. "min 85ps") would spuriously fire
67// when run through kicad-cli pcb drc because BOARD_LOADER::Load skipped the tuning-profile cache
68// rebuild that PCB_EDIT_FRAME::OpenProjectFiles performs. Without the cache, the matched-length
69// provider sees every track's propagation delay as 0 ps and reports it as below the rule minimum.
70//
71// IMPORTANT: this test must use BOARD_LOADER::Load directly, NOT KI_TEST::LoadBoard.
72// KI_TEST::LoadBoard calls SynchronizeTuningProfileProperties itself, which would mask the bug.
73BOOST_FIXTURE_TEST_CASE( DRCIssue23868PropagationDelayCacheAfterLoad, DRC_ISSUE_23868_FIXTURE )
74{
75 PROJECT* project = loadProject();
76
77 std::unique_ptr<BOARD> board = BOARD_LOADER::Load( boardPath(), PCB_IO_MGR::KICAD_SEXP,
78 project );
79
80 BOOST_REQUIRE( board );
81
82 BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings();
83
85 BOOST_REQUIRE_MESSAGE( bds.m_DRCEngine->RulesValid(),
86 "BOARD_LOADER did not parse the .kicad_dru file" );
87
88 for( int code = DRCE_FIRST; code <= DRCE_LAST; ++code )
90
92
93 std::vector<std::pair<wxString, wxString>> violations;
94
96 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I&, int,
97 const std::function<void( PCB_MARKER* )>& )
98 {
99 wxString ruleName;
100
101 if( aItem->GetViolatingRule() )
102 ruleName = aItem->GetViolatingRule()->m_Name;
103
104 violations.emplace_back( ruleName, aItem->GetErrorMessage( false ) );
105 } );
106
107 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
108
109 BOOST_TEST_MESSAGE( "Total violations: " << violations.size() );
110
111 for( const auto& [rule, msg] : violations )
112 BOOST_TEST_MESSAGE( "Violation rule='" << rule.ToStdString()
113 << "' msg='" << msg.ToStdString() << "'" );
114
115 // The reproduction board routes its DIFF_100 pairs to lengths whose propagation delay is well
116 // inside the 85 ps .. 1020 ps window defined by the diff_propagation_delay rule. The GUI
117 // confirms zero length-out-of-range violations. Before the fix, BOARD_LOADER::Load returned a
118 // board whose tuning-profile cache was empty, so every routed pair reported 0 ps and tripped
119 // the min-length check.
120 for( const auto& [rule, msg] : violations )
121 {
122 BOOST_CHECK_MESSAGE( rule != wxT( "diff_propagation_delay" ),
123 "diff_propagation_delay reported a spurious violation: "
124 << msg.ToStdString() );
125 }
126}
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:164
bool RulesValid()
Definition drc_engine.h:274
@ KICAD_SEXP
S-expression Pcbnew file format.
Definition pcb_io_mgr.h:54
Container for project specific data.
Definition project.h:62
@ DRCE_FIRST
Definition drc_item.h:35
@ DRCE_LENGTH_OUT_OF_RANGE
Definition drc_item.h:101
@ DRCE_LAST
Definition drc_item.h:121
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:683