20#include <boost/test/unit_test.hpp>
51 (generator_version "9.99")
62 (uuid "11111111-1111-1111-1111-111111111111")
68 (uuid "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaa01")
74 (uuid "33333333-3333-3333-3333-333333333333")
80 (uuid "cccccccc-cccc-cccc-cccc-cccccccccc01")
84 (segment (start 0 0) (end 2 0) (width 0.2) (layer "F.Cu") (net 1))
85 (segment (start 5 0) (end 35 0) (width 0.2) (layer "F.Cu") (net 2))
86 (segment (start 38 0) (end 40 0) (width 0.2) (layer "F.Cu") (net 3))
93static const char*
DRU_TEXT = R
"KICAD((version 1)
96 (condition "A.NetClass == 'Default'")
97 (constraint stub_length (min 0mm) (max 5mm))
107 namespace fs = std::filesystem;
109 fs::path tmpDir = fs::temp_directory_path() /
"kicad_drc_stub_length";
110 fs::create_directories( tmpDir );
112 fs::path pcbPath = tmpDir /
"stub_length.kicad_pcb";
113 fs::path druPath = tmpDir /
"stub_length.kicad_dru";
116 std::ofstream pcbOut( pcbPath );
121 std::ofstream druOut( druPath );
126 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
127 plugin.
LoadBoard( pcbPath.string(), board.get() );
128 board->BuildConnectivity();
130 NETINFO_ITEM* netA = board->FindNet( wxS(
"/TRUNK_A" ) );
132 NETINFO_ITEM* netC = board->FindNet( wxS(
"/TRUNK_C" ) );
145 for(
FOOTPRINT* fp : board->Footprints() )
147 for(
PAD*
pad : fp->Pads() )
165 auto drcEngine = std::make_shared<DRC_ENGINE>( board.get(), &bds );
166 wxFileName ruleFile( druPath.string() );
167 drcEngine->InitEngine( ruleFile );
178 std::vector<wxString> stubMessages;
180 drcEngine->SetViolationHandler(
181 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I&,
int,
185 stubMessages.push_back( aItem->GetErrorMessage(
false ) );
190 auto matchesNet = [&](
const wxString& netName )
192 for(
const wxString& msg : stubMessages )
194 if( msg.Contains( wxString::Format( wxS(
"'%s'" ), netName ) ) )
201 bool aFlagged = matchesNet( netA->
GetNetname() );
202 bool bFlagged = matchesNet( netB->
GetNetname() );
203 bool cFlagged = matchesNet( netC->
GetNetname() );
206 "Intermediate stub net MID_B should fire stub_length violation" );
208 "Trunk endpoint net TRUNK_A (owns terminal_pad_0) must not fire" );
210 "Trunk endpoint net TRUNK_C (owns terminal_pad_1) must not fire" );
213 fs::remove( pcbPath, ec );
214 fs::remove( druPath, ec );
220 namespace fs = std::filesystem;
222 fs::path tmpDir = fs::temp_directory_path() /
"kicad_drc_stub_length";
223 fs::create_directories( tmpDir );
225 fs::path pcbPath = tmpDir /
"stub_length_2net.kicad_pcb";
226 fs::path druPath = tmpDir /
"stub_length_2net.kicad_dru";
231 static const char* TWO_NET_BOARD = R
"KICAD(
235 (generator_version "9.99")
245 (uuid "44444444-4444-4444-4444-444444444444")
251 (uuid "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaa02")
257 (uuid "55555555-5555-5555-5555-555555555555")
263 (uuid "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbb02")
267 (segment (start 0 0) (end 30 0) (width 0.2) (layer "F.Cu") (net 1))
268 (segment (start 30 0) (end 60 0) (width 0.2) (layer "F.Cu") (net 2))
272 static const char* TWO_NET_DRU = R
"KICAD((version 1)
275 (condition "A.NetClass == 'Default'")
276 (constraint stub_length (min 0mm) (max 5mm))
281 std::ofstream pcbOut( pcbPath );
282 pcbOut << TWO_NET_BOARD;
286 std::ofstream druOut( druPath );
287 druOut << TWO_NET_DRU;
291 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
292 plugin.LoadBoard( pcbPath.string(), board.get() );
293 board->BuildConnectivity();
307 for(
FOOTPRINT* fp : board->Footprints() )
309 for(
PAD*
pad : fp->Pads() )
327 auto drcEngine = std::make_shared<DRC_ENGINE>( board.get(), &bds );
328 wxFileName ruleFile( druPath.string() );
329 drcEngine->InitEngine( ruleFile );
342 drcEngine->SetViolationHandler(
343 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I&,
int,
353 "Two-net chain with both ends owning terminal pads must not "
354 "fire any stub_length violation, got "
358 fs::remove( pcbPath, ec );
359 fs::remove( druPath, ec );
365 namespace fs = std::filesystem;
367 fs::path tmpDir = fs::temp_directory_path() /
"kicad_drc_stub_length";
368 fs::create_directories( tmpDir );
370 fs::path pcbPath = tmpDir /
"stub_length_pad_to_die.kicad_pcb";
371 fs::path druPath = tmpDir /
"stub_length_pad_to_die.kicad_dru";
377 static const char* PAD_TO_DIE_BOARD = R
"KICAD(
381 (generator_version "9.99")
392 (uuid "66666666-6666-6666-6666-666666666666")
398 (uuid "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaa03")
404 (uuid "77777777-7777-7777-7777-777777777777")
410 (uuid "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbb03")
416 (uuid "88888888-8888-8888-8888-888888888888")
422 (uuid "cccccccc-cccc-cccc-cccc-cccccccccc03")
426 (segment (start 0 0) (end 2 0) (width 0.2) (layer "F.Cu") (net 1))
427 (segment (start 3 0) (end 5 0) (width 0.2) (layer "F.Cu") (net 2))
428 (segment (start 8 0) (end 10 0) (width 0.2) (layer "F.Cu") (net 3))
432 static const char* PAD_TO_DIE_DRU = R
"KICAD((version 1)
435 (condition "A.NetClass == 'Default'")
436 (constraint stub_length (min 0mm) (max 5mm))
441 std::ofstream pcbOut( pcbPath );
442 pcbOut << PAD_TO_DIE_BOARD;
446 std::ofstream druOut( druPath );
447 druOut << PAD_TO_DIE_DRU;
451 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
452 plugin.LoadBoard( pcbPath.string(), board.get() );
454 NETINFO_ITEM* netA = board->FindNet( wxS( "/TRUNK_A" ) );
456 NETINFO_ITEM* netC = board->FindNet( wxS(
"/TRUNK_C" ) );
470 for(
FOOTPRINT* fp : board->Footprints() )
472 for(
PAD*
pad : fp->Pads() )
496 board->BuildConnectivity();
500 auto drcEngine = std::make_shared<DRC_ENGINE>( board.get(), &bds );
501 wxFileName ruleFile( druPath.string() );
502 drcEngine->InitEngine( ruleFile );
513 std::vector<wxString> stubMessages;
515 drcEngine->SetViolationHandler(
516 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I&,
int,
520 stubMessages.push_back( aItem->GetErrorMessage(
false ) );
525 auto matchesNet = [&](
const wxString& netName )
527 for(
const wxString& msg : stubMessages )
529 if( msg.Contains( wxString::Format( wxS(
"'%s'" ), netName ) ) )
537 "Stub net MID_B with 2 mm route + 10 mm pad-to-die must violate "
538 "the 5 mm stub_length budget" );
541 fs::remove( pcbPath, ec );
542 fs::remove( druPath, ec );
553 const wxString DRU_TIME = wxS(
555 "(rule \"StubBudgetTime\"\n"
556 " (condition \"A.NetClass == 'Default'\")\n"
557 " (constraint stub_length (max 100ps))\n"
563 std::vector<std::shared_ptr<DRC_RULE>> rules;
568 "stub_length with ps units must parse without error, got: "
569 <<
reporter.GetMessages().ToStdString() );
571 BOOST_REQUIRE_EQUAL( rules.size(), 1u );
573 std::optional<DRC_CONSTRAINT> stubConstraint =
592 const wxString DRU_LAYER = wxS(
594 "(rule \"GoodReturnPath\"\n"
595 " (condition \"A.NetClass == 'Default'\")\n"
596 " (constraint return_path (layer \"B.Cu\"))\n"
602 std::vector<std::shared_ptr<DRC_RULE>> rules;
607 "return_path with a layer must parse without error, got: "
608 <<
reporter.GetMessages().ToStdString() );
610 BOOST_REQUIRE_EQUAL( rules.size(), 1u );
612 std::optional<DRC_CONSTRAINT> rpConstraint =
constexpr EDA_IU_SCALE pcbIUScale
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.
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 ...
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
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
static const char * DRU_TEXT
static const char * BOARD_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_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I