← Back to team overview

kicad-developers team mailing list archive

Re: [RFC] Pcbnew tests/utils

 

Hi Wayne,

Great, glad it's working OK. Here are a couple of follow-up patches
(they've already been though Jenkins):

1) Reinstate the polygon_generator tool, but as a subunit of
pcbnew_tools. This utility has been non-compiled since the eeschema
GAL landed. I imagine that's because of some CMake breakage in that
merge. With the pcbnew_tools framework, it's easy to slot in now
without any extra CMake (other than the file listing).
2) Add a simple unit test on co-routines - basically a simple
automated version of the common_tools coroutine utility. I'm not
really sure of the test coverage it provides, but it seems like a
decent, simple, high-level test. Perhaps the CERN folks have ideas for
good ways to exercise the co-routine code?

Cheers,

John

On Wed, Jan 23, 2019 at 6:36 PM Wayne Stambaugh <stambaughw@xxxxxxxxx> wrote:
>
> Hey John,
>
> I don't know which dependency versions the Jenkins msys2 builder is
> using so that may have something to do with it.  Either the gcc and/or
> boost versions are the likely culprit.
>
> In any event, your changes resolved the issue so I merged your patch set.
>
> Thanks,
>
> Wayne
>
> On 1/23/2019 12:48 PM, John Beard wrote:
> > Hi Wayne,
> >
> > Hmm, odd, I wonder how I ever got that building on Jenkins Msys2!
> >
> > This patch set is updated to use a method of building that I think
> > will work. It's basically the same method as currently used by
> > pnsrouter, connectivity and friends, where the intermediate library
> > does not declare its own target_link_libraries but the end executable
> > does. It's still not quite ideal (but with the current units code, it
> > can't be), but it seems to work and it's somewhat consistent with
> > existing practice. So it seems rather tidier now.
> >
> > Perhaps we'll run into more build issues, but for now at least,
> > Jenkins is happy...
> >
> > Cheers,
> >
> > John
> >
> >
> > On Wed, Jan 23, 2019 at 4:10 PM Wayne Stambaugh <stambaughw@xxxxxxxxx> wrote:
> >>
> >> Hey John,
> >>
> >> I'm getting a bunch of build errors on windows.  It looks like it's
> >> having issues finding std::set.
> >>
> >> In file included from
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/common/test_color4d.cpp:28:0:
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:
> >> In function 'void KI_TEST::CheckUnorderedMatches(const EXP_CONT&, const
> >> FOUND_CONT&, MATCH_PRED)':
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:124:10:
> >> error: 'set' is not a member of 'std'
> >>      std::set<const EXP_OBJ*> matched;
> >>           ^~~
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:124:10:
> >> note: suggested alternative: 'get'
> >>      std::set<const EXP_OBJ*> matched;
> >>           ^~~
> >>           get
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:124:14:
> >> error: expected primary-expression before 'const'
> >>      std::set<const EXP_OBJ*> matched;
> >>               ^~~~~
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:133:17:
> >> error: 'matched' was not declared in this scope
> >>                  matched.insert( &expected );
> >>                  ^~~~~~~
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:133:17:
> >> note: suggested alternative: 'matherr'
> >>                  matched.insert( &expected );
> >>                  ^~~~~~~
> >>                  matherr
> >> In file included from
> >> C:/msys64/mingw32/include/boost/test/test_tools.hpp:45:0,
> >>                  from C:/msys64/mingw32/include/boost/test/unit_test.hpp:18,
> >>                  from
> >> C:/msys64/mingw32/include/boost/test/test_case_template.hpp:13,
> >>                  from
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/common/test_color4d.cpp:24:
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:142:30:
> >> error: 'matched' was not declared in this scope
> >>          BOOST_CHECK_MESSAGE( matched.count( &exp ) > 0, "Expected item
> >> was not found. Expected: \n"
> >>                               ^
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:142:30:
> >> note: suggested alternative: 'matherr'
> >> In file included from
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/common/test_color4d.cpp:28:0:
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:147:33:
> >> error: 'matched' was not declared in this scope
> >>      for( const EXP_OBJ* found : matched )
> >>                                  ^~~~~~~
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:147:33:
> >> note: suggested alternative: 'matherr'
> >>      for( const EXP_OBJ* found : matched )
> >>                                  ^~~~~~~
> >>                                  matherr
> >> [ 66%] Built target qa_common_tools
> >> In file included from
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/common/test_color4d.cpp:28:0:
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:
> >> In function 'void KI_TEST::CheckUnorderedMatches(const EXP_CONT&, const
> >> FOUND_CONT&, MATCH_PRED)':
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:124:10:
> >> error: 'set' is not a member of 'std'
> >>      std::set<const EXP_OBJ*> matched;
> >>           ^~~
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:124:10:
> >> note: suggested alternative: 'get'
> >>      std::set<const EXP_OBJ*> matched;
> >>           ^~~
> >>           get
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:124:14:
> >> error: expected primary-expression before 'const'
> >>      std::set<const EXP_OBJ*> matched;
> >>               ^~~~~
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:133:17:
> >> error: 'matched' was not declared in this scope
> >>                  matched.insert( &expected );
> >>                  ^~~~~~~
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:133:17:
> >> note: suggested alternative: 'matherr'
> >>                  matched.insert( &expected );
> >>                  ^~~~~~~
> >>                  matherr
> >> In file included from
> >> C:/msys64/mingw32/include/boost/test/test_tools.hpp:45:0,
> >>                  from C:/msys64/mingw32/include/boost/test/unit_test.hpp:18,
> >>                  from
> >> C:/msys64/mingw32/include/boost/test/test_case_template.hpp:13,
> >>                  from
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/common/test_color4d.cpp:24:
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:142:30:
> >> error: 'matched' was not declared in this scope
> >>          BOOST_CHECK_MESSAGE( matched.count( &exp ) > 0, "Expected item
> >> was not found. Expected: \n"
> >>                               ^
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:142:30:
> >> note: suggested alternative: 'matherr'
> >> In file included from
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/common/test_color4d.cpp:28:0:
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:147:33:
> >> error: 'matched' was not declared in this scope
> >>      for( const EXP_OBJ* found : matched )
> >>                                  ^~~~~~~
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:147:33:
> >> note: suggested alternative: 'matherr'
> >>      for( const EXP_OBJ* found : matched )
> >>                                  ^~~~~~~
> >>                                  matherr
> >> [ 66%] Linking CXX executable gerbview.exe
> >> In file included from
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/common/test_color4d.cpp:28:0:
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:
> >> In function 'void KI_TEST::CheckUnorderedMatches(const EXP_CONT&, const
> >> FOUND_CONT&, MATCH_PRED)':
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:124:10:
> >> error: 'set' is not a member of 'std'
> >>      std::set<const EXP_OBJ*> matched;
> >>           ^~~
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:124:10:
> >> note: suggested alternative: 'get'
> >>      std::set<const EXP_OBJ*> matched;
> >>           ^~~
> >>           get
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:124:14:
> >> error: expected primary-expression before 'const'
> >>      std::set<const EXP_OBJ*> matched;
> >>               ^~~~~
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:133:17:
> >> error: 'matched' was not declared in this scope
> >>                  matched.insert( &expected );
> >>                  ^~~~~~~
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:133:17:
> >> note: suggested alternative: 'matherr'
> >>                  matched.insert( &expected );
> >>                  ^~~~~~~
> >>                  matherr
> >> In file included from
> >> C:/msys64/mingw32/include/boost/test/test_tools.hpp:45:0,
> >>                  from C:/msys64/mingw32/include/boost/test/unit_test.hpp:18,
> >>                  from
> >> C:/msys64/mingw32/include/boost/test/test_case_template.hpp:13,
> >>                  from
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/common/test_color4d.cpp:24:
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:142:30:
> >> error: 'matched' was not declared in this scope
> >>          BOOST_CHECK_MESSAGE( matched.count( &exp ) > 0, "Expected item
> >> was not found. Expected: \n"
> >>                               ^
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:142:30:
> >> note: suggested alternative: 'matherr'
> >> In file included from
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/common/test_color4d.cpp:28:0:
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:147:33:
> >> error: 'matched' was not declared in this scope
> >>      for( const EXP_OBJ* found : matched )
> >>                                  ^~~~~~~
> >> C:/msys64/home/wstambaugh/src/kicad-trunk/qa/unit_test_utils/include/unit_test_utils/unit_test_utils.h:147:33:
> >> note: suggested alternative: 'matherr'
> >>      for( const EXP_OBJ* found : matched )
> >>                                  ^~~~~~~
> >>                                  matherr
> >>
> >>
> >> On 1/22/2019 1:12 PM, John Beard wrote:
> >>> Hi,
> >>>
> >>> Thanks Wayne for merging the utility program stuff.
> >>>
> >>> This brings me onto the subject of PCB utility programs in the same
> >>> vein. Attached are some fun patches:
> >>>
> >>> 1) Some DRC-related groundwork
> >>> 2) A Pcbnew unit test that can test a DRC function and the breaking
> >>> out of the courtyard DRC functions. Also makes a so called
> >>> "qa_pcbnew_utils" "library" *In theory* that can be shared between
> >>> Pcbnew unit tests and Pcbnew utility programs.
> >>> 3) A Pcbnew DRC util that allows to run the courtyard DRC (broken out
> >>> in #2) from the command line. This is essentially what I used to
> >>> generate the benchmarks the other day. Also can be used for fuzz
> >>> testing, as well as debugging, developing and profiling.
> >>> 4) Port the PCB parser utility over to the same executable.
> >>>
> >>> To run the DRC util, for example, with timing and marker information:
> >>>
> >>> $ qa/pcbnew_tools/qa_pcbnew_tools drc -vtm --courtyard-overlap
> >>> --courtyard-missing /path/to/pcb.kicad_pcb
> >>> Parsing: /path/to/pcb.kicad_pcb
> >>> Running DRC check: Courtyard overlap
> >>> Took: 1736us
> >>> DRC markers: 1
> >>> 0: ErrType(45): Courtyards overlap
> >>>     @(24.500 mm, 20.000 mm): Footprint <no reference> on F.Cu
> >>>     @(23.600 mm, 20.000 mm): Footprint <no reference> on F.Cu
> >>> Running DRC check: Courtyard missing
> >>> Took: 131us
> >>> DRC markers: 0
> >>>
> >>> However, I have had the traditional difficulty getting this to link
> >>> using a library for "qa_pcbnew_utils". What is in the patch #2 is a
> >>> nasty and heinous hack that just about gets it working on
> >>> Linux/Msys2/MSVC, but it's highly sub-optimal (it just puts the files
> >>> and link_libraries in variables :s) So, that's why this is an "RFC":
> >>> any ideas for getting this to work properly will be highly
> >>> appreciated.
> >>>
> >>> Also, because this uses the same way of linking into pcbnew, it's even
> >>> *more* brutal on the RAM needs at link-time: the targets "pcbnew",
> >>> "qa_pcbnew" (unit tests) and "qa_pcbnew_tools" (the discussed utility
> >>> tools) are all quite slow.
> >>>
> >>> 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 b18d3088520f6081b5b39546f10989bc64102de2 Mon Sep 17 00:00:00 2001
From: John Beard <john.j.beard@xxxxxxxxx>
Date: Wed, 23 Jan 2019 12:31:53 +0000
Subject: [PATCH 2/2] QA: Add coroutine unit test

This adds a simple unit test to qa_common to check coroutines
produce expected events in the right order.

This is an automated analogue to the user-facing tool in
qa/common_tools.
---
 qa/common/CMakeLists.txt                      |   1 +
 qa/common/test_coroutine.cpp                  | 177 ++++++++++++++++++
 .../tools/coroutines/coroutines.cpp           |   7 +
 3 files changed, 185 insertions(+)
 create mode 100644 qa/common/test_coroutine.cpp

diff --git a/qa/common/CMakeLists.txt b/qa/common/CMakeLists.txt
index ab5bdcd26..8e2f89209 100644
--- a/qa/common/CMakeLists.txt
+++ b/qa/common/CMakeLists.txt
@@ -37,6 +37,7 @@ set( common_srcs
     ../../common/observable.cpp
 
     test_color4d.cpp
+    test_coroutine.cpp
     test_format_units.cpp
     test_hotkey_store.cpp
     test_title_block.cpp
diff --git a/qa/common/test_coroutine.cpp b/qa/common/test_coroutine.cpp
new file mode 100644
index 000000000..ad0824ca4
--- /dev/null
+++ b/qa/common/test_coroutine.cpp
@@ -0,0 +1,177 @@
+/*
+ * 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
+ */
+
+/**
+ * @file test_coroutine.cpp
+ * Test suite for coroutines.
+ *
+ * See also the coroutine utility in qa/common_tools for a command line
+ * test utility.
+ */
+
+#include <unit_test_utils/unit_test_utils.h>
+
+#include <tool/coroutine.h>
+
+#include <common.h>
+
+
+/**
+ * An event in a simple coroutine harness.
+ */
+struct COROUTINE_TEST_EVENT
+{
+    enum class TYPE
+    {
+        START,
+        CALL,
+        YIELD,
+        RETURNED,
+        END,
+    };
+
+    TYPE m_type;
+    int  m_value;
+
+    bool operator==( const COROUTINE_TEST_EVENT& aOther ) const
+    {
+        return m_type == aOther.m_type && m_value == aOther.m_value;
+    }
+
+    bool operator!=( const COROUTINE_TEST_EVENT& aOther ) const
+    {
+        return !operator==( aOther );
+    }
+};
+
+
+/**
+ * Define a stream function for logging this type.
+ *
+ * TODO: convert to boost_test_print_type when Boost minver > 1.64
+ */
+std::ostream& operator<<( std::ostream& os, const COROUTINE_TEST_EVENT& aObj )
+{
+    os << "COROUTINE_TEST_EVENT[ type: " << (int) aObj.m_type << ", value: " << aObj.m_value
+       << " ]";
+    return os;
+}
+
+
+/**
+ * Simple coroutine harness that runs a coroutine that increments a number up
+ * to a pre-set limit, spitting out coroutine events as it goes.
+ *
+ * This can then be used to ensure the events are occurring as expected.
+ */
+class COROUTINE_INCREMENTING_HARNESS
+{
+public:
+    /**
+     * The coroutine test take ints and returns them
+     */
+    using TEST_COROUTINE = COROUTINE<int, int>;
+
+    using EVT_HANDLER = std::function<void( const COROUTINE_TEST_EVENT& )>;
+
+    COROUTINE_INCREMENTING_HARNESS( EVT_HANDLER aHandler, int aCount )
+            : m_handler( aHandler ), m_count( aCount )
+    {
+    }
+
+    int CountTo( int n )
+    {
+        m_handler( { COROUTINE_TEST_EVENT::TYPE::START, 0 } );
+
+        for( int i = 1; i <= n; i++ )
+        {
+            m_handler( { COROUTINE_TEST_EVENT::TYPE::YIELD, i } );
+            m_cofunc->KiYield( i );
+        }
+
+        return 0;
+    }
+
+    void Run()
+    {
+        m_cofunc =
+                std::make_unique<TEST_COROUTINE>( this, &COROUTINE_INCREMENTING_HARNESS::CountTo );
+        m_handler( { COROUTINE_TEST_EVENT::TYPE::CALL, m_count } );
+        m_cofunc->Call( m_count );
+
+        int ret_val = 0;
+
+        while( m_cofunc->Running() )
+        {
+            ret_val = m_cofunc->ReturnValue();
+            m_handler( { COROUTINE_TEST_EVENT::TYPE::RETURNED, ret_val } );
+            m_cofunc->Resume();
+        }
+
+        m_handler( { COROUTINE_TEST_EVENT::TYPE::END, ret_val } );
+    }
+
+    EVT_HANDLER                     m_handler;
+    std::unique_ptr<TEST_COROUTINE> m_cofunc;
+    int                             m_count;
+};
+
+/**
+ * Declare the test suite
+ */
+BOOST_AUTO_TEST_SUITE( Coroutine )
+
+
+/**
+ * A basic test to repeatedly call a coroutine and check that it yields
+ * values as expected.
+ */
+BOOST_AUTO_TEST_CASE( Increment )
+{
+    const int count = 2;
+
+    const std::vector<COROUTINE_TEST_EVENT> exp_events = {
+        { COROUTINE_TEST_EVENT::TYPE::CALL, count },
+        { COROUTINE_TEST_EVENT::TYPE::START, 0 },
+        { COROUTINE_TEST_EVENT::TYPE::YIELD, 1 },
+        { COROUTINE_TEST_EVENT::TYPE::RETURNED, 1 },
+        { COROUTINE_TEST_EVENT::TYPE::YIELD, 2 },
+        { COROUTINE_TEST_EVENT::TYPE::RETURNED, 2 },
+        { COROUTINE_TEST_EVENT::TYPE::END, 2 },
+    };
+
+    std::vector<COROUTINE_TEST_EVENT> received_events;
+
+    auto handler = [&]( const COROUTINE_TEST_EVENT& aEvent ) {
+        received_events.push_back( aEvent );
+    };
+
+    COROUTINE_INCREMENTING_HARNESS harness( handler, count );
+
+    harness.Run();
+
+    BOOST_CHECK_EQUAL_COLLECTIONS(
+            received_events.begin(), received_events.end(), exp_events.begin(), exp_events.end() );
+}
+
+BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
diff --git a/qa/common_tools/tools/coroutines/coroutines.cpp b/qa/common_tools/tools/coroutines/coroutines.cpp
index 28f83045d..0bea0ce8d 100644
--- a/qa/common_tools/tools/coroutines/coroutines.cpp
+++ b/qa/common_tools/tools/coroutines/coroutines.cpp
@@ -35,6 +35,13 @@
 
 typedef COROUTINE<int, int> MyCoroutine;
 
+/**
+ * A simple harness that counts to a preset value in a couroutine, yielding
+ * each value.
+ *
+ * This is a user-facing version of the "Increment" unit test in the "Coroutine"
+ * suite, in qa_common.
+ */
 class CoroutineExample
 {
 public:
-- 
2.20.1

From c92607d16b7e859a55c8b0e8c7a5085b5c3d6dc7 Mon Sep 17 00:00:00 2001
From: John Beard <john.j.beard@xxxxxxxxx>
Date: Tue, 22 Jan 2019 22:56:10 +0000
Subject: [PATCH 1/2] QA: Reinstate polygon_generator as a sub-util of
 qa_pcbnew_tools

This program has been disabled for some time, but it's not
broken (even if the CMake was!).

Merging into the pcbnew_tools QA program reduces the CMake burden
and puts this tool in the same place as the others.
---
 qa/CMakeLists.txt                             |  1 -
 qa/pcbnew_tools/CMakeLists.txt                |  2 +
 qa/pcbnew_tools/pcbnew_tools.cpp              |  2 +
 .../polygon_generator/polygon_generator.cpp}  | 33 +++++--
 .../polygon_generator/polygon_generator.h     | 32 +++++++
 qa/polygon_generator/CMakeLists.txt           | 92 -------------------
 6 files changed, 59 insertions(+), 103 deletions(-)
 rename qa/{polygon_generator/test_polygon_generator.cpp => pcbnew_tools/tools/polygon_generator/polygon_generator.cpp} (85%)
 create mode 100644 qa/pcbnew_tools/tools/polygon_generator/polygon_generator.h
 delete mode 100644 qa/polygon_generator/CMakeLists.txt

diff --git a/qa/CMakeLists.txt b/qa/CMakeLists.txt
index f178e775f..179962ebe 100644
--- a/qa/CMakeLists.txt
+++ b/qa/CMakeLists.txt
@@ -29,4 +29,3 @@ add_subdirectory( pcbnew_tools )
 
 # add_subdirectory( pcb_test_window )
 # add_subdirectory( polygon_triangulation )
-# add_subdirectory( polygon_generator )
diff --git a/qa/pcbnew_tools/CMakeLists.txt b/qa/pcbnew_tools/CMakeLists.txt
index 1e0e09739..9b01c24e1 100644
--- a/qa/pcbnew_tools/CMakeLists.txt
+++ b/qa/pcbnew_tools/CMakeLists.txt
@@ -33,6 +33,8 @@ add_executable( qa_pcbnew_tools
 
     tools/pcb_parser/pcb_parser_tool.cpp
 
+    tools/polygon_generator/polygon_generator.cpp
+
     # Older CMakes cannot link OBJECT libraries
     # https://cmake.org/pipermail/cmake/2013-November/056263.html
     $<TARGET_OBJECTS:pcbnew_kiface_objects>
diff --git a/qa/pcbnew_tools/pcbnew_tools.cpp b/qa/pcbnew_tools/pcbnew_tools.cpp
index 7c4c4824a..dc19d0355 100644
--- a/qa/pcbnew_tools/pcbnew_tools.cpp
+++ b/qa/pcbnew_tools/pcbnew_tools.cpp
@@ -25,6 +25,7 @@
 
 #include "tools/drc_tool/drc_tool.h"
 #include "tools/pcb_parser/pcb_parser_tool.h"
+#include "tools/polygon_generator/polygon_generator.h"
 
 /**
  * List of registered tools.
@@ -35,6 +36,7 @@
 const static std::vector<UTILITY_PROGRAM*> known_tools = {
     &drc_tool,
     &pcb_parser_tool,
+    &polygon_generator_tool,
 };
 
 
diff --git a/qa/polygon_generator/test_polygon_generator.cpp b/qa/pcbnew_tools/tools/polygon_generator/polygon_generator.cpp
similarity index 85%
rename from qa/polygon_generator/test_polygon_generator.cpp
rename to qa/pcbnew_tools/tools/polygon_generator/polygon_generator.cpp
index 5981d527c..09af99144 100644
--- a/qa/polygon_generator/test_polygon_generator.cpp
+++ b/qa/pcbnew_tools/tools/polygon_generator/polygon_generator.cpp
@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2017 CERN
  * @author Tomasz Wlostowski <tomasz.wlostowski@xxxxxxx>
+ * Copyright (C) 2019 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
@@ -22,24 +23,26 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
 
-#include <geometry/shape_poly_set.h>
-#include <geometry/shape_line_chain.h>
+#include "polygon_generator.h"
+
 #include <geometry/shape_file_io.h>
+#include <geometry/shape_line_chain.h>
+#include <geometry/shape_poly_set.h>
 
 #include <io_mgr.h>
 #include <kicad_plugin.h>
 
 #include <class_board.h>
-#include <class_zone.h>
-#include <class_pad.h>
-#include <class_track.h>
 #include <class_drawsegment.h>
 #include <class_module.h>
+#include <class_pad.h>
+#include <class_track.h>
+#include <class_zone.h>
 
 BOARD* loadBoard( const std::string& filename )
 {
     PLUGIN::RELEASER pi( new PCB_IO );
-    BOARD* brd = nullptr;
+    BOARD*           brd = nullptr;
 
     try
     {
@@ -47,8 +50,7 @@ BOARD* loadBoard( const std::string& filename )
     }
     catch( const IO_ERROR& ioe )
     {
-        wxString msg = wxString::Format( _( "Error loading board.\n%s" ),
-                ioe.Problem() );
+        wxString msg = wxString::Format( _( "Error loading board.\n%s" ), ioe.Problem() );
 
         printf( "%s\n", (const char*) msg.mb_str() );
         return nullptr;
@@ -72,12 +74,12 @@ void process( const BOARD_CONNECTED_ITEM* item, int net )
 
     item->TransformShapeWithClearanceToPolygon( pset, 1, segsPerCircle, correctionFactor );
 
-    SHAPE_FILE_IO shapeIo;    // default = stdout
+    SHAPE_FILE_IO shapeIo; // default = stdout
     shapeIo.Write( &pset );
 }
 
 
-int main( int argc, char* argv[] )
+int polygon_gererator_main( int argc, char* argv[] )
 {
     if( argc < 2 )
     {
@@ -109,4 +111,15 @@ int main( int argc, char* argv[] )
 
         printf( "endnet\n" );
     }
+
+    return 0;
 }
+
+/*
+ * Define the tool interface
+ */
+UTILITY_PROGRAM polygon_generator_tool = {
+    "polygon_generator",
+    "Dump board geometry as a set of polygons",
+    polygon_gererator_main,
+};
\ No newline at end of file
diff --git a/qa/pcbnew_tools/tools/polygon_generator/polygon_generator.h b/qa/pcbnew_tools/tools/polygon_generator/polygon_generator.h
new file mode 100644
index 000000000..a1faee298
--- /dev/null
+++ b/qa/pcbnew_tools/tools/polygon_generator/polygon_generator.h
@@ -0,0 +1,32 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2019 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 PCBNEW_TOOLS_POLYGON_GENERATOR_UTILITY_H
+#define PCBNEW_TOOLS_POLYGON_GENERATOR_UTILITY_H
+
+#include <utility_program.h>
+
+/// A tool to parse kicad PCBs from the command line
+extern UTILITY_PROGRAM polygon_generator_tool;
+
+#endif //PCBNEW_TOOLS_POLYGON_GENERATOR_UTILITY_H
\ No newline at end of file
diff --git a/qa/polygon_generator/CMakeLists.txt b/qa/polygon_generator/CMakeLists.txt
deleted file mode 100644
index ba79297fb..000000000
--- a/qa/polygon_generator/CMakeLists.txt
+++ /dev/null
@@ -1,92 +0,0 @@
-#
-# This program source code file is part of KiCad, a free EDA CAD application.
-#
-# Copyright (C) 2017 CERN
-# @author Alejandro García Montoro <alejandro.garciamontoro@xxxxxxxxx>
-#
-# 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(Boost COMPONENTS unit_test_framework REQUIRED)
-#find_package( wxWidgets 3.0.0 COMPONENTS gl aui adv html core net base xml stc REQUIRED )
-
-add_definitions(-DPCBNEW -DBOOST_TEST_DYN_LINK)
-
-if( BUILD_GITHUB_PLUGIN )
-    set( GITHUB_PLUGIN_LIBRARIES github_plugin )
-endif()
-
-add_dependencies( pnsrouter pcbcommon pcad2kicadpcb ${GITHUB_PLUGIN_LIBRARIES} )
-
-add_executable(test_polygon_generator
-  ../qa_utils/mocks.cpp
-  ../../common/base_units.cpp
-  test_polygon_generator.cpp
-)
-
-include_directories( BEFORE ${INC_BEFORE} )
-include_directories(
-    ${CMAKE_SOURCE_DIR}
-    ${CMAKE_SOURCE_DIR}/include
-    ${CMAKE_SOURCE_DIR}/3d-viewer
-    ${CMAKE_SOURCE_DIR}/common
-    ${CMAKE_SOURCE_DIR}/pcbnew
-    ${CMAKE_SOURCE_DIR}/pcbnew/router
-    ${CMAKE_SOURCE_DIR}/pcbnew/tools
-    ${CMAKE_SOURCE_DIR}/pcbnew/dialogs
-    ${CMAKE_SOURCE_DIR}/polygon
-    ${CMAKE_SOURCE_DIR}/common/geometry
-    ${CMAKE_SOURCE_DIR}/qa/common
-    ${Boost_INCLUDE_DIR}
-    ${INC_AFTER}
-)
-
-target_link_libraries( test_polygon_generator
-    polygon
-    pnsrouter
-    common
-    pcbcommon
-    bitmaps
-    polygon
-    pnsrouter
-    common
-    pcbcommon
-    bitmaps
-    polygon
-    pnsrouter
-    common
-    pcbcommon
-    bitmaps
-    polygon
-    pnsrouter
-    common
-    pcbcommon
-    bitmaps
-    gal
-    pcad2kicadpcb
-    common
-    pcbcommon
-    ${GITHUB_PLUGIN_LIBRARIES}
-    common
-    pcbcommon
-    ${Boost_FILESYSTEM_LIBRARY}
-    ${Boost_SYSTEM_LIBRARY}
-    ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}
-    ${wxWidgets_LIBRARIES}
-)
-
-
-- 
2.20.1


Follow ups

References