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 <math/vector2d.h>
26#include <pcb_marker.h>
27#include <drc/drc_engine.h>
28#include <drc/drc_item.h>
29
30
31BOOST_AUTO_TEST_SUITE( DRCErrorLimit )
32
33
34// ReportViolation enforces the per-code cap under its own lock, so a code can never report more
35// violations than its limit no matter how many times (or from how many threads) it is hit. With
36// the cap check removed the handler fires on every call and the count runs past the limit.
38{
39 DRC_ENGINE engine;
40
41 std::atomic<int> reported( 0 );
42
44 [&]( const std::shared_ptr<DRC_ITEM>&, const VECTOR2I&, int,
45 const std::function<void( PCB_MARKER* )>& )
46 {
47 reported.fetch_add( 1 );
48 } );
49
50 const int code = DRCE_ASSERTION_FAILURE;
51
52 auto emit =
53 [&]()
54 {
55 engine.ReportViolation( DRC_ITEM::Create( code ), VECTOR2I(), 0,
56 []( PCB_MARKER* ) {} );
57 };
58
59 while( !engine.IsErrorLimitExceeded( code ) )
60 emit();
61
62 const int capped = reported.load();
63
64 BOOST_TEST( capped > 0 );
65
66 for( int ii = 0; ii < 500; ++ii )
67 emit();
68
69 BOOST_TEST( reported.load() == capped );
70}
71
72
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 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:417
@ DRCE_ASSERTION_FAILURE
Definition drc_item.h:86
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
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