KiCad PCB EDA Suite
Loading...
Searching...
No Matches
qa_pns_regressions_main.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 (C) 2020-2022 KiCad Developers.
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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#define BOOST_TEST_NO_MAIN
25
26#include <wx/cmdline.h>
27#include <wx/stdstream.h>
28#include <wx/wfstream.h>
29
33
34#include "pns_log_file.h"
36
37#include <boost/test/included/unit_test.hpp>
38
39using namespace boost::unit_test;
40
41#if 0
42
43bool runSingleTest( REPORTER* aReporter, wxString name, wxString testDirPath )
44{
45 PNS_LOG_FILE logFile;
46 PNS_LOG_PLAYER player;
47
48
49 wxString fn( testDirPath );
50 fn = fn.Append( "/" );
51 fn = fn.Append( name );
52 fn = fn.Append( "/pns" );
53
54
55 wxFileName fname( fn );
56
57 aReporter->Report( wxString::Format( "Running test '%s' from '%s'", name, fname.GetFullPath() ),
59
60 //fname.A
61
62 if( !logFile.Load( fname, aReporter ) )
63 {
64 aReporter->Report(
65 wxString::Format( "Failed to load test '%s' from '%s'", name, fname.GetFullPath() ),
67 }
68
69 player.SetReporter( aReporter );
70 player.ReplayLog( &logFile, 0 );
71 bool pass = player.CompareResults( &logFile );
72 return pass;
73}
74
75
76int main( int argc, char* argv[] )
77{
78
79
80 int passed = 0, failed = 0;
81
82 for( auto casename : testCases )
83 {
84 if( runSingleTest( &reporter, casename, cl_parser.GetParam( 0 ) ) )
85 passed++;
86 else
87 failed++;
88 }
89
90 reporter.Report(
91 wxString::Format( "SUMMARY: %d/%d tests cases PASSED", passed,
92 (int) testCases.size() ),
94
95
96 return failed ? -1 : 0;
97}
98#endif
99
101{
102 PNS_TEST_CASE( std::string name, std::string path ) : m_name( name ), m_dataPath( path ){};
103
104 std::string GetDataPath() const { return m_dataPath; }
105 std::string GetName() const { return m_name; }
106 std::string m_dataPath;
107 std::string m_name;
108};
109
110
112{
113public:
115 {
118 }
119
121 {
122 delete m_Reporter;
123 delete m_Log;
124 }
125
128};
129
130
132{
133public:
134 static void RunTest( PNS_TEST_CASE* aTestData )
135 {
136 // printf( "Run %s\n", aTestData->GetName().c_str() );
137
138 PNS_LOG_FILE logFile;
139 PNS_LOG_PLAYER player;
140
141 if( !logFile.Load( wxString( aTestData->GetDataPath() ), m_logger.m_Reporter ) )
142 {
143 m_logger.m_Reporter->Report( wxString::Format( "Failed to load test '%s' from '%s'",
144 aTestData->GetName(), aTestData->GetDataPath() ),
146 }
147
149 player.ReplayLog( &logFile, 0 );
150 bool pass = player.CompareResults( &logFile );
151
152 if( !pass )
153 BOOST_TEST_FAIL( "replay results inconsistent with reference reslts" );
154 }
155
157};
158
159
161
162
163std::vector<PNS_TEST_CASE*> createTestCases()
164{
165 std::string absPath = KI_TEST::GetPcbnewTestDataDir() + std::string( "/pns_regressions/" );
166 std::vector<PNS_TEST_CASE*> testCases;
167
168 wxFileName fnameList( absPath + "tests.lst" );
169 wxTextFile fp( fnameList.GetFullPath() );
170
171 if( !fp.Open() )
172 {
173 wxString str =
174 wxString::Format( "Failed to load test list from '%s'.", fnameList.GetFullPath() );
175 BOOST_TEST_ERROR( str.c_str().AsChar() );
176 return testCases;
177 }
178
179 std::vector<wxString> lines;
180
181 if( !fp.Eof() )
182 {
183 lines.push_back( fp.GetFirstLine() );
184
185 while( !fp.Eof() )
186 {
187 auto l = fp.GetNextLine();
188 if( l.Length() > 0 )
189 {
190 lines.push_back( l );
191 }
192 }
193 }
194
195 fp.Close();
196
197 for( auto l : lines )
198 {
199 wxString fn( absPath );
200 fn = fn.Append( wxT( "/" ) );
201 fn = fn.Append( l );
202 fn = fn.Append( wxT( "/pns" ) );
203
204 testCases.push_back( new PNS_TEST_CASE( l.ToStdString(), fn.ToStdString() ) );
205 }
206
207 wxString str = wxString::Format( "Loaded %d test cases from '%s'.", (int) testCases.size(),
208 fnameList.GetFullPath() );
209
210 BOOST_TEST_MESSAGE( str.c_str().AsChar() );
211
212 return testCases;
213}
214
215static test_suite* init_pns_test_suite( int argc, char* argv[] )
216{
217 test_suite* pnsTestSuite = BOOST_TEST_SUITE( "pns_regressions" );
218
219 auto testCases = createTestCases();
220
221 for( auto& c : testCases )
222 {
223 pnsTestSuite->add(
224 BOOST_TEST_CASE_NAME( std::bind( &PNS_TEST_FIXTURE::RunTest, c ), c->GetName() ) );
225 }
226
227 framework::master_test_suite().add( pnsTestSuite );
228 return 0;
229}
230
231int main( int argc, char* argv[] )
232{
233 return unit_test_main( init_pns_test_suite, argc, argv );
234}
const char * name
Definition: DXF_plotter.cpp:57
General utilities for PCB file IO for QA programs.
KI_TEST::CONSOLE_LOG * m_Log
KI_TEST::CONSOLE_MSG_REPORTER * m_Reporter
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
bool Load(const wxFileName &logFileName, REPORTER *aRpt)
bool CompareResults(PNS_LOG_FILE *aLog)
void ReplayLog(PNS_LOG_FILE *aLog, int aStartEventIndex=0, int aFrom=0, int aTo=-1, bool aUpdateExpectedResult=false)
void SetReporter(REPORTER *aReporter)
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:72
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
main()
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
std::vector< PNS_TEST_CASE * > createTestCases()
static test_suite * init_pns_test_suite(int argc, char *argv[])
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_INFO
std::string GetName() const
std::string GetDataPath() const
PNS_TEST_CASE(std::string name, std::string path)
static void RunTest(PNS_TEST_CASE *aTestData)
static FIXTURE_LOGGER m_logger