public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] [gdb/testsuite] Add cache_verify option for gdb_caching_procs
@ 2020-03-16 13:39 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2020-03-16 13:39 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2f89101fe8b6a2423116a1ad1891f56bf6fc9510

commit 2f89101fe8b6a2423116a1ad1891f56bf6fc9510
Author: Tom de Vries <tdevries@suse.de>
Date:   Mon Mar 16 14:39:07 2020 +0100

    [gdb/testsuite] Add cache_verify option for gdb_caching_procs
    
    Test-case gdb.base/gdb-caching-proc.exp tests whether procs declared using
    gdb_caching_proc give the same results when called more than once.
    
    While this tests consistency of the procs in the context of that test-case, it
    doesn't test consistency across the call sites.
    
    Add a local variable cache_verify to proc gdb_do_cache, that can be set to 1
    to verify gdb_caching_proc consistency across the call sites.
    
    Likewise, add a local variable cache_verify_proc to set to the name of the
    gdb_caching_proc to verify.  This can f.i. be used when changing an existing
    proc into a gdb_caching_proc.
    
    Tested on x86_64-linux, with cache_verify set to both 0 and 1.
    
    gdb/testsuite/ChangeLog:
    
    2020-03-16  Tom de Vries  <tdevries@suse.de>
    
            * lib/cache.exp (gdb_do_cache): Add and handle local variables
            cache_verify and cache_verify_proc.

Diff:
---
 gdb/testsuite/ChangeLog     |  5 +++++
 gdb/testsuite/lib/cache.exp | 37 ++++++++++++++++++++++++++++++++-----
 2 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 9387c686a05..c0b5a3aba85 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-03-16  Tom de Vries  <tdevries@suse.de>
+
+	* lib/cache.exp (gdb_do_cache): Add and handle local variables
+	cache_verify and cache_verify_proc.
+
 2020-03-15  Tom de Vries  <tdevries@suse.de>
 
 	* gdb.server/solib-list.exp: Handle
diff --git a/gdb/testsuite/lib/cache.exp b/gdb/testsuite/lib/cache.exp
index 25bfe025109..71a385e8361 100644
--- a/gdb/testsuite/lib/cache.exp
+++ b/gdb/testsuite/lib/cache.exp
@@ -52,30 +52,57 @@ proc gdb_do_cache {name} {
     global gdb_data_cache objdir
     global GDB_PARALLEL
 
+    # Normally, if we have a cached value, we skip computation and return
+    # the cached value.  If set to 1, instead don't skip computation and
+    # verify against the cached value.
+    set cache_verify 0
+
+    # Alternatively, set this to do cache_verify only for one proc.
+    set cache_verify_proc ""
+    if { $name == $cache_verify_proc } {
+	set cache_verify 1
+    }
+
     # See if some other process wrote the cache file.  Cache value per
     # "board" to handle runs with multiple options
     # (e.g. unix/{-m32,-64}) correctly.  We use "file join" here
     # because we later use this in a real filename.
     set cache_name [file join [target_info name] $name]
 
+    set is_cached 0
     if {[info exists gdb_data_cache($cache_name)]} {
-	verbose "$name: returning '$gdb_data_cache($cache_name)' from cache" 2
-	return $gdb_data_cache($cache_name)
+	set cached $gdb_data_cache($cache_name)
+	verbose "$name: returning '$cached' from cache" 2
+	if { $cache_verify == 0 } {
+	    return $cached
+	}
+	set is_cached 1
     }
 
-    if {[info exists GDB_PARALLEL]} {
+    if { $is_cached == 0 && [info exists GDB_PARALLEL] } {
 	set cache_filename [make_gdb_parallel_path cache $cache_name]
 	if {[file exists $cache_filename]} {
 	    set fd [open $cache_filename]
 	    set gdb_data_cache($cache_name) [read -nonewline $fd]
 	    close $fd
-	    verbose "$name: returning '$gdb_data_cache($cache_name)' from file cache" 2
-	    return $gdb_data_cache($cache_name)
+	    set cached $gdb_data_cache($cache_name)
+	    verbose "$name: returning '$cached' from file cache" 2
+	    if { $cache_verify == 0 } {
+		return $cached
+	    }
+	    set is_cached 1
 	}
     }
 
     set real_name gdb_real__$name
     set gdb_data_cache($cache_name) [gdb_do_cache_wrap $real_name]
+    if { $cache_verify == 1 && $is_cached == 1 } {
+	set computed $gdb_data_cache($cache_name)
+	if { $cached != $computed } {
+	    error [join [list "Inconsistent results for $cache_name:"
+			 "cached: $cached vs. computed: $computed"]]
+	}
+    }
 
     if {[info exists GDB_PARALLEL]} {
 	verbose "$name: returning '$gdb_data_cache($cache_name)' and writing file" 2


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-03-16 13:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-16 13:39 [binutils-gdb] [gdb/testsuite] Add cache_verify option for gdb_caching_procs Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).