GNU Binutils with patches for OS216
Revisión | 809ac8acb172bf2cb05dd8a6b1f72cd38f3e58fa (tree) |
---|---|
Tiempo | 2017-06-20 19:34:13 |
Autor | Yao Qi <yao.qi@lina...> |
Commiter | Yao Qi |
[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.
@@ -8,6 +8,9 @@ | ||
8 | 8 | /* Define to 1 if using `alloca.c'. */ |
9 | 9 | #undef C_ALLOCA |
10 | 10 | |
11 | +/* Define if self-testing features should be enabled */ | |
12 | +#undef GDB_SELF_TEST | |
13 | + | |
11 | 14 | /* Define to 1 if you have `alloca', as a function or macro. */ |
12 | 15 | #undef HAVE_ALLOCA |
13 | 16 |
@@ -5813,6 +5813,12 @@ fi | ||
5813 | 5813 | fi |
5814 | 5814 | |
5815 | 5815 | |
5816 | +if $development; then | |
5817 | + | |
5818 | +$as_echo "#define GDB_SELF_TEST 1" >>confdefs.h | |
5819 | + | |
5820 | +fi | |
5821 | + | |
5816 | 5822 | case ${build_alias} in |
5817 | 5823 | "") build_noncanonical=${build} ;; |
5818 | 5824 | *) build_noncanonical=${build_alias} ;; |
@@ -56,6 +56,11 @@ else | ||
56 | 56 | fi |
57 | 57 | GDB_AC_LIBMCHECK(${libmcheck_default}) |
58 | 58 | |
59 | +if $development; then | |
60 | + AC_DEFINE(GDB_SELF_TEST, 1, | |
61 | + [Define if self-testing features should be enabled]) | |
62 | +fi | |
63 | + | |
59 | 64 | ACX_NONCANONICAL_TARGET |
60 | 65 | ACX_NONCANONICAL_HOST |
61 | 66 |
@@ -3507,6 +3507,9 @@ detach_or_kill_for_exit_cleanup (void *ignore) | ||
3507 | 3507 | END_CATCH |
3508 | 3508 | } |
3509 | 3509 | |
3510 | +#include "../selftest.h" | |
3511 | +#include "../selftest.c" | |
3512 | + | |
3510 | 3513 | /* Main function. This is called by the real "main" function, |
3511 | 3514 | wrapped in a TRY_CATCH that handles any uncaught exceptions. */ |
3512 | 3515 |
@@ -3521,6 +3524,7 @@ captured_main (int argc, char *argv[]) | ||
3521 | 3524 | volatile int multi_mode = 0; |
3522 | 3525 | volatile int attach = 0; |
3523 | 3526 | int was_running; |
3527 | + bool selftest = false; | |
3524 | 3528 | |
3525 | 3529 | while (*next_arg != NULL && **next_arg == '-') |
3526 | 3530 | { |
@@ -3639,6 +3643,11 @@ captured_main (int argc, char *argv[]) | ||
3639 | 3643 | startup_with_shell = false; |
3640 | 3644 | else if (strcmp (*next_arg, "--once") == 0) |
3641 | 3645 | run_once = 1; |
3646 | + else if (strcmp (*next_arg, "--self-test") == 0) | |
3647 | + { | |
3648 | + selftest = true; | |
3649 | + break; | |
3650 | + } | |
3642 | 3651 | else |
3643 | 3652 | { |
3644 | 3653 | fprintf (stderr, "Unknown argument: %s\n", *next_arg); |
@@ -3654,7 +3663,8 @@ captured_main (int argc, char *argv[]) | ||
3654 | 3663 | port = *next_arg; |
3655 | 3664 | next_arg++; |
3656 | 3665 | } |
3657 | - if (port == NULL || (!attach && !multi_mode && *next_arg == NULL)) | |
3666 | + if ((port == NULL || (!attach && !multi_mode && *next_arg == NULL)) | |
3667 | + && !selftest) | |
3658 | 3668 | { |
3659 | 3669 | gdbserver_usage (stderr); |
3660 | 3670 | exit (1); |
@@ -3712,6 +3722,12 @@ captured_main (int argc, char *argv[]) | ||
3712 | 3722 | own_buf = (char *) xmalloc (PBUFSIZ + 1); |
3713 | 3723 | mem_buf = (unsigned char *) xmalloc (PBUFSIZ); |
3714 | 3724 | |
3725 | + if (selftest) | |
3726 | + { | |
3727 | + run_self_tests (); | |
3728 | + throw_quit ("Quit"); | |
3729 | + } | |
3730 | + | |
3715 | 3731 | if (pid == 0 && *next_arg != NULL) |
3716 | 3732 | { |
3717 | 3733 | int i, n; |
@@ -15,8 +15,15 @@ | ||
15 | 15 | |
16 | 16 | You should have received a copy of the GNU General Public License |
17 | 17 | 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 | |
19 | 22 | #include "defs.h" |
23 | +#endif | |
24 | +#include "common-defs.h" | |
25 | +#include "common-exceptions.h" | |
26 | +#include "common-debug.h" | |
20 | 27 | #include "selftest.h" |
21 | 28 | #include <vector> |
22 | 29 |
@@ -50,15 +57,24 @@ run_self_tests (void) | ||
50 | 57 | CATCH (ex, RETURN_MASK_ERROR) |
51 | 58 | { |
52 | 59 | ++failed; |
60 | + #ifndef GDBSERVER | |
53 | 61 | exception_fprintf (gdb_stderr, ex, _("Self test failed: ")); |
62 | + #endif | |
54 | 63 | } |
55 | 64 | END_CATCH |
56 | 65 | |
66 | +#ifndef GDBSERVER | |
57 | 67 | /* Clear GDB internal state. */ |
58 | 68 | registers_changed (); |
59 | 69 | reinit_frame_cache (); |
70 | +#endif | |
60 | 71 | } |
61 | 72 | |
73 | + #ifdef GDBSERVER | |
74 | + debug_printf ("Ran %lu unit tests, %d failed\n", | |
75 | + (long) tests.size (), failed); | |
76 | + #else | |
62 | 77 | printf_filtered (_("Ran %lu unit tests, %d failed\n"), |
63 | 78 | (long) tests.size (), failed); |
79 | + #endif | |
64 | 80 | } |
@@ -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 | +} |