gdbsupport: record and print failed selftest names

Message ID 20231103155141.36997-1-simon.marchi@efficios.com
State New
Headers
Series gdbsupport: record and print failed selftest names |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 warning Patch is already merged
linaro-tcwg-bot/tcwg_gdb_build--master-arm warning Patch is already merged
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm warning Patch is already merged

Commit Message

Simon Marchi Nov. 3, 2023, 3:51 p.m. UTC
  Since "maint selftest" now runs quite a lot of tests (especially in an
all-targets build), I thought it would be useful to print a summary at
the end of what failed.  So, implement that.

Print the summary before the "Ran %d unit tests, %zu failed\n" line, so
that that one remains the last line, and the gdb.gdb/unittest.exp
doesn't need to be changed.

The output looks like (if I force a failure in a test):

    (gdb) maint selftest
    ...
    Running selftest value_copy.
    Running selftest xml_escape_text.
    Running selftest xml_escape_text_append.

    Failures:
      aarch64-analyze-prologue

    Ran 4134 unit tests, 1 failed
    (gdb)

Change-Id: If3aaabdd6f8078d0e6e50e8d08f3e558ab85277e
---
 gdbsupport/selftest.cc | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)


base-commit: 88bfe6ac8bcbaf1eb0c1e4be02c21a5c048b7335
  

Comments

Tom Tromey Nov. 3, 2023, 6:22 p.m. UTC | #1
>>>>> "Simon" == Simon Marchi <simon.marchi@efficios.com> writes:

Simon> Since "maint selftest" now runs quite a lot of tests (especially in an
Simon> all-targets build), I thought it would be useful to print a summary at
Simon> the end of what failed.  So, implement that.

Simon> Print the summary before the "Ran %d unit tests, %zu failed\n" line, so
Simon> that that one remains the last line, and the gdb.gdb/unittest.exp
Simon> doesn't need to be changed.

Definitely nice to have.  Thanks.
Approved-By: Tom Tromey <tom@tromey.com>

Tom
  
Simon Marchi Nov. 3, 2023, 6:26 p.m. UTC | #2
On 11/3/23 14:22, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@efficios.com> writes:
> 
> Simon> Since "maint selftest" now runs quite a lot of tests (especially in an
> Simon> all-targets build), I thought it would be useful to print a summary at
> Simon> the end of what failed.  So, implement that.
> 
> Simon> Print the summary before the "Ran %d unit tests, %zu failed\n" line, so
> Simon> that that one remains the last line, and the gdb.gdb/unittest.exp
> Simon> doesn't need to be changed.
> 
> Definitely nice to have.  Thanks.
> Approved-By: Tom Tromey <tom@tromey.com>
> 
> Tom

Thanks, pushed.

Simon
  

Patch

diff --git a/gdbsupport/selftest.cc b/gdbsupport/selftest.cc
index c2e393661459..15c52421b801 100644
--- a/gdbsupport/selftest.cc
+++ b/gdbsupport/selftest.cc
@@ -72,8 +72,9 @@  run_verbose ()
 void
 run_tests (gdb::array_view<const char *const> filters, bool verbose)
 {
-  int ran = 0, failed = 0;
+  int ran = 0;
   run_verbose_ = verbose;
+  std::vector<const char *> failed;
 
   for (const auto &test : all_selftests ())
     {
@@ -101,15 +102,25 @@  run_tests (gdb::array_view<const char *const> filters, bool verbose)
 	}
       catch (const gdb_exception_error &ex)
 	{
-	  ++failed;
 	  debug_printf ("Self test failed: %s\n", ex.what ());
+	  failed.push_back (test.name.c_str ());
 	}
 
       reset ();
     }
 
-  debug_printf (_("Ran %d unit tests, %d failed\n"),
-		ran, failed);
+  if (!failed.empty ())
+    {
+      debug_printf ("\nFailures:\n");
+
+      for (const char *name : failed)
+	debug_printf ("  %s\n", name);
+
+      debug_printf ("\n");
+    }
+
+  debug_printf (_("Ran %d unit tests, %zu failed\n"),
+		ran, failed.size ());
 }
 
 /* See selftest.h.  */