From ba446952fe50d3857b753c1763135c2c29c6474a Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Tue, 27 Oct 2015 14:09:22 -0400
Subject: [PATCH 00/16] Unit tests framework (v3)

This is a followup to these proposals:
 * v1: https://gcc.gnu.org/ml/gcc-patches/2015-06/msg00765.html
 * v2: https://gcc.gnu.org/ml/gcc-patches/2015-06/msg01224.html

The following patch kit adds a unit tests framework for gcc,
as a new subdirectory below gcc/testsuite.

The aim is to give us direct coverage of low level implementation
details that aren't well covered by our existing tests, such as
our data structures, gengtype, etc.  This will let us have tests
that directly poke at specific internal APIs and verify that the
right thing happens, rather than having to write source code and
option combinations that we hope touches the relevant state.
It should make it trivial to add new unit tests.

I see it as complementary to our existing test approaches.

Like previous versions of the patch kit it uses the Google Test
framework, since I've had good experiences with it:
  http://code.google.com/p/googletest/
and like v2 of the kit it embeds a two-file copy of v1.7 of
the kit, to avoid adding extra dependencies (one .h file and one
.c file).

v1 of the kit was structured as a frontend, v2 of the kit as
a plugin that was built as if it were a frontend.  Both of
these approaches were problematic, so this version
of the patch kit simply builds as a test case within the
plugin.exp suites.

In this approach, each of gcc.dg and g++.dg have a plugin.exp that
lists plugins to be built and source files to then compile with
the plugin.  This patch kit inserts into them references to the plugin
within ../../unittests, so that we can run the tests within both cc1
and cc1plus without having to list everything twice.  The plugin
is built by plugin.exp and plugin-support.exp as per the existing
test cases.  Doing so requires #include-ing everything relevant
within unittests-plugin.c.

The plugin uses a custom gtest reporter that reports results in
DejaGnu format.  The kit adds some logic to testsuite/lib/prune.exp
to parse the DejaGnu output on stderr e.g.:
  PASS: ggc_test.inheritance
and re-emits it at the Tcl level, so that the unit test results from
the plugin are reported within the regular test output like this:
  PASS: gcc.dg/plugin/unittests.c -fplugin=./unittests-plugin.so  ggc_test.inheritance

Successfully bootstrapped&regrtested on x86_64-pc-linux-gnu
(on top of r229364); adds 61 new PASS results to each of gcc.sum and
g++.sum.

I've broken up the patches into logical chunks in the hope of making
review easier, but this is effectively one change, and would be
committed as such.  Though if any individual testcases are
problematic, they could be deferred, if that will help get the rest
of the work approved.

[There are some FIXMEs in the testcases indicating room for further
testing, and I've not fully reduced the #includes in them; is the
"blessed" #include order documented yet, and do we have tooling
in "contrib" for this yet?]

With those caveats, OK for trunk?

David Malcolm (16):
  Add unittest infrastructure
  Add embedded copy of gtest-1.7 to unittests
  Add test-bitmap.c to unittests
  Add test-cfg.c to unittests
  Add test-et-forest.c to unittests
  Add test-folding.c to unittests
  Add test-functions.c to unittests
  Add test-ggc.c to unittests
  Add test-gimple.c to unittests
  Add test-hash-map.c to unittests
  Add test-hash-set.c to unittests
  Add test-locations.c to unittests
  Add test-rtl.c to unittests
  Add test-tree.c to unittests
  Add test-vec.c to unittests
  Add test-wide-int.c to unittests

 gcc/testsuite/g++.dg/plugin/plugin.exp     |     4 +-
 gcc/testsuite/g++.dg/plugin/unittests.C    |     9 +
 gcc/testsuite/gcc.dg/plugin/plugin.exp     |     1 +
 gcc/testsuite/gcc.dg/plugin/unittests.c    |     9 +
 gcc/testsuite/lib/plugin-support.exp       |    29 +-
 gcc/testsuite/lib/prune.exp                |    43 +
 gcc/testsuite/unittests/gtest-all.c        |  9592 +++++++++++++
 gcc/testsuite/unittests/gtest/gtest.h      | 20061 +++++++++++++++++++++++++++
 gcc/testsuite/unittests/test-bitmap.c      |   116 +
 gcc/testsuite/unittests/test-cfg.c         |   319 +
 gcc/testsuite/unittests/test-et-forest.c   |   121 +
 gcc/testsuite/unittests/test-folding.c     |   120 +
 gcc/testsuite/unittests/test-functions.c   |   645 +
 gcc/testsuite/unittests/test-ggc.c         |   299 +
 gcc/testsuite/unittests/test-gimple.c      |   178 +
 gcc/testsuite/unittests/test-hash-map.c    |    77 +
 gcc/testsuite/unittests/test-hash-set.c    |    53 +
 gcc/testsuite/unittests/test-locations.c   |   145 +
 gcc/testsuite/unittests/test-rtl.c         |    94 +
 gcc/testsuite/unittests/test-tree.c        |   101 +
 gcc/testsuite/unittests/test-vec.c         |   161 +
 gcc/testsuite/unittests/test-wide-int.c    |   185 +
 gcc/testsuite/unittests/unittests-plugin.c |   213 +
 23 files changed, 32573 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/plugin/unittests.C
 create mode 100644 gcc/testsuite/gcc.dg/plugin/unittests.c
 create mode 100644 gcc/testsuite/unittests/gtest-all.c
 create mode 100644 gcc/testsuite/unittests/gtest/gtest.h
 create mode 100644 gcc/testsuite/unittests/test-bitmap.c
 create mode 100644 gcc/testsuite/unittests/test-cfg.c
 create mode 100644 gcc/testsuite/unittests/test-et-forest.c
 create mode 100644 gcc/testsuite/unittests/test-folding.c
 create mode 100644 gcc/testsuite/unittests/test-functions.c
 create mode 100644 gcc/testsuite/unittests/test-ggc.c
 create mode 100644 gcc/testsuite/unittests/test-gimple.c
 create mode 100644 gcc/testsuite/unittests/test-hash-map.c
 create mode 100644 gcc/testsuite/unittests/test-hash-set.c
 create mode 100644 gcc/testsuite/unittests/test-locations.c
 create mode 100644 gcc/testsuite/unittests/test-rtl.c
 create mode 100644 gcc/testsuite/unittests/test-tree.c
 create mode 100644 gcc/testsuite/unittests/test-vec.c
 create mode 100644 gcc/testsuite/unittests/test-wide-int.c
 create mode 100644 gcc/testsuite/unittests/unittests-plugin.c

-- 
1.8.5.3

