diff mbox series

[pushed] testsuite: split out parts of jit.dg/jit.exp into a new lib/valgrind.exp

Message ID 20240801005114.1003918-1-dmalcolm@redhat.com
State New
Headers show
Series [pushed] testsuite: split out parts of jit.dg/jit.exp into a new lib/valgrind.exp | expand

Commit Message

David Malcolm Aug. 1, 2024, 12:51 a.m. UTC
I want to reuse some of the support for valgrind in jit.exp
in my upcoming testsuite for https://gcc.gnu.org/wiki/libdiagnostics
so this patch splits that out into a valgrind.exp.

No functional change intended.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r15-2468-g64fbaf36a3834c.

gcc/testsuite/ChangeLog:
	* jit.dg/jit.exp: Add load_lib valgrind.exp.
	(proc report_leak): Move to valgrind.exp, and add argument
	leak_report_function rather than hardcoding xfail.
	(parse_valgrind_logfile): Likewise.
	(fixed_host_execute): Pass xfail to parse_valgrind_logfile.
	* lib/valgrind.exp: New file, based on the above.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
---
 gcc/testsuite/jit.dg/jit.exp   | 47 +++------------------------
 gcc/testsuite/lib/valgrind.exp | 58 ++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 43 deletions(-)
 create mode 100644 gcc/testsuite/lib/valgrind.exp
diff mbox series

Patch

diff --git a/gcc/testsuite/jit.dg/jit.exp b/gcc/testsuite/jit.dg/jit.exp
index 893ff5f6dd0..57b133b6d8c 100644
--- a/gcc/testsuite/jit.dg/jit.exp
+++ b/gcc/testsuite/jit.dg/jit.exp
@@ -38,6 +38,7 @@  load_lib gcc.exp
 load_lib g++.exp
 load_lib dejagnu.exp
 load_lib target-supports-dg.exp
+load_lib valgrind.exp
 
 # Skip these tests for targets that don't support -lgccjit
 if { ![check_effective_target_lgccjit] } {
@@ -47,48 +48,6 @@  if { ![check_effective_target_lgccjit] } {
 # The default do-what keyword.
 set dg-do-what-default compile
 
-# Look for lines of the form:
-#   definitely lost: 11,316 bytes in 235 blocks
-#   indirectly lost: 352 bytes in 4 blocks
-# Ideally these would report zero bytes lost (which is a PASS);
-# for now, report non-zero leaks as XFAILs.
-proc report_leak {kind name logfile line} {
-    set match [regexp "$kind lost: .*" $line result]
-    if $match {
-	verbose "Saw \"$result\" within \"$line\"" 4
-	# Extract bytes and blocks.
-	# These can contain commas as well as numerals,
-	# but we only care about whether we have zero.
-	regexp "$kind lost: (.+) bytes in (.+) blocks" \
-	    $result -> bytes blocks
-	verbose "bytes: '$bytes'" 4
-	verbose "blocks: '$blocks'" 4
-	if { $bytes == 0 } {
-	    pass "$name: $logfile: $result"
-	} else {
-	    xfail "$name: $logfile: $result"
-	}
-    }
-}
-
-proc parse_valgrind_logfile {name logfile} {
-    verbose "parse_valgrind_logfile: $logfile" 2
-    if [catch {set f [open $logfile]}] {
-	fail "$name: unable to read $logfile"
-	return
-    }
-
-    while { [gets $f line] >= 0 } {
-	# Strip off the PID prefix e.g. ==7675==
-	set line [regsub "==\[0-9\]*== " $line ""]
-	verbose $line 2
-
-	report_leak "definitely" $name $logfile $line
-	report_leak "indirectly" $name $logfile $line
-    }
-    close $f
-}
-
 # Given WRES, the result from "wait", issue a PASS
 # if the spawnee exited cleanly, or a FAIL for various kinds of
 # unexpected exits.
@@ -327,7 +286,9 @@  proc fixed_host_execute {args} {
  
     if $run_under_valgrind {
 	upvar 2 name name
-	parse_valgrind_logfile $name $valgrind_logfile
+	# Use xfail to report leaks, as libgccjit isn't yet clean of
+	# memory leaks (PR jit/63854)
+	parse_valgrind_logfile $name $valgrind_logfile xfail
     }
 
     # force a close of the executable to be safe.
diff --git a/gcc/testsuite/lib/valgrind.exp b/gcc/testsuite/lib/valgrind.exp
new file mode 100644
index 00000000000..7d4f7ce51da
--- /dev/null
+++ b/gcc/testsuite/lib/valgrind.exp
@@ -0,0 +1,58 @@ 
+# Copyright (C) 2014-2024 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 GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# Look for lines of the form:
+#   definitely lost: 11,316 bytes in 235 blocks
+#   indirectly lost: 352 bytes in 4 blocks
+# Report zero bytes lost as a a PASS.
+# Use LEAK_REPORT_FUNCTION to report non-zero bytes lost (either fail or xfail)
+
+proc report_leak {kind name logfile line leak_report_function} {
+    set match [regexp "$kind lost: .*" $line result]
+    if $match {
+	verbose "Saw \"$result\" within \"$line\"" 4
+	# Extract bytes and blocks.
+	# These can contain commas as well as numerals,
+	# but we only care about whether we have zero.
+	regexp "$kind lost: (.+) bytes in (.+) blocks" \
+	    $result -> bytes blocks
+	verbose "bytes: '$bytes'" 4
+	verbose "blocks: '$blocks'" 4
+	if { $bytes == 0 } {
+	    pass "$name: $logfile: $result"
+	} else {
+	    $leak_report_function "$name: $logfile: $result"
+	}
+    }
+}
+
+proc parse_valgrind_logfile {name logfile leak_report_function} {
+    verbose "parse_valgrind_logfile: $logfile" 2
+    if [catch {set f [open $logfile]}] {
+	fail "$name: unable to read $logfile"
+	return
+    }
+
+    while { [gets $f line] >= 0 } {
+	# Strip off the PID prefix e.g. ==7675==
+	set line [regsub "==\[0-9\]*== " $line ""]
+	verbose $line 2
+
+	report_leak "definitely" $name $logfile $line $leak_report_function
+	report_leak "indirectly" $name $logfile $line $leak_report_function
+    }
+    close $f
+}