qa: introducing headless regression test suite for the P&S. Works by playing out pre-recorded events and comparing the resulting geometry against a human-approved reference.

Other changes:
- store all router settings (ROUTING_SETTINGS) in the debug dump in a separate JSON file
- store router mode (single/diff/tune) in the event log file
- factor out the regression test player and the graphical log/debug tool into separate main files
- bring CONSOLE_LOG and CONSOLE_MSG_REPORTER to the common test headers
This commit is contained in:
Tomasz Wlostowski 2022-10-24 00:15:32 +02:00
parent dfa6d22524
commit 99bcdf7979
11 changed files with 661 additions and 852 deletions

View File

@ -25,10 +25,10 @@
find_package(Boost COMPONENTS unit_test_framework REQUIRED) find_package(Boost COMPONENTS unit_test_framework REQUIRED)
find_package( wxWidgets 3.0.0 COMPONENTS gl aui adv html core net base xml stc REQUIRED ) find_package( wxWidgets 3.0.0 COMPONENTS gl aui adv html core net base xml stc REQUIRED )
add_definitions(-DBOOST_TEST_DYN_LINK -DPCBNEW -DTEST_APP_GUI) add_definitions(-DBOOST_TEST_DYN_LINK -DPCBNEW)
add_executable( test_pns set( COMMON_SRCS
../../../pcbnew/drc/drc_rule.cpp ../../../pcbnew/drc/drc_rule.cpp
../../../pcbnew/drc/drc_rule_condition.cpp ../../../pcbnew/drc/drc_rule_condition.cpp
../../../pcbnew/drc/drc_rule_parser.cpp ../../../pcbnew/drc/drc_rule_parser.cpp
@ -54,6 +54,10 @@ add_executable( test_pns
pns_log_file.cpp pns_log_file.cpp
pns_log_player.cpp pns_log_player.cpp
pns_test_debug_decorator.cpp pns_test_debug_decorator.cpp
)
add_executable( pns_debug_tool
${COMMON_SRCS}
pns_log_viewer_frame.cpp pns_log_viewer_frame.cpp
pns_log_viewer_frame_base.cpp pns_log_viewer_frame_base.cpp
label_manager.cpp label_manager.cpp
@ -63,21 +67,58 @@ add_executable( test_pns
../../qa_utils/mocks.cpp ../../qa_utils/mocks.cpp
playground.cpp playground.cpp
main.cpp pns_debug_tool_main.cpp
) )
# Pcbnew tests, so pretend to be pcbnew (for units, etc) add_executable( qa_pns_regressions
target_compile_definitions( test_pns ${COMMON_SRCS}
PRIVATE PCBNEW ../../qa_utils/pcb_test_frame.cpp
../../qa_utils/test_app_main.cpp
../../qa_utils/utility_program.cpp
../../qa_utils/mocks.cpp
qa_pns_regressions_main.cpp
) )
# Pcbnew tests, so pretend to be pcbnew (for units, etc)
target_compile_definitions( pns_debug_tool
PRIVATE PCBNEW
)
target_compile_definitions( qa_pns_regressions
PRIVATE PCBNEW TEST_APP_NO_MAIN
)
# Anytime we link to the kiface_objects, we have to add a dependency on the last object # Anytime we link to the kiface_objects, we have to add a dependency on the last object
# to ensure that the generated lexer files are finished being used before the qa runs in a # to ensure that the generated lexer files are finished being used before the qa runs in a
# multi-threaded build # multi-threaded build
add_dependencies( test_pns pcbnew ) add_dependencies( pns_debug_tool pcbnew )
add_dependencies( qa_pns_regressions pcbnew )
target_link_libraries( test_pns target_link_libraries( pns_debug_tool
qa_pcbnew_utils
connectivity
pcbcommon
pnsrouter
gal
common
gal
qa_utils
dxflib_qcad
tinyspline_lib
nanosvg
idf3
pcbcommon
3d-viewer
${PCBNEW_IO_LIBRARIES}
${wxWidgets_LIBRARIES}
${GDI_PLUS_LIBRARIES}
${PYTHON_LIBRARIES}
${Boost_LIBRARIES}
${PCBNEW_EXTRA_LIBS} # -lrt must follow Boost
)
target_link_libraries( qa_pns_regressions
qa_pcbnew_utils qa_pcbnew_utils
connectivity connectivity
pcbcommon pcbcommon

View File

@ -1,3 +1,26 @@
/*
* 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
*/
#include <gal/graphics_abstraction_layer.h> #include <gal/graphics_abstraction_layer.h>
#include <gal/color4d.h> #include <gal/color4d.h>
#include <view/view_overlay.h> #include <view/view_overlay.h>

View File

@ -1,3 +1,27 @@
/*
* 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
*/
#ifndef __LABEL_MANAGER_H #ifndef __LABEL_MANAGER_H
#define __LABEL_MANAGER_H #define __LABEL_MANAGER_H
@ -38,4 +62,4 @@ private:
std::vector<LABEL> m_labels; std::vector<LABEL> m_labels;
}; };
#endif #endif

View File

@ -1,6 +1,31 @@
/*
* 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
*/
#include <wx/cmdline.h> #include <wx/cmdline.h>
#include <qa_utils/utility_registry.h> #include <qa_utils/utility_registry.h>
#include <pcbnew_utils/board_test_utils.h>
#include "pns_log_file.h" #include "pns_log_file.h"
#include "pns_log_viewer_frame.h" #include "pns_log_viewer_frame.h"
@ -46,7 +71,8 @@ int replay_main_func( int argc, char* argv[] )
{ {
wxCmdLineParser cl_parser( argc, argv ); wxCmdLineParser cl_parser( argc, argv );
cl_parser.SetDesc( g_cmdLineDesc ); cl_parser.SetDesc( g_cmdLineDesc );
cl_parser.AddUsageText( _( "PNS Log (Re)player. Allows to step through the log written by the ROUTER_TOOL " cl_parser.AddUsageText(
_( "PNS Log (Re)player. Allows to step through the log written by the ROUTER_TOOL "
"in debug KiCad builds." ) ); "in debug KiCad builds." ) );
int cmd_parsed_ok = cl_parser.Parse(); int cmd_parsed_ok = cl_parser.Parse();
@ -59,24 +85,28 @@ int replay_main_func( int argc, char* argv[] )
if( cmd_parsed_ok != 0 ) if( cmd_parsed_ok != 0 )
{ {
printf("P&S Log Replay/Debug tool. For command line options, call %s -h.\n\n", argv[0] ); printf("P&S Log Replay/Debug tool. For command line options, call %s -h.\n\n", argv[0] );
// Help and invalid input both stop here
return ( cmd_parsed_ok == -1 ) ? KI_TEST::RET_CODES::OK : KI_TEST::RET_CODES::BAD_CMDLINE; return ( cmd_parsed_ok == -1 ) ? KI_TEST::RET_CODES::OK : KI_TEST::RET_CODES::BAD_CMDLINE;
} }
wxString filename; wxString filename;
#if 0
long iter_limit = 256; long iter_limit = 256;
long steps_limit = -1; long steps_limit = -1;
cl_parser.Found( "iteration-limit", &iter_limit ); cl_parser.Found( "iteration-limit", &iter_limit );
cl_parser.Found( "steps-limit", &steps_limit ); cl_parser.Found( "steps-limit", &steps_limit );
filename = cl_parser.GetParam(0); #endif
printf("iters %d steps %d file '%s'\n", iter_limit, steps_limit, (const char *) filename.c_str() ); filename = cl_parser.GetParam(0);
auto frame = new PNS_LOG_VIEWER_FRAME( nullptr ); auto frame = new PNS_LOG_VIEWER_FRAME( nullptr );
PNS_LOG_FILE* logFile = new PNS_LOG_FILE; PNS_LOG_FILE* logFile = new PNS_LOG_FILE;
logFile->Load( wxFileName( argv[1] ) );
KI_TEST::CONSOLE_LOG log;
KI_TEST::CONSOLE_MSG_REPORTER reporter( &log );
logFile->Load( wxFileName( argv[1] ), &reporter );
frame->SetLogFile( logFile ); frame->SetLogFile( logFile );
return 0; return 0;

View File

@ -27,6 +27,8 @@
#include "pns_log_file.h" #include "pns_log_file.h"
#include <router/pns_segment.h>
#include <board_design_settings.h> #include <board_design_settings.h>
#include <pcbnew/plugins/kicad/pcb_plugin.h> #include <pcbnew/plugins/kicad/pcb_plugin.h>
@ -58,13 +60,217 @@ static const wxString readLine( FILE* f )
} }
PNS_LOG_FILE::PNS_LOG_FILE() PNS_LOG_FILE::PNS_LOG_FILE() :
m_mode( PNS::ROUTER_MODE::PNS_MODE_ROUTE_SINGLE )
{ {
m_routerSettings.reset( new PNS::ROUTING_SETTINGS( nullptr, "" ) ); m_routerSettings.reset( new PNS::ROUTING_SETTINGS( nullptr, "" ) );
} }
static std::shared_ptr<SHAPE> parseShape( SHAPE_TYPE expectedType, wxStringTokenizer& aTokens )
{
SHAPE_TYPE type = static_cast<SHAPE_TYPE> ( wxAtoi( aTokens.GetNextToken() ) );
bool PNS_LOG_FILE::Load( const wxFileName& logFileName ) if( type == SHAPE_TYPE::SH_SEGMENT )
{
std::shared_ptr<SHAPE_SEGMENT> sh( new SHAPE_SEGMENT );
VECTOR2I a,b;
a.x = wxAtoi( aTokens.GetNextToken() );
a.y = wxAtoi( aTokens.GetNextToken() );
b.x = wxAtoi( aTokens.GetNextToken() );
b.y = wxAtoi( aTokens.GetNextToken() );
int width = wxAtoi( aTokens.GetNextToken() );
sh->SetSeg( SEG( a, b ));
sh->SetWidth( width );
return sh;
}
else if ( type == SHAPE_TYPE::SH_CIRCLE )
{
std::shared_ptr<SHAPE_CIRCLE> sh( new SHAPE_CIRCLE );
VECTOR2I a;
a.x = wxAtoi( aTokens.GetNextToken() );
a.y = wxAtoi( aTokens.GetNextToken() );
int radius = wxAtoi( aTokens.GetNextToken() );
sh->SetCenter( a );
sh->SetRadius( radius );
return sh;
}
return nullptr;
}
bool parseCommonPnsProps( PNS::ITEM* aItem, const wxString& cmd, wxStringTokenizer& aTokens )
{
if( cmd == "net" )
{
aItem->SetNet( wxAtoi( aTokens.GetNextToken() ) );
return true;
} else if ( cmd == "layers" )
{
int start = wxAtoi( aTokens.GetNextToken() );
int end = wxAtoi( aTokens.GetNextToken() );
aItem->SetLayers( LAYER_RANGE( start, end ));
return true;
}
return false;
}
static PNS::SEGMENT* parsePnsSegmentFromString( PNS::SEGMENT* aSeg, wxStringTokenizer& aTokens )
{
PNS::SEGMENT* seg = new ( PNS::SEGMENT );
while( aTokens.CountTokens() )
{
wxString cmd = aTokens.GetNextToken();
if( !parseCommonPnsProps( seg, cmd, aTokens ) )
{
if ( cmd == "shape" )
{
auto sh = parseShape( SH_SEGMENT, aTokens );
if(!sh)
return nullptr;
seg->SetShape( *static_cast<SHAPE_SEGMENT*>(sh.get()) );
}
}
}
return seg;
}
static PNS::VIA* parsePnsViaFromString( PNS::VIA* aSeg, wxStringTokenizer& aTokens )
{
PNS::VIA* via = new ( PNS::VIA );
while( aTokens.CountTokens() )
{
wxString cmd = aTokens.GetNextToken();
if( !parseCommonPnsProps( via, cmd, aTokens ) )
{
if ( cmd == "shape" )
{
auto sh = parseShape( SH_CIRCLE, aTokens );
if(!sh)
return nullptr;
auto *sc = static_cast<SHAPE_CIRCLE*>( sh.get() );
via->SetPos( sc->GetCenter() );
via->SetDiameter( 2 * sc->GetRadius() );
}
else if ( cmd == "drill" )
{
via->SetDrill( wxAtoi( aTokens.GetNextToken() ) );
}
}
}
return via;
}
static PNS::ITEM* parseItemFromString( wxStringTokenizer& aTokens )
{
wxString type = aTokens.GetNextToken();
if( type == "segment" )
{
auto seg = new PNS::SEGMENT();
return parsePnsSegmentFromString( seg, aTokens );
}
else if( type == "via" )
{
auto seg = new PNS::VIA();
return parsePnsViaFromString( seg, aTokens );
}
return nullptr;
}
bool comparePnsItems( const PNS::ITEM*a , const PNS::ITEM* b )
{
if( a->Kind() != b->Kind() )
return false;
if( a->Net() != b->Net() )
return false;
if( a->Layers() != b->Layers() )
return false;
if( a->Kind() == PNS::ITEM::VIA_T )
{
auto va = static_cast<const PNS::VIA*>(a);
auto vb = static_cast<const PNS::VIA*>(b);
if( va->Diameter() != vb->Diameter() )
return false;
if( va->Drill() != vb->Drill() )
return false;
if( va->Pos() != vb->Pos() )
return false;
}
else if ( a->Kind() == PNS::ITEM::SEGMENT_T )
{
auto sa = static_cast<const PNS::SEGMENT*>(a);
auto sb = static_cast<const PNS::SEGMENT*>(b);
if( sa->Seg() != sb->Seg() )
return false;
if( sa->Width() != sb->Width() )
return false;
}
return true;
}
bool PNS_LOG_FILE::COMMIT_STATE::Compare( const PNS_LOG_FILE::COMMIT_STATE& aOther )
{
COMMIT_STATE check( aOther );
//printf("pre-compare: %d/%d\n", check.m_addedItems.size(), check.m_removedIds.size() );
//printf("pre-compare (log): %d/%d\n", m_addedItems.size(), m_removedIds.size() );
for( auto uuid : m_removedIds )
{
if( check.m_removedIds.find( uuid ) != check.m_removedIds.end() )
{
check.m_removedIds.erase( uuid );
}
else
{
return false; // removed twice? wtf
}
}
for( auto item : m_addedItems )
{
for( auto chk : check.m_addedItems )
{
if( comparePnsItems( item, chk ) )
{
check.m_addedItems.erase( chk );
break;
}
}
}
//printf("post-compare: %d/%d\n", check.m_addedItems.size(), check.m_removedIds.size() );
return check.m_addedItems.empty() && check.m_removedIds.empty();
}
bool PNS_LOG_FILE::Load( const wxFileName& logFileName, REPORTER* aRpt )
{ {
wxFileName fname_log( logFileName ); wxFileName fname_log( logFileName );
fname_log.SetExt( wxT( "log" ) ); fname_log.SetExt( wxT( "log" ) );
@ -76,9 +282,13 @@ bool PNS_LOG_FILE::Load( const wxFileName& logFileName )
fname_project.SetExt( wxT( "kicad_pro" ) ); fname_project.SetExt( wxT( "kicad_pro" ) );
fname_project.MakeAbsolute(); fname_project.MakeAbsolute();
wxFileName fname_settings( logFileName );
fname_settings.SetExt( wxT( "settings" ) );
FILE* f = fopen( fname_log.GetFullPath().c_str(), "rb" ); FILE* f = fopen( fname_log.GetFullPath().c_str(), "rb" );
printf("Loading dump from '%s'\n", (const char*) fname_log.GetFullPath().c_str() ); aRpt->Report( wxString::Format( "Loading log from '%s'", fname_log.GetFullPath() ) );
if( !f ) if( !f )
return false; return false;
@ -92,7 +302,11 @@ bool PNS_LOG_FILE::Load( const wxFileName& logFileName )
wxString cmd = tokens.GetNextToken(); wxString cmd = tokens.GetNextToken();
if( cmd == "event" ) if( cmd == wxT("mode") )
{
m_mode = static_cast<PNS::ROUTER_MODE>( wxAtoi( tokens.GetNextToken() ) );
}
else if( cmd == wxT("event") )
{ {
EVENT_ENTRY evt; EVENT_ENTRY evt;
evt.p.x = wxAtoi( tokens.GetNextToken() ); evt.p.x = wxAtoi( tokens.GetNextToken() );
@ -101,18 +315,29 @@ bool PNS_LOG_FILE::Load( const wxFileName& logFileName )
evt.uuid = KIID( tokens.GetNextToken() ); evt.uuid = KIID( tokens.GetNextToken() );
m_events.push_back( evt ); m_events.push_back( evt );
} }
else if( cmd == "config" ) else if ( cmd == wxT("added") )
{ {
m_routerSettings->SetMode( (PNS::PNS_MODE) wxAtoi( tokens.GetNextToken() ) ); auto item = parseItemFromString( tokens );
m_routerSettings->SetRemoveLoops( wxAtoi( tokens.GetNextToken() ) ); m_commitState.m_addedItems.insert( item );
m_routerSettings->SetFixAllSegments( wxAtoi( tokens.GetNextToken() ) ); }
m_routerSettings->SetCornerMode( else if ( cmd == wxT("removed") )
(DIRECTION_45::CORNER_MODE) wxAtoi( tokens.GetNextToken() ) ); {
m_commitState.m_removedIds.insert( KIID( tokens.GetNextToken() ) );
} }
} }
fclose( f ); fclose( f );
aRpt->Report( wxString::Format( wxT("Loading router settings from '%s'"), fname_settings.GetFullPath() ) );
bool ok = m_routerSettings->LoadFromRawFile( fname_settings.GetFullPath() );
if( !ok )
{
aRpt->Report( wxString::Format( wxT("Failed to load routing settings. Usign defaults.")) , RPT_SEVERITY_WARNING );
}
aRpt->Report( wxString::Format( wxT("Loading project settings from '%s'"), fname_settings.GetFullPath() ) );
m_settingsMgr.reset( new SETTINGS_MANAGER ( true ) ); m_settingsMgr.reset( new SETTINGS_MANAGER ( true ) );
m_settingsMgr->LoadProject( fname_project.GetFullPath() ); m_settingsMgr->LoadProject( fname_project.GetFullPath() );
@ -120,6 +345,8 @@ bool PNS_LOG_FILE::Load( const wxFileName& logFileName )
try try
{ {
PCB_PLUGIN io; PCB_PLUGIN io;
aRpt->Report( wxString::Format( wxT("Loading board snapshot from '%s'"), fname_dump.GetFullPath() ) );
m_board.reset( io.Load( fname_dump.GetFullPath(), nullptr, nullptr ) ); m_board.reset( io.Load( fname_dump.GetFullPath(), nullptr, nullptr ) );
m_board->SetProject( m_settingsMgr->GetProject( fname_project.GetFullPath() ) ); m_board->SetProject( m_settingsMgr->GetProject( fname_project.GetFullPath() ) );
@ -139,8 +366,8 @@ bool PNS_LOG_FILE::Load( const wxFileName& logFileName )
} }
catch( const PARSE_ERROR& parse_error ) catch( const PARSE_ERROR& parse_error )
{ {
printf( "parse error : %s (%s)\n", (const char*) parse_error.Problem().c_str(), aRpt->Report( wxString::Format( "parse error : %s (%s)\n", parse_error.Problem(),
(const char*) parse_error.What().c_str() ); parse_error.What() ), RPT_SEVERITY_ERROR );
return false; return false;
} }

View File

@ -30,12 +30,15 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include <set>
#include <wx/filename.h> #include <wx/filename.h>
#include <kiid.h> #include <kiid.h>
#include <math/vector2d.h> #include <math/vector2d.h>
#include <router/pns_logger.h> #include <router/pns_logger.h>
#include <router/pns_router.h>
#include <router/pns_item.h> #include <router/pns_item.h>
#include <router/pns_routing_settings.h> #include <router/pns_routing_settings.h>
@ -58,8 +61,24 @@ public:
KIID uuid; KIID uuid;
}; };
struct COMMIT_STATE
{
COMMIT_STATE() {};
COMMIT_STATE( const COMMIT_STATE& aOther ) :
m_removedIds( aOther.m_removedIds ),
m_addedItems( aOther.m_addedItems )
{
}
std::set<KIID> m_removedIds;
std::set<PNS::ITEM*> m_addedItems;
bool Compare( const COMMIT_STATE& aOther );
};
// Loads a P&S event log and the associated board file. These two always go together. // Loads a P&S event log and the associated board file. These two always go together.
bool Load( const wxFileName& logFileName ); bool Load( const wxFileName& logFileName, REPORTER* aRpt );
BOARD_CONNECTED_ITEM* ItemById( const EVENT_ENTRY& evt ); BOARD_CONNECTED_ITEM* ItemById( const EVENT_ENTRY& evt );
@ -70,11 +89,17 @@ public:
PNS::ROUTING_SETTINGS* GetRoutingSettings() const { return m_routerSettings.get(); } PNS::ROUTING_SETTINGS* GetRoutingSettings() const { return m_routerSettings.get(); }
const COMMIT_STATE& GetExpectedResult() const { return m_commitState; }
PNS::ROUTER_MODE GetMode() const { return m_mode; }
private: private:
std::shared_ptr<SETTINGS_MANAGER> m_settingsMgr; std::shared_ptr<SETTINGS_MANAGER> m_settingsMgr;
std::unique_ptr<PNS::ROUTING_SETTINGS> m_routerSettings; std::unique_ptr<PNS::ROUTING_SETTINGS> m_routerSettings;
std::vector<EVENT_ENTRY> m_events; std::vector<EVENT_ENTRY> m_events;
std::shared_ptr<BOARD> m_board; std::shared_ptr<BOARD> m_board;
COMMIT_STATE m_commitState;
PNS::ROUTER_MODE m_mode;
}; };
#endif #endif

View File

@ -25,14 +25,7 @@
#include "pns_log_file.h" #include "pns_log_file.h"
#include "pns_log_player.h" #include "pns_log_player.h"
#if 0 #include <pcbnew_utils/board_test_utils.h>
#include <qa/drc_proto/drc_proto.h>
#include <board_design_settings.h>
#include <pcbnew/drc/drc_engine.h>
#include <pcbnew/drc/drc_test_provider.h>
#include <pns_arc.h>
#endif
#define PNSLOGINFO PNS::DEBUG_DECORATOR::SRC_LOCATION_INFO( __FILE__, __FUNCTION__, __LINE__ ) #define PNSLOGINFO PNS::DEBUG_DECORATOR::SRC_LOCATION_INFO( __FILE__, __FUNCTION__, __LINE__ )
@ -40,6 +33,7 @@ using namespace PNS;
PNS_LOG_PLAYER::PNS_LOG_PLAYER() PNS_LOG_PLAYER::PNS_LOG_PLAYER()
{ {
SetReporter( &NULL_REPORTER::GetInstance() );
} }
@ -49,11 +43,6 @@ PNS_LOG_PLAYER::~PNS_LOG_PLAYER()
delete m_debugDecorator; delete m_debugDecorator;
} }
void PNS_LOG_PLAYER::SetMode( PNS::ROUTER_MODE mode )
{
m_mode = mode;
}
void PNS_LOG_PLAYER::createRouter() void PNS_LOG_PLAYER::createRouter()
{ {
m_viewTracker.reset( new PNS_LOG_VIEW_TRACKER ); m_viewTracker.reset( new PNS_LOG_VIEW_TRACKER );
@ -62,7 +51,6 @@ void PNS_LOG_PLAYER::createRouter()
m_iface->SetBoard( m_board.get() ); m_iface->SetBoard( m_board.get() );
m_router->SetInterface( m_iface.get() ); m_router->SetInterface( m_iface.get() );
m_router->ClearWorld(); m_router->ClearWorld();
m_router->SetMode( m_mode );
m_router->SyncWorld(); m_router->SyncWorld();
m_router->LoadSettings( new PNS::ROUTING_SETTINGS( nullptr, "" ) ); m_router->LoadSettings( new PNS::ROUTING_SETTINGS( nullptr, "" ) );
m_router->Settings().SetMode( PNS::RM_Walkaround ); m_router->Settings().SetMode( PNS::RM_Walkaround );
@ -75,6 +63,27 @@ void PNS_LOG_PLAYER::createRouter()
m_iface->SetDebugDecorator( m_debugDecorator ); m_iface->SetDebugDecorator( m_debugDecorator );
} }
const PNS_LOG_FILE::COMMIT_STATE PNS_LOG_PLAYER::GetRouterUpdatedItems()
{
PNS_LOG_FILE::COMMIT_STATE state;
std::vector<PNS::ITEM*> added, removed;
m_router->GetUpdatedItems( removed, added );
//printf("a %d r %d\n", added.size(), removed.size() );
for( auto item : removed )
{
state.m_removedIds.insert( item->Parent()->m_Uuid );
}
for( auto item : added )
{
state.m_addedItems.insert( item );
}
return state;
}
void PNS_LOG_PLAYER::ReplayLog( PNS_LOG_FILE* aLog, int aStartEventIndex, int aFrom, int aTo ) void PNS_LOG_PLAYER::ReplayLog( PNS_LOG_FILE* aLog, int aStartEventIndex, int aFrom, int aTo )
{ {
m_board = aLog->GetBoard(); m_board = aLog->GetBoard();
@ -83,9 +92,8 @@ void PNS_LOG_PLAYER::ReplayLog( PNS_LOG_FILE* aLog, int aStartEventIndex, int aF
m_router->LoadSettings( aLog->GetRoutingSettings() ); m_router->LoadSettings( aLog->GetRoutingSettings() );
printf( "Router mode: %d\n", m_router->Settings().Mode() );
int eventIdx = 0; int eventIdx = 0;
int totalEvents = aLog->Events().size();
for( auto evt : aLog->Events() ) for( auto evt : aLog->Events() )
{ {
@ -103,9 +111,12 @@ void PNS_LOG_PLAYER::ReplayLog( PNS_LOG_FILE* aLog, int aStartEventIndex, int aF
{ {
m_debugDecorator->NewStage( "route-start", 0, PNSLOGINFO ); m_debugDecorator->NewStage( "route-start", 0, PNSLOGINFO );
m_viewTracker->SetStage( m_debugDecorator->GetStageCount() - 1 ); m_viewTracker->SetStage( m_debugDecorator->GetStageCount() - 1 );
m_debugDecorator->Message(
wxString::Format( "route-start (%d, %d)", evt.p.x, evt.p.y ) ); auto msg = wxString::Format( "event [%d/%d]: route-start (%d, %d)", eventIdx, totalEvents, evt.p.x, evt.p.y );
printf( " rtr start-route (%d, %d) %p \n", evt.p.x, evt.p.y, ritem );
m_debugDecorator->Message( msg );
m_reporter->Report( msg );
m_router->StartRouting( evt.p, ritem, ritem ? ritem->Layers().Start() : F_Cu ); m_router->StartRouting( evt.p, ritem, ritem ? ritem->Layers().Start() : F_Cu );
break; break;
} }
@ -114,10 +125,13 @@ void PNS_LOG_PLAYER::ReplayLog( PNS_LOG_FILE* aLog, int aStartEventIndex, int aF
{ {
m_debugDecorator->NewStage( "drag-start", 0, PNSLOGINFO ); m_debugDecorator->NewStage( "drag-start", 0, PNSLOGINFO );
m_viewTracker->SetStage( m_debugDecorator->GetStageCount() - 1 ); m_viewTracker->SetStage( m_debugDecorator->GetStageCount() - 1 );
m_debugDecorator->Message(
wxString::Format( "drag-start (%d, %d)", evt.p.x, evt.p.y ) ); auto msg = wxString::Format( "event [%d/%d]: drag-start (%d, %d)", eventIdx, totalEvents, evt.p.x, evt.p.y );
m_debugDecorator->Message( msg );
m_reporter->Report( msg );
bool rv = m_router->StartDragging( evt.p, ritem, 0 ); bool rv = m_router->StartDragging( evt.p, ritem, 0 );
printf( " rtr start-drag (%d, %d) %p ret %d\n", evt.p.x, evt.p.y, ritem, rv ? 1 : 0 );
break; break;
} }
@ -135,7 +149,12 @@ void PNS_LOG_PLAYER::ReplayLog( PNS_LOG_FILE* aLog, int aStartEventIndex, int aF
{ {
m_debugDecorator->NewStage( "move", 0, PNSLOGINFO ); m_debugDecorator->NewStage( "move", 0, PNSLOGINFO );
m_viewTracker->SetStage( m_debugDecorator->GetStageCount() - 1 ); m_viewTracker->SetStage( m_debugDecorator->GetStageCount() - 1 );
m_debugDecorator->Message( wxString::Format( "move (%d, %d)", evt.p.x, evt.p.y ) );
auto msg = wxString::Format( "event [%d/%d]: move (%d, %d)", eventIdx, totalEvents, evt.p.x, evt.p.y );
m_debugDecorator->Message( msg );
m_reporter->Report( msg );
bool ret = m_router->Move( evt.p, ritem ); bool ret = m_router->Move( evt.p, ritem );
m_debugDecorator->SetCurrentStageStatus( ret ); m_debugDecorator->SetCurrentStageStatus( ret );
break; break;
@ -144,6 +163,12 @@ void PNS_LOG_PLAYER::ReplayLog( PNS_LOG_FILE* aLog, int aStartEventIndex, int aF
case LOGGER::EVT_TOGGLE_VIA: case LOGGER::EVT_TOGGLE_VIA:
{ {
m_debugDecorator->NewStage( "toggle-via", 0, PNSLOGINFO ); m_debugDecorator->NewStage( "toggle-via", 0, PNSLOGINFO );
auto msg = wxString::Format( "event [%d/%d]: toggle-via", eventIdx, totalEvents );
m_debugDecorator->Message( msg );
m_reporter->Report( msg );
m_viewTracker->SetStage( m_debugDecorator->GetStageCount() - 1 ); m_viewTracker->SetStage( m_debugDecorator->GetStageCount() - 1 );
m_router->ToggleViaPlacement(); m_router->ToggleViaPlacement();
break; break;
@ -198,6 +223,16 @@ void PNS_LOG_PLAYER::ReplayLog( PNS_LOG_FILE* aLog, int aStartEventIndex, int aF
} }
#endif #endif
} }
}
bool PNS_LOG_PLAYER::CompareResults( PNS_LOG_FILE* aLog )
{
auto cstate = GetRouterUpdatedItems();
return cstate.Compare( aLog->GetExpectedResult() );
} }
@ -253,3 +288,4 @@ void PNS_LOG_VIEW_TRACKER::DisplayItem( const PNS::ITEM* aItem )
m_vitems[m_currentStage].push_back( ent ); m_vitems[m_currentStage].push_back( ent );
//printf("DBG disp cur %d cnt %d\n", m_currentStage, m_vitems[m_currentStage].size() ); //printf("DBG disp cur %d cnt %d\n", m_currentStage, m_vitems[m_currentStage].size() );
} }

View File

@ -34,6 +34,7 @@
class PNS_TEST_DEBUG_DECORATOR; class PNS_TEST_DEBUG_DECORATOR;
class PNS_LOG_FILE; class PNS_LOG_FILE;
class PNS_LOG_PLAYER; class PNS_LOG_PLAYER;
class REPORTER;
class PNS_LOG_VIEW_TRACKER class PNS_LOG_VIEW_TRACKER
{ {
@ -81,20 +82,28 @@ public:
PNS_LOG_PLAYER(); PNS_LOG_PLAYER();
~PNS_LOG_PLAYER(); ~PNS_LOG_PLAYER();
void SetMode( PNS::ROUTER_MODE mode );
void ReplayLog( PNS_LOG_FILE* aLog, int aStartEventIndex = 0, int aFrom = 0, int aTo = -1 ); void ReplayLog( PNS_LOG_FILE* aLog, int aStartEventIndex = 0, int aFrom = 0, int aTo = -1 );
void SetReporter( REPORTER* aReporter ) { m_reporter = aReporter; }
PNS_TEST_DEBUG_DECORATOR* GetDebugDecorator() { return m_debugDecorator; }; PNS_TEST_DEBUG_DECORATOR* GetDebugDecorator() { return m_debugDecorator; };
std::shared_ptr<PNS_LOG_VIEW_TRACKER> GetViewTracker() { return m_viewTracker; } std::shared_ptr<PNS_LOG_VIEW_TRACKER> GetViewTracker() { return m_viewTracker; }
void SetTimeLimit( uint64_t microseconds ) { m_timeLimitUs = microseconds; }
bool CompareResults( PNS_LOG_FILE* aLog );
const PNS_LOG_FILE::COMMIT_STATE GetRouterUpdatedItems();
private: private:
void createRouter(); void createRouter();
PNS::ROUTER_MODE m_mode;
std::shared_ptr<PNS_LOG_VIEW_TRACKER> m_viewTracker; std::shared_ptr<PNS_LOG_VIEW_TRACKER> m_viewTracker;
PNS_TEST_DEBUG_DECORATOR* m_debugDecorator; PNS_TEST_DEBUG_DECORATOR* m_debugDecorator;
std::shared_ptr<BOARD> m_board; std::shared_ptr<BOARD> m_board;
std::unique_ptr<PNS_LOG_PLAYER_KICAD_IFACE> m_iface; std::unique_ptr<PNS_LOG_PLAYER_KICAD_IFACE> m_iface;
std::unique_ptr<PNS::ROUTER> m_router; std::unique_ptr<PNS::ROUTER> m_router;
uint64_t m_timeLimitUs;
REPORTER* m_reporter;
}; };
#endif #endif

View File

@ -1,798 +0,0 @@
/*
* 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
*/
// WARNING - this Tom's crappy PNS hack tool code. Please don't complain about its quality
// (unless you want to improve it).
#include <wx/clipbrd.h>
#include <qa_utils/utility_registry.h>
#include <pgm_base.h>
#include <profile.h>
#include <trace_helpers.h>
#include <view/view_overlay.h>
#include "pns_log.h"
#include "router/pns_diff_pair.h"
#include "router/pns_utils.h"
#include "pns_log_viewer_frame.h"
#include "qa/drc_proto/drc_proto.h"
#include "label_manager.h"
#define TOM_EXTRA_DEBUG
class WX_SHAPE_TREE_ITEM_DATA : public wxClientData
{
public:
WX_SHAPE_TREE_ITEM_DATA( PNS_TEST_DEBUG_DECORATOR::DEBUG_ENT* item ) : m_item( item ){};
PNS_TEST_DEBUG_DECORATOR::DEBUG_ENT* m_item;
};
PNS_LOG_VIEWER_OVERLAY::PNS_LOG_VIEWER_OVERLAY( KIGFX::GAL* aGal )
{
m_labelMgr.reset( new LABEL_MANAGER( aGal ) );
}
void PNS_LOG_VIEWER_OVERLAY::AnnotatedPolyline( const SHAPE_LINE_CHAIN& aL, std::string name,
bool aShowVertexNumbers )
{
Polyline( aL );
if( aShowVertexNumbers)
m_labelMgr->Add( aL, GetStrokeColor() );
}
void PNS_LOG_VIEWER_OVERLAY::AnnotatedPoint( const VECTOR2I p, int size, std::string name, bool aShowVertexNumbers )
{
Line( p + VECTOR2D( size, size ), p - VECTOR2D( size, size ) );
Line( p + VECTOR2D( -size, size ), p - VECTOR2D( -size, size ) );
if( name.length() > 0 )
m_labelMgr->Add( p, name, GetStrokeColor() );
}
void PNS_LOG_VIEWER_OVERLAY::Arc( const SHAPE_ARC& arc )
{
double radius = arc.GetRadius();
EDA_ANGLE start_angle = arc.GetStartAngle();
EDA_ANGLE angle = arc.GetCentralAngle();
KIGFX::VIEW_OVERLAY::SetLineWidth( arc.GetWidth() / 10 );
KIGFX::VIEW_OVERLAY::Arc( arc.GetCenter(), radius, start_angle, start_angle + angle );
COLOR4D prevStrokeCol = KIGFX::VIEW_OVERLAY::GetStrokeColor();
COLOR4D lightStrokeCol = prevStrokeCol.WithAlpha(0.5);
KIGFX::VIEW_OVERLAY::SetStrokeColor( lightStrokeCol );
KIGFX::VIEW_OVERLAY::SetLineWidth( arc.GetWidth() );
KIGFX::VIEW_OVERLAY::Arc( arc.GetCenter(), radius, start_angle, start_angle + angle );
KIGFX::VIEW_OVERLAY::SetStrokeColor( prevStrokeCol );
}
void PNS_LOG_VIEWER_OVERLAY::DrawAnnotations()
{
m_labelMgr->Redraw( this );
}
PNS_LOG_VIEWER_FRAME::PNS_LOG_VIEWER_FRAME( wxFrame* frame ) : PNS_LOG_VIEWER_FRAME_BASE( frame )
{
LoadSettings();
createView( this, PCB_DRAW_PANEL_GAL::GAL_TYPE_OPENGL );
m_viewSizer->Add( m_galPanel.get(), 1, wxEXPAND, 5 );
Layout();
Show( true );
Maximize();
Raise();
auto settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
m_galPanel->GetView()->GetPainter()->GetSettings() );
PCB_DISPLAY_OPTIONS opts;
opts.m_ZoneDisplayMode = ZONE_DISPLAY_MODE::SHOW_ZONE_OUTLINE;
double opacity = 0.5;
opts.m_TrackOpacity = opacity; ///< Opacity override for all tracks
opts.m_ViaOpacity = opacity; ///< Opacity override for all types of via
opts.m_PadOpacity = opacity; ///< Opacity override for SMD pads and PTHs
opts.m_ZoneOpacity = opacity; ///< Opacity override for filled zone areas
settings->LoadDisplayOptions( opts );
m_listPopupMenu = new wxMenu( wxT( "" ) );
m_listPopupMenu->Append( ID_LIST_COPY, wxT( "Copy selected geometry" ), wxT( "" ),
wxITEM_NORMAL );
m_listPopupMenu->Append( ID_LIST_SHOW_ALL, wxT( "Show all" ), wxT( "" ), wxITEM_NORMAL );
m_listPopupMenu->Append( ID_LIST_SHOW_NONE, wxT( "Show none" ), wxT( "" ), wxITEM_NORMAL );
m_itemList->Connect( m_itemList->GetId(), wxEVT_TREELIST_ITEM_CONTEXT_MENU,
wxMouseEventHandler( PNS_LOG_VIEWER_FRAME::onListRightClick ), nullptr,
this );
//m_itemList->Connect(m_itemList->GetId(),wxEVT_LISTBOX,wxCommandEventHandler(PNS_LOG_VIEWER_FRAME::onListSelect),nullptr,this);
m_itemList->Connect( m_itemList->GetId(), wxEVT_TREELIST_SELECTION_CHANGED,
wxCommandEventHandler( PNS_LOG_VIEWER_FRAME::onListSelect ),
nullptr, this );
m_itemList->Connect( m_itemList->GetId(), wxEVT_TREELIST_ITEM_CHECKED,
wxCommandEventHandler( PNS_LOG_VIEWER_FRAME::onListChecked ),
nullptr, this );
m_itemList->AppendColumn( "Type" );
m_itemList->AppendColumn( "Value" );
m_itemList->AppendColumn( "File" );
m_itemList->AppendColumn( "Method" );
m_itemList->AppendColumn( "Line" );
m_overlay.reset( new PNS_LOG_VIEWER_OVERLAY ( m_galPanel->GetGAL() ) );
m_galPanel->GetView()->Add( m_overlay.get() );
}
PNS_LOG_VIEWER_FRAME::~PNS_LOG_VIEWER_FRAME()
{
m_overlay = nullptr;
}
void PNS_LOG_VIEWER_FRAME::createUserTools()
{
}
PNS_TEST_DEBUG_DECORATOR::STAGE* PNS_LOG_VIEWER_FRAME::getCurrentStage()
{
PNS_TEST_DEBUG_DECORATOR* dbgd = m_env->GetDebugDecorator();
int count = dbgd->GetStageCount();
int iter = m_rewindIter;
if( count <= 0 )
return nullptr;
if( iter < 0 )
iter = 0;
if( iter >= count )
iter = count - 1;
return dbgd->GetStage( iter );
}
void PNS_LOG_VIEWER_FRAME::drawLoggedItems( int iter )
{
if( !m_env )
return;
PNS_TEST_DEBUG_DECORATOR::STAGE* st = getCurrentStage();
if( !st )
return;
m_overlay.reset( new PNS_LOG_VIEWER_OVERLAY ( m_galPanel->GetGAL() ) );
m_galPanel->GetView()->Add( m_overlay.get() );
auto drawShapes = [&]( PNS_TEST_DEBUG_DECORATOR::DEBUG_ENT* ent ) -> bool
{
bool isEnabled = ent->IsVisible();
bool isSelected = false;
if( !isEnabled )
return true;
for( auto& sh : ent->m_shapes )
{
COLOR4D color = ent->m_color;
int lineWidth = ent->m_width;
m_overlay->SetIsStroke( true );
m_overlay->SetIsFill( false );
if( isSelected )
{
color.Brighten( 0.5 );
}
m_overlay->SetStrokeColor( color );
m_overlay->SetLineWidth( ent->m_width );
switch( sh->Type() )
{
case SH_CIRCLE:
{
auto cir = static_cast<SHAPE_CIRCLE*>( sh );
m_overlay->Circle( cir->GetCenter(), cir->GetRadius() );
break;
}
case SH_SEGMENT:
{
auto seg = static_cast<SHAPE_SEGMENT*>( sh );
m_overlay->Line( seg->GetSeg().A, seg->GetSeg().B );
break;
}
case SH_RECT:
{
auto rect = static_cast<SHAPE_RECT*>( sh );
m_overlay->Rectangle( rect->GetPosition(), rect->GetPosition() + rect->GetSize() );
break;
}
case SH_LINE_CHAIN:
{
auto lc = static_cast<SHAPE_LINE_CHAIN*>( sh );
m_overlay->AnnotatedPolyline( *lc, ent->m_name.ToStdString(), ent->m_hasLabels && isSelected );
break;
}
default:
break;
}
}
return true;
};
st->m_entries->IterateTree( drawShapes );
m_overlay->DrawAnnotations();
m_galPanel->GetView()->MarkDirty();
m_galPanel->GetParent()->Refresh();
}
static BOARD* loadBoard( const std::string& filename )
{
PLUGIN::RELEASER pi( new PCB_PLUGIN );
BOARD* brd = nullptr;
try
{
brd = pi->Load( wxString( filename.c_str() ), nullptr, nullptr );
}
catch( const IO_ERROR& )
{
return nullptr;
}
return brd;
}
void PNS_LOG_VIEWER_FRAME::SetLogFile( PNS_LOG_FILE* aLog )
{
m_logFile.reset( aLog );
SetBoard( m_logFile->GetBoard() );
m_env.reset( new PNS_TEST_ENVIRONMENT );
m_env->SetMode( PNS::PNS_MODE_ROUTE_SINGLE );
m_env->ReplayLog( m_logFile.get(), 0, 0, -1);
auto dbgd = m_env->GetDebugDecorator();
int n_stages = dbgd->GetStageCount();
m_rewindSlider->SetMax( n_stages - 1 );
m_rewindSlider->SetValue( n_stages - 1 );
m_rewindIter = n_stages - 1;
auto extents = m_board->GetBoundingBox();
BOX2D bbd;
bbd.SetOrigin( extents.GetOrigin() );
bbd.SetWidth( extents.GetWidth() );
bbd.SetHeight( extents.GetHeight() );
bbd.Inflate( std::min( bbd.GetWidth(), bbd.GetHeight() ) / 5 );
m_galPanel->GetView()->SetViewport( bbd );
drawLoggedItems( m_rewindIter );
updateDumpPanel( m_rewindIter );
}
void PNS_LOG_VIEWER_FRAME::SetBoard2( std::shared_ptr<BOARD> aBoard )
{
SetBoard( aBoard );
auto extents = m_board->GetBoundingBox();
BOX2D bbd;
bbd.SetOrigin( extents.GetOrigin() );
bbd.SetWidth( extents.GetWidth() );
bbd.SetHeight( extents.GetHeight() );
bbd.Inflate( std::min( bbd.GetWidth(), bbd.GetHeight() ) / 5 );
m_galPanel->GetView()->SetViewport( bbd );
}
void PNS_LOG_VIEWER_FRAME::onReload( wxCommandEvent& event )
{
event.Skip();
}
void PNS_LOG_VIEWER_FRAME::onExit( wxCommandEvent& event )
{
event.Skip();
}
void PNS_LOG_VIEWER_FRAME::onListChecked( wxCommandEvent& event )
{
syncModel();
drawLoggedItems( m_rewindIter );
}
void PNS_LOG_VIEWER_FRAME::onRewindScroll( wxScrollEvent& event )
{
m_rewindIter = event.GetPosition();
drawLoggedItems( m_rewindIter );
updateDumpPanel( m_rewindIter );
char str[128];
sprintf( str, "%d", m_rewindIter );
m_rewindPos->SetValue( str );
event.Skip();
}
void PNS_LOG_VIEWER_FRAME::onBtnRewindLeft( wxCommandEvent& event )
{
if( m_rewindIter > 0 )
{
m_rewindIter--;
drawLoggedItems( m_rewindIter );
updateDumpPanel( m_rewindIter );
char str[128];
sprintf( str, "%d", m_rewindIter );
m_rewindPos->SetValue( str );
}
}
void PNS_LOG_VIEWER_FRAME::onBtnRewindRight( wxCommandEvent& event )
{
auto dbgd = m_env->GetDebugDecorator();
int count = dbgd->GetStageCount();
if( m_rewindIter < count )
{
m_rewindIter++;
drawLoggedItems( m_rewindIter );
updateDumpPanel( m_rewindIter );
char str[128];
sprintf( str, "%d", m_rewindIter );
m_rewindPos->SetValue( str );
}
}
void PNS_LOG_VIEWER_FRAME::onRewindCountText( wxCommandEvent& event )
{
if( !m_env )
return;
int val = wxAtoi( m_rewindPos->GetValue() );
auto dbgd = m_env->GetDebugDecorator();
int count = dbgd->GetStageCount();
if( val < 0 )
val = 0;
if( val >= count )
val = count - 1;
m_rewindIter = val;
m_rewindSlider->SetValue( m_rewindIter );
drawLoggedItems( m_rewindIter );
updateDumpPanel( m_rewindIter );
event.Skip();
}
void PNS_LOG_VIEWER_FRAME::syncModel()
{
for( wxTreeListItem item = m_itemList->GetFirstItem(); item.IsOk();
item = m_itemList->GetNextItem( item ) )
{
WX_SHAPE_TREE_ITEM_DATA* idata =
static_cast<WX_SHAPE_TREE_ITEM_DATA*>( m_itemList->GetItemData( item ) );
if( idata )
{
bool checked = m_itemList->GetCheckedState( item ) == wxCHK_CHECKED;
bool selected = m_itemList->IsSelected( item );
idata->m_item->m_visible = checked || selected;
idata->m_item->m_selected = selected;
}
}
}
void PNS_LOG_VIEWER_FRAME::onListRightClick( wxMouseEvent& event )
{
auto sel = m_itemList->GetPopupMenuSelectionFromUser( *m_listPopupMenu );
switch( sel )
{
case ID_LIST_SHOW_NONE:
m_itemList->CheckItemRecursively( m_itemList->GetRootItem(), wxCHK_UNCHECKED );
syncModel();
drawLoggedItems( m_rewindIter );
break;
case ID_LIST_SHOW_ALL:
m_itemList->CheckItemRecursively( m_itemList->GetRootItem(), wxCHK_CHECKED );
syncModel();
drawLoggedItems( m_rewindIter );
break;
case ID_LIST_COPY:
{
wxString s;
PNS_TEST_DEBUG_DECORATOR::STAGE* st = getCurrentStage();
if( !st )
return;
auto formatShapes = [&]( PNS_TEST_DEBUG_DECORATOR::DEBUG_ENT* ent ) -> bool
{
if( ent->m_selected )
{
for( auto sh : ent->m_shapes )
{
s += "// " + ent->m_name + "\n " + sh->Format() + "; \n";
}
}
return true;
};
st->m_entries->IterateTree( formatShapes );
if( wxTheClipboard->Open() )
{
// This data objects are held by the clipboard,
// so do not delete them in the app.
wxTheClipboard->SetData( new wxTextDataObject( s ) );
wxTheClipboard->Flush(); // Allow data to be available after closing KiCad
wxTheClipboard->Close();
}
return;
}
}
}
void PNS_LOG_VIEWER_FRAME::onListSelect( wxCommandEvent& event )
{
syncModel();
drawLoggedItems( m_rewindIter );
}
void PNS_LOG_VIEWER_FRAME::buildListTree( wxTreeListItem item,
PNS_TEST_DEBUG_DECORATOR::DEBUG_ENT* ent, int depth )
{
#ifdef EXTRA_VERBOSE
for( int i = 0; i < depth * 2; i++ )
printf( " " );
if( ent->m_msg.length() )
printf( "MSG: %s\n", ent->m_msg.c_str() );
else
printf( "SHAPES: %s [%d]\n", ent->m_name.c_str(), ent->m_children.size() );
#endif
wxTreeListItem ritem;
printf("depth %d\n", depth );
if( ent->m_msg.length() )
{
ritem = m_itemList->AppendItem( item, "Child" );
m_itemList->SetItemText( ritem, 0, "Message" );
m_itemList->SetItemText( ritem, 1, ent->m_msg );
}
else
{
ritem = m_itemList->AppendItem( item, "Child" );
int n_verts = 0;
for(auto sh : ent->m_shapes )
{
if ( sh->Type() == SH_LINE_CHAIN )
{
n_verts += static_cast<const SHAPE_LINE_CHAIN*>( sh )->PointCount();
}
}
m_itemList->SetItemText( ritem, 0, wxString::Format( "Shapes [%d verts]", n_verts ) );
m_itemList->SetItemText( ritem, 1, ent->m_name );
}
m_itemList->SetItemText( ritem, 2, wxFileNameFromPath( ent->m_srcLoc.fileName ) );
m_itemList->SetItemText( ritem, 3, ent->m_srcLoc.funcName );
m_itemList->SetItemText( ritem, 4, wxString::Format("%d", ent->m_srcLoc.line ) );
m_itemList->SetItemData( ritem, new WX_SHAPE_TREE_ITEM_DATA( ent ) );
if( !ent->m_children.size() )
return;
for( auto child : ent->m_children )
{
buildListTree( ritem, child, depth + 1 );
}
}
static void expandAllChildren( wxTreeListCtrl* tree, int maxLevel = 0 )
{
wxTreeListItem child = tree->GetFirstItem ();
while( child.IsOk() )
{
WX_SHAPE_TREE_ITEM_DATA* idata =
static_cast<WX_SHAPE_TREE_ITEM_DATA*>( tree->GetItemData( child ) );
if( idata->m_item->m_level > maxLevel )
tree->Expand ( child );
else
tree->Collapse ( child );
child = tree->GetNextItem( child );
}
}
static void collapseAllChildren( wxTreeListCtrl* tree )
{
wxTreeListItem child = tree->GetFirstItem ();
while( child.IsOk() )
{
tree->Collapse ( child );
child = tree->GetNextItem( child );
}
}
void PNS_LOG_VIEWER_FRAME::updateDumpPanel( int iter )
{
if( !m_env )
return;
auto dbgd = m_env->GetDebugDecorator();
int count = dbgd->GetStageCount();
wxArrayString dumpStrings;
if( count <= 0 )
return;
if( iter < 0 )
iter = 0;
if( iter >= count )
iter = count - 1;
auto st = dbgd->GetStage( iter );
auto rootItem = m_itemList->GetRootItem();
m_itemList->DeleteAllItems();
buildListTree( rootItem, st->m_entries );
m_itemList->CheckItemRecursively( rootItem, wxCHK_UNCHECKED );
collapseAllChildren( m_itemList );
m_itemList->Refresh();
}
int replay_main_func( int argc, char* argv[] )
{
auto frame = new PNS_LOG_VIEWER_FRAME( nullptr );
// drcCreateTestsProviderClearance();
// drcCreateTestsProviderEdgeClearance();
if( argc >= 2 && std::string( argv[1] ) == "-h" )
{
printf( "PNS Log (Re)player. Allows to step through the log written by the ROUTER_TOOL "
"in debug KiCad builds. " );
printf( "Requires a board file with UUIDs and a matching log file. Both are written to "
"/tmp when you press '0' during routing." );
return 0;
}
if( argc < 3 )
{
printf( "Expected parameters: log_file.log board_file.dump\n" );
return 0;
}
PNS_LOG_FILE* logFile = new PNS_LOG_FILE;
logFile->Load( argv[1], argv[2] );
frame->SetLogFile( logFile );
//SetTopFrame( frame ); // wxApp gets a face.
return 0;
}
static bool registered2 = UTILITY_REGISTRY::Register( {
"replay",
"PNS Log Player",
replay_main_func,
} );
int render_perftest_main_func( int argc, char* argv[] )
{
auto frame = new PNS_LOG_VIEWER_FRAME( nullptr );
// drcCreateTestsProviderClearance();
// drcCreateTestsProviderEdgeClearance();
if( argc >= 2 && std::string( argv[1] ) == "-h" )
{
printf( "PCB render performance test. Just renders a board without UI update overhead.\n" );
return 0;
}
if( argc < 2 )
{
printf( "Expected parameters: board_file\n" );
return 0;
}
PROF_TIMER cnt("load-board");
std::shared_ptr<BOARD> brd ( loadBoard( argv[1] ) );
cnt.Stop();
KI_TRACE( traceGalProfile, "%s\n", cnt.to_string() );
frame->SetBoard2( brd );
return 0;
}
static bool registered3 = UTILITY_REGISTRY::Register( {
"render_perftest",
"Renderer performance test",
render_perftest_main_func,
} );
VECTOR2I NearestPointFixpt( SEG seg, const VECTOR2I& aP )
{
VECTOR2I d = seg.B - seg.A;
SEG::ecoord l_squared = d.Dot( d );
if( l_squared == 0 )
return seg.A;
SEG::ecoord t = d.Dot( aP - seg.A );
if( t < 0 )
return seg.A;
else if( t > l_squared )
return seg.B;
int xp = rescale( t, (SEG::ecoord) d.x, l_squared );
int yp = rescale( t, (SEG::ecoord) d.y, l_squared );
return seg.A + VECTOR2I( xp, yp );
}
VECTOR2D NearestPointDbl( SEG seg, const VECTOR2I& aP )
{
VECTOR2D d = seg.B - seg.A;
double l_squared = d.Dot(d);
if( l_squared == 0 )
return seg.A;
double t = d.Dot(VECTOR2D( aP - seg.A ) );
if( t < 0 )
return seg.A;
else if( t > l_squared )
return seg.B;
double xp = t * d.x / l_squared;
double yp = t * d.y / l_squared;
return VECTOR2D(seg.A) + VECTOR2D( xp, yp );
}
int ttt_main_func( int argc, char* argv[] )
{
int n = 1000000;
std::vector<VECTOR2I> pts;
std::vector<SEG> segs;
std::vector<VECTOR2D> rv;
std::vector<VECTOR2I> rvi;
rv.resize(n);
rvi.resize(n);
for (int i = 0; i < n ;i++)
{
pts.push_back(VECTOR2I(random()%100000000, random()%100000000));
segs.push_back(SEG( VECTOR2I(random()%100000000, random()%100000000), VECTOR2I(random()%100000000, random()%100000000) ) );
}
PROF_TIMER tmrFix("nearest-fixpt");
for(int i = 0; i < n ; i++)
{
rvi[i] = NearestPointFixpt( segs[i], pts[i]);
}
tmrFix.Show();
PROF_TIMER tmrDbl("nearest-double");
for(int i = 0; i < n ; i++)
{
rv[i] = NearestPointDbl( segs[i], pts[i]);
}
tmrDbl.Show();
return 0;
}
static bool registered4 = UTILITY_REGISTRY::Register( {
"ttt",
"Renderer performance test",
ttt_main_func,
} );

View File

@ -67,6 +67,12 @@ void PNS_LOG_VIEWER_OVERLAY::AnnotatedPolyline( const SHAPE_LINE_CHAIN& aL, std:
if( name.length() > 0 && aL.PointCount() > 0 ) if( name.length() > 0 && aL.PointCount() > 0 )
m_labelMgr->Add( aL.CPoint( -1 ), name, GetStrokeColor() ); m_labelMgr->Add( aL.CPoint( -1 ), name, GetStrokeColor() );
if( aShowVertexNumbers )
{
for( int i = 0; i < aL.PointCount(); i++ )
m_labelMgr->Add( aL.CPoint(i), wxString::Format("%d", i ), GetStrokeColor() );
}
} }
@ -217,6 +223,9 @@ void PNS_LOG_VIEWER_FRAME::drawLoggedItems( int iter )
bool isEnabled = ent->IsVisible(); bool isEnabled = ent->IsVisible();
bool isSelected = ent->m_selected; bool isSelected = ent->m_selected;
if( m_searchString.Length() > 0 )
isEnabled = ent->m_filterMatch;
if( !isEnabled ) if( !isEnabled )
return true; return true;
@ -293,8 +302,6 @@ void PNS_LOG_VIEWER_FRAME::SetLogFile( PNS_LOG_FILE* aLog )
SetBoard( m_logFile->GetBoard() ); SetBoard( m_logFile->GetBoard() );
m_logPlayer.reset( new PNS_LOG_PLAYER ); m_logPlayer.reset( new PNS_LOG_PLAYER );
m_logPlayer->SetMode( PNS::PNS_MODE_ROUTE_SINGLE );
m_logPlayer->ReplayLog( m_logFile.get(), 0, 0, -1); m_logPlayer->ReplayLog( m_logFile.get(), 0, 0, -1);
auto dbgd = m_logPlayer->GetDebugDecorator(); auto dbgd = m_logPlayer->GetDebugDecorator();

View File

@ -0,0 +1,185 @@
/*
* 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
*/
#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>
#include "pns_log_file.h"
#include "pns_log_viewer_frame.h"
static const wxCmdLineEntryDesc g_cmdLineDesc[] = {
{
wxCMD_LINE_SWITCH,
"h",
"help",
_( "displays help on the command line parameters" ).mb_str(),
wxCMD_LINE_VAL_NONE,
wxCMD_LINE_OPTION_HELP,
},
{
wxCMD_LINE_OPTION,
"i",
"iteration-limit",
_( "Max number of iterations" ).mb_str(),
wxCMD_LINE_VAL_NUMBER,
wxCMD_LINE_PARAM_OPTIONAL,
},
{
wxCMD_LINE_OPTION,
"s",
"steps-limit",
_( "execute log up to steps-limit events" ).mb_str(),
wxCMD_LINE_VAL_NUMBER,
wxCMD_LINE_PARAM_OPTIONAL,
},
{
wxCMD_LINE_PARAM,
"directory with tests",
"directory with tests",
_( "directory with tests (containing tests.lst)" ).mb_str(),
wxCMD_LINE_VAL_STRING,
wxCMD_LINE_OPTION_MANDATORY,
},
{ wxCMD_LINE_NONE }
};
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;
}
int main( int argc, char* argv[] )
{
wxCmdLineParser cl_parser( argc, argv );
cl_parser.SetDesc( g_cmdLineDesc );
cl_parser.AddUsageText( _( "P&S Regression Test Suite. Compares live router results against "
"prerecorded references." ) );
int cmd_parsed_ok = cl_parser.Parse();
if( cl_parser.Found( "help" ) )
{
return 0;
}
if( cmd_parsed_ok != 0 )
{
printf( "P&S Regression Test Suite. For command line options, call %s -h.\n\n", argv[0] );
// Help and invalid input both stop here
return ( cmd_parsed_ok == -1 ) ? KI_TEST::RET_CODES::OK : KI_TEST::RET_CODES::BAD_CMDLINE;
}
wxString dirname;
long iter_limit = 256;
long steps_limit = -1;
cl_parser.Found( "iteration-limit", &iter_limit );
cl_parser.Found( "steps-limit", &steps_limit );
wxFileName fname_list( cl_parser.GetParam( 0 ), "tests.lst" );
KI_TEST::CONSOLE_LOG log;
KI_TEST::CONSOLE_MSG_REPORTER reporter( &log );
wxTextFile fp( fname_list.GetFullPath() );
if( !fp.Open() )
{
reporter.Report(
wxString::Format( "Failed to load test list from '%s'.", fname_list.GetFullPath() ),
RPT_SEVERITY_ERROR );
return -1;
}
std::vector<wxString> testCases;
if( !fp.Eof() )
{
testCases.push_back( fp.GetFirstLine() );
while( !fp.Eof() )
{
auto l = fp.GetNextLine();
if( l.Length() > 0 )
testCases.push_back( l );
}
}
fp.Close();
reporter.Report( wxString::Format( "Loaded %d test cases from '%s'.", (int) testCases.size(),
fname_list.GetFullPath() ),
RPT_SEVERITY_INFO );
int passed = 0, failed = 0;
for( auto casename : testCases )
{
if( runSingleTest( &reporter, casename, cl_parser.GetParam( 0 ) ) )
passed++;
else
failed++;
}
reporter.Report(
wxString::Format( "SUMMARY: %d/%d tests cases PASSED", passed,
(int) testCases.size() ),
RPT_SEVERITY_INFO );
return failed ? -1 : 0;
}