gprof: Fix tests on Solaris [PR34237]

The gprof tests FAIL on Solaris:

tst-gmon-gprof.sh ../gprof tst-gmon
--- expected
+++ actual
@@ -1,3 +1,4 @@
 f1 2000
 f2 1000
 f3 1
+main 1
FAIL

main is included in the call graph, probably because Solaris still uses
the original BSD gmon.out format.

This patch allows for that difference.  To distinguish between targets
with non-default handling, $target is passed to the test scripts.

As detailed in the PR, the powerpc with function descriptors special
case only applies to AIX, so that variant is guarded accordingly.

Tested on amd64-pc-solaris2.11, sparcv9-sun-solaris2.11, and
x86_64-pc-linux-gnu.

2026-06-08  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	gprof:
	PR gprof/34237
	* testsuite/Makefile.am (tst-gmon-gprof.out): Pass $(target) to
	tst-gmon-gprof.sh.
	(tst-gmon-gprof-l.out): Likewise.
	(tst-gmon-gprof-l2.out): Likewise.
	* testsuite/Makefile.in: Regenerate.

	* testsuite/tst-gmon-gprof.sh (expected_dot): Remove.
	<*-*-solaris2*>: Allow main in execution counters.
	<powerpc-*-aix* | rs6000-*-aix*>: Handle function descriptor case here.
	* testsuite/tst-gmon-gprof-l.sh: Likewise.
	* testsuite/tst-gmon-gprof-l2.sh: Likewise.
This commit is contained in:
Rainer Orth 2026-06-11 10:05:03 +02:00
parent f4441fd82f
commit c52a3e8683
5 changed files with 48 additions and 24 deletions

View file

@ -33,12 +33,12 @@ tst-gmon.$(OBJEXT): tst-gmon.c
tst-gmon: tst-gmon.$(OBJEXT)
$(LINK) tst-gmon.$(OBJEXT)
tst-gmon-gprof.out: tst-gmon$(EXEEXT) $(GPROF)
$(srcdir)/tst-gmon-gprof.sh $(GPROF) tst-gmon$(EXEEXT)
$(srcdir)/tst-gmon-gprof.sh $(GPROF) tst-gmon$(EXEEXT) $(target)
check_SCRIPTS += tst-gmon-gprof-l.sh
check_DATA += tst-gmon-gprof-l.out
tst-gmon-gprof-l.out: tst-gmon$(EXEEXT) $(GPROF)
$(srcdir)/tst-gmon-gprof-l.sh $(GPROF) tst-gmon$(EXEEXT)
$(srcdir)/tst-gmon-gprof-l.sh $(GPROF) tst-gmon$(EXEEXT) $(target)
# Create a separated-debuginfo version of the initial binary
check_SCRIPTS += tst-gmon-gprof-l2.sh
@ -49,7 +49,7 @@ tst-gmon2$(EXEEXT) tst-gmon2.debug: tst-gmon$(EXEEXT)
objcopy --add-gnu-debuglink=tst-gmon2.debug tst-gmon2$(EXEEXT)
tst-gmon-gprof-l2.out: tst-gmon2$(EXEEXT) tst-gmon2.debug $(GPROF)
$(srcdir)/tst-gmon-gprof-l2.sh $(GPROF) tst-gmon2$(EXEEXT)
$(srcdir)/tst-gmon-gprof-l2.sh $(GPROF) tst-gmon2$(EXEEXT) $(target)
check_DATA += tst-gmon-gprof-l2.out
MOSTLYCLEANFILES += tst-gmon2$(EXEEXT) tst-gmon2.debug

View file

@ -898,9 +898,9 @@ uninstall-am:
@NATIVE_TRUE@tst-gmon: tst-gmon.$(OBJEXT)
@NATIVE_TRUE@ $(LINK) tst-gmon.$(OBJEXT)
@NATIVE_TRUE@tst-gmon-gprof.out: tst-gmon$(EXEEXT) $(GPROF)
@NATIVE_TRUE@ $(srcdir)/tst-gmon-gprof.sh $(GPROF) tst-gmon$(EXEEXT)
@NATIVE_TRUE@ $(srcdir)/tst-gmon-gprof.sh $(GPROF) tst-gmon$(EXEEXT) $(target)
@NATIVE_TRUE@tst-gmon-gprof-l.out: tst-gmon$(EXEEXT) $(GPROF)
@NATIVE_TRUE@ $(srcdir)/tst-gmon-gprof-l.sh $(GPROF) tst-gmon$(EXEEXT)
@NATIVE_TRUE@ $(srcdir)/tst-gmon-gprof-l.sh $(GPROF) tst-gmon$(EXEEXT) $(target)
@NATIVE_TRUE@tst-gmon2$(EXEEXT) tst-gmon2.debug: tst-gmon$(EXEEXT)
@NATIVE_TRUE@ cp -p tst-gmon$(EXEEXT) tst-gmon2$(EXEEXT)
@NATIVE_TRUE@ objcopy --only-keep-debug tst-gmon2$(EXEEXT) tst-gmon2.debug
@ -908,7 +908,7 @@ uninstall-am:
@NATIVE_TRUE@ objcopy --add-gnu-debuglink=tst-gmon2.debug tst-gmon2$(EXEEXT)
@NATIVE_TRUE@tst-gmon-gprof-l2.out: tst-gmon2$(EXEEXT) tst-gmon2.debug $(GPROF)
@NATIVE_TRUE@ $(srcdir)/tst-gmon-gprof-l2.sh $(GPROF) tst-gmon2$(EXEEXT)
@NATIVE_TRUE@ $(srcdir)/tst-gmon-gprof-l2.sh $(GPROF) tst-gmon2$(EXEEXT) $(target)
# Run all tests in series, so they don't fight over the gmon.out file
@NATIVE_TRUE@.NOTPARALLEL:

View file

@ -24,6 +24,7 @@ if test -z "$GPROF"; then
fi
program="$2"
target="$3"
# Generate gmon.out
data=gmon.out
rm -f $data
@ -40,11 +41,9 @@ exec 2>&1
actual=${program}.actual-l
expected=${program}.expected-l
expected_dot=${program}.expected_dot-l
cleanup () {
rm -f "$actual"
rm -f "$expected"
rm -f "$expected_dot"
}
trap cleanup 0
@ -54,19 +53,28 @@ cat > "$expected" <<EOF
40 f3 1
EOF
# Special version for powerpc with function descriptors.
cat > "$expected_dot" <<EOF
case "$target" in
*-*-solaris2*)
# Solaris with the BSD gmon.out format includes main in the call graph.
cat >> $expected <<EOF
51 main 1
EOF
;;
powerpc-*-aix* | rs6000-*-aix*)
# Special version for powerpc with function descriptors.
cat > "$expected" <<EOF
25 .f1 2000
31 .f2 1000
40 .f3 1
EOF
;;
esac
"$GPROF" -l -C "$program" "$data" \
| awk -F '[(): ]' '/executions/{print $2, $5, $8}' \
| sort > "$actual"
if cmp -s "$actual" "$expected_dot" \
|| diff -u --label expected "$expected" --label actual "$actual" ; then
if diff -u --label expected "$expected" --label actual "$actual" ; then
echo "PASS"
else
echo "FAIL"

View file

@ -24,6 +24,7 @@ if test -z "$GPROF"; then
fi
program="$2"
target="$3"
# Generate gmon.out
data=gmon.out
rm -f $data
@ -40,11 +41,9 @@ exec 2>&1
actual=${program}.actual-l
expected=${program}.expected-l
expected_dot=${program}.expected_dot-l
cleanup () {
rm -f "$actual"
rm -f "$expected"
rm -f "$expected_dot"
}
trap cleanup 0
@ -54,19 +53,28 @@ cat > "$expected" <<EOF
40 f3 1
EOF
# Special version for powerpc with function descriptors.
cat > "$expected_dot" <<EOF
case "$target" in
*-*-solaris2*)
# Solaris with the BSD gmon.out format includes main in the call graph.
cat >> $expected <<EOF
51 main 1
EOF
;;
powerpc-*-aix* | rs6000-*-aix*)
# Special version for powerpc with function descriptors.
cat > "$expected" <<EOF
25 .f1 2000
31 .f2 1000
40 .f3 1
EOF
;;
esac
"$GPROF" -l -C "$program" "$data" \
| awk -F '[(): ]' '/executions/{print $2, $5, $8}' \
| sort > "$actual"
if cmp -s "$actual" "$expected_dot" \
|| diff -u --label expected "$expected" --label actual "$actual" ; then
if diff -u --label expected "$expected" --label actual "$actual" ; then
echo "PASS"
else
echo "FAIL"

View file

@ -24,6 +24,7 @@ if test -z "$GPROF"; then
fi
program="$2"
target="$3"
# Generate gmon.out
data=gmon.out
rm -f $data
@ -40,11 +41,9 @@ exec 2>&1
actual=${program}.actual
expected=${program}.expected
expected_dot=${program}.expected_dot
cleanup () {
rm -f "$actual"
rm -f "$expected"
rm -f "$expected_dot"
}
trap cleanup 0
@ -54,19 +53,28 @@ f2 1000
f3 1
EOF
# Special version for powerpc with function descriptors.
cat > "$expected_dot" <<EOF
case "$target" in
*-*-solaris2*)
# Solaris with the BSD gmon.out format includes main in the call graph.
cat >> $expected <<EOF
main 1
EOF
;;
powerpc-*-aix* | rs6000-*-aix*)
# Special version for powerpc with function descriptors.
cat > "$expected" <<EOF
.f1 2000
.f2 1000
.f3 1
EOF
;;
esac
"$GPROF" -C "$program" "$data" \
| awk -F '[(): ]' '/executions/{print $5, $8}' \
| sort > "$actual"
if cmp -s "$actual" "$expected_dot" \
|| diff -u --label expected "$expected" --label actual "$actual" ; then
if diff -u --label expected "$expected" --label actual "$actual" ; then
echo "PASS"
else
echo "FAIL"