public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "Alexandra Hájková" <ahajkova@redhat.com>
To: gdb-patches@sourceware.org
Cc: ahajkova@redhat.com
Subject: [PATCH 6/6] Add defaultinf.exp test to the testsuite
Date: Fri, 17 Nov 2023 12:18:40 +0100	[thread overview]
Message-ID: <20231117111840.2040709-7-ahajkova@redhat.com> (raw)
In-Reply-To: <20231117111840.2040709-1-ahajkova@redhat.com>

Test the behaviour of the inferior when GDBserver is run locally
and using stdio. The inferior should be able to write to STOUT
and STDERR and read from STDIN.
---
 gdb/testsuite/gdb.server/defaultinf.c   | 39 ++++++++++++++++
 gdb/testsuite/gdb.server/defaultinf.exp | 59 +++++++++++++++++++++++++
 2 files changed, 98 insertions(+)
 create mode 100644 gdb/testsuite/gdb.server/defaultinf.c
 create mode 100644 gdb/testsuite/gdb.server/defaultinf.exp

diff --git a/gdb/testsuite/gdb.server/defaultinf.c b/gdb/testsuite/gdb.server/defaultinf.c
new file mode 100644
index 00000000000..8963c7dbabf
--- /dev/null
+++ b/gdb/testsuite/gdb.server/defaultinf.c
@@ -0,0 +1,39 @@
+/* Copyright 2023 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int
+main ()
+{
+  printf ("Hello stdout!\n");
+  fprintf (stderr, "Hello stderr!\n");
+
+  char *line = NULL;
+  size_t len = 0;
+  ssize_t nread;
+
+  while ((nread = getline (&line, &len, stdin)) != -1)
+    {
+      if (line[nread - 1] == '\n')
+	line[nread - 1] = '\0';
+      printf ("Got line len %zd: '%s'\n", nread, line);
+    }
+
+  printf ("Got EOF\n");
+  free (line);
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.server/defaultinf.exp b/gdb/testsuite/gdb.server/defaultinf.exp
new file mode 100644
index 00000000000..03163e150e0
--- /dev/null
+++ b/gdb/testsuite/gdb.server/defaultinf.exp
@@ -0,0 +1,59 @@
+# This testcase is part of GDB, the GNU debugger.
+
+# Copyright 2023 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test the behaviour of the inferior when GDBserver is run locally
+# and using stdio. The inferior should be able to write to STOUT
+# and STDERR and read from STDIN.
+
+require {!is_remote target} {!is_remote host}
+
+load_lib gdbserver-support.exp
+
+require allow_gdbserver_tests
+
+set gdbserver [find_gdbserver]
+if { $gdbserver == "" } {
+    unsupported "could not find GDBserver"
+    return
+}
+
+standard_testfile
+
+if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
+    return -1
+}
+
+clean_restart ${testfile}
+
+gdb_test "target remote | ${::gdbserver} - [standard_output_file $testfile]" ".*" \
+    "start gdbserver using pipe syntax"
+
+  set input_msg "hello world"
+  set input_len [expr [string length ${input_msg}] + 1]
+  gdb_test_multiple "c" "Test STDOUT/ERR, STDIN" {
+    -re "Hello stdout!\r\nHello stderr!" {
+      send_gdb "${input_msg}\n"
+      exp_continue
+    }
+    -re  "${input_msg}\r\nGot line len ${input_len}: '${input_msg}'" {
+      send_gdb "\004"
+      exp_continue
+    }
+    -re "Got EOF" {
+      pass "$gdb_test_name"
+    }
+  }
-- 
2.41.0


  parent reply	other threads:[~2023-11-17 11:18 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-17 11:18 [PATCH 0/6] Add vDefaultInferiorFd feature Alexandra Hájková
2023-11-17 11:18 ` [PATCH 1/6] gdb.server/non-existing-program.exp: Use gdbserver_start Alexandra Hájková
2023-11-17 11:18 ` [PATCH 2/6] gdb/ser-pipe.c: Duplicate the file descriptors Alexandra Hájková
2023-12-12 19:42   ` Tom Tromey
2023-11-17 11:18 ` [PATCH 3/6] Add new vDefaultInferiorFd packet Alexandra Hájková
2023-11-17 12:09   ` Eli Zaretskii
2023-12-12 20:03   ` Tom Tromey
2023-11-17 11:18 ` [PATCH 4/6] gdbserver/linux-low.cc: Connect the inferior to the terminal Alexandra Hájková
2023-12-12 20:10   ` Tom Tromey
2023-11-17 11:18 ` [PATCH 5/6] remote.c: Add terminal handling functions Alexandra Hájková
2023-12-12 20:11   ` Tom Tromey
2023-11-17 11:18 ` Alexandra Hájková [this message]
2023-11-27 10:01 ` [PATCH 0/6] Add vDefaultInferiorFd feature Alexandra Petlanova Hajkova
2023-12-01 20:22 ` Tom Tromey
2023-12-04 11:08   ` Andrew Burgess
2023-12-04 12:11   ` Alexandra Petlanova Hajkova
2023-12-05 16:00     ` Tom Tromey
2023-12-08 13:06       ` Andrew Burgess
2023-12-12 20:14   ` Tom Tromey

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=20231117111840.2040709-7-ahajkova@redhat.com \
    --to=ahajkova@redhat.com \
    --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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).