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

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.

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>
This commit is contained in:
David Malcolm 2024-07-31 20:38:41 -04:00
parent 55982d1682
commit 64fbaf36a3
2 changed files with 62 additions and 43 deletions

View file

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

View file

@ -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
}