Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] [gdb] Add selftest for tui_setup_io
@ 2026-04-03 11:31 Tom de Vries
  2026-04-10 13:31 ` Guinevere Larsen
  0 siblings, 1 reply; 3+ messages in thread
From: Tom de Vries @ 2026-04-03 11:31 UTC (permalink / raw)
  To: gdb-patches

Add a selftest for the problem described in commit b171f68e945 ("[gdb/tui]
Make tui_setup_io more robust").
---
 gdb/tui/tui-io.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index 4b4bc818430..642b88ead0c 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -46,6 +46,7 @@
 #include "pager.h"
 #include "gdbsupport/gdb-checked-static-cast.h"
 #include "logging-file.h"
+#include "gdbsupport/selftest.h"
 
 /* This redefines CTRL if it is not already defined, so it must come
    after terminal state related include files like <term.h> and
@@ -1328,3 +1329,36 @@ tui_getc (FILE *fp)
       return 0;
     }
 }
+
+#if GDB_SELF_TEST
+namespace selftests {
+namespace tui {
+namespace io {
+
+static void
+run_tests ()
+{
+  if (!tui_active)
+    {
+      /* Calling tui_setup_io (0) when tui is disabled should have no effect.  */
+      tui_setup_io (0);
+
+      /* If the output streams are reduced to nullptrs, then the self-test
+	 infrastructure will crash when trying to report these failures.  */
+      SELF_CHECK (*redirectable_stdout () != nullptr);
+      SELF_CHECK (*redirectable_stderr () != nullptr);
+      SELF_CHECK (*redirectable_stdlog () != nullptr);
+    }
+}
+
+} /* namespace io */
+} /* namespace tui */
+} /* namespace selftests */
+#endif /* GDB_SELF_TEST */
+
+INIT_GDB_FILE (tui_io)
+{
+#if GDB_SELF_TEST
+  selftests::register_test ("tui-io", selftests::tui::io::run_tests);
+#endif
+}

base-commit: db4f00be62d3396374df989b5f938c3ebec6833e
-- 
2.51.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] [gdb] Add selftest for tui_setup_io
  2026-04-03 11:31 [PATCH] [gdb] Add selftest for tui_setup_io Tom de Vries
@ 2026-04-10 13:31 ` Guinevere Larsen
  2026-04-10 13:51   ` Tom de Vries
  0 siblings, 1 reply; 3+ messages in thread
From: Guinevere Larsen @ 2026-04-10 13:31 UTC (permalink / raw)
  To: Tom de Vries, gdb-patches

On 4/3/26 8:31 AM, Tom de Vries wrote:
> Add a selftest for the problem described in commit b171f68e945 ("[gdb/tui]
> Make tui_setup_io more robust").

Hi Tom!

I looked over this patch and it makes sense, and I verified that it does 
trigger a crash before the listed commit, so it is properly testing it.

Reviewed-By: Guinevere Larsen <guinevere@redhat.com>

-- 
Cheers,
Guinevere Larsen
It/she


> ---
>   gdb/tui/tui-io.c | 34 ++++++++++++++++++++++++++++++++++
>   1 file changed, 34 insertions(+)
>
> diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
> index 4b4bc818430..642b88ead0c 100644
> --- a/gdb/tui/tui-io.c
> +++ b/gdb/tui/tui-io.c
> @@ -46,6 +46,7 @@
>   #include "pager.h"
>   #include "gdbsupport/gdb-checked-static-cast.h"
>   #include "logging-file.h"
> +#include "gdbsupport/selftest.h"
>   
>   /* This redefines CTRL if it is not already defined, so it must come
>      after terminal state related include files like <term.h> and
> @@ -1328,3 +1329,36 @@ tui_getc (FILE *fp)
>         return 0;
>       }
>   }
> +
> +#if GDB_SELF_TEST
> +namespace selftests {
> +namespace tui {
> +namespace io {
> +
> +static void
> +run_tests ()
> +{
> +  if (!tui_active)
> +    {
> +      /* Calling tui_setup_io (0) when tui is disabled should have no effect.  */
> +      tui_setup_io (0);
> +
> +      /* If the output streams are reduced to nullptrs, then the self-test
> +	 infrastructure will crash when trying to report these failures.  */
> +      SELF_CHECK (*redirectable_stdout () != nullptr);
> +      SELF_CHECK (*redirectable_stderr () != nullptr);
> +      SELF_CHECK (*redirectable_stdlog () != nullptr);
> +    }
> +}
> +
> +} /* namespace io */
> +} /* namespace tui */
> +} /* namespace selftests */
> +#endif /* GDB_SELF_TEST */
> +
> +INIT_GDB_FILE (tui_io)
> +{
> +#if GDB_SELF_TEST
> +  selftests::register_test ("tui-io", selftests::tui::io::run_tests);
> +#endif
> +}
>
> base-commit: db4f00be62d3396374df989b5f938c3ebec6833e


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] [gdb] Add selftest for tui_setup_io
  2026-04-10 13:31 ` Guinevere Larsen
@ 2026-04-10 13:51   ` Tom de Vries
  0 siblings, 0 replies; 3+ messages in thread
From: Tom de Vries @ 2026-04-10 13:51 UTC (permalink / raw)
  To: Guinevere Larsen, gdb-patches

On 4/10/26 3:31 PM, Guinevere Larsen wrote:
> On 4/3/26 8:31 AM, Tom de Vries wrote:
>> Add a selftest for the problem described in commit b171f68e945 ("[gdb/ 
>> tui]
>> Make tui_setup_io more robust").
> 
> Hi Tom!
> 
> I looked over this patch and it makes sense, and I verified that it does 
> trigger a crash before the listed commit, so it is properly testing it.

Hi Guinevere,

thanks for the review, I've pushed this.

- Tom

> Reviewed-By: Guinevere Larsen <guinevere@redhat.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-10 13:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-03 11:31 [PATCH] [gdb] Add selftest for tui_setup_io Tom de Vries
2026-04-10 13:31 ` Guinevere Larsen
2026-04-10 13:51   ` Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox