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