]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[RFC] 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>
Tue, 20 Jun 2017 10:34:13 +0000 (11:34 +0100)
This patch uses GDB self test in GDBserver.  The self tests are run if
GDBserver is started with option --self-test.

gdb/gdbserver:

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

* configure.ac: AC_DEFINE GDB_SELF_TEST if $development.
* configure, config.in: Re-generated.
* server.c: Include sefltest.h and selftest.c.
(captured_main): Handle option --self-test.
gdb:

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

* selftest.c: Adjust it for GDBserver.

gdb/testsuite:

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

* gdb.server/unittest.exp: New.

gdb/gdbserver/config.in
gdb/gdbserver/configure
gdb/gdbserver/configure.ac
gdb/gdbserver/server.c
gdb/selftest.c
gdb/testsuite/gdb.server/unittest.exp [new file with mode: 0644]

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 1d7a8b0278e688de5b5a7b101be3ff946aeade87..d0dcbeec093cf02d60a12fa902d80cc71a2f72b2 100644 (file)
@@ -3507,6 +3507,9 @@ detach_or_kill_for_exit_cleanup (void *ignore)
   END_CATCH
 }
 
+#include "../selftest.h"
+#include "../selftest.c"
+
 /* Main function.  This is called by the real "main" function,
    wrapped in a TRY_CATCH that handles any uncaught exceptions.  */
 
@@ -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,11 @@ 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, "--self-test") == 0)
+       {
+         selftest = true;
+         break;
+       }
       else
        {
          fprintf (stderr, "Unknown argument: %s\n", *next_arg);
@@ -3654,7 +3663,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);
@@ -3712,6 +3722,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;
index 14b76f6f2596ee6c7a0f9959c75823dec1c3781f..c9477495d84536289b2af6e0ef9efe2c1f757e51 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 "config.h"
+#ifdef GDBSERVER
+#define QUIT do {} while (0)
+#else
 #include "defs.h"
+#endif
+#include "common-defs.h"
+#include "common-exceptions.h"
+#include "common-debug.h"
 #include "selftest.h"
 #include <vector>
 
@@ -50,15 +57,24 @@ 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
     }
 
+  #ifdef GDBSERVER
+  debug_printf ("Ran %lu unit tests, %d failed\n",
+               (long) tests.size (), failed);
+  #else
   printf_filtered (_("Ran %lu unit tests, %d failed\n"),
                   (long) tests.size (), failed);
+  #endif
 }
diff --git a/gdb/testsuite/gdb.server/unittest.exp b/gdb/testsuite/gdb.server/unittest.exp
new file mode 100644 (file)
index 0000000..6dc4b6e
--- /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 --self-test"
+
+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"
+    }
+    -re "Ran $decimal unit tests, $decimal failed" {
+       fail "unit tests"
+    }
+}