← Back to team overview

kicad-developers team mailing list archive

Re: [RFC/PATCH] Generic utility tool

 

Hi Wayne,

Here is a rebased patch set that includes the original co-routine
utility and also the io_benchmark utility.

io_benchmark is now run like this:

$ qa/common_tools/qa_common_tools io_benchmark <params as before>

Cheers,

John

On Sat, Jan 19, 2019 at 7:54 PM Wayne Stambaugh <stambaughw@xxxxxxxxx> wrote:
>
> Hey John,
>
> I don't think there is any disadvantage to rolling the other tests into
> the qa test executable.
>
> Thanks,
>
> Wayne
>
> On 1/19/19 10:25 AM, John Beard wrote:
> > Hi Wayne,
> >
> > I'll rebase the patch. Would you like me to roll the other
> > common-library QA utility classes (io_benchmark, etc) up into this
> > executable as a follow-up?
> >
> > Cheers,
> >
> > John
> >
> >
> > On Sat, Jan 19, 2019 at 2:58 PM Wayne Stambaugh <stambaughw@xxxxxxxxx> wrote:
> >>
> >> John,
> >>
> >> The original patch no longer applies cleanly.  It looks useful so I
> >> don't see any reason not to merge it.
> >>
> >> Cheers,
> >>
> >> Wayne
> >>
> >> On 1/19/2019 9:30 AM, John Beard wrote:
> >>> Hi,
> >>>
> >>> A very gentle bump here. I'm thinking about a utility to assist in
> >>> debugging/benchmarking/testing/developing DRC routines (currently
> >>> working on some DRC unit testing, but the testing utils are easily
> >>> re-used into a small utility-style executable).
> >>>
> >>> However, I am cognisant of the costs of adding things like this,
> >>> especially with such large link times and RAM usage of things that
> >>> suck in the pcbnew object library. So I'd like to know if:
> >>>
> >>> 1) These kinds of utilities are wanted at all, or are they adding
> >>> maintenance overhead for tools no-one ever uses? I'd understand that
> >>> perspective, as I appreciate developer time is highly limited and
> >>> cross-platform breakage is so easy to perpetrate.
> >>> 2) If wanted, is a "merged" approach appreciated, or keep them
> >>> separate, in the hopes of once day having shared libs and much reduced
> >>> link time/effort?
> >>>
> >>> Cheers,
> >>>
> >>> John
> >>>
> >>> _______________________________________________
> >>> Mailing list: https://launchpad.net/~kicad-developers
> >>> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> >>> Unsubscribe : https://launchpad.net/~kicad-developers
> >>> More help   : https://help.launchpad.net/ListHelp
> >>>
> >>
> >> _______________________________________________
> >> Mailing list: https://launchpad.net/~kicad-developers
> >> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> >> Unsubscribe : https://launchpad.net/~kicad-developers
> >> More help   : https://help.launchpad.net/ListHelp
From 684e1f72426412f6a7a3442dc813502c190edc69 Mon Sep 17 00:00:00 2001
From: John Beard <john.j.beard@xxxxxxxxx>
Date: Mon, 24 Dec 2018 14:43:08 +0000
Subject: [PATCH 2/2] QA: Move io_benchmark into common_tools

---
 qa/common_tools/CMakeLists.txt                |  2 ++
 qa/common_tools/main.cpp                      |  2 ++
 .../tools}/io_benchmark/io_benchmark.cpp      | 21 +++++++------
 .../tools/io_benchmark/io_benchmark.h         | 31 +++++++++++++++++++
 tools/CMakeLists.txt                          |  3 --
 tools/io_benchmark/CMakeLists.txt             | 17 ----------
 6 files changed, 47 insertions(+), 29 deletions(-)
 rename {tools => qa/common_tools/tools}/io_benchmark/io_benchmark.cpp (97%)
 create mode 100644 qa/common_tools/tools/io_benchmark/io_benchmark.h
 delete mode 100644 tools/io_benchmark/CMakeLists.txt

diff --git a/qa/common_tools/CMakeLists.txt b/qa/common_tools/CMakeLists.txt
index 6c033b02a..2842cd2b3 100644
--- a/qa/common_tools/CMakeLists.txt
+++ b/qa/common_tools/CMakeLists.txt
@@ -34,6 +34,8 @@ add_executable( qa_common_tools
     main.cpp
 
     tools/coroutines/coroutines.cpp
+
+    tools/io_benchmark/io_benchmark.cpp
 )
 
 include_directories(
diff --git a/qa/common_tools/main.cpp b/qa/common_tools/main.cpp
index 64ca80eec..1733b6184 100644
--- a/qa/common_tools/main.cpp
+++ b/qa/common_tools/main.cpp
@@ -24,6 +24,7 @@
 #include <common.h>
 
 #include "tools/coroutines/coroutine_tools.h"
+#include "tools/io_benchmark/io_benchmark.h"
 
 #include <wx/cmdline.h>
 
@@ -35,6 +36,7 @@
  */
 const static std::vector<UTILITY_PROGRAM*> known_tools = {
     &coroutine_tool,
+    &io_benchmark_tool,
 };
 
 
diff --git a/tools/io_benchmark/io_benchmark.cpp b/qa/common_tools/tools/io_benchmark/io_benchmark.cpp
similarity index 97%
rename from tools/io_benchmark/io_benchmark.cpp
rename to qa/common_tools/tools/io_benchmark/io_benchmark.cpp
index 0c11a96c3..ce919c01d 100644
--- a/tools/io_benchmark/io_benchmark.cpp
+++ b/qa/common_tools/tools/io_benchmark/io_benchmark.cpp
@@ -21,6 +21,8 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
 
+#include "io_benchmark.h"
+
 #include <wx/wx.h>
 #include <richio.h>
 
@@ -377,13 +379,7 @@ BENCH_REPORT executeBenchMark( const BENCHMARK& aBenchmark, int aReps,
 }
 
 
-enum RET_CODES
-{
-    BAD_ARGS = 1,
-};
-
-
-int main( int argc, char* argv[] )
+int io_benchmark_func( int argc, char* argv[] )
 {
     auto& os = std::cout;
 
@@ -392,7 +388,7 @@ int main( int argc, char* argv[] )
         os << "Usage: " << argv[0] << " <FILE> <REPS> [" << getBenchFlags() << "]\n\n";
         os << "Benchmarks:\n";
         os << getBenchDescriptions();
-        return BAD_ARGS;
+        return RET_CODES::BAD_CMDLINE;
     }
 
     wxFileName inFile( argv[1] );
@@ -423,5 +419,12 @@ int main( int argc, char* argv[] )
             << std::endl;;
     }
 
-    return 0;
+    return RET_CODES::OK;
 }
+
+
+UTILITY_PROGRAM io_benchmark_tool = {
+    "io_benchmark",
+    "Benchmark various kinds of IO methods",
+    io_benchmark_func,
+};
\ No newline at end of file
diff --git a/qa/common_tools/tools/io_benchmark/io_benchmark.h b/qa/common_tools/tools/io_benchmark/io_benchmark.h
new file mode 100644
index 000000000..e3493a80d
--- /dev/null
+++ b/qa/common_tools/tools/io_benchmark/io_benchmark.h
@@ -0,0 +1,31 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2018 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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 IO_BENCHMARK_H
+#define IO_BENCHMARK_H
+
+#include <utility_program.h>
+
+extern UTILITY_PROGRAM io_benchmark_tool;
+
+#endif // IO_BENCHMARK_H
\ No newline at end of file
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index 40a27018f..46c9744fa 100644
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -45,6 +45,3 @@ target_link_libraries( utf8_tests
     common
     ${wxWidgets_LIBRARIES}
     )
-
-
-add_subdirectory( io_benchmark )
diff --git a/tools/io_benchmark/CMakeLists.txt b/tools/io_benchmark/CMakeLists.txt
deleted file mode 100644
index bbab2a9c6..000000000
--- a/tools/io_benchmark/CMakeLists.txt
+++ /dev/null
@@ -1,17 +0,0 @@
-
-include_directories( BEFORE ${INC_BEFORE} )
-
-set( IOBENCHMARK_SRCS
-    io_benchmark.cpp
-)
-
-add_executable( io_benchmark
-    ${IOBENCHMARK_SRCS}
-)
-
-target_link_libraries( io_benchmark
-    common
-    qa_utils
-    ${wxWidgets_LIBRARIES}
-)
-
-- 
2.20.1

From 13e3f89e0a60584d68d834ba9ea268e7d2b2fbf9 Mon Sep 17 00:00:00 2001
From: John Beard <john.j.beard@xxxxxxxxx>
Date: Mon, 24 Dec 2018 14:16:20 +0000
Subject: [PATCH 1/2] QA: Add a generic utility tool executable.

The intention here is to make it possible to wrap up many of the
KiCad utility tools into a single executable. This reduces link times
as well as the duplication of CMake files needed to build very
similar tools.

This particular tool should be suitable for any code in common,
code in pcbnew and other end-executables probalby will need an
analagous version linked to the relevant kiface.

The first tool is the coroutine_example.cpp test case, which
can be useful when learning, debugging or porting the coroutine
infrastructure.
---
 include/tool/coroutine.h                      |   1 +
 include/tool/examples/Makefile                |   5 +-
 include/tool/examples/coroutine_example.cpp   |  49 -------
 qa/CMakeLists.txt                             |   3 +-
 qa/common_tools/CMakeLists.txt                |  59 ++++++++
 qa/common_tools/main.cpp                      | 123 ++++++++++++++++
 .../tools/coroutines/coroutine_tools.h        |  10 ++
 .../tools/coroutines/coroutines.cpp           | 131 ++++++++++++++++++
 qa/qa_utils/utility_program.h                 |  77 ++++++++++
 9 files changed, 404 insertions(+), 54 deletions(-)
 delete mode 100644 include/tool/examples/coroutine_example.cpp
 create mode 100644 qa/common_tools/CMakeLists.txt
 create mode 100644 qa/common_tools/main.cpp
 create mode 100644 qa/common_tools/tools/coroutines/coroutine_tools.h
 create mode 100644 qa/common_tools/tools/coroutines/coroutines.cpp
 create mode 100644 qa/qa_utils/utility_program.h

diff --git a/include/tool/coroutine.h b/include/tool/coroutine.h
index 5aedc3ecb..84552b276 100644
--- a/include/tool/coroutine.h
+++ b/include/tool/coroutine.h
@@ -26,6 +26,7 @@
 #ifndef __COROUTINE_H
 #define __COROUTINE_H
 
+#include <cassert>
 #include <cstdlib>
 
 #include <type_traits>
diff --git a/include/tool/examples/Makefile b/include/tool/examples/Makefile
index a60526368..8f0875776 100644
--- a/include/tool/examples/Makefile
+++ b/include/tool/examples/Makefile
@@ -3,7 +3,4 @@ CXXFLAGS = -I../.. -I../../boost
 all: delegate_example coroutine_example
 
 delegate_example:	delegate_example.cpp
-	g++ -o $@ $^ $(CXXFLAGS)
-	
-coroutine_example:	coroutine_example.cpp
-	g++ -o $@ $^ $(CXXFLAGS) -lboost_context
\ No newline at end of file
+	g++ -o $@ $^ $(CXXFLAGS)
\ No newline at end of file
diff --git a/include/tool/examples/coroutine_example.cpp b/include/tool/examples/coroutine_example.cpp
deleted file mode 100644
index c36de8bbe..000000000
--- a/include/tool/examples/coroutine_example.cpp
+++ /dev/null
@@ -1,49 +0,0 @@
-#include <cstdio>
-#include <string>
-
-#include <tool/coroutine.h>
-
-typedef COROUTINE<int, int> MyCoroutine;
-
-class MyClass
-{
-public:
-    int CountTo( int n )
-    {
-        printf( "%s: Coroutine says hi. I will count from 1 to %d and yield each value.\n",
-                __FUNCTION__,
-                n );
-
-        for( int i = 1; i <= n; i++ )
-        {
-            printf( "%s: Yielding %d\n", __FUNCTION__, i );
-            cofunc.Yield( i );
-        }
-    }
-
-    void Run()
-    {
-        cofunc = MyCoroutine( this, &MyClass::CountTo );
-        printf( "%s: Calling coroutine that will count from 1 to 5.\n", __FUNCTION__ );
-        cofunc.Call( 5 );
-
-        while( cofunc.Running() )
-        {
-            printf( "%s: Got value: %d\n", __FUNCTION__, cofunc.ReturnValue() );
-            cofunc.Resume();
-        }
-
-        printf( "%s: Done!\n", __FUNCTION__ );
-    }
-
-    MyCoroutine cofunc;
-};
-
-
-main() {
-    MyClass obj;
-
-    obj.Run();
-
-    return 0;
-}
diff --git a/qa/CMakeLists.txt b/qa/CMakeLists.txt
index f44721628..1c774d838 100644
--- a/qa/CMakeLists.txt
+++ b/qa/CMakeLists.txt
@@ -22,7 +22,8 @@ add_subdirectory( pcbnew )
 add_subdirectory( eeschema )
 add_subdirectory( shape_poly_set_refactor )
 
-# Utility/test programs
+# Utility/debugging/profiling programs
+add_subdirectory( common_tools )
 add_subdirectory( pcb_parse_input )
 
 # add_subdirectory( pcb_test_window )
diff --git a/qa/common_tools/CMakeLists.txt b/qa/common_tools/CMakeLists.txt
new file mode 100644
index 000000000..6c033b02a
--- /dev/null
+++ b/qa/common_tools/CMakeLists.txt
@@ -0,0 +1,59 @@
+# This program source code file is part of KiCad, a free EDA CAD application.
+#
+# Copyright (C) 2018 KiCad Developers, see CHANGELOG.TXT for contributors.
+#
+# 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
+
+find_package( wxWidgets 3.0.0 COMPONENTS gl aui adv html core net base xml stc REQUIRED )
+
+add_executable( qa_common_tools
+
+    # # stuff from common due to...units?
+    # ../../common/eda_text.cpp
+
+    # stuff from common which is needed...why?
+    ../../common/colors.cpp
+    ../../common/observable.cpp
+
+    # The main entry point
+    main.cpp
+
+    tools/coroutines/coroutines.cpp
+)
+
+include_directories(
+    ${CMAKE_SOURCE_DIR}
+    ${CMAKE_SOURCE_DIR}/include
+    ${CMAKE_SOURCE_DIR}/polygon
+    ${INC_AFTER}
+)
+
+target_link_libraries( qa_common_tools
+    common
+    legacy_gal
+    polygon
+    bitmaps
+    gal
+    qa_utils
+    ${wxWidgets_LIBRARIES}
+)
+
+# we need to pretend to be something to appease the units code
+target_compile_definitions( qa_common_tools
+    PRIVATE PCBNEW
+)
\ No newline at end of file
diff --git a/qa/common_tools/main.cpp b/qa/common_tools/main.cpp
new file mode 100644
index 000000000..64ca80eec
--- /dev/null
+++ b/qa/common_tools/main.cpp
@@ -0,0 +1,123 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2018 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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 <common.h>
+
+#include "tools/coroutines/coroutine_tools.h"
+
+#include <wx/cmdline.h>
+
+/**
+ * List of registered tools.
+ *
+ * This is a pretty rudimentary way to register, but for a simple purpose,
+ * it's effective enough. When you have a new tool, add it to this list.
+ */
+const static std::vector<UTILITY_PROGRAM*> known_tools = {
+    &coroutine_tool,
+};
+
+
+/**
+ * Print the names and descriptions of the registered tools
+ */
+static void show_tool_list()
+{
+    for( const auto& tool : known_tools )
+    {
+        std::cout << tool->m_name << ": \t" << tool->m_desc << std::endl;
+    }
+}
+
+
+/**
+ * Get the utility program that matches a tool name
+ * @param  aName the name to look for
+ * @return       the tool function
+ */
+UTILITY_PROGRAM::FUNC* get_program( const std::string& aName )
+{
+    for( const auto& tool : known_tools )
+    {
+        if( tool->m_name == aName )
+            return &tool->m_func;
+    }
+
+    return nullptr;
+}
+
+
+void print_usage( char* name )
+{
+    std::cout << "Run a utility tool." << std::endl;
+
+    std::cout << "Usage: " << name << " [-h] [-l] [TOOL [TOOL_OPTIONS]]" << std::endl;
+
+    std::cout << "  -h      show this message and exit." << std::endl
+              << "  -l      print known tools and exit." << std::endl;
+
+    std::cout << std::endl;
+    std::cout << "Known tools: " << std::endl;
+
+    show_tool_list();
+}
+
+
+int main( int argc, char** argv )
+{
+    wxMessageOutput::Set( new wxMessageOutputStderr );
+
+    // Need at least one parameter
+    if( argc < 2 )
+    {
+        print_usage( argv[0] );
+        return RET_CODES::BAD_CMDLINE;
+    }
+
+    const std::string arg1( argv[1] );
+
+    if( argc == 2 )
+    {
+        if( arg1 == "-h" )
+        {
+            print_usage( argv[0] );
+            return RET_CODES::OK;
+        }
+        else if( arg1 == "-l" )
+        {
+            show_tool_list();
+            return RET_CODES::OK;
+        }
+    }
+
+    auto func = get_program( arg1 );
+
+    if( !func )
+    {
+        std::cout << "Tool " << arg1 << " not found." << std::endl;
+        return RET_CODES::UNKNOWN_TOOL;
+    }
+
+    // pass on the rest of the commands
+    return ( *func )( argc - 1, argv + 1 );
+}
\ No newline at end of file
diff --git a/qa/common_tools/tools/coroutines/coroutine_tools.h b/qa/common_tools/tools/coroutines/coroutine_tools.h
new file mode 100644
index 000000000..414d0acbf
--- /dev/null
+++ b/qa/common_tools/tools/coroutines/coroutine_tools.h
@@ -0,0 +1,10 @@
+
+#ifndef COROUTINES_UTILTY_H
+#define COROUTINES_UTILTY_H
+
+#include <utility_program.h>
+
+/// A tool to test a simple coroutine
+extern UTILITY_PROGRAM coroutine_tool;
+
+#endif
\ No newline at end of file
diff --git a/qa/common_tools/tools/coroutines/coroutines.cpp b/qa/common_tools/tools/coroutines/coroutines.cpp
new file mode 100644
index 000000000..28f83045d
--- /dev/null
+++ b/qa/common_tools/tools/coroutines/coroutines.cpp
@@ -0,0 +1,131 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2018 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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 "coroutine_tools.h"
+
+#include <cstdio>
+#include <string>
+
+#include <common.h>
+
+#include <tool/coroutine.h>
+
+#include <wx/cmdline.h>
+
+
+typedef COROUTINE<int, int> MyCoroutine;
+
+class CoroutineExample
+{
+public:
+    CoroutineExample( int aCount ) : m_count( aCount )
+    {
+    }
+
+    int CountTo( int n )
+    {
+        printf( "%s: Coroutine says hi. I will count from 1 to %d and yield each value.\n",
+                __FUNCTION__, n );
+
+        for( int i = 1; i <= n; i++ )
+        {
+            printf( "%s: Yielding %d\n", __FUNCTION__, i );
+            m_cofunc->KiYield( i );
+        }
+
+        return 0;
+    }
+
+    void Run()
+    {
+        m_cofunc = std::make_unique<MyCoroutine>( this, &CoroutineExample::CountTo );
+        printf( "%s: Calling coroutine that will count from 1 to 5.\n", __FUNCTION__ );
+        m_cofunc->Call( m_count );
+
+        while( m_cofunc->Running() )
+        {
+            printf( "%s: Got value: %d\n", __FUNCTION__, m_cofunc->ReturnValue() );
+            m_cofunc->Resume();
+        }
+
+        printf( "%s: Done!\n", __FUNCTION__ );
+    }
+
+    std::unique_ptr<MyCoroutine> m_cofunc;
+    int                          m_count;
+};
+
+
+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,
+            "c",
+            "count",
+            _( "how high to count" ).mb_str(),
+            wxCMD_LINE_VAL_NUMBER,
+            wxCMD_LINE_PARAM_OPTIONAL,
+    },
+    { wxCMD_LINE_NONE }
+};
+
+
+static int coroutine_main_func( int argc, char** argv )
+{
+    wxCmdLineParser cl_parser( argc, argv );
+    cl_parser.SetDesc( g_cmdLineDesc );
+    cl_parser.AddUsageText( _( "Test a simple coroutine that yields a given number of times" ) );
+
+    int cmd_parsed_ok = cl_parser.Parse();
+    if( cmd_parsed_ok != 0 )
+    {
+        // Help and invalid input both stop here
+        return ( cmd_parsed_ok == -1 ) ? RET_CODES::OK : RET_CODES::BAD_CMDLINE;
+    }
+
+    long count = 5;
+    cl_parser.Found( "count", &count );
+
+    CoroutineExample obj( (int) count );
+
+    obj.Run();
+
+    return RET_CODES::OK;
+}
+
+
+/*
+ * Define the tool interface
+ */
+UTILITY_PROGRAM coroutine_tool = {
+    "coroutine",
+    "Test a simple coroutine",
+    coroutine_main_func,
+};
\ No newline at end of file
diff --git a/qa/qa_utils/utility_program.h b/qa/qa_utils/utility_program.h
new file mode 100644
index 000000000..e9708f873
--- /dev/null
+++ b/qa/qa_utils/utility_program.h
@@ -0,0 +1,77 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
+ *
+ * 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 UTILITY_PROGRAM_H
+#define UTILITY_PROGRAM_H
+
+#include <functional>
+
+/**
+ * Return codes for tools
+ */
+enum RET_CODES
+{
+    /// Tool exited OK
+    OK = 0,
+
+    /// The command line was not correct for the tool
+    BAD_CMDLINE = 1,
+
+    /// The tool asked for was not found
+    UNKNOWN_TOOL = 2,
+
+    /// Tools can define their own statuses from here onwards
+    TOOL_SPECIFIC = 10,
+};
+
+
+/**
+ * Description of a "utility program", which is a program that
+ * takes some command line and does "something".
+ *
+ * Likely uses of this are:
+ *
+ * * Test programs and demos
+ * * Benchmarks
+ * * Fuzz targets
+ *
+ * This structure allows a single executable to select a program from
+ * many registered programs to avoid having to maintain "N" similar CMake
+ * scripts and perform "N" linkages.
+ */
+struct UTILITY_PROGRAM
+{
+    /// A function that provides the program for a given command line
+    using FUNC = std::function<int( int argc, char** argv )>;
+
+    /// The name of the program (this is used to select one)
+    std::string m_name;
+
+    /// Description of the program
+    std::string m_desc;
+
+    /// The function to call to run the program
+    FUNC m_func;
+};
+
+#endif // UTILITY_PROGRAM_H
\ No newline at end of file
-- 
2.20.1


Follow ups

References