KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_allegro_boards.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
21
22#include "allegro_block_tests.h"
23#include "allegro_test_utils.h"
24
25#include <filesystem>
26#include <fstream>
27
28#include <boost/test/data/test_case.hpp>
29
30#include <json_common.h>
31
32#include <board.h>
33#include <reporter.h>
35
38
40
51
52using namespace ALLEGRO;
53using namespace KI_TEST;
54
55
61{
62 uint8_t m_BlockType;
65 const nlohmann::json& m_BlockTestJson;
66};
67
73{
74 // The board name in the JSON registry
75 std::string m_BrdName;
76
78 std::vector<ALLEGRO_BLOCK_TEST_DESCRIPTOR> m_BlockTests;
80
82 std::vector<BOARD_EXPECTATION_TEST::DESCRIPTOR> m_ExpectationTests;
83};
84
85
94{
95 nlohmann::json m_Json;
96 std::vector<ALLEGRO_BOARD_TEST_DESCRIPTOR> m_BoardTests;
97
98 const nlohmann::json& GetBoardJson( const std::string& aBoardName ) const
99 {
100 return m_Json["boards"][aBoardName];
101 }
102};
103
104
105static std::vector<uint8_t> loadDataByUri( const std::string& aDataSource )
106{
107 // For now, we only support loading from files, but in the future we could also support
108 // loading from other sources (e.g. from compiled-in data, base64, etc.)
109
110 // Split off the protocol (e.g. "file://") if present, to get the actual path
111 std::string path, protocol;
112 const std::string sep = "://";
113
114 size_t sepPos = aDataSource.find( sep );
115 if( sepPos != std::string::npos )
116 {
117 protocol = aDataSource.substr( 0, sepPos );
118 path = aDataSource.substr( sepPos + sep.size() );
119 }
120 else
121 {
122 // No protocol
123 throw std::runtime_error( "Unsupported data source URI (missing protocol): " + aDataSource );
124 }
125
126 if( protocol == "file" )
127 {
128 // This means get it from a file in the QD data
129 return KI_TEST::LoadBinaryData( path, std::nullopt );
130 }
131
132 throw std::runtime_error( "Unsupported data source protocol: " + protocol );
133}
134
135
136ALLEGRO::FMT_VER getFormatVersionFromStr( const std::string& aFmtVerStr )
137{
138 // clang-format off
139 static const std::map<std::string, ALLEGRO::FMT_VER> fmtVerStrMap{
140 { "16.0", FMT_VER::V_160 },
141 { "16.2", FMT_VER::V_162 },
142 { "16.4", FMT_VER::V_164 },
143 { "16.5", FMT_VER::V_165 },
144 { "16.6", FMT_VER::V_166 },
145 { "17.2", FMT_VER::V_172 },
146 { "17.4", FMT_VER::V_174 },
147 { "17.5", FMT_VER::V_175 },
148 { "18.0", FMT_VER::V_180 },
149 { "18.1", FMT_VER::V_181 },
150 { "19.0", FMT_VER::V_190 },
151 };
152 // clang-format on
153
154 auto it = fmtVerStrMap.find( aFmtVerStr );
155 if( it != fmtVerStrMap.end() )
156 {
157 return it->second;
158 }
159
160 return FMT_VER::V_UNKNOWN;
161}
162
163
164static std::unique_ptr<HEADER_TEST_INFO> createHeaderTestEntry( const std::string& boardDir,
165 const nlohmann::json& headerTestEntry )
166{
167 std::unique_ptr<HEADER_TEST_INFO> headerTest;
168
169 if( !headerTestEntry.is_object() )
170 {
171 throw std::runtime_error( "Header test entry is not a valid JSON object" );
172 }
173
174 // Default header location
175 const std::string headerDataUri = std::string( "file://" ) + boardDir + "header.bin";
176
177 return std::make_unique<HEADER_TEST_INFO>( headerDataUri, headerTestEntry.value( "skip", false ) );
178}
179
180
181static BLOCK_TEST_INFO createBlockTestEntry( const std::string& boardDir,
182 const ALLEGRO_BLOCK_TEST_DESCRIPTOR& aBlockTestDescriptor )
183{
184 const nlohmann::json& blockTestJson = aBlockTestDescriptor.m_BlockTestJson;
185 const bool skipBlock = blockTestJson.value( "skip", false );
186
187 const uint8_t& blockType = aBlockTestDescriptor.m_BlockType;
188 const size_t& blockOffset = aBlockTestDescriptor.m_BlockOffset;
189
190 // Default block data location is a file with a name based on the block type and offset
191 wxString blockDataLoc = wxString::Format( "0x%02x_0x%08zx.bin", blockType, blockOffset );
192
193 const std::string blockDataUri = std::string( "file://" ) + boardDir + blockDataLoc.ToStdString();
194
195 const bool extraBlockTest = blockTestJson.value( "extraBlockTest", false );
196
197 return BLOCK_TEST_INFO{
198 blockType,
199 blockOffset,
200 skipBlock,
201 extraBlockTest,
202 blockDataUri,
203 };
204}
205
206
212
213
214static BOARD_TEST_INFO createBoardTestInfo( const std::string& aBrdName, const nlohmann::json& boardTestEntry )
215{
216 const ALLEGRO::FMT_VER formatVersion =
217 getFormatVersionFromStr( boardTestEntry.value( "formatVersion", "unknown" ) );
218
219 return BOARD_TEST_INFO{ aBrdName, formatVersion };
220}
221
222
224{
225public:
226 void RunHeaderTest( const std::string& aBrdName, const nlohmann::json& aBoardTestJson )
227 {
228 BOOST_TEST_CONTEXT( wxString::Format( "Testing header from board %s", aBrdName ) )
229 {
230 BOARD_TEST_INFO brdDef = createBoardTestInfo( aBrdName, aBoardTestJson );
231
232 const std::string boardDir = AllegroBoardDataDir( aBrdName );
233
234 std::unique_ptr<HEADER_TEST_INFO> headerTest = nullptr;
235
236 if( aBoardTestJson.contains( "header" ) && aBoardTestJson["header"].is_object() )
237 {
238 headerTest = createHeaderTestEntry( boardDir, aBoardTestJson["header"] );
239 }
240
241 BOOST_REQUIRE( headerTest != nullptr );
242
243 if( headerTest->m_Skip )
244 {
245 BOOST_TEST_MESSAGE( "Skipping test for this header" );
246 return;
247 }
248
249 // Read in the header data
250 std::vector<uint8_t> headerData = loadDataByUri( headerTest->m_HeaderDataSource );
251 FILE_STREAM fileStream( headerData.data(), headerData.size() );
252 HEADER_PARSER parser( fileStream );
253
254 std::unique_ptr<FILE_HEADER> header = parser.ParseHeader();
255
256 BOOST_REQUIRE( header != nullptr );
257
258 // We don't expect any known header to be in an unknown format
260
261 // Make sure the format version matches what the board is expected to be
262 if( brdDef.m_FormatVersion != FMT_VER::V_UNKNOWN )
263 {
264 BOOST_TEST( parser.GetFormatVersion() == brdDef.m_FormatVersion );
265 }
266
267 // Other header tests - validate some commonly used fields?
268
269 // The parser should have consumed all the data in the header
270 BOOST_TEST( fileStream.Position() == headerData.size() );
271 }
272 }
273
274
275 void RunBlockTest( const std::string& aBrdName, const nlohmann::json& aBoardTestJson,
276 const ALLEGRO_BLOCK_TEST_DESCRIPTOR& aBlockTest )
277 {
278 const BOARD_TEST_INFO brdDef = createBoardTestInfo( aBrdName, aBoardTestJson );
279 const BLOCK_TEST_INFO blockTest = createBlockTestEntry( AllegroBoardDataDir( aBrdName ), aBlockTest );
280
281 BOOST_TEST_CONTEXT( wxString::Format( "Testing block type %#02x at offset %#010zx from board %s",
282 blockTest.m_BlockType, blockTest.m_BlockOffset, aBrdName ) )
283 {
284 if( blockTest.m_Skip )
285 {
286 BOOST_TEST_MESSAGE( "Skipping test for this block" );
287 return;
288 }
289
290 // Read in the block data, and create a FILE_STREAM for it
291 std::vector<uint8_t> data = loadDataByUri( blockTest.m_DataSource );
292 FILE_STREAM fileStream( data.data(), data.size() );
293
294 BLOCK_PARSER parser( fileStream, brdDef.m_FormatVersion );
295
296 bool endOfObjectsMarker = false;
297 std::unique_ptr<BLOCK_BASE> block = parser.ParseBlock( endOfObjectsMarker );
298
299 // Compare the result to the expected results
300 BOOST_REQUIRE( block != nullptr );
301
302 // The parser should have consumed all the data in the block
303 BOOST_TEST( fileStream.Position() == data.size() );
304
305 // Look up and run additional ad-hoc block-level tests
306 if( blockTest.m_ExtraBlockTest )
307 {
308 KI_TEST::RunAdditionalBlockTest( aBrdName, blockTest.m_BlockOffset, *block );
309 }
310 }
311 }
312};
313
314
315static void AssertNoErrors( const CAPTURING_REPORTER& aReporter )
316{
317 if( aReporter.GetErrorCount() > 0 )
318 {
319 std::ostringstream ss;
320 ss << "Expected no errors, but found " << aReporter.GetErrorCount() << " errors:";
321
322 for( const auto& msg : aReporter.GetMessages() )
323 {
324 if( msg.severity == RPT_SEVERITY_ERROR )
325 {
326 ss << "\n " << msg.text;
327 }
328 }
329 BOOST_TEST_MESSAGE( ss.str() );
330 }
331 BOOST_TEST( aReporter.GetErrorCount() == 0 );
332}
333
334
335void RunBoardLoad( const std::string& aBrdName, const nlohmann::json& aBoardTestJson )
336{
337 BOARD* board = nullptr;
338
339 BOOST_TEST_CONTEXT( "Testing load from board: " << aBrdName )
340 {
341 if( aBoardTestJson.contains( "boardFile" ) )
342 {
343 const std::string boardFilePath =
344 KI_TEST::AllegroBoardDataDir( aBrdName ) + aBoardTestJson["boardFile"].get<std::string>();
345
346 if( !std::filesystem::exists( boardFilePath ) )
347 {
348 BOOST_FAIL( "Board file does not exist: " + boardFilePath );
349 return;
350 }
351
354
355 const bool expectLoadFailure = aBoardTestJson.value( "expectLoadFailure", false );
356
357 if( expectLoadFailure )
358 {
359 BOOST_CHECK( board == nullptr );
360 BOOST_TEST_MESSAGE( "Board load was expected to fail, and it did." );
361 return;
362 }
363 else
364 {
365 BOOST_CHECK_MESSAGE( board != nullptr, "Board load was expected to succeed, but it failed." );
366
367 // Can allow a certain number of warnings, but no errors
369
370 // Can check max warnings here if we want
371 if( reporter.GetWarningCount() > 0 )
372 {
373 std::ostringstream ss;
374 ss << aBrdName << ": " << reporter.GetWarningCount() << " warnings";
375
376 for( const auto& msg : reporter.GetMessages() )
377 {
378 if( msg.severity == RPT_SEVERITY_WARNING )
379 {
380 ss << "\n " << msg.text;
381 }
382 }
383
384 BOOST_TEST_MESSAGE( ss.str() );
385 }
386
387 KI_TEST::PrintBoardStats( board, aBrdName );
388 }
389 }
390 }
391}
392
393
394static uint8_t getByteFromHexStr( const nlohmann::json& aJsonEntry, const std::string& aFieldName )
395{
396 if( !aJsonEntry.contains( aFieldName ) )
397 {
398 throw std::runtime_error( "Block test entry is missing the '" + aFieldName + "' field" );
399 }
400
401 if( aJsonEntry[aFieldName].is_number_unsigned() )
402 {
403 const unsigned long value = aJsonEntry[aFieldName].get<unsigned long>();
404 if( value > 0xFF )
405 {
406 throw std::runtime_error( "Value is too large to fit in a byte: " + std::to_string( value ) );
407 }
408 return static_cast<uint8_t>( value );
409 }
410 else if( aJsonEntry[aFieldName].is_string() )
411 {
412 const std::string aHexStr = aJsonEntry[aFieldName];
413
414 const unsigned long value = std::stoul( aHexStr, nullptr, 0 );
415 if( value > 0xFF )
416 {
417 throw std::runtime_error( "Value is too large to fit in a byte: " + aHexStr );
418 }
419 return static_cast<uint8_t>( value );
420 }
421
422 throw std::runtime_error( "Block test entry has an invalid '" + aFieldName
423 + "' field (must be a byte value as a number or hex string)" );
424}
425
426
427static ALLEGRO_BLOCK_TEST_DESCRIPTOR createBlockTestDescriptor( const nlohmann::json& aBlockTestJson )
428{
429 const uint8_t blockType = getByteFromHexStr( aBlockTestJson, "type" );
430
431 if( !aBlockTestJson.contains( "offset" ) || !aBlockTestJson["offset"].is_string() )
432 {
433 throw std::runtime_error( "Block test entry is missing a valid 'offset' field" );
434 }
435
436 const std::string block_offset = aBlockTestJson["offset"];
437 const size_t blockOffset = std::stoul( block_offset, nullptr, 0 );
438
440 blockType,
441 blockOffset,
442 aBlockTestJson,
443 };
444}
445
446
454static std::vector<ALLEGRO_BOARD_TEST_DESCRIPTOR> getBoardTestDefinitions( const nlohmann::json& aJson )
455{
456 if( !aJson.contains( "boards" ) || !aJson["boards"].is_object() )
457 {
458 throw std::runtime_error( "Test register JSON file does not contain a valid 'boards' object." );
459 }
460
461 std::vector<ALLEGRO_BOARD_TEST_DESCRIPTOR> boardTests;
462
463 for( auto& [boardName, boardEntry] : aJson["boards"].items() )
464 {
466 .m_BrdName = boardName,
467 .m_HasHeaderTest = boardEntry.contains( "header" ),
468 .m_BlockTests = {},
469 .m_HasBoardFile = boardEntry.contains( "boardFile" ),
470 .m_ExpectationTests = {},
471 };
472
473 if( boardEntry.contains( "blocks" ) && boardEntry["blocks"].is_array() )
474 {
475 for( const auto& blockTestEntry : boardEntry["blocks"] )
476 {
477 boardTestRef.m_BlockTests.emplace_back( createBlockTestDescriptor( blockTestEntry ) );
478 }
479 }
480
481 if( boardEntry.contains( "boardExpectations" ) )
482 {
483 const auto& expectationsEntry = boardEntry["boardExpectations"];
484
485 boardTestRef.m_ExpectationTests =
487 }
488
489 boardTests.push_back( std::move( boardTestRef ) );
490 }
491
492 return boardTests;
493}
494
495
497{
498 static ALLEGRO_BLOCK_TEST_REGISTRY registry = []()
499 {
501
502 // There is currently one registry file, but we could have more, e.g. if we
503 // stored the test definitions on a per-board basis in the board data dirs
504 const std::filesystem::path testRegisterJsonPath( AllegroBoardDataDir( "" ) + "board_data_registry.json" );
505 std::ifstream jsonFileStream( testRegisterJsonPath );
506
507 reg.m_Json = nlohmann::json::parse( jsonFileStream, nullptr, true, true );
509
510 return reg;
511 }();
512
513 return registry;
514}
515
516
520static std::vector<std::string> getBoardTestLabels( const nlohmann::json& boardTestJson )
521{
522 std::vector<std::string> labels;
523
524 if( boardTestJson.contains( "testLabels" ) && boardTestJson["testLabels"].is_array() )
525 {
526 for( const auto& label : boardTestJson["testLabels"] )
527 {
528 if( label.is_string() )
529 {
530 labels.push_back( label.get<std::string>() );
531 }
532 }
533 }
534
535 return labels;
536}
537
538
548static std::vector<boost::unit_test::test_suite*> buildAllegroBoardSuites()
549{
550 using BTS = boost::unit_test::test_suite;
551 std::vector<BTS*> suites;
552 BTS* blockSuite = suites.emplace_back( BOOST_TEST_SUITE( "AllegroBlocks" ) );
553 const ALLEGRO_BLOCK_TEST_REGISTRY* registry = nullptr;
554
555 try
556 {
557 registry = &buildTestRegistry();
558 }
559 catch( const std::exception& ex )
560 {
561 std::string msg = "Failed to load Allegro block test definitions: " + std::string( ex.what() );
562
563 // Register one failing test to report the error, so that we don't just silently skip all the tests
564 const auto failingTestFunction = [=]()
565 {
566 BOOST_TEST( false, msg );
567 };
568
569 blockSuite->add(
570 boost::unit_test::make_test_case(
571 failingTestFunction,
572 "FailureToLoadTestDefinitions",
573 __FILE__,
574 __LINE__
575 )
576 );
577
578 return suites;
579 }
580
581 for( const ALLEGRO_BOARD_TEST_DESCRIPTOR& boardTest : registry->m_BoardTests )
582 {
583 BTS* boardSuite = BOOST_TEST_SUITE( boardTest.m_BrdName );
584 blockSuite->add( boardSuite );
585
586 const nlohmann::json& boardTestJson = registry->GetBoardJson( boardTest.m_BrdName );
587
588 if( boardTest.m_HasHeaderTest )
589 {
590 // Note: captures ref-to-static
591 const auto testRunFunction = [&]()
592 {
594 fixture.RunHeaderTest( boardTest.m_BrdName, boardTestJson );
595 };
596
597 boardSuite->add(
598 boost::unit_test::make_test_case(
599 testRunFunction,
600 "Header",
601 __FILE__,
602 __LINE__
603 )
604 );
605 }
606
607 for( const auto& blockTest : boardTest.m_BlockTests )
608 {
609 // All these captures come from data stored in a static variable, so we can take them
610 // by reference here.
611 const auto testRunFunction = [&boardTest, &boardTestJson, &blockTest]()
612 {
614 fixture.RunBlockTest( boardTest.m_BrdName, boardTestJson, blockTest );
615 };
616
617 wxString testName =
618 wxString::Format( "Block_0x%02x_offset_0x%010zx", blockTest.m_BlockType, blockTest.m_BlockOffset );
619
620 boardSuite->add(
621 boost::unit_test::make_test_case(
622 testRunFunction,
623 testName.ToStdString(),
624 __FILE__,
625 __LINE__
626 )
627 );
628 }
629 }
630
631 // Separate test suite for board expectations, which will run after the header and block parsing tests,
632 // and will have access to the fully parsed board (and obviously be much slower)
633 BTS* boardSuites = suites.emplace_back( BOOST_TEST_SUITE( "AllegroBoards" ) );
634
635 for( const ALLEGRO_BOARD_TEST_DESCRIPTOR& boardTest : registry->m_BoardTests )
636 {
637 if( !boardTest.m_HasBoardFile )
638 {
639 continue;
640 }
641
642 // Board-level suite
643 BTS* boardSuite = BOOST_TEST_SUITE( boardTest.m_BrdName );
644 boardSuites->add( boardSuite );
645
646 const nlohmann::json& boardTestData = registry->GetBoardJson( boardTest.m_BrdName );
647
648 const std::vector<std::string> testLabels = getBoardTestLabels( boardTestData );
649 boost::unit_test::test_case* loadingTestCase = nullptr;
650
651 if( boardTest.m_HasBoardFile )
652 {
653 const auto testLoadFunction = [&boardTest, &boardTestData]()
654 {
655 RunBoardLoad( boardTest.m_BrdName, boardTestData );
656 };
657
658 // The first test unit loads (and caches) the board.
659 loadingTestCase = boost::unit_test::make_test_case(
660 testLoadFunction,
661 "Import",
662 __FILE__,
663 __LINE__
664 );
665
666 for( const std::string& label : testLabels )
667 {
668 loadingTestCase->add_label( label );
669 }
670
671 boardSuite->add( loadingTestCase );
672 }
673
674 if( boardTest.m_ExpectationTests.size() > 0 )
675 {
676 BTS* expectationsSuite = BOOST_TEST_SUITE( "Expectations" );
677 boardSuite->add( expectationsSuite );
678
679 for( const BOARD_EXPECTATION_TEST::DESCRIPTOR& expectationTestRef : boardTest.m_ExpectationTests )
680 {
681 const auto testRunFunction = [&boardTest, &boardTestData, &expectationTestRef]()
682 {
683 if( !boardTestData.contains( "boardFile" ) )
684 {
685 BOOST_FAIL(
686 "Board test JSON does not contain a 'boardFile' entry - cannot run expectations test" );
687 return;
688 }
689
690 const std::string boardFilePath = KI_TEST::AllegroBoardDataDir( boardTest.m_BrdName )
691 + boardTestData["boardFile"].get<std::string>();
692
693 const BOARD* board = KI_TEST::ALLEGRO_CACHED_LOADER::GetInstance().GetCachedBoard( boardFilePath );
694
695 if( !board )
696 {
697 BOOST_FAIL( "Failed to load cached board for expectations test: " + boardFilePath );
698 return;
699 }
700
701 KI_TEST::BOARD_EXPECTATION_TEST::RunFromRef( boardTest.m_BrdName, *board, expectationTestRef );
702 };
703
704 boost::unit_test::test_case* expectationTestCase = boost::unit_test::make_test_case(
705 testRunFunction,
706 expectationTestRef.m_TestName,
707 __FILE__,
708 __LINE__
709 );
710
711 // Label the expectations test case with any tags from the JSON
712 for( const std::string& label : expectationTestRef.m_Tags )
713 {
714 expectationTestCase->add_label( label );
715 }
716
717 expectationsSuite->add( expectationTestCase );
718 }
719
720 // We can only run the expectations test after the board has been loaded
721 // and that test passes.
722 BOOST_REQUIRE( loadingTestCase != nullptr );
723 expectationsSuite->depends_on( loadingTestCase );
724 }
725 }
726
727 return suites;
728}
729
730
736{
738 {
739 std::vector<boost::unit_test::test_suite*> suites = buildAllegroBoardSuites();
740
741 for( boost::unit_test::test_suite* suite : suites )
742 {
743 boost::unit_test::framework::master_test_suite().add( suite );
744 }
745 }
General utilities for PCB file IO for QA programs.
The block parser is responsible for parsing individual blocks of data from the file stream.
std::unique_ptr< BLOCK_BASE > ParseBlock(bool &aEndOfObjectsMarker)
Parse one block from the stream, returning a BLOCK_BASE representing the raw data of the block.
Stream that reads primitive types from a memory buffer containing Allegro .brd (or ....
size_t Position() const
Parses a .brd header, taking care of any version-specific differences.
std::unique_ptr< FILE_HEADER > ParseHeader()
FMT_VER GetFormatVersion() const
Get the parsed format version.
void RunBlockTest(const std::string &aBrdName, const nlohmann::json &aBoardTestJson, const ALLEGRO_BLOCK_TEST_DESCRIPTOR &aBlockTest)
void RunHeaderTest(const std::string &aBrdName, const nlohmann::json &aBoardTestJson)
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
static ALLEGRO_CACHED_LOADER & GetInstance()
Get the singleton instance of the Allegro board cache loader.
static std::vector< DESCRIPTOR > ExtractExpectationTestsFromJson(const nlohmann::json &aExpectationArray)
Extracts expectation tests from the given JSON array and returns a list of test references that can b...
static void RunFromRef(const std::string &aBrdName, const BOARD &aBoard, const BOARD_EXPECTATION_TEST::DESCRIPTOR &aExpectationTestRef)
Constructs a BOARD_EXPECTATION_TEST from the given JSON definition, and runs it on the given board.
BOARD * LoadAndCache(const std::string &aFilePath, REPORTER *aReporter)
Load (or reload) board for the given file path and send the load messages to the given reporter.
BOARD * GetCachedBoard(const std::string &aFilePath)
Get a cached board for the given file path, or load it if not already cached, without forcing a reloa...
Custom REPORTER that captures all messages for later analysis in the unit test framework.
const std::vector< MESSAGE > & GetMessages() const
FMT_VER
The format of an Allegro file.
Test utilities for timestamps.
std::string AllegroBoardDataDir(const std::string &aBoardName)
void RunAdditionalBlockTest(const std::string &aBoardName, size_t aBlockOffset, const ALLEGRO::BLOCK_BASE &aBlock)
Look up and run any additional ad-hoc tests for a block.
std::vector< uint8_t > LoadBinaryData(const std::string &aFilePath, std::optional< size_t > aLoadBytes=std::nullopt)
Load the contents of a file into a vector of bytes.
void PrintBoardStats(const BOARD *aBoard, const std::string &aBoardName)
Print detailed board statistics for debugging using test-framework logging.
@ RPT_SEVERITY_WARNING
@ RPT_SEVERITY_ERROR
Just enough information about a block-level test to be able to name and register it with the test run...
const nlohmann::json & m_BlockTestJson
Handy ref to the JSON entry for this block test.
The registry of known Allegro board and block tests, populated at static init time by reading the JSO...
const nlohmann::json & GetBoardJson(const std::string &aBoardName) const
std::vector< ALLEGRO_BOARD_TEST_DESCRIPTOR > m_BoardTests
Just enough information about the board test to be able to name and register any tests for this board...
std::vector< BOARD_EXPECTATION_TEST::DESCRIPTOR > m_ExpectationTests
List of expectation tests found in the JSON for this board.
std::vector< ALLEGRO_BLOCK_TEST_DESCRIPTOR > m_BlockTests
ALLEGRO::FMT_VER m_FormatVersion
A complete description of a block test.
uint8_t m_BlockType
The type of the block, as in the first byte.
std::string m_DataSource
The the source of the block data (probably a filename)
bool m_ExtraBlockTest
Do we have an additional block-level test to run for this block?
size_t m_BlockOffset
The offset within the board file where this block is located (used for error messages)
bool m_Skip
Whether to skip this test while parsers don't support a certain format.
Lightweight descriptor for a BOARD_EXPECTATION_TEST, which can be used to refer to the test unambiguo...
std::string m_TestName
If the test has a name, it's that, else an index - this is for naming the test for filtering.
std::vector< std::string > m_Tags
Tags associated with the test, which can be used for filtering.
static struct RegisterBlockSuites s_registerHeaderBlockSuites
static void AssertNoErrors(const CAPTURING_REPORTER &aReporter)
static std::unique_ptr< HEADER_TEST_INFO > createHeaderTestEntry(const std::string &boardDir, const nlohmann::json &headerTestEntry)
static uint8_t getByteFromHexStr(const nlohmann::json &aJsonEntry, const std::string &aFieldName)
static BOARD_TEST_INFO createBoardTestInfo(const std::string &aBrdName, const nlohmann::json &boardTestEntry)
static BLOCK_TEST_INFO createBlockTestEntry(const std::string &boardDir, const ALLEGRO_BLOCK_TEST_DESCRIPTOR &aBlockTestDescriptor)
static std::vector< uint8_t > loadDataByUri(const std::string &aDataSource)
static ALLEGRO_BLOCK_TEST_DESCRIPTOR createBlockTestDescriptor(const nlohmann::json &aBlockTestJson)
static std::vector< boost::unit_test::test_suite * > buildAllegroBoardSuites()
This function initializes the test suites for Allegro block and board parsing.
void RunBoardLoad(const std::string &aBrdName, const nlohmann::json &aBoardTestJson)
static std::vector< std::string > getBoardTestLabels(const nlohmann::json &boardTestJson)
Get the labels associated with a board test, which can be used to e.g.
static std::vector< ALLEGRO_BOARD_TEST_DESCRIPTOR > getBoardTestDefinitions(const nlohmann::json &aJson)
Construct a list of test descriptrs (lightweight objects) for the boards we have test data for,...
static const ALLEGRO_BLOCK_TEST_REGISTRY & buildTestRegistry()
ALLEGRO::FMT_VER getFormatVersionFromStr(const std::string &aFmtVerStr)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_REQUIRE(res.columns()==1)
BOOST_TEST(netlist.find("R_G1 ARM_OUT1 DIE_B R='0.001 / ((SW_STATE)") !=std::string::npos)
std::string path
IbisParser parser & reporter
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")