public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-1701] testsuite: clarify scan-dump file globbing behavior
@ 2020-06-29  7:22 Frederik Harwath
  0 siblings, 0 replies; only message in thread
From: Frederik Harwath @ 2020-06-29  7:22 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:d4501bbedca267f2051e4f57415d6d2a61306915

commit r11-1701-gd4501bbedca267f2051e4f57415d6d2a61306915
Author: Frederik Harwath <frederik@codesourcery.com>
Date:   Mon Jun 29 08:42:56 2020 +0200

    testsuite: clarify scan-dump file globbing behavior
    
    The test commands for scanning optimization dump files
    perform globbing on the argument that specifies the suffix
    of the dump files to be scanned.  This behavior is currently
    undocumented.  Furthermore, the current implementation of
    "scan-dump" and similar procedures yields an error whenever
    the file name globbing matches more than one file (due to an
    attempt to call "open" on multiple files) while a failure to
    match any file results in an unresolved test.
    
    This commit documents the globbing behavior.  The dump
    scanning procedures are changed to make the test unresolved
    if globbing matches more than one file.
    
    gcc/ChangeLog:
    
    2020-06-29  Frederik Harwath  <frederik@codesourcery.com>
    
            * doc/sourcebuild.texi: Describe globbing of the
            dump file scanning commands "suffix" argument.
    
    gcc/testsuite/ChangeLog:
    
    2020-06-29  Frederik Harwath  <frederik@codesourcery.com>
    
            * lib/scandump.exp (glob-dump-file): New proc.
            (scan-dump): Use glob-dump-file for file name expansion.
            (scan-dump-times): Likewise.
            (scan-dump-dem): Likewise.
            (scan-dump-dem-not): Likewise.
    
    Reviewed-by: Thomas Schwinge <thomas@codesourcery.com>

Diff:
---
 gcc/doc/sourcebuild.texi       | 13 ++++++++++
 gcc/testsuite/lib/scandump.exp | 54 +++++++++++++++++++++++++++++++++---------
 2 files changed, 56 insertions(+), 11 deletions(-)

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index a12af822443..5b5b845afe6 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -2943,6 +2943,19 @@ Passes if @var{regex} does not match demangled text in the dump file with
 suffix @var{suffix}.
 @end table
 
+The @var{suffix} argument which describes the dump file to be scanned
+may contain a glob pattern that must expand to exactly one file
+name. This is useful if, e.g., different pass instances are executed
+depending on torture testing command-line flags, producing dump files
+whose names differ only in their pass instance number suffix.  For
+example, to scan instances 1, 2, 3 of a tree pass ``mypass'' for
+occurrences of the string ``code has been optimized'', use:
+@smallexample
+/* @{ dg-options "-fdump-tree-mypass" @} */
+/* @{ dg-final @{ scan-tree-dump "code has been optimized" "mypass\[1-3\]" @} @} */
+@end smallexample
+
+
 @subsubsection Check for output files
 
 @table @code
diff --git a/gcc/testsuite/lib/scandump.exp b/gcc/testsuite/lib/scandump.exp
index 2479c89d3c7..6cb208f1cef 100644
--- a/gcc/testsuite/lib/scandump.exp
+++ b/gcc/testsuite/lib/scandump.exp
@@ -42,6 +42,34 @@ proc dump-base { args } {
     return $dumpbase
 }
 
+# Expand dump file name pattern to exactly one file.
+# Return a single dump file name or an empty string
+# if the pattern matches no file or more than one file.
+#
+# Argument 0 is the testcase name
+# Argument 1 is the dump file glob pattern
+proc glob-dump-file { args } {
+
+    set pattern [lindex $args 1]
+    set dump_file "[glob -nocomplain $pattern]"
+    set num_files [llength $dump_file]
+
+    if { $num_files != 1 } {
+	set testcase [lindex $args 0]
+	if { $num_files == 0 } {
+	    verbose -log "$testcase: dump file does not exist"
+	}
+
+	if { $num_files > 1 } {
+	    verbose -log "$testcase: multiple dump files found"
+	}
+
+	return
+    }
+
+    return $dump_file
+}
+
 # Utility for scanning compiler result, invoked via dg-final.
 # Call pass if pattern is present, otherwise fail.
 #
@@ -70,10 +98,10 @@ proc scan-dump { args } {
     set testname "$testcase scan-[lindex $args 0]-dump $suf \"$printable_pattern\""
     set src [file tail $filename]
     set dumpbase [dump-base $src [lindex $args 3]]
-    set output_file "[glob -nocomplain $dumpbase.[lindex $args 2]]"
+
+    set pattern "$dumpbase.[lindex $args 2]"
+    set output_file "[glob-dump-file $testcase $pattern]"
     if { $output_file == "" } {
-	verbose -log "$testcase: dump file does not exist"
-	verbose -log "dump file: $dumpbase.$suf"
 	unresolved "$testname"
 	return
     }
@@ -116,9 +144,10 @@ proc scan-dump-times { args } {
     set testname "$testcase scan-[lindex $args 0]-dump-times $suf \"$printable_pattern\" [lindex $args 2]"
     set src [file tail $filename]
     set dumpbase [dump-base $src [lindex $args 4]]
-    set output_file "[glob -nocomplain $dumpbase.[lindex $args 3]]"
+
+    set pattern "$dumpbase.[lindex $args 3]"
+    set output_file "[glob-dump-file $testcase $pattern]"
     if { $output_file == "" } {
-	verbose -log "$testcase: dump file does not exist"
 	unresolved "$testname"
 	return
     }
@@ -162,9 +191,10 @@ proc scan-dump-not { args } {
     set testname "$testcase scan-[lindex $args 0]-dump-not $suf \"$printable_pattern\""
     set src [file tail $filename]
     set dumpbase [dump-base $src [lindex $args 3]]
-    set output_file "[glob -nocomplain $dumpbase.[lindex $args 2]]"
+
+    set pattern "$dumpbase.[lindex $args 2]"
+    set output_file "[glob-dump-file $testcase $pattern]"
     if { $output_file == "" } {
-	verbose -log "$testcase: dump file does not exist"
 	unresolved "$testname"
 	return
     }
@@ -219,9 +249,10 @@ proc scan-dump-dem { args } {
     set testname "$testcase scan-[lindex $args 0]-dump-dem $suf \"$printable_pattern\""
     set src [file tail $filename]
     set dumpbase [dump-base $src [lindex $args 3]]
-    set output_file "[glob -nocomplain $dumpbase.[lindex $args 2]]"
+
+    set pattern "$dumpbase.[lindex $args 2]"
+    set output_file "[glob-dump-file $testcase $pattern]"
     if { $output_file == "" } {
-	verbose -log "$testcase: dump file does not exist"
 	unresolved "$testname"
 	return
     }
@@ -275,9 +306,10 @@ proc scan-dump-dem-not { args } {
     set testname "$testcase scan-[lindex $args 0]-dump-dem-not $suf \"$printable_pattern\""
     set src [file tail $filename]
     set dumpbase [dump-base $src [lindex $args 3]]
-    set output_file "[glob -nocomplain $dumpbase.[lindex $args 2]]"
+
+    set pattern "$dumpbase.[lindex $args 2]"
+    set output_file "[glob-dump-file $testcase $pattern]"
     if { $output_file == "" } {
-	verbose -log "$testcase: dump file does not exist"
 	unresolved "$testname"
 	return
     }


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

only message in thread, other threads:[~2020-06-29  7:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-29  7:22 [gcc r11-1701] testsuite: clarify scan-dump file globbing behavior Frederik Harwath

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).