From: Simon Marchi <simon.marchi@efficios.com>
To: gcc-patches@sourceware.org, gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 6/6] gdb: remove manual printing of values in some selftests
Date: Mon, 19 Oct 2026 12:58:22 -0400 [thread overview]
Message-ID: <20261019165929.792697-7-simon.marchi@efficios.com> (raw)
In-Reply-To: <20261019165929.792697-1-simon.marchi@efficios.com>
Now that SELF_CHECK prints the values of the operands of a failing
comparison, some selftests no longer need to print them by hand.
- split-name.c: check_split_name prints the result and expected
components on failure. Remove that, and components_to_string, which
is now unused.
- disasm-selftests.c: disassemble_insn prints the expected string on
failure. Remove that. Keep printing the instruction bytes, which
give context.
- remote-arg-selftests.c: the test counts failures, prints the split
and joined arguments in verbose mode, and checks the failure count at
the end. Replace that with a SELF_CHECK for each comparison. Keep
printing the input in verbose mode. The test now stops at the first
failing case, like most selftests.
Change-Id: I1e4cc3da7e607c36bb0d67ef9562bb8216a2d42f
---
gdb/disasm-selftests.c | 9 +---
gdb/split-name.c | 28 ------------
gdb/unittests/remote-arg-selftests.c | 65 ++--------------------------
3 files changed, 6 insertions(+), 96 deletions(-)
diff --git a/gdb/disasm-selftests.c b/gdb/disasm-selftests.c
index 1aa399a57d4a..9bd9e497b533 100644
--- a/gdb/disasm-selftests.c
+++ b/gdb/disasm-selftests.c
@@ -401,19 +401,14 @@ disassemble_insn (gdbarch *gdbarch, gdb::byte_vector &insn,
std::string buffer
= disassemble_one_insn_to_string (gdbarch, insn);
- bool check_ok = buffer == expected;
-
- if (run_verbose () || !check_ok)
+ if (run_verbose () || buffer != expected)
{
for (gdb_byte b : insn)
debug_printf ("0x%02x ", b);
debug_printf ("-> %s\n", buffer.c_str ());
}
- if (!check_ok)
- debug_printf ("expected: %s\n", expected.c_str ());
-
- SELF_CHECK (check_ok);
+ SELF_CHECK (buffer == expected);
}
} /* namespace selftests */
diff --git a/gdb/split-name.c b/gdb/split-name.c
index b8605c4040f4..ea71e0589d1b 100644
--- a/gdb/split-name.c
+++ b/gdb/split-name.c
@@ -19,7 +19,6 @@
#include "split-name.h"
#include "cp-support.h"
-#include "gdbsupport/enumerate.h"
#include "gdbsupport/selftest.h"
/* See split-name.h. */
@@ -82,27 +81,6 @@ split_name (const char *name, split_style style)
namespace selftests {
-/* Return a string representation of COMPONENTS, for debugging. */
-
-static std::string
-components_to_string (const std::vector<std::string_view> &components)
-{
- std::string str = "{";
-
- for (auto [i, component] : gdb::ranges::views::enumerate (components))
- {
- if (i > 0)
- str += ",";
-
- str += " \"";
- str += component;
- str += "\"";
- }
-
- str += " }";
- return str;
-}
-
/* Check that splitting NAME using STYLE gives EXPECTED. */
static void
@@ -110,12 +88,6 @@ check_split_name (const char *name, split_style style,
const std::vector<std::string_view> &expected)
{
std::vector<std::string_view> result = split_name (name, style);
-
- if (result != expected)
- debug_printf ("split_name (\"%s\"): got %s, expected %s\n", name,
- components_to_string (result).c_str (),
- components_to_string (expected).c_str ());
-
SELF_CHECK (result == expected);
}
diff --git a/gdb/unittests/remote-arg-selftests.c b/gdb/unittests/remote-arg-selftests.c
index e55a7185c618..a306925c48dd 100644
--- a/gdb/unittests/remote-arg-selftests.c
+++ b/gdb/unittests/remote-arg-selftests.c
@@ -82,7 +82,6 @@ arg_test_desc desc[] = {
static void
self_test ()
{
- int failure_count = 0;
for (const auto &d : desc)
{
if (run_verbose ())
@@ -94,50 +93,11 @@ self_test ()
/* Split argument string into individual arguments. */
std::vector<std::string> split_args = gdb::remote_args::split (d.input);
-
- if (run_verbose ())
- {
- debug_printf ("Split:\n");
-
- size_t len = std::max (split_args.size (), d.split.size ());
- for (size_t i = 0; i < len; ++i)
- {
- const char *got = "N/A";
- const char *expected = got;
-
- if (i < split_args.size ())
- got = split_args[i].c_str ();
-
- if (i < d.split.size ())
- expected = d.split[i].c_str ();
-
- debug_printf (" got (%s), expected (%s)\n", got, expected);
- }
- }
-
- if (split_args != d.split)
- {
- ++failure_count;
- if (run_verbose ())
- debug_printf ("FAIL\n");
- continue;
- }
+ SELF_CHECK (split_args == d.split);
/* Now join the arguments. */
- std::string joined_args
- = gdb::remote_args::join (split_args);
-
- if (run_verbose ())
- debug_printf ("Joined (%s), expected (%s)\n",
- joined_args.c_str (), d.joined.c_str ());
-
- if (joined_args != d.joined)
- {
- ++failure_count;
- if (run_verbose ())
- debug_printf ("FAIL\n");
- continue;
- }
+ std::string joined_args = gdb::remote_args::join (split_args);
+ SELF_CHECK (joined_args == d.joined);
/* The contents of JOINED_ARGS will not be identical to D.INPUT.
There are multiple ways that an argument can be escaped, and our
@@ -146,25 +106,8 @@ self_test ()
SPLIT_ARGS. So test that next. */
std::vector<std::string> split_args_v2
= gdb::remote_args::split (joined_args);
-
- if (split_args_v2 != split_args)
- {
- ++failure_count;
- if (run_verbose ())
- {
- debug_printf ("Re-split:\n");
- for (const auto &a : split_args_v2)
- debug_printf (" got (%s)\n", a.c_str ());
- debug_printf ("FAIL\n");
- }
- continue;
- }
-
- if (run_verbose ())
- debug_printf ("PASS\n");
+ SELF_CHECK (split_args_v2 == split_args);
}
-
- SELF_CHECK (failure_count == 0);
}
} /* namespace remote_args_tests */
--
2.56.0
prev parent reply other threads:[~2026-10-19 17:01 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-19 16:58 [PATCH 0/6] Make SELF_CHECK print operands of comparisons Simon Marchi
2026-10-19 16:58 ` [PATCH 1/6] gdb/unittests: catch gdb_exception_error in scoped_mmap test Simon Marchi
2026-10-19 16:58 ` [PATCH 2/6] gdbsupport/selftest: print expression when selftest fails and re-format Simon Marchi
2026-10-19 16:58 ` [PATCH 3/6] include/diagnostics.h: add DIAGNOSTIC_IGNORE_PARENTHESES Simon Marchi
2026-10-19 16:58 ` [PATCH 4/6] gdb/gmp-utils: rename gdb_mp{z,q,f}::str to to_string Simon Marchi
2026-10-19 16:58 ` [PATCH 5/6] gdbsupport/selftest: print operand values when a SELF_CHECK fails Simon Marchi
2026-10-27 14:13 ` Tom Tromey
2026-10-27 17:06 ` Simon Marchi
2026-10-19 16:58 ` Simon Marchi [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261019165929.792697-7-simon.marchi@efficios.com \
--to=simon.marchi@efficios.com \
--cc=gcc-patches@sourceware.org \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox