KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_error_limit.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
21
22#include <atomic>
23#include <functional>
24
25#include <board.h>
26#include <math/vector2d.h>
27#include <pcb_marker.h>
28#include <drc/drc_engine.h>
29#include <drc/drc_item.h>
30#include <drc/drc_rule.h>
31
32
33BOOST_AUTO_TEST_SUITE( DRCErrorLimit )
34
35
36// ReportViolation enforces the per-code cap under its own lock, so a code can never report more
37// violations than its limit no matter how many times (or from how many threads) it is hit. With
38// the cap check removed the handler fires on every call and the count runs past the limit.
40{
41 DRC_ENGINE engine;
42
43 std::atomic<int> reported( 0 );
44
46 [&]( const std::shared_ptr<DRC_ITEM>&, const VECTOR2I&, int,
47 const std::function<void( PCB_MARKER* )>& )
48 {
49 reported.fetch_add( 1 );
50 } );
51
52 const int code = DRCE_ASSERTION_FAILURE;
53
54 auto emit =
55 [&]()
56 {
57 engine.ReportViolation( DRC_ITEM::Create( code ), VECTOR2I(), 0,
58 []( PCB_MARKER* ) {} );
59 };
60
61 while( !engine.IsErrorLimitExceeded( code ) )
62 emit();
63
64 const int capped = reported.load();
65
66 BOOST_TEST( capped > 0 );
67
68 for( int ii = 0; ii < 500; ++ii )
69 emit();
70
71 BOOST_TEST( reported.load() == capped );
72}
73
74
75BOOST_AUTO_TEST_CASE( InitEngineResetsLastErrorCode )
76{
77 BOARD board;
78 DRC_ENGINE engine( &board, &board.GetDesignSettings() );
79
80 while( !engine.IsErrorLimitExceeded( DRCE_LAST ) )
81 {
83 []( PCB_MARKER* ) {} );
84 }
85
87
88 engine.InitEngine( std::make_shared<DRC_RULE>( wxT( "Reset limits" ) ) );
89
90 BOOST_CHECK( !engine.IsErrorLimitExceeded( DRCE_LAST ) );
91}
92
93
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:373
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition board.cpp:1158
Design Rule Checker object that performs all the DRC tests.
Definition drc_engine.h:129
void SetViolationHandler(DRC_VIOLATION_HANDLER aHandler)
Set an optional DRC violation handler (receives DRC_ITEMs and positions).
Definition drc_engine.h:164
bool IsErrorLimitExceeded(int error_code)
void InitEngine(const wxFileName &aRulePath)
Initialize the DRC engine.
void ReportViolation(const std::shared_ptr< DRC_ITEM > &aItem, const VECTOR2I &aPos, int aMarkerLayer, const std::function< void(PCB_MARKER *)> &aPathGenerator={})
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition drc_item.cpp:418
@ DRCE_ASSERTION_FAILURE
Definition drc_item.h:87
@ DRCE_LAST
Definition drc_item.h:123
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(CapIsExact)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST(netlist.find("R_G1 ARM_OUT1 DIE_B R='0.001 / ((SW_STATE)") !=std::string::npos)
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683