• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Revisión809ac8acb172bf2cb05dd8a6b1f72cd38f3e58fa (tree)
Tiempo2017-06-20 19:34:13
AutorYao Qi <yao.qi@lina...>
CommiterYao Qi

Log Message

[RFC] GDBserver self test

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.

Cambiar Resumen

Diferencia incremental

--- a/gdb/gdbserver/config.in
+++ b/gdb/gdbserver/config.in
@@ -8,6 +8,9 @@
88 /* Define to 1 if using `alloca.c'. */
99 #undef C_ALLOCA
1010
11+/* Define if self-testing features should be enabled */
12+#undef GDB_SELF_TEST
13+
1114 /* Define to 1 if you have `alloca', as a function or macro. */
1215 #undef HAVE_ALLOCA
1316
--- a/gdb/gdbserver/configure
+++ b/gdb/gdbserver/configure
@@ -5813,6 +5813,12 @@ fi
58135813 fi
58145814
58155815
5816+if $development; then
5817+
5818+$as_echo "#define GDB_SELF_TEST 1" >>confdefs.h
5819+
5820+fi
5821+
58165822 case ${build_alias} in
58175823 "") build_noncanonical=${build} ;;
58185824 *) build_noncanonical=${build_alias} ;;
--- a/gdb/gdbserver/configure.ac
+++ b/gdb/gdbserver/configure.ac
@@ -56,6 +56,11 @@ else
5656 fi
5757 GDB_AC_LIBMCHECK(${libmcheck_default})
5858
59+if $development; then
60+ AC_DEFINE(GDB_SELF_TEST, 1,
61+ [Define if self-testing features should be enabled])
62+fi
63+
5964 ACX_NONCANONICAL_TARGET
6065 ACX_NONCANONICAL_HOST
6166
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -3507,6 +3507,9 @@ detach_or_kill_for_exit_cleanup (void *ignore)
35073507 END_CATCH
35083508 }
35093509
3510+#include "../selftest.h"
3511+#include "../selftest.c"
3512+
35103513 /* Main function. This is called by the real "main" function,
35113514 wrapped in a TRY_CATCH that handles any uncaught exceptions. */
35123515
@@ -3521,6 +3524,7 @@ captured_main (int argc, char *argv[])
35213524 volatile int multi_mode = 0;
35223525 volatile int attach = 0;
35233526 int was_running;
3527+ bool selftest = false;
35243528
35253529 while (*next_arg != NULL && **next_arg == '-')
35263530 {
@@ -3639,6 +3643,11 @@ captured_main (int argc, char *argv[])
36393643 startup_with_shell = false;
36403644 else if (strcmp (*next_arg, "--once") == 0)
36413645 run_once = 1;
3646+ else if (strcmp (*next_arg, "--self-test") == 0)
3647+ {
3648+ selftest = true;
3649+ break;
3650+ }
36423651 else
36433652 {
36443653 fprintf (stderr, "Unknown argument: %s\n", *next_arg);
@@ -3654,7 +3663,8 @@ captured_main (int argc, char *argv[])
36543663 port = *next_arg;
36553664 next_arg++;
36563665 }
3657- if (port == NULL || (!attach && !multi_mode && *next_arg == NULL))
3666+ if ((port == NULL || (!attach && !multi_mode && *next_arg == NULL))
3667+ && !selftest)
36583668 {
36593669 gdbserver_usage (stderr);
36603670 exit (1);
@@ -3712,6 +3722,12 @@ captured_main (int argc, char *argv[])
37123722 own_buf = (char *) xmalloc (PBUFSIZ + 1);
37133723 mem_buf = (unsigned char *) xmalloc (PBUFSIZ);
37143724
3725+ if (selftest)
3726+ {
3727+ run_self_tests ();
3728+ throw_quit ("Quit");
3729+ }
3730+
37153731 if (pid == 0 && *next_arg != NULL)
37163732 {
37173733 int i, n;
--- a/gdb/selftest.c
+++ b/gdb/selftest.c
@@ -15,8 +15,15 @@
1515
1616 You should have received a copy of the GNU General Public License
1717 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18-
18+#include "config.h"
19+#ifdef GDBSERVER
20+#define QUIT do {} while (0)
21+#else
1922 #include "defs.h"
23+#endif
24+#include "common-defs.h"
25+#include "common-exceptions.h"
26+#include "common-debug.h"
2027 #include "selftest.h"
2128 #include <vector>
2229
@@ -50,15 +57,24 @@ run_self_tests (void)
5057 CATCH (ex, RETURN_MASK_ERROR)
5158 {
5259 ++failed;
60+ #ifndef GDBSERVER
5361 exception_fprintf (gdb_stderr, ex, _("Self test failed: "));
62+ #endif
5463 }
5564 END_CATCH
5665
66+#ifndef GDBSERVER
5767 /* Clear GDB internal state. */
5868 registers_changed ();
5969 reinit_frame_cache ();
70+#endif
6071 }
6172
73+ #ifdef GDBSERVER
74+ debug_printf ("Ran %lu unit tests, %d failed\n",
75+ (long) tests.size (), failed);
76+ #else
6277 printf_filtered (_("Ran %lu unit tests, %d failed\n"),
6378 (long) tests.size (), failed);
79+ #endif
6480 }
--- /dev/null
+++ b/gdb/testsuite/gdb.server/unittest.exp
@@ -0,0 +1,41 @@
1+# This testcase is part of GDB, the GNU debugger.
2+
3+# Copyright 2017 Free Software Foundation, Inc.
4+
5+# This program is free software; you can redistribute it and/or modify
6+# it under the terms of the GNU General Public License as published by
7+# the Free Software Foundation; either version 3 of the License, or
8+# (at your option) any later version.
9+#
10+# This program is distributed in the hope that it will be useful,
11+# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+# GNU General Public License for more details.
14+#
15+# You should have received a copy of the GNU General Public License
16+# along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
18+load_lib gdbserver-support.exp
19+
20+standard_testfile
21+
22+if { [skip_gdbserver_tests] } {
23+ return 0
24+}
25+
26+global server_spawn_id
27+
28+set gdbserver [find_gdbserver]
29+set gdbserver_command "$gdbserver --self-test"
30+
31+set server_spawn_id [remote_spawn target $gdbserver_command]
32+
33+gdb_expect {
34+ -i $server_spawn_id
35+ -re "Ran $decimal unit tests, 0 failed" {
36+ pass "unit tests"
37+ }
38+ -re "Ran $decimal unit tests, $decimal failed" {
39+ fail "unit tests"
40+ }
41+}