2022-10-23 22:15:32 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020-2022 KiCad Developers.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2022-10-30 23:01:08 +00:00
|
|
|
#define BOOST_TEST_NO_MAIN
|
|
|
|
|
2022-10-23 22:15:32 +00:00
|
|
|
#include <wx/cmdline.h>
|
|
|
|
#include <wx/stdstream.h>
|
|
|
|
#include <wx/wfstream.h>
|
|
|
|
|
|
|
|
#include <qa_utils/utility_registry.h>
|
|
|
|
#include <pcbnew_utils/board_test_utils.h>
|
2022-10-30 23:01:08 +00:00
|
|
|
#include <pcbnew_utils/board_file_utils.h>
|
2022-10-23 22:15:32 +00:00
|
|
|
|
|
|
|
#include "pns_log_file.h"
|
|
|
|
#include "pns_log_viewer_frame.h"
|
|
|
|
|
2022-10-30 23:01:08 +00:00
|
|
|
#include <boost/test/included/unit_test.hpp>
|
2022-10-23 22:15:32 +00:00
|
|
|
|
2022-10-30 23:01:08 +00:00
|
|
|
using namespace boost::unit_test;
|
|
|
|
|
|
|
|
#if 0
|
2022-10-23 22:15:32 +00:00
|
|
|
|
|
|
|
bool runSingleTest( REPORTER* aReporter, wxString name, wxString testDirPath )
|
|
|
|
{
|
|
|
|
PNS_LOG_FILE logFile;
|
|
|
|
PNS_LOG_PLAYER player;
|
|
|
|
|
|
|
|
|
|
|
|
wxString fn( testDirPath );
|
|
|
|
fn = fn.Append( "/" );
|
|
|
|
fn = fn.Append( name );
|
|
|
|
fn = fn.Append( "/pns" );
|
|
|
|
|
|
|
|
|
|
|
|
wxFileName fname( fn );
|
|
|
|
|
|
|
|
aReporter->Report( wxString::Format( "Running test '%s' from '%s'", name, fname.GetFullPath() ),
|
|
|
|
RPT_SEVERITY_INFO );
|
|
|
|
|
|
|
|
//fname.A
|
|
|
|
|
|
|
|
if( !logFile.Load( fname, aReporter ) )
|
|
|
|
{
|
|
|
|
aReporter->Report(
|
|
|
|
wxString::Format( "Failed to load test '%s' from '%s'", name, fname.GetFullPath() ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
|
|
|
}
|
|
|
|
|
|
|
|
player.SetReporter( aReporter );
|
|
|
|
player.ReplayLog( &logFile, 0 );
|
|
|
|
bool pass = player.CompareResults( &logFile );
|
|
|
|
return pass;
|
|
|
|
}
|
|
|
|
|
2022-10-30 23:01:08 +00:00
|
|
|
|
2022-10-23 22:15:32 +00:00
|
|
|
int main( int argc, char* argv[] )
|
|
|
|
{
|
2022-10-30 23:01:08 +00:00
|
|
|
|
2022-10-23 22:15:32 +00:00
|
|
|
|
2022-10-30 23:01:08 +00:00
|
|
|
int passed = 0, failed = 0;
|
2022-10-23 22:15:32 +00:00
|
|
|
|
2022-10-30 23:01:08 +00:00
|
|
|
for( auto casename : testCases )
|
2022-10-23 22:15:32 +00:00
|
|
|
{
|
2022-10-30 23:01:08 +00:00
|
|
|
if( runSingleTest( &reporter, casename, cl_parser.GetParam( 0 ) ) )
|
|
|
|
passed++;
|
|
|
|
else
|
|
|
|
failed++;
|
2022-10-23 22:15:32 +00:00
|
|
|
}
|
|
|
|
|
2022-10-30 23:01:08 +00:00
|
|
|
reporter.Report(
|
|
|
|
wxString::Format( "SUMMARY: %d/%d tests cases PASSED", passed,
|
|
|
|
(int) testCases.size() ),
|
|
|
|
RPT_SEVERITY_INFO );
|
|
|
|
|
|
|
|
|
|
|
|
return failed ? -1 : 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct PNS_TEST_CASE
|
|
|
|
{
|
|
|
|
PNS_TEST_CASE( std::string name, std::string path ) : m_name( name ), m_dataPath( path ){};
|
|
|
|
|
|
|
|
std::string GetDataPath() const { return m_dataPath; }
|
|
|
|
std::string GetName() const { return m_name; }
|
|
|
|
std::string m_dataPath;
|
|
|
|
std::string m_name;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class PNS_TEST_FIXTURE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static void RunTest( PNS_TEST_CASE* aTestData )
|
2022-10-23 22:15:32 +00:00
|
|
|
{
|
2022-10-30 23:01:08 +00:00
|
|
|
// printf( "Run %s\n", aTestData->GetName().c_str() );
|
|
|
|
|
|
|
|
PNS_LOG_FILE logFile;
|
|
|
|
PNS_LOG_PLAYER player;
|
|
|
|
|
|
|
|
if( !m_log )
|
|
|
|
m_log = new KI_TEST::CONSOLE_LOG;
|
2022-10-23 22:15:32 +00:00
|
|
|
|
2022-10-30 23:01:08 +00:00
|
|
|
if( !m_reporter )
|
|
|
|
m_reporter = new KI_TEST::CONSOLE_MSG_REPORTER( m_log );
|
2022-10-23 22:15:32 +00:00
|
|
|
|
2022-10-30 23:01:08 +00:00
|
|
|
if( !logFile.Load( wxString( aTestData->GetDataPath() ), m_reporter ) )
|
|
|
|
{
|
|
|
|
m_reporter->Report( wxString::Format( "Failed to load test '%s' from '%s'",
|
|
|
|
aTestData->GetName(), aTestData->GetDataPath() ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
|
|
|
}
|
2022-10-23 22:15:32 +00:00
|
|
|
|
2022-10-30 23:01:08 +00:00
|
|
|
player.SetReporter( m_reporter );
|
|
|
|
player.ReplayLog( &logFile, 0 );
|
|
|
|
bool pass = player.CompareResults( &logFile );
|
2022-10-23 22:15:32 +00:00
|
|
|
|
2022-10-30 23:01:08 +00:00
|
|
|
if( !pass )
|
|
|
|
BOOST_TEST_FAIL( "replay results inconsistent with reference reslts" );
|
|
|
|
}
|
2022-10-23 22:15:32 +00:00
|
|
|
|
2022-10-30 23:01:08 +00:00
|
|
|
static KI_TEST::CONSOLE_LOG* m_log;
|
|
|
|
static KI_TEST::CONSOLE_MSG_REPORTER* m_reporter;
|
|
|
|
};
|
2022-10-23 22:15:32 +00:00
|
|
|
|
2022-10-30 23:01:08 +00:00
|
|
|
KI_TEST::CONSOLE_LOG* PNS_TEST_FIXTURE::m_log = nullptr;
|
|
|
|
KI_TEST::CONSOLE_MSG_REPORTER* PNS_TEST_FIXTURE::m_reporter = nullptr;
|
2022-10-23 22:15:32 +00:00
|
|
|
|
2022-10-30 23:01:08 +00:00
|
|
|
std::vector<PNS_TEST_CASE*> createTestCases()
|
|
|
|
{
|
|
|
|
std::string absPath = KI_TEST::GetPcbnewTestDataDir() + std::string( "/pns_regressions/" );
|
|
|
|
std::vector<PNS_TEST_CASE*> testCases;
|
|
|
|
|
|
|
|
wxFileName fnameList( absPath + "tests.lst" );
|
|
|
|
wxTextFile fp( fnameList.GetFullPath() );
|
2022-10-23 22:15:32 +00:00
|
|
|
|
|
|
|
if( !fp.Open() )
|
|
|
|
{
|
2022-10-30 23:01:08 +00:00
|
|
|
wxString str =
|
|
|
|
wxString::Format( "Failed to load test list from '%s'.", fnameList.GetFullPath() );
|
|
|
|
BOOST_TEST_ERROR( str.c_str().AsChar() );
|
|
|
|
return testCases;
|
2022-10-23 22:15:32 +00:00
|
|
|
}
|
|
|
|
|
2022-10-30 23:01:08 +00:00
|
|
|
std::vector<wxString> lines;
|
2022-10-23 22:15:32 +00:00
|
|
|
|
|
|
|
if( !fp.Eof() )
|
|
|
|
{
|
2022-10-30 23:01:08 +00:00
|
|
|
lines.push_back( fp.GetFirstLine() );
|
|
|
|
|
2022-10-23 22:15:32 +00:00
|
|
|
while( !fp.Eof() )
|
|
|
|
{
|
|
|
|
auto l = fp.GetNextLine();
|
|
|
|
if( l.Length() > 0 )
|
2022-10-30 23:01:08 +00:00
|
|
|
{
|
|
|
|
lines.push_back( l );
|
|
|
|
}
|
2022-10-23 22:15:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fp.Close();
|
|
|
|
|
2022-10-30 23:01:08 +00:00
|
|
|
for( auto l : lines )
|
2022-10-23 22:15:32 +00:00
|
|
|
{
|
2022-10-30 23:01:08 +00:00
|
|
|
wxString fn( absPath );
|
|
|
|
fn = fn.Append( wxT( "/" ) );
|
|
|
|
fn = fn.Append( l );
|
|
|
|
fn = fn.Append( wxT( "/pns" ) );
|
|
|
|
|
|
|
|
testCases.push_back( new PNS_TEST_CASE( l.ToStdString(), fn.ToStdString() ) );
|
2022-10-23 22:15:32 +00:00
|
|
|
}
|
|
|
|
|
2022-10-30 23:01:08 +00:00
|
|
|
wxString str = wxString::Format( "Loaded %d test cases from '%s'.", (int) testCases.size(),
|
|
|
|
fnameList.GetFullPath() );
|
2022-10-23 22:15:32 +00:00
|
|
|
|
2022-10-30 23:01:08 +00:00
|
|
|
BOOST_TEST_MESSAGE( str.c_str().AsChar() );
|
2022-10-23 22:15:32 +00:00
|
|
|
|
2022-10-30 23:01:08 +00:00
|
|
|
return testCases;
|
|
|
|
}
|
|
|
|
|
|
|
|
static test_suite* init_pns_test_suite( int argc, char* argv[] )
|
|
|
|
{
|
|
|
|
test_suite* pnsTestSuite = BOOST_TEST_SUITE( "pns_regressions" );
|
|
|
|
|
|
|
|
auto testCases = createTestCases();
|
|
|
|
|
|
|
|
for( auto& c : testCases )
|
|
|
|
{
|
|
|
|
pnsTestSuite->add(
|
|
|
|
BOOST_TEST_CASE_NAME( std::bind( &PNS_TEST_FIXTURE::RunTest, c ), c->GetName() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
framework::master_test_suite().add( pnsTestSuite );
|
|
|
|
return 0;
|
2022-10-23 22:15:32 +00:00
|
|
|
}
|
2022-10-30 23:01:08 +00:00
|
|
|
|
|
|
|
int main( int argc, char* argv[] )
|
|
|
|
{
|
|
|
|
return unit_test_main( init_pns_test_suite, argc, argv );
|
|
|
|
}
|