20#include <boost/test/unit_test.hpp>
50static const char*
BOARD_FILE =
"net_chains/stub_length.kicad_pcb";
55static const char*
DRU_TEXT = R
"KICAD((version 1)
58 (condition "A.NetClass == 'Default'")
59 (constraint stub_length (min 0mm) (max 5mm))
69 namespace fs = std::filesystem;
73 fs::path druPath = tmpDir.
Path() /
"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;
177 fs::path druPath = tmpDir.
Path() /
"stub_length_2net.kicad_dru";
182 static const char* TWO_NET_BOARD_FILE =
"net_chains/stub_length_two_net.kicad_pcb";
184 static const char* TWO_NET_DRU = R
"KICAD((version 1)
187 (condition "A.NetClass == 'Default'")
188 (constraint stub_length (min 0mm) (max 5mm))
193 std::ofstream druOut( druPath );
194 druOut << TWO_NET_DRU;
199 board->BuildConnectivity();
213 for(
FOOTPRINT* fp : board->Footprints() )
215 for(
PAD*
pad : fp->Pads() )
233 auto drcEngine = std::make_shared<DRC_ENGINE>( board.get(), &bds );
234 wxFileName ruleFile( druPath.string() );
235 drcEngine->InitEngine( ruleFile );
248 drcEngine->SetViolationHandler(
249 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I&,
int,
258 BOOST_CHECK_MESSAGE( stubCount == 0,
259 "Two-net chain with both ends owning terminal pads must not "
260 "fire any stub_length violation, got "
264 fs::remove( druPath, ec );
270 namespace fs = std::filesystem;
274 fs::path druPath = tmpDir.
Path() /
"stub_length_pad_to_die.kicad_dru";
280 static const char* PAD_TO_DIE_BOARD_FILE =
"net_chains/stub_length_pad_to_die.kicad_pcb";
282 static const char* PAD_TO_DIE_DRU = R
"KICAD((version 1)
285 (condition "A.NetClass == 'Default'")
286 (constraint stub_length (min 0mm) (max 5mm))
291 std::ofstream druOut( druPath );
292 druOut << PAD_TO_DIE_DRU;
298 NETINFO_ITEM* netA = board->FindNet( wxS( "/TRUNK_A" ) );
300 NETINFO_ITEM* netC = board->FindNet( wxS(
"/TRUNK_C" ) );
314 for(
FOOTPRINT* fp : board->Footprints() )
316 for(
PAD*
pad : fp->Pads() )
340 board->BuildConnectivity();
344 auto drcEngine = std::make_shared<DRC_ENGINE>( board.get(), &bds );
345 wxFileName ruleFile( druPath.string() );
346 drcEngine->InitEngine( ruleFile );
357 std::vector<wxString> stubMessages;
359 drcEngine->SetViolationHandler(
360 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I&,
int,
364 stubMessages.push_back( aItem->GetErrorMessage(
false ) );
369 auto matchesNet = [&](
const wxString& netName )
371 for(
const wxString& msg : stubMessages )
373 if( msg.Contains( wxString::Format( wxS(
"'%s'" ), netName ) ) )
380 BOOST_CHECK_MESSAGE( matchesNet( netB->
GetNetname() ),
381 "Stub net MID_B with 2 mm route + 10 mm pad-to-die must violate "
382 "the 5 mm stub_length budget" );
385 fs::remove( druPath, ec );
396 const wxString DRU_TIME = wxS(
398 "(rule \"StubBudgetTime\"\n"
399 " (condition \"A.NetClass == 'Default'\")\n"
400 " (constraint stub_length (max 100ps))\n"
406 std::vector<std::shared_ptr<DRC_RULE>> rules;
411 "stub_length with ps units must parse without error, got: "
412 <<
reporter.GetMessages().ToStdString() );
414 BOOST_REQUIRE_EQUAL( rules.size(), 1u );
416 std::optional<DRC_CONSTRAINT> stubConstraint =
435 const wxString DRU_LAYER = wxS(
437 "(rule \"GoodReturnPath\"\n"
438 " (condition \"A.NetClass == 'Default'\")\n"
439 " (constraint return_path (layer \"B.Cu\"))\n"
445 std::vector<std::shared_ptr<DRC_RULE>> rules;
450 "return_path with a layer must parse without error, got: "
451 <<
reporter.GetMessages().ToStdString() );
453 BOOST_REQUIRE_EQUAL( rules.size(), 1u );
455 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)
const std::filesystem::path & Path() const
Get the path to the temporary directory as a std::filesystem::path.
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 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...
A wrapper for reporting to a wxString object.
@ NET_CHAIN_STUB_LENGTH_CONSTRAINT
@ NET_CHAIN_RETURN_PATH_CONSTRAINT
@ DRCE_LIB_FOOTPRINT_ISSUES
@ DRCE_NET_CHAIN_STUB_TOO_LONG
@ DRCE_DRILL_OUT_OF_RANGE
@ DRCE_LIB_FOOTPRINT_MISMATCH
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