From patchwork Wed May 3 16:18:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 20235 Received: (qmail 82711 invoked by alias); 3 May 2017 16:18:36 -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 82559 invoked by uid 89); 3 May 2017 16:18:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wr0-f170.google.com Received: from mail-wr0-f170.google.com (HELO mail-wr0-f170.google.com) (209.85.128.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 03 May 2017 16:18:33 +0000 Received: by mail-wr0-f170.google.com with SMTP id w50so112678655wrc.0 for ; Wed, 03 May 2017 09:18:35 -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=1h+LGYm2DamzW+IIRxOfwMZ5rhW73qriRkID2lr673U=; b=IDqRI9kVA8fa6A9P0OiXHPGl9FzW37nyqIlyoZsrSbtezRhVgBDKG9+x97wXReJcpk eKxSIOD3g+wfLYnXU5nCKqdIAvVsmwXMYMduhh5t8LV9bZkAF1LQGGrQOEqkxdDZUmen wjTkmhgEtAKTch4Zo69NbDQRcIVL86RaQoRcXg+PzB7K/W/pUVbZSyHSdQe5p4BvB8/9 t0T+YPgqZ3Nz4/Tkt+pmazzaORQ0u6da+ob+4aRJJF/0mv2j8q+q0Y07PypuejVPsPvb sErsxe/K3fg754ck7R6ZJSIXjNYkrCih7bjBAm8uzp/omjqUwdVGpI3lBlpzOwy6I+aS qhRQ== X-Gm-Message-State: AN3rC/7d+CtNIfn41beBKzmWHSHodq4GRM0MGskBB3FqEtYN3p/OLMUo vt2JEsstPqFFR4hv X-Received: by 10.223.152.6 with SMTP id v6mr23651814wrb.60.1493828313582; Wed, 03 May 2017 09:18:33 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com ([194.214.185.158]) by smtp.gmail.com with ESMTPSA id k18sm17524044wre.9.2017.05.03.09.18.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 03 May 2017 09:18:33 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 1/2] Add current_regcache unit test Date: Wed, 3 May 2017 17:18:29 +0100 Message-Id: <1493828310-15731-2-git-send-email-yao.qi@linaro.org> In-Reply-To: <1493828310-15731-1-git-send-email-yao.qi@linaro.org> References: <1493828310-15731-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes This patch adds a unit test to current_regcache, to make sure it is correctly updated by get_thread_arch_aspace_regcache and registers_changed_ptid. gdb: 2017-05-02 Yao Qi * regcache.c [GDB_SELF_TEST]: Include selftest.h. (current_regcache_size): New function. (current_regcache_test): New function. (_initialize_regcache) [GDB_SELF_TEST]: Register the unit test. --- gdb/regcache.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/gdb/regcache.c b/gdb/regcache.c index 03f172e..40781bc 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -1679,6 +1679,77 @@ maintenance_print_remote_registers (char *args, int from_tty) regcache_print (args, regcache_dump_remote); } +#if GDB_SELF_TEST +#include "selftest.h" + +namespace selftests { + +/* Return the number of elements in current_regcache. */ + +static size_t +current_regcache_size () +{ + size_t i = 0; + for (auto list = current_regcache; list; list = list->next) + i++; + + return i; +} + +static void +current_regcache_test (void) +{ + /* It is empty at the start. */ + SELF_CHECK (current_regcache_size () == 0); + + ptid_t ptid1 (1), ptid2 (2), ptid3 (3); + + /* Get regcache from ptid1, a new regcache is added to + current_regcache. */ + regcache *regcache = get_thread_arch_aspace_regcache (ptid1, + target_gdbarch (), + NULL); + + SELF_CHECK (regcache != NULL); + SELF_CHECK (regcache->ptid () == ptid1); + SELF_CHECK (current_regcache_size () == 1); + + /* Get regcache from ptid2, a new regcache is added to + current_regcache. */ + regcache = get_thread_arch_aspace_regcache (ptid2, + target_gdbarch (), + NULL); + SELF_CHECK (regcache != NULL); + SELF_CHECK (regcache->ptid () == ptid2); + SELF_CHECK (current_regcache_size () == 2); + + /* Get regcache from ptid3, a new regcache is added to + current_regcache. */ + regcache = get_thread_arch_aspace_regcache (ptid3, + target_gdbarch (), + NULL); + SELF_CHECK (regcache != NULL); + SELF_CHECK (regcache->ptid () == ptid3); + SELF_CHECK (current_regcache_size () == 3); + + /* Get regcache from ptid2 again, nothing is added to + current_regcache. */ + regcache = get_thread_arch_aspace_regcache (ptid2, + target_gdbarch (), + NULL); + SELF_CHECK (regcache != NULL); + SELF_CHECK (regcache->ptid () == ptid2); + SELF_CHECK (current_regcache_size () == 3); + + /* Mark ptid2 is changed, so regcache of ptid2 should be removed from + current_regcache. */ + registers_changed_ptid (ptid2); + SELF_CHECK (current_regcache_size () == 2); +} + +} // namespace selftests +#endif /* GDB_SELF_TEST */ + extern initialize_file_ftype _initialize_regcache; /* -Wmissing-prototype */ void @@ -1718,5 +1789,7 @@ Print the internal register configuration including each register's\n\ remote register number and buffer offset in the g/G packets.\n\ Takes an optional file parameter."), &maintenanceprintlist); - +#if GDB_SELF_TEST + register_self_test (selftests::current_regcache_test); +#endif }