20#include <boost/test/unit_test.hpp>
49static const char*
BOARD_FILE =
"net_chains/stub_length.kicad_pcb";
54static const char*
DRU_TEXT = R
"KICAD((version 1)
57 (condition "A.NetClass == 'Default'")
58 (constraint stub_length (min 0mm) (max 5mm))
68 namespace fs = std::filesystem;
70 fs::path tmpDir = fs::temp_directory_path() /
"kicad_drc_stub_length";
71 fs::create_directories( tmpDir );
73 fs::path druPath = tmpDir /
"stub_length.kicad_dru";
76 std::ofstream druOut( druPath );
82 board->BuildConnectivity();
84 NETINFO_ITEM* netA = board->FindNet( wxS(
"/TRUNK_A" ) );
86 NETINFO_ITEM* netC = board->FindNet( wxS(
"/TRUNK_C" ) );
99 for(
FOOTPRINT* fp : board->Footprints() )
101 for(
PAD*
pad : fp->Pads() )
119 auto drcEngine = std::make_shared<DRC_ENGINE>( board.get(), &bds );
120 wxFileName ruleFile( druPath.string() );
121 drcEngine->InitEngine( ruleFile );
132 std::vector<wxString> stubMessages;
134 drcEngine->SetViolationHandler(
135 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I&,
int,
139 stubMessages.push_back( aItem->GetErrorMessage(
false ) );
144 auto matchesNet = [&](
const wxString& netName )
146 for(
const wxString& msg : stubMessages )
148 if( msg.Contains( wxString::Format( wxS(
"'%s'" ), netName ) ) )
155 bool aFlagged = matchesNet( netA->
GetNetname() );
156 bool bFlagged = matchesNet( netB->
GetNetname() );
157 bool cFlagged = matchesNet( netC->
GetNetname() );
159 BOOST_CHECK_MESSAGE( bFlagged,
160 "Intermediate stub net MID_B should fire stub_length violation" );
161 BOOST_CHECK_MESSAGE( !aFlagged,
162 "Trunk endpoint net TRUNK_A (owns terminal_pad_0) must not fire" );
163 BOOST_CHECK_MESSAGE( !cFlagged,
164 "Trunk endpoint net TRUNK_C (owns terminal_pad_1) must not fire" );
167 fs::remove( druPath, ec );
173 namespace fs = std::filesystem;
175 fs::path tmpDir = fs::temp_directory_path() /
"kicad_drc_stub_length";
176 fs::create_directories( tmpDir );
178 fs::path druPath = tmpDir /
"stub_length_2net.kicad_dru";
183 static const char* TWO_NET_BOARD_FILE =
"net_chains/stub_length_two_net.kicad_pcb";
185 static const char* TWO_NET_DRU = R
"KICAD((version 1)
188 (condition "A.NetClass == 'Default'")
189 (constraint stub_length (min 0mm) (max 5mm))
194 std::ofstream druOut( druPath );
195 druOut << TWO_NET_DRU;
200 board->BuildConnectivity();
214 for(
FOOTPRINT* fp : board->Footprints() )
216 for(
PAD*
pad : fp->Pads() )
234 auto drcEngine = std::make_shared<DRC_ENGINE>( board.get(), &bds );
235 wxFileName ruleFile( druPath.string() );
236 drcEngine->InitEngine( ruleFile );
249 drcEngine->SetViolationHandler(
250 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I&,
int,
259 BOOST_CHECK_MESSAGE( stubCount == 0,
260 "Two-net chain with both ends owning terminal pads must not "
261 "fire any stub_length violation, got "
265 fs::remove( druPath, ec );
271 namespace fs = std::filesystem;
273 fs::path tmpDir = fs::temp_directory_path() /
"kicad_drc_stub_length";
274 fs::create_directories( tmpDir );
276 fs::path druPath = tmpDir /
"stub_length_pad_to_die.kicad_dru";
282 static const char* PAD_TO_DIE_BOARD_FILE =
"net_chains/stub_length_pad_to_die.kicad_pcb";
284 static const char* PAD_TO_DIE_DRU = R
"KICAD((version 1)
287 (condition "A.NetClass == 'Default'")
288 (constraint stub_length (min 0mm) (max 5mm))
293 std::ofstream druOut( druPath );
294 druOut << PAD_TO_DIE_DRU;
300 NETINFO_ITEM* netA = board->FindNet( wxS( "/TRUNK_A" ) );
302 NETINFO_ITEM* netC = board->FindNet( wxS(
"/TRUNK_C" ) );
316 for(
FOOTPRINT* fp : board->Footprints() )
318 for(
PAD*
pad : fp->Pads() )
342 board->BuildConnectivity();
346 auto drcEngine = std::make_shared<DRC_ENGINE>( board.get(), &bds );
347 wxFileName ruleFile( druPath.string() );
348 drcEngine->InitEngine( ruleFile );
359 std::vector<wxString> stubMessages;
361 drcEngine->SetViolationHandler(
362 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I&,
int,
366 stubMessages.push_back( aItem->GetErrorMessage(
false ) );
371 auto matchesNet = [&](
const wxString& netName )
373 for(
const wxString& msg : stubMessages )
375 if( msg.Contains( wxString::Format( wxS(
"'%s'" ), netName ) ) )
382 BOOST_CHECK_MESSAGE( matchesNet( netB->
GetNetname() ),
383 "Stub net MID_B with 2 mm route + 10 mm pad-to-die must violate "
384 "the 5 mm stub_length budget" );
387 fs::remove( druPath, ec );
398 const wxString DRU_TIME = wxS(
400 "(rule \"StubBudgetTime\"\n"
401 " (condition \"A.NetClass == 'Default'\")\n"
402 " (constraint stub_length (max 100ps))\n"
408 std::vector<std::shared_ptr<DRC_RULE>> rules;
413 "stub_length with ps units must parse without error, got: "
414 <<
reporter.GetMessages().ToStdString() );
416 BOOST_REQUIRE_EQUAL( rules.size(), 1u );
418 std::optional<DRC_CONSTRAINT> stubConstraint =
437 const wxString DRU_LAYER = wxS(
439 "(rule \"GoodReturnPath\"\n"
440 " (condition \"A.NetClass == 'Default'\")\n"
441 " (constraint return_path (layer \"B.Cu\"))\n"
447 std::vector<std::shared_ptr<DRC_RULE>> rules;
452 "return_path with a layer must parse without error, got: "
453 <<
reporter.GetMessages().ToStdString() );
455 BOOST_REQUIRE_EQUAL( rules.size(), 1u );
457 std::optional<DRC_CONSTRAINT> rpConstraint =
constexpr EDA_IU_SCALE pcbIUScale
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
void Parse(std::vector< std::shared_ptr< DRC_RULE > > &aRules, REPORTER *aReporter)
Handle the data for a net.
const wxString & GetNetname() const
void SetNetChain(const wxString &aNetChain)
void SetTerminalPad(int aIndex, PAD *aPad)
void SetPadToDieLength(int aLength)
A #PLUGIN 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...
A wrapper for reporting to a wxString object.
@ DRCE_LIB_FOOTPRINT_ISSUES
@ DRCE_NET_CHAIN_STUB_TOO_LONG
@ DRCE_DRILL_OUT_OF_RANGE
@ DRCE_LIB_FOOTPRINT_MISMATCH
@ NET_CHAIN_STUB_LENGTH_CONSTRAINT
@ NET_CHAIN_RETURN_PATH_CONSTRAINT
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
static const char * BOARD_FILE
static const char * DRU_TEXT
BOOST_AUTO_TEST_CASE(StubLengthFiresOnIntermediateNetOnly)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
IbisParser parser & reporter
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I