From f3173ba8c8b94cc1c246f715cde6303764a4184c Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 2 Jun 2016 15:06:17 -0400
Subject: [PATCH 00/16] v6 of -fself-test/unit-testing patch

Given that we're now using an "abort on first failure" model, I
renamed all of the EXPECT_ macros to ASSERT_ (for consistency with
GTest).

As per Bernd's suggestions I eliminated the runner class and moved
to a more function-based rather than class-based approach.

At this point, the only reasons left for "class test" were
auto-registration, and giving names to tests.

So I tried removing it, and invoking tests manually.

I like the resulting code; it seems much simpler and clearer, with
very little "magic".

The following is an updated version of the patch kit that uses this
simpler approach.

In theory there's a slight risk to the manual-invocation approach.
If you forget a test within a file, the compiler tells you:

../../src/gcc/vec.c:204:1: warning: ‘void test_quick_push()’ defined but not used [-Wunused-function]

but if you forget to call the file from selftests.c, there's no warning.
I believe that adding a new test file will be a rare event, so this
kind of mistake will (I hope) be unlikely.
I've verified that the pass count before/after the change matches up.
By constrast, the auto-registration approach put us at the mercy of
the implementation of C++ global constructors, and I ran into at
least one surprise with that
( https://sourceware.org/bugzilla/show_bug.cgi?id=20152 ).

I've added the wide-int tests back.  These are parametrized by type,
and it was fairly easy to do this manually using templates once I
eliminated test registration.  I also added some new tests to
diagnostic-show-locus.c.

Although I'm posted this as a patch kit, it would be applied in one
commit: the initial patch makes reference to tests added in later
patches. I split it up so that each test file is in its own patch,
to make review easier (I hope).

As in v5, the tests are run in gcc/Makefile.in at each stage of a
bootstrap:
  $ grep "fself-test:" test/experiment/x86_64-pc-linux-gnu/build/make.log
  -fself-test: 621 pass(es) in 0.013000 seconds
  -fself-test: 621 pass(es) in 0.006000 seconds
  -fself-test: 621 pass(es) in 0.007000 seconds

Successfully bootstrapped&regression tested on x86_64-pc-linux-gnu.
A test against all configurations using contrib/config-list.mk is
in progress.

OK for trunk?

David Malcolm (16):
  Core of selftest framework (v6)
  diagnostic-show-locus.c: add selftests
  spellcheck.c: convert Levenshtein test from a plugin to a selftest
  bitmap.c: add selftests
  tree-cfg.c: add selftests
  et-forest.c: add selftests
  fold-const.c: add selftests
  Add function-tests.c
  gimple.c: add selftests
  Add hash-map-tests.c
  Add hash-set-tests.c
  input.c: add selftests
  Add rtl-tests.c
  tree.c: add selftests
  vec.c: add selftests
  wide-int.cc: add selftests

 gcc/Makefile.in                                  |  31 +-
 gcc/bitmap.c                                     | 110 ++++
 gcc/common.opt                                   |   4 +
 gcc/diagnostic-show-locus.c                      | 156 ++++++
 gcc/et-forest.c                                  | 112 ++++
 gcc/fold-const.c                                 |  75 +++
 gcc/function-tests.c                             | 639 +++++++++++++++++++++++
 gcc/gimple.c                                     | 119 +++++
 gcc/hash-map-tests.c                             |  88 ++++
 gcc/hash-set-tests.c                             |  64 +++
 gcc/input.c                                      | 112 ++++
 gcc/rtl-tests.c                                  | 108 ++++
 gcc/selftest-run-tests.c                         |  77 +++
 gcc/selftest.c                                   |  49 ++
 gcc/selftest.h                                   | 153 ++++++
 gcc/spellcheck.c                                 |  45 ++
 gcc/testsuite/gcc.dg/plugin/levenshtein-test-1.c |   9 -
 gcc/testsuite/gcc.dg/plugin/levenshtein_plugin.c |  64 ---
 gcc/testsuite/gcc.dg/plugin/plugin.exp           |   1 -
 gcc/toplev.c                                     |  26 +
 gcc/toplev.h                                     |   2 +
 gcc/tree-cfg.c                                   | 277 ++++++++++
 gcc/tree.c                                       |  60 +++
 gcc/vec.c                                        | 162 ++++++
 gcc/wide-int.cc                                  | 152 ++++++
 25 files changed, 2616 insertions(+), 79 deletions(-)
 create mode 100644 gcc/function-tests.c
 create mode 100644 gcc/hash-map-tests.c
 create mode 100644 gcc/hash-set-tests.c
 create mode 100644 gcc/rtl-tests.c
 create mode 100644 gcc/selftest-run-tests.c
 create mode 100644 gcc/selftest.c
 create mode 100644 gcc/selftest.h
 delete mode 100644 gcc/testsuite/gcc.dg/plugin/levenshtein-test-1.c
 delete mode 100644 gcc/testsuite/gcc.dg/plugin/levenshtein_plugin.c

-- 
1.8.5.3

