## Process this file with automake to create Makefile.in
##
-## Copyright (C) 1996-2019 Red Hat, Inc.
+## Copyright (C) 1996-2026 Red Hat, Inc.
## This file is part of elfutils.
##
## This file is free software; you can redistribute it and/or modify
endif
endif
-if HAVE_CXX11
+if HAVE_CXX20
check_PROGRAMS += funcretval_test++11
funcretval_test__11_SOURCES = funcretval_test++11.cxx
TESTS += run-funcretval++11.sh
funcretval_test_struct_SOURCES = funcretval_test_struct.c
TESTS += run-funcretval-struct-native.sh
+if ENABLE_STACKPROF
+TESTS += run-stackprof-user.sh run-stackprof-user-gprof.sh
+TESTS += run-stackprof-system.sh run-stackprof-system-gprof.sh
+endif
+if HAVE_LIBPFM
+export HAVE_LIBPFM = 1
+endif
+
EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
run-ar-N.sh \
run-show-die-info.sh run-get-files.sh run-get-lines.sh \
testfile-sysroot.tar.bz2 run-sysroot.sh \
run-test-manyfuncs.sh manyfuncs.c \
run-debuginfod-seekable.sh thread-safety-subr.sh \
+ run-stackprof-user.sh run-stackprof-user-gprof.sh \
+ run-stackprof-system.sh run-stackprof-system-gprof.sh \
run-eu-search-cfi.sh run-eu-search-macros.sh \
run-eu-search-lines.sh run-eu-search-die.sh
--- /dev/null
+#!/usr/bin/env bash
+#
+# Copyright (C) 2026 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file 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.
+#
+# elfutils 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 this program. If not, see <http://www.gnu.org/licenses/>.
+
+set -x
+
+. $srcdir/test-subr.sh
+
+# prerequisites
+type timeout 2>/dev/null || (echo "no timeout installed"; exit 77)
+expr `whoami` = "root" || (echo "run as root"; exit 77)
+
+# run systemwide scan
+tempfiles test.out
+# produce gprof data
+testrun timeout -p -sINT 10 ${abs_top_builddir}/src/stackprof -v -v 2>&1 | tee test.out
+
+grep "^perf_event_attr configuration" test.out
+grep "Starting stack profile collection systemwide" test.out
+grep -E "^[0-9]+ " test.out
+
+# run it again, producing gprof data
+testrun timeout -p -sINT 10 ${abs_top_builddir}/src/stackprof -v -v -g 2>&1 | tee test.out
+tempfiles test.out
+tempfiles gmon.*
+grep "^perf_event_attr configuration type=1 config=0 sample_freq=" test.out
+grep "Starting stack profile collection systemwide" test.out
+grep -E "^buildid [0-9a-f]+" test.out
+
+export DEBUGINFOD_URLS=https://debuginfod.elfutils.org/
+
+for f in gmon.*.out
+do
+ exe="`basename "$f" .out`.exe"
+ if [ ! -f "$exe" ];
+ then
+ echo "NOTE: finding $f executable by buildid"
+ buildid=`echo "$f" | cut -f2 -d.`
+ if testrun ${abs_top_builddir}/debuginfod/debuginfod-find -v executable $buildid; then
+ ln -s "`${abs_top_builddir}/debuginfod/debuginfod-find executable $buildid`" "$exe"
+ else
+ echo "SKIPPING: executable not found"
+ continue
+ fi
+ fi
+ tempfiles "$exe"
+ echo "NOTE: analyzing $exe `readlink $exe`"
+ tempfiles gprof_output.txt
+ # Try a plain gprof attempt on the executable
+ if gprof "$exe" "$f" > gprof_output.txt 2>&1; then
+ # Success, use the output
+ cat gprof_output.txt
+ else
+ # Fall back to debuginfod if necessary (e.g., if debug info is missing)
+ echo "NOTE: stripped binary found, attempting to find debuginfo"
+ if testrun ${abs_top_builddir}/debuginfod/debuginfod-find -v debuginfo $exe; then
+ debuginfo="`${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $exe`"
+ gprof "$debuginfo" "$f"
+ else
+ echo "SKIPPING: debuginfo not found"
+ continue
+ fi
+ fi
+done
+
+exit 0
--- /dev/null
+#!/usr/bin/env bash
+#
+# Copyright (C) 2026 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file 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.
+#
+# elfutils 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 this program. If not, see <http://www.gnu.org/licenses/>.
+
+set -x
+
+. $srcdir/test-subr.sh
+
+# prerequisites
+type timeout 2>/dev/null || (echo "no timeout installed"; exit 77)
+expr `whoami` = "root" || (echo "run as root"; exit 77)
+
+# run systemwide scan
+tempfiles test.out
+testrun timeout -p -sINT 10 ${abs_top_builddir}/src/stackprof -v -v 2>&1 | tee test.out
+
+grep "^perf_event_attr configuration" test.out
+grep "Starting stack profile collection systemwide" test.out
+grep -E "^[0-9]+ " test.out
+
+# run it again, producing gprof data
+testrun timeout -p -sINT 10 ${abs_top_builddir}/src/stackprof -v -v -g 2>&1 | tee test.out
+
+tempfiles gmon.*
+grep "^perf_event_attr configuration type=1 config=0 sample_freq=" test.out
+grep "Starting stack profile collection systemwide" test.out
+grep -E "^buildid [0-9a-f]+" test.out
+
+
+exit 0
--- /dev/null
+#!/usr/bin/env bash
+#
+# Copyright (C) 2026 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file 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.
+#
+# elfutils 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 this program. If not, see <http://www.gnu.org/licenses/>.
+
+set -x
+
+. $srcdir/test-subr.sh
+
+# prerequisites
+type timeout 2>/dev/null || (echo "no timeout installed"; exit 77)
+type gprof 2>/dev/null || (echo "no gprof installed"; exit 77)
+
+# produce gprof data
+testrun ${abs_top_builddir}/src/stackprof -v -v -g -- timeout 2 /bin/sh -c "while true; do true; done" 2>&1 | tee test.out
+tempfiles test.out
+tempfiles gmon.*
+grep "^perf_event_attr configuration" test.out
+grep "Starting stack profile collection pid" test.out
+grep -E "^buildid [0-9a-f]+" test.out
+
+export DEBUGINFOD_URLS=https://debuginfod.elfutils.org/
+
+for f in gmon.*.out
+do
+ exe="`basename "$f" .out`.exe"
+ if [ ! -f "$exe" ];
+ then
+ echo "NOTE: finding $f executable by buildid"
+ buildid=`echo "$f" | cut -f2 -d.`
+ if testrun ${abs_top_builddir}/debuginfod/debuginfod-find -v executable $buildid; then
+ ln -s "`${abs_top_builddir}/debuginfod/debuginfod-find executable $buildid`" "$exe"
+ else
+ echo "SKIPPING: executable not found"
+ continue
+ fi
+ fi
+ tempfiles "$exe"
+ echo "NOTE: analyzing $exe `readlink $exe`"
+ tempfiles gprof_output.txt
+ # Try a plain gprof attempt on the executable
+ if gprof "$exe" "$f" > gprof_output.txt 2>&1; then
+ # Success, use the output
+ cat gprof_output.txt
+ else
+ # Fall back to debuginfod if necessary (e.g., if debug info is missing)
+ echo "NOTE: stripped binary found, attempting to find debuginfo"
+ if testrun ${abs_top_builddir}/debuginfod/debuginfod-find -v debuginfo $exe; then
+ debuginfo="`${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $exe`"
+ gprof "$debuginfo" "$f"
+ else
+ echo "SKIPPING: debuginfo not found"
+ continue
+ fi
+ fi
+done
+
+exit 0
--- /dev/null
+#!/usr/bin/env bash
+#
+# Copyright (C) 2026 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file 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.
+#
+# elfutils 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 this program. If not, see <http://www.gnu.org/licenses/>.
+
+set -x
+
+. $srcdir/test-subr.sh
+
+# prerequisites
+type timeout 2>/dev/null || (echo "no timeout installed"; exit 77)
+
+# run a cpu-hungry shell script fragment, analyze verbose stats
+tempfiles test.out
+testrun ${abs_top_builddir}/src/stackprof -v -v -- timeout 2 /bin/sh -c "while true; do true; done" 2>&1 | tee test.out
+
+grep "^perf_event_attr configuration" test.out
+grep "Starting stack profile collection pid" test.out
+grep -E "^[0-9]+ sh --" test.out
+
+
+# run it again, producing gprof data
+testrun ${abs_top_builddir}/src/stackprof -v -v -g -- timeout 2 /bin/sh -c "while true; do true; done" 2>&1 | tee test.out
+
+tempfiles gmon.*
+grep "^perf_event_attr configuration type=1 config=0 sample_freq=" test.out
+grep "Starting stack profile collection pid" test.out
+grep -E "^buildid [0-9a-f]+" test.out
+rm gmon.*
+
+
+if [ "x$HAVE_LIBPFM" = "x1" ]; then
+ # test libpfm event listing
+ testrun ${abs_top_builddir}/src/stackprof --event-list 2>&1 | tee test.out
+ wc -l < test.out
+ grep "^perf::BRANCHES" test.out
+
+ # test libpfm event listing
+ testrun ${abs_top_builddir}/src/stackprof -v -v -e perf::BRANCHES:freq=4000 -v -v -g -- timeout 2 /bin/sh -c "while true; do true; done" 2>&1 | tee test.out
+
+ tempfiles gmon.*
+ grep "^perf_event_attr configuration type=0 config=4 sample_freq=4000" test.out
+ grep "Starting stack profile collection pid" test.out
+ grep -E "^buildid [0-9a-f]+" test.out
+fi
+
+
+exit 0