public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Yao Qi <qiyaoltc@gmail.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 14/25] [RFC] GDBserver self test
Date: Mon, 12 Jun 2017 08:42:00 -0000	[thread overview]
Message-ID: <1497256916-4958-15-git-send-email-yao.qi@linaro.org> (raw)
In-Reply-To: <1497256916-4958-1-git-send-email-yao.qi@linaro.org>

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               |  3 +++
 gdb/gdbserver/configure               | 12 +++++++---
 gdb/gdbserver/configure.ac            |  5 +++++
 gdb/gdbserver/server.c                | 18 ++++++++++++++-
 gdb/selftest.c                        | 18 ++++++++++++++-
 gdb/testsuite/gdb.server/unittest.exp | 41 +++++++++++++++++++++++++++++++++++
 6 files changed, 92 insertions(+), 5 deletions(-)
 create mode 100644 gdb/testsuite/gdb.server/unittest.exp

diff --git a/gdb/gdbserver/config.in b/gdb/gdbserver/config.in
index 34a7443..5dacbac 100644
--- a/gdb/gdbserver/config.in
+++ b/gdb/gdbserver/config.in
@@ -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
 
diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure
index b314c41..8d439ec 100755
--- a/gdb/gdbserver/configure
+++ b/gdb/gdbserver/configure
@@ -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} ;;
@@ -7498,9 +7504,9 @@ _ACEOF
 fi
 
 
-# See if <sys/user.h> supports the %fs_base and %gs_base amd64 segment
-# registers.  Older amd64 Linux's don't have the fs_base and gs_base
-# members of `struct user_regs_struct'.
+# See if <sys/user.h> supports the %fs_base and %gs_bas amd64 segment registers.
+# Older amd64 Linux's don't have the fs_base and gs_base members of
+# `struct user_regs_struct'.
 ac_fn_c_check_member "$LINENO" "struct user_regs_struct" "fs_base" "ac_cv_member_struct_user_regs_struct_fs_base" "#include <sys/user.h>
 "
 if test "x$ac_cv_member_struct_user_regs_struct_fs_base" = x""yes; then :
diff --git a/gdb/gdbserver/configure.ac b/gdb/gdbserver/configure.ac
index 4ea7913..36e21c5 100644
--- a/gdb/gdbserver/configure.ac
+++ b/gdb/gdbserver/configure.ac
@@ -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
 
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 69fcab1..428a9db 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -3487,6 +3487,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.  */
 
@@ -3501,6 +3504,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 == '-')
     {
@@ -3608,6 +3612,11 @@ captured_main (int argc, char *argv[])
 	disable_randomization = 0;
       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);
@@ -3623,7 +3632,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);
@@ -3676,6 +3686,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/selftest.c b/gdb/selftest.c
index 14b76f6..c947749 100644
--- a/gdb/selftest.c
+++ b/gdb/selftest.c
@@ -15,8 +15,15 @@
 
    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
index 0000000..6dc4b6e
--- /dev/null
+++ b/gdb/testsuite/gdb.server/unittest.exp
@@ -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"
+    }
+}
-- 
1.9.1

  parent reply	other threads:[~2017-06-12  8:42 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
2017-06-12  8:42 ` [PATCH 24/25] [GDBserver] Use pre-generated amd64-linux tdesc as test Yao Qi
2017-06-12  8:42 ` [PATCH 16/25] Dynamically composite xml in reply to GDB Yao Qi
2017-06-12  8:42 ` [PATCH 21/25] Lazily and dynamically create amd64-linux target descriptions Yao Qi
2017-06-12  8:42 ` [PATCH 13/25] Dynamically create tdesc in GDBserver Yao Qi
2017-06-12  8:42 ` [PATCH 22/25] Regenerate two regformats/i386/.dat files Yao Qi
2017-06-22 12:43   ` Yao Qi
2017-06-12  8:42 ` [PATCH 07/25] Lazily and dynamically create i386-linux target descriptions Yao Qi
2017-06-20 11:01   ` Pedro Alves
2017-06-20 14:07     ` Yao Qi
2017-06-28 15:30       ` Pedro Alves
2017-06-12  8:42 ` [PATCH 09/25] Use target_desc fields expedite_regs and xmltarget ifndef IN_PROCESS_AGENT Yao Qi
2017-06-28 16:16   ` Pedro Alves
2017-06-28 17:42     ` Pedro Alves
2017-06-28 17:45       ` Pedro Alves
2017-06-29 11:45     ` Yao Qi
2017-06-12  8:42 ` [PATCH 10/25] Adjust code generated by regformats/regdat.sh Yao Qi
2017-06-20 11:09   ` Pedro Alves
2017-06-21 14:28     ` Yao Qi
2017-06-12  8:42 ` [PATCH 19/25] GDBserver: remove srv_i386_linux_xmlfiles Yao Qi
2017-06-12  8:42 ` [PATCH 03/25] Class-fy tdesc_reg tdesc_type and tdesc_feature Yao Qi
2017-06-19 20:55   ` Simon Marchi
2017-06-19 21:30   ` Simon Marchi
2017-06-20 10:31     ` Yao Qi
2017-06-12  8:42 ` [PATCH 01/25] Move initialize_tdesc_mips* calls from mips-linux-nat.c to mips-linux-tdep.c Yao Qi
2017-06-12 15:25   ` Maciej W. Rozycki
2017-06-13  8:07     ` Yao Qi
2017-06-12  8:42 ` [PATCH 02/25] Adjust the order of 32bit-linux.xml and 32bit-sse.xml in i386/i386-linux.xml Yao Qi
2017-06-19 20:22   ` Simon Marchi
2017-06-19 21:24     ` Pedro Alves
2017-06-19 21:48       ` Simon Marchi
2017-06-19 21:56         ` Pedro Alves
2017-06-20  9:20           ` Yao Qi
2017-06-20 10:12             ` Pedro Alves
2017-06-20 11:09               ` Yao Qi
2017-06-12  8:42 ` Yao Qi [this message]
2017-06-28 17:09   ` [PATCH 14/25] [RFC] GDBserver self test Pedro Alves
2017-06-29  9:08     ` Yao Qi
2017-06-12  8:42 ` [PATCH 20/25] Centralize amd64-linux target descriptions Yao Qi
2017-06-12  8:42 ` [PATCH 17/25] Remove features/i386/i386-*linux.c Yao Qi
2017-06-12  8:42 ` [PATCH 23/25] [GDBserver] Convert amd64-linux target descriptions Yao Qi
2017-06-28 19:00   ` Pedro Alves
2017-06-12  8:42 ` [PATCH 15/25] [RFC] GDBserver unit test to i386_tdesc Yao Qi
2017-06-28 17:22   ` Pedro Alves
2017-06-29  9:27     ` Yao Qi
2017-06-12  8:42 ` [PATCH 12/25] [GDBserver] Centralize tdesc for i386-linux Yao Qi
2017-06-12  8:42 ` [PATCH 06/25] Generate c for feature instead of tdesc Yao Qi
2017-06-12 14:48   ` Eli Zaretskii
2017-06-13 12:07     ` Yao Qi
2017-06-13 14:49       ` Eli Zaretskii
2017-06-13 15:31         ` Yao Qi
2017-06-13 15:41           ` Eli Zaretskii
2017-06-14 16:21             ` Yao Qi
2017-06-14 16:32               ` Eli Zaretskii
2017-06-15 13:19                 ` Yao Qi
2017-06-15 14:45                   ` Eli Zaretskii
2017-06-20 10:59   ` Pedro Alves
2017-06-22 14:49     ` Yao Qi
2017-06-22 15:36       ` Pedro Alves
2017-06-22 15:58         ` Yao Qi
2017-06-26 21:38   ` Simon Marchi
2017-06-29 15:24     ` Yao Qi
2017-06-12  8:42 ` [PATCH 18/25] [GDBserver] Use pre-generated tdesc as test Yao Qi
2017-06-12  8:42 ` [PATCH 05/25] Use visitor pattern for "maint print c-tdesc" Yao Qi
2017-06-20 23:37   ` Simon Marchi
2017-06-12  8:42 ` [PATCH 25/25] Remove features/i386/amd64-*linux.c and features/i386/x32-*linux.c Yao Qi
2017-06-12  8:42 ` [PATCH 08/25] Add "maint check xml-descriptions" to test builtin xml target descriptions Yao Qi
2017-06-28 16:13   ` Pedro Alves
2017-06-12  8:42 ` [PATCH 11/25] Use VEC for target_desc.reg_defs Yao Qi
2017-06-28 19:01   ` Pedro Alves
2017-06-29 11:05     ` Yao Qi
2017-06-29 11:31       ` Pedro Alves
2017-06-29 13:24         ` Yao Qi
2017-06-12  8:42 ` [PATCH 04/25] Centralize i386 linux target descriptions Yao Qi
2017-06-19 21:27   ` Simon Marchi
2017-06-19 19:59 ` [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Simon Marchi
2017-06-20 11:02   ` Yao Qi
2017-06-26 14:45   ` Tedeschi, Walfred
2017-06-27 13:49     ` Alan Hayward
2017-06-28  8:28       ` Yao Qi
2017-06-28  8:06     ` Yao Qi
2017-06-28 19:06 ` Pedro Alves

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=1497256916-4958-15-git-send-email-yao.qi@linaro.org \
    --to=qiyaoltc@gmail.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).