This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH 03/21] Various selftest::runner tweaks.
- From: David Malcolm <dmalcolm at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Bernd Schmidt <bschmidt at redhat dot com>, Jeff Law <law at redhat dot com>, David Malcolm <dmalcolm at redhat dot com>
- Date: Wed, 1 Jun 2016 17:19:45 -0400
- Subject: [PATCH 03/21] Various selftest::runner tweaks.
- Authentication-results: sourceware.org; auth=none
- References: <1447952699-40820-1-git-send-email-dmalcolm at redhat dot com> <1464816003-35862-1-git-send-email-dmalcolm at redhat dot com>
* move almost everything to a logfile (albeit without a way of
setting it up yet)
* tweaks to failure-handling
* abort on failure
The practical upshot is that the output is much less verbose:
* if everything succeeds, the only output is of the form:
-fself-test: 576 pass(es); 0 failure(s) in 0.028000 seconds
* if something fails, the failing test is identified on stderr,
and the process immediately aborts (the idea being to make
it easy to locate within the debugger).
gcc/ChangeLog:
* selftest.c (runner::runner): Initialize m_logfile.
(runner::~runner): Use m_logfile, with an alternate
print to stderr if m_logfile is NULL.
(runner::begin_test): Log to m_logfile, and conditionalize
it on m_logfile being non-NULL.
(runner::pass): Likewise.
(runner::end_test): Likewise.
(runner::fail): Use m_logfile if non-NULL, stderr otherwise.
Abort on failure.
* selftest.h (selftest::runner): Add field m_logfile.
---
gcc/selftest.c | 31 +++++++++++++++++++++++--------
gcc/selftest.h | 1 +
2 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/gcc/selftest.c b/gcc/selftest.c
index af95312..42e07e3 100644
--- a/gcc/selftest.c
+++ b/gcc/selftest.c
@@ -81,7 +81,8 @@ selftest::run_all_tests ()
runner::runner ()
: m_passes (0),
m_failures (0),
- m_start_time (get_run_time ())
+ m_start_time (get_run_time ()),
+ m_logfile (NULL)
{
}
@@ -91,9 +92,16 @@ runner::~runner ()
{
long finish_time = get_run_time ();
long elapsed_time = finish_time - m_start_time;
- fprintf (stderr, "NOTE: %i pass(es); %i failure(s) in %ld.%06ld seconds\n",
- m_passes, m_failures,
- elapsed_time / 1000000, elapsed_time % 1000000);
+ if (m_logfile)
+ fprintf (m_logfile,
+ "NOTE: %i pass(es); %i failure(s) in %ld.%06ld seconds\n",
+ m_passes, m_failures,
+ elapsed_time / 1000000, elapsed_time % 1000000);
+ else
+ fprintf (stderr,
+ "-fself-test: %i pass(es); %i failure(s) in %ld.%06ld seconds\n",
+ m_passes, m_failures,
+ elapsed_time / 1000000, elapsed_time % 1000000);
}
/* Notify the user that a particular test is about to be run. */
@@ -101,7 +109,8 @@ runner::~runner ()
void
runner::begin_test (test *t)
{
- fprintf (stderr, "NOTE: %s: test starting\n", t->get_name ());
+ if (m_logfile)
+ fprintf (m_logfile, "NOTE: %s: test starting\n", t->get_name ());
}
/* Record and report the successful outcome of some aspect of a test. */
@@ -109,7 +118,9 @@ runner::begin_test (test *t)
void
runner::pass (const char *file, int line, test *t, const char *msg)
{
- fprintf (stderr, "%s:%i: PASS: %s: %s\n", file, line, t->get_name (), msg);
+ if (m_logfile)
+ fprintf (m_logfile, "%s:%i: PASS: %s: %s\n",
+ file, line, t->get_name (), msg);
m_passes++;
}
@@ -118,8 +129,11 @@ runner::pass (const char *file, int line, test *t, const char *msg)
void
runner::fail (const char *file, int line, test *t, const char *msg)
{
- fprintf (stderr, "%s:%i: FAIL: %s: %s\n", file, line, t->get_name (), msg);
+ fprintf (m_logfile ? m_logfile : stderr,
+ "%s:%i: FAIL: %s: %s\n",
+ file, line, t->get_name (), msg);
m_failures++;
+ abort ();
}
/* Notify the user that a particular test has finished running. */
@@ -127,7 +141,8 @@ runner::fail (const char *file, int line, test *t, const char *msg)
void
runner::end_test (test *t)
{
- fprintf (stderr, "NOTE: %s: test ending\n", t->get_name ());
+ if (m_logfile)
+ fprintf (m_logfile, "NOTE: %s: test ending\n", t->get_name ());
}
/* Implementation of class ::selftest::registrator. */
diff --git a/gcc/selftest.h b/gcc/selftest.h
index 720e1d5..95262ce 100644
--- a/gcc/selftest.h
+++ b/gcc/selftest.h
@@ -55,6 +55,7 @@ private:
int m_passes;
int m_failures;
long m_start_time;
+ FILE *m_logfile;
};
/* The class ::selftest::test is a base class from which specific
--
1.8.5.3