From patchwork Tue Oct 9 13:47:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 29678 Received: (qmail 38412 invoked by alias); 9 Oct 2018 13:47:51 -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 38398 invoked by uid 89); 9 Oct 2018 13:47:51 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_PASS autolearn=ham version=3.3.2 spammy=first, 26pm, 26PM, sk:counter X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 09 Oct 2018 13:47:49 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D106CB012; Tue, 9 Oct 2018 13:47:46 +0000 (UTC) Date: Tue, 9 Oct 2018 15:47:47 +0200 From: Tom de Vries To: Pedro Alves Cc: gdb-patches@sourceware.org Subject: [gdb/testsuite] Add gdb-caching-proc.exp testcase Message-ID: <20181009134747.GA1742@delia> References: <20181004174015.GA20307@delia> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-IsSubscribed: yes On Tue, Oct 09, 2018 at 01:58:26PM +0100, Pedro Alves wrote: > Can you please > submit the gdb-caching-proc.exp separately, with its own rationale? > Hi, When caching a proc using gdb_caching_proc, it will become less likely to be executed, and consequently it's going to be harder to detect that the proc is racy. OTOH, in general the proc is easy to rerun. So, add a test-case to run all uncached gdb_caching_procs a number of times and detect inconsistent results. The purpose of caching is to reduce runtime, so rerunning is somewhat counter-productive in that aspect, but it's better than uncached, because the number of reruns is constant-bounded, and the increase in runtime is bound to this test-case, and can be disabled on slow targets. Tested on x86_64-linux. OK for trunk? Thanks, - Tom [gdb/testsuite] Add gdb-caching-proc.exp testcase 2018-10-09 Tom de Vries * gdb.base/gdb-caching-proc.exp: New file. --- gdb/testsuite/gdb.base/gdb-caching-proc.exp | 111 ++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/gdb/testsuite/gdb.base/gdb-caching-proc.exp b/gdb/testsuite/gdb.base/gdb-caching-proc.exp new file mode 100644 index 0000000000..87c20fc574 --- /dev/null +++ b/gdb/testsuite/gdb.base/gdb-caching-proc.exp @@ -0,0 +1,111 @@ +# Copyright 2018 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 . + +# When caching a proc using gdb_caching_proc, it will become less likely to +# be executed, and consequently it's going to be harder to detect that the +# proc is racy. OTOH, in general the proc is easy to rerun. So, run all +# uncached gdb_caching_procs a number of times and detect inconsistent results. +# The purpose of caching is to reduce runtime, so rerunning is somewhat +# counter-productive in that aspect, but it's better than uncached, because the +# number of reruns is constant-bounded, and the increase in runtime is bound to +# this test-case, and could be disabled on slow targets. + +# Test gdb_caching_proc NAME +proc test_proc { name } { + set real_name gdb_real__$name + + set first [$real_name] + lappend resultlist $first + + # Ten repetitions was enough to trigger target_supports_scheduler_locking, + # and costs about 20 seconds on an i7-6600U. + set repeat 10 + + set resultlist [list] + set racy 0 + for {set i 0} {$i < $repeat} {incr i} { + set rerun [$real_name] + lappend resultlist $rerun + if { $rerun != $first } { + set racy 1 + } + } + + if { $racy == 0 } { + pass "$name consistency" + } else { + fail "$name consistency" + verbose -log "$name: $resultlist" + } +} + +# Test gdb_caching_procs in FILE +proc test_file { file } { + upvar obj obj + set procnames [list] + + set fp [open $file] + while { [gets $fp line] >= 0 } { + if [regexp -- "^gdb_caching_proc \[ \t\]*(\[^ \t\]*)" $line \ + match procname] { + lappend procnames $procname + } + } + close $fp + + if { [llength $procnames] == 0 } { + return + } + + if { [file tail $file] == "gdb.exp" } { + # Already loaded + } else { + load_lib [file tail $file] + } + + foreach procname $procnames { + switch $procname { + "is_address_zero_readable" { set setup_gdb 1 } + "target_is_gdbserver" { set setup_gdb 1 } + default {set setup_gdb 0 } + } + + if { $setup_gdb } { + clean_restart $obj + } + + test_proc $procname + + if { $setup_gdb } { + gdb_exit + } + } +} + +# Init +set me "gdb_caching_proc" +set src { int main() { return 0; } } +if { ![gdb_simple_compile $me $src executable] } { + return 0 +} + +# Test gdb_caching_procs in gdb/testsuite/lib/*.exp +set files [eval glob -types f $srcdir/lib/*.exp] +foreach file $files { + test_file $file +} + +# Cleanup +remote_file build delete $obj