KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_return_path_per_segment.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
20#include <boost/test/unit_test.hpp>
21
23
24#include <filesystem>
25#include <fstream>
26
27#include <board.h>
29#include <drc/drc_engine.h>
30#include <drc/drc_item.h>
31#include <netinfo.h>
32#include <pcb_marker.h>
34
35
36// Trunk on F.Cu from x=0..30 at y=0. B.Cu zone covers only x=0..15. Per-segment
37// check should report exactly one return-path break, anchored at the
38// uncovered run (around x=22.5).
39static const char* PARTIAL_PCB = "net_chains/return_path_partial.kicad_pcb";
40
41
42// Trunk fully off-zone: a single track from (0,0) to (30,0) with a B.Cu
43// zone only at x=40..50 — no overlap. Expect exactly one marker (covering
44// the whole track with no zone overlap).
45static const char* FULLY_UNSHADOWED_PCB = "net_chains/return_path_unshadowed.kicad_pcb";
46
47
48static const char* DRU_TEXT = R"((version 1)
49(rule "ReturnPath"
50 (condition "A.NetClass == 'Default'")
51 (constraint length (min 0mm) (max 200mm))
52 (constraint return_path (layer "B.Cu"))
53)
54)";
55
56
57namespace
58{
59size_t runReturnPathDrc( const char* aBoardFile, const wxString& aChainName,
60 const wxString& aChainTag,
61 const std::string& aSubdir )
62{
63 namespace fs = std::filesystem;
64 fs::path tmpDir = fs::temp_directory_path() / aSubdir;
65 fs::create_directories( tmpDir );
66 fs::path druPath = tmpDir / "ret.kicad_dru";
67
68 {
69 std::ofstream out( druPath );
70 out << DRU_TEXT;
71 }
72
73 PCB_IO_KICAD_SEXPR plugin;
74 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
75 plugin.LoadBoard( KI_TEST::GetPcbnewTestDataDir() + aBoardFile, board.get() );
76 board->BuildConnectivity();
77
78 NETINFO_ITEM* sig = board->FindNet( aChainName );
79 BOOST_REQUIRE( sig );
80 sig->SetNetChain( aChainTag );
81
82 BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings();
83
84 auto drcEngine = std::make_shared<DRC_ENGINE>( board.get(), &bds );
85 wxFileName ruleFile( druPath.string() );
86 drcEngine->InitEngine( ruleFile );
87 bds.m_DRCEngine = drcEngine;
88
96
97 size_t markerCount = 0;
98
99 drcEngine->SetViolationHandler(
100 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I&, int,
101 const std::function<void( PCB_MARKER* )>& )
102 {
103 if( aItem->GetErrorCode() == DRCE_NET_CHAIN_RETURN_PATH_BREAK )
104 markerCount++;
105 } );
106
107 drcEngine->RunTests( EDA_UNITS::MM, true, false );
108
109 fs::remove( druPath );
110
111 return markerCount;
112}
113}
114
115
116BOOST_AUTO_TEST_SUITE( DRCReturnPathPerSegment )
117
118
119BOOST_AUTO_TEST_CASE( PartiallyShadowedTrunkReportsOneMarker )
120{
121 size_t n = runReturnPathDrc( PARTIAL_PCB, wxS( "/CHAIN_PARTIAL" ),
122 wxS( "PARTIAL" ),
123 "kicad_drc_ret_partial" );
124 BOOST_CHECK_EQUAL( n, 1u );
125}
126
127
128BOOST_AUTO_TEST_CASE( FullyUnshadowedTrunkReportsOneMarker )
129{
130 size_t n = runReturnPathDrc( FULLY_UNSHADOWED_PCB, wxS( "/CHAIN_FULL" ),
131 wxS( "FULL" ),
132 "kicad_drc_ret_full" );
133 BOOST_CHECK_EQUAL( n, 1u );
134}
135
136
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
Handle the data for a net.
Definition netinfo.h:46
void SetNetChain(const wxString &aNetChain)
Definition netinfo.h:113
A #PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.
BOARD * LoadBoard(const wxString &aFileName, BOARD *aAppendToMe, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr) override
Load information from some input file format that this PCB_IO implementation knows about into either ...
@ DRCE_UNCONNECTED_ITEMS
Definition drc_item.h:37
@ DRCE_LIB_FOOTPRINT_ISSUES
Definition drc_item.h:80
@ DRCE_INVALID_OUTLINE
Definition drc_item.h:70
@ DRCE_DRILL_OUT_OF_RANGE
Definition drc_item.h:58
@ DRCE_NET_CHAIN_RETURN_PATH_BREAK
Definition drc_item.h:104
@ DRCE_DANGLING_VIA
Definition drc_item.h:48
@ DRCE_LIB_FOOTPRINT_MISMATCH
Definition drc_item.h:81
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_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
static const char * DRU_TEXT
static const char * FULLY_UNSHADOWED_PCB
static const char * PARTIAL_PCB
BOOST_AUTO_TEST_CASE(PartiallyShadowedTrunkReportsOneMarker)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683