]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
GDBserver self test
authorYao Qi <yao.qi@linaro.org>
Fri, 26 May 2017 10:56:58 +0000 (11:56 +0100)
committerYao Qi <yao.qi@linaro.org>
Mon, 10 Jul 2017 11:02:49 +0000 (12:02 +0100)
This patch uses GDB self test in GDBserver.  The self tests are run if
GDBserver is started with option --selftest.

We decide to still reuse GDB's selftest in GDBserver, so this patch moves
selftest.{c,h} to common/, and use some #ifdef as few as I can.

gdb:

2017-07-07  Yao Qi  <yao.qi@linaro.org>

* NEWS: Mention GDBserver's new option "--selftest".
* Makefile.in (SFILES): Remove selftest.c, add common/selftest.c.
* selftest.c: Move it common/selftest.c.
* selftest.h: Move it common/selftest.h.

gdb/gdbserver:

2017-07-07  Yao Qi  <yao.qi@linaro.org>

* Makefile.in (OBS): Add selftest.o.
* configure.ac: AC_DEFINE GDB_SELF_TEST if $development.
* configure, config.in: Re-generated.
* server.c: Include common/sefltest.h.
(captured_main): Handle option --selftest.
(gdbserver_usage): Print usage for "--selftest".

gdb/testsuite:

2017-05-26  Yao Qi  <yao.qi@linaro.org>

* gdb.server/unittest.exp: New.

gdb/doc:

2017-07-07  Yao Qi  <yao.qi@linaro.org>

* gdb.texinfo (Server): Document "--selftest".

gdb/Makefile.in
gdb/NEWS
gdb/common/selftest.c [moved from gdb/selftest.c with 82% similarity]
gdb/common/selftest.h [moved from gdb/selftest.h with 100% similarity]
gdb/doc/gdb.texinfo
gdb/gdbserver/Makefile.in
gdb/gdbserver/config.in
gdb/gdbserver/configure
gdb/gdbserver/configure.ac
gdb/gdbserver/server.c
gdb/testsuite/gdb.server/unittest.exp [new file with mode: 0644]

index b27f6982d4afdc30deb969911021e2a32a69ea05..ece7de95d914d91b075d3b6577fcf4d926474c78 100644 (file)
@@ -1178,7 +1178,6 @@ SFILES = \
        reverse.c \
        rust-exp.y \
        rust-lang.c \
-       selftest.c \
        selftest-arch.c \
        sentinel-frame.c \
        ser-base.c \
@@ -1244,6 +1243,7 @@ SFILES = \
        common/ptid.c \
        common/rsp-low.c \
        common/run-time-clock.c \
+       common/selftest.c \
        common/signals.c \
        common/signals-state-save-restore.c \
        common/vec.c \
index 9cd1df1cfe204cb7f3cdab1e860d587d70312e02..8fca3782026f38e2dc640a405215a97ee48e5d02 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,14 +3,19 @@
 
 *** Changes since GDB 8.0
 
-* On Unix systems, GDBserver now does globbing expansion and variable
-  substitution in inferior command line arguments.
-
-  This is done by starting inferiors using a shell, like GDB does.
-  See "set startup-with-shell" in the user manual for how to disable
-  this from GDB when using "target extended-remote".  When using
-  "target remote", you can disable the startup with shell by using the
-  new "--no-startup-with-shell" GDBserver command line option.
+* New features in the GDB remote stub, GDBserver
+
+  ** New "--selftest" command line option runs some GDBserver self
+     tests.  These self tests are disabled in release.
+
+  ** On Unix systems, GDBserver now does globbing expansion and variable
+     substitution in inferior command line arguments.
+
+     This is done by starting inferiors using a shell, like GDB does.
+     See "set startup-with-shell" in the user manual for how to disable
+     this from GDB when using "target extended-remote".  When using
+     "target remote", you can disable the startup with shell by using the
+     new "--no-startup-with-shell" GDBserver command line option.
 
 * New remote packets
 
similarity index 82%
rename from gdb/selftest.c
rename to gdb/common/selftest.c
index 14b76f6f2596ee6c7a0f9959c75823dec1c3781f..d9c7ab0f6c51cd033d340d86848837e49dce4b05 100644 (file)
    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 "defs.h"
+#include "common-defs.h"
+#ifdef GDBSERVER
+#define QUIT do {} while (0)
+#else
+#include "defs.h" /* for QUIT */
+#endif
+#include "common-exceptions.h"
+#include "common-debug.h"
 #include "selftest.h"
 #include <vector>
 
@@ -50,15 +57,19 @@ run_self_tests (void)
       CATCH (ex, RETURN_MASK_ERROR)
        {
          ++failed;
+#ifndef GDBSERVER
          exception_fprintf (gdb_stderr, ex, _("Self test failed: "));
+#endif
        }
       END_CATCH
 
+#ifndef GDBSERVER
       /* Clear GDB internal state.  */
       registers_changed ();
       reinit_frame_cache ();
+#endif
     }
 
-  printf_filtered (_("Ran %lu unit tests, %d failed\n"),
-                  (long) tests.size (), failed);
+  debug_printf ("Ran %lu unit tests, %d failed\n",
+               (long) tests.size (), failed);
 }
similarity index 100%
rename from gdb/selftest.h
rename to gdb/common/selftest.h
index 17b4c696d95b4bdcc95164703bde16de5bcdd266..e26287df2449d70e2de0e40c08d1bed115547ba1 100644 (file)
@@ -20253,6 +20253,15 @@ environment:
 $ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
 @end smallexample
 
+@cindex @option{--selftest}
+The @option{--wrapper} option runs the self tests in @code{gdbserver}:
+
+@smallexample
+$ gdbserver --selftest
+Ran 2 unit tests, 0 failed
+@end smallexample
+
+These tests are disabled in release.
 @subsection Connecting to @code{gdbserver}
 
 The basic procedure for connecting to the remote target is:
index 89f91aabd28517e4f60c17c7d7349d55e52850d6..9b5982bb4e4ab8b65c2106ad0022ccc8973028cb 100644 (file)
@@ -258,6 +258,7 @@ OBS = \
        regcache.o \
        remote-utils.o \
        rsp-low.o \
+       selftest.o \
        server.o \
        signals.o \
        signals-state-save-restore.o \
index 34a7443433874313e45a38f87cdae5dc8ddc66ec..5dacbacbed29835ae4723b27fd52583e97ebe729 100644 (file)
@@ -8,6 +8,9 @@
 /* Define to 1 if using `alloca.c'. */
 #undef C_ALLOCA
 
+/* Define if self-testing features should be enabled */
+#undef GDB_SELF_TEST
+
 /* Define to 1 if you have `alloca', as a function or macro. */
 #undef HAVE_ALLOCA
 
index 35aeabc314117c421bcca06ebb096456a4decdbb..30aa95b8f1da9911a36aae594f071f2e15606364 100755 (executable)
@@ -5813,6 +5813,12 @@ fi
   fi
 
 
+if $development; then
+
+$as_echo "#define GDB_SELF_TEST 1" >>confdefs.h
+
+fi
+
  case ${build_alias} in
   "") build_noncanonical=${build} ;;
   *) build_noncanonical=${build_alias} ;;
index 4ea7913c9818aa0e2d96ac5891c28962ee3dc0bc..36e21c5002df199b60e8322743d95c4f91177bf6 100644 (file)
@@ -56,6 +56,11 @@ else
 fi
 GDB_AC_LIBMCHECK(${libmcheck_default})
 
+if $development; then
+  AC_DEFINE(GDB_SELF_TEST, 1,
+            [Define if self-testing features should be enabled])
+fi
+
 ACX_NONCANONICAL_TARGET
 ACX_NONCANONICAL_HOST
 
index 38383510e8bff76792c0a246482b9dba9665ac2b..4ca09dd12fdb3d8901f24b861fc18ee1a0dcbcaf 100644 (file)
@@ -40,6 +40,8 @@
 #include "job-control.h"
 #include "environ.h"
 
+#include "common/selftest.h"
+
 /* The environment to pass to the inferior when creating it.  */
 
 static gdb_environ our_environ;
@@ -3357,6 +3359,7 @@ gdbserver_usage (FILE *stream)
           "                          Options:\n"
           "                            vCont, Tthread, qC, qfThreadInfo and \n"
           "                            threads (disable all threading packets).\n"
+          "  --selftest            Run self tests.\n"
           "\n"
           "For more information, consult the GDB manual (available as on-line \n"
           "info or a printed manual).\n");
@@ -3521,6 +3524,7 @@ captured_main (int argc, char *argv[])
   volatile int multi_mode = 0;
   volatile int attach = 0;
   int was_running;
+  bool selftest = false;
 
   while (*next_arg != NULL && **next_arg == '-')
     {
@@ -3639,6 +3643,8 @@ captured_main (int argc, char *argv[])
        startup_with_shell = false;
       else if (strcmp (*next_arg, "--once") == 0)
        run_once = 1;
+      else if (strcmp (*next_arg, "--selftest") == 0)
+       selftest = true;
       else
        {
          fprintf (stderr, "Unknown argument: %s\n", *next_arg);
@@ -3654,7 +3660,8 @@ captured_main (int argc, char *argv[])
       port = *next_arg;
       next_arg++;
     }
-  if (port == NULL || (!attach && !multi_mode && *next_arg == NULL))
+  if ((port == NULL || (!attach && !multi_mode && *next_arg == NULL))
+       && !selftest)
     {
       gdbserver_usage (stderr);
       exit (1);
@@ -3670,7 +3677,8 @@ captured_main (int argc, char *argv[])
      starting the inferior.  Inferiors created in this scenario have
      stdin,stdout redirected.  So do this here before we call
      start_inferior.  */
-  remote_prepare (port);
+  if (port != NULL)
+    remote_prepare (port);
 
   bad_attach = 0;
   pid = 0;
@@ -3711,6 +3719,12 @@ captured_main (int argc, char *argv[])
   own_buf = (char *) xmalloc (PBUFSIZ + 1);
   mem_buf = (unsigned char *) xmalloc (PBUFSIZ);
 
+  if (selftest)
+    {
+      run_self_tests ();
+      throw_quit ("Quit");
+    }
+
   if (pid == 0 && *next_arg != NULL)
     {
       int i, n;
diff --git a/gdb/testsuite/gdb.server/unittest.exp b/gdb/testsuite/gdb.server/unittest.exp
new file mode 100644 (file)
index 0000000..584a23d
--- /dev/null
@@ -0,0 +1,41 @@
+# This testcase is part of GDB, the GNU debugger.
+
+# Copyright 2017 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/>.
+
+load_lib gdbserver-support.exp
+
+standard_testfile
+
+if { [skip_gdbserver_tests] } {
+    return 0
+}
+
+global server_spawn_id
+
+set gdbserver [find_gdbserver]
+set gdbserver_command "$gdbserver --selftest"
+
+set server_spawn_id [remote_spawn target $gdbserver_command]
+
+gdb_expect {
+    -i $server_spawn_id
+    -re "Ran $decimal unit tests, 0 failed" {
+       pass "unit tests"
+    }
+    default {
+       fail "unit tests"
+    }
+}