From patchwork Mon Jun 12 08:41:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 20925 Received: (qmail 71354 invoked by alias); 12 Jun 2017 08:42:21 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 70987 invoked by uid 89); 12 Jun 2017 08:42:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-io0-f170.google.com Received: from mail-io0-f170.google.com (HELO mail-io0-f170.google.com) (209.85.223.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 12 Jun 2017 08:42:12 +0000 Received: by mail-io0-f170.google.com with SMTP id y77so52278801ioe.3 for ; Mon, 12 Jun 2017 01:42:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=J3eXXaLg7T35SfYo+2x+7c8XjdvT1/1S4XiYgEmL1MM=; b=RFo8NK94yGgNICX3Gmfs2BlUX4tPu/94cv8+MEgYWvkotwqqEGTHJl9t3CJs+7GJWo 3Juk+ATfhelJ+O7xKpafqgLb4g759AJkY5txufOhdFfdUFUBxIKJAlaDiOr4PNU8SjM1 6ghF0NhFJJ0oj2Afpr6Gv9ywyybZ4b4STS24Z/tEKuNZ5/Wa901cvd6ZP4Ywjdkq/etL YxowT7l2SqxS0SPr5ef58i2IeAx0szY4JHw3kVP4DbSF/0oD2lSxs9bMSgNpU3Or9nBY cz8Pf3U2S1BRjka3x41nzf3CbzT8BEkvfidGRHxq764qUilt0e/aRIxiUa292WvQyRSK ADkA== X-Gm-Message-State: AODbwcBY+ymfaIYIz99OwIhQrG/B4W2pTb6gbXOZAptnDPa87lz3QnJc 2NuncqsAiB7nhDOV X-Received: by 10.107.169.17 with SMTP id s17mr54022599ioe.1.1497256934947; Mon, 12 Jun 2017 01:42:14 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com (static.42.136.251.148.clients.your-server.de. [148.251.136.42]) by smtp.gmail.com with ESMTPSA id u4sm5280289itu.1.2017.06.12.01.42.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 Jun 2017 01:42:14 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 14/25] [RFC] GDBserver self test Date: Mon, 12 Jun 2017 09:41:45 +0100 Message-Id: <1497256916-4958-15-git-send-email-yao.qi@linaro.org> In-Reply-To: <1497256916-4958-1-git-send-email-yao.qi@linaro.org> References: <1497256916-4958-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes 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 * 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 * selftest.c: Adjust it for GDBserver. gdb/testsuite: 2017-05-26 Yao Qi * 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 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 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 " 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 . */ - +#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 @@ -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 . + +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" + } +}