]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
tests/*stackprof*: apply improvements to all tests users/serhei/try-eu-stackprof
authorSerhei Makarov <serhei@serhei.io>
Tue, 23 Jun 2026 20:58:30 +0000 (16:58 -0400)
committerSerhei Makarov <serhei@serhei.io>
Tue, 23 Jun 2026 20:58:30 +0000 (16:58 -0400)
tests/run-stackprof-system-gprof.sh
tests/run-stackprof-system.sh
tests/run-stackprof-user-gprof.sh
tests/run-stackprof-user.sh
tests/stackprof-subr.sh

index b9dc839f7fb6f80560f64686edf52e02d96dd74b..c281167c9b96b05784b93b5e7e5a5fc4c91ca94a 100755 (executable)
@@ -23,10 +23,11 @@ unset VALGRIND_CMD
 
 # prerequisites
 type timeout 2>/dev/null || (echo "no timeout installed"; exit 77)
+type gprof 2>/dev/null || (echo "no gprof installed"; exit 77)
 check_perf_event_open || (echo "perf_event_open fails (check kernel.perf_event_paranoid + kernel config)"; exit 77)
 expr `whoami` = "root" || (echo "not running as root"; exit 77)
 
-tempfiles test.out gmon.*
+tempfiles test.out
 
 # run systemwide scan, no gprof output
 testrun timeout -p --kill-after=5 10 ${abs_top_builddir}/src/stackprof -v 2>&1 | tee test.out
@@ -37,39 +38,12 @@ grep -E "^[0-9]+ " test.out # -- pid / sample counts entries
 # run systemwide scan again, with gprof output
 # reduce verbosity, bump post-processing timeout compared to the first run
 testrun timeout -p --kill-after=10 10 ${abs_top_builddir}/src/stackprof -g 2>&1 | tee test.out
+tempfiles gmon.*
 grep "^perf_event_attr configuration" test.out
 grep "Starting stack profile collection systemwide" test.out
 grep -E "^buildid [0-9a-f]+" test.out
 
 stackprof_debuginfod_setup
-
-for f in gmon.*.out
-do
-    tempfiles "$exe" gprof_output.txt
-    exe="`basename "$f" .out`.exe"
-    if [ ! -f "$exe" ]; then
-        buildid=`echo "$f" | cut -f2 -d.`
-        if ! testrun ${abs_top_builddir}/debuginfod/debuginfod-find -v executable $buildid; then
-            echo "$exe not found, skipping"
-            continue
-        fi
-        ln -s "`${abs_top_builddir}/debuginfod/debuginfod-find executable $buildid`" "$exe"
-    fi
-    exe_info="$exe (`readlink $exe`)"
-    # try a plain gprof run on the executable
-    if gprof "$exe" "$f" > gprof_output.txt 2>&1; then
-        echo "$exe_info"
-        cat gprof_output.txt
-        continue
-    fi
-    # else fall back to debuginfod
-    if ! testrun ${abs_top_builddir}/debuginfod/debuginfod-find -v debuginfo $exe; then
-        echo "$exe_info is a stripped binary, debuginfo not found, skipping"
-        continue
-    fi
-    debuginfo="`${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $exe`"
-    echo "$exe_info"
-    gprof "$debuginfo" "$f"
-done
+stackprof_check_gmon_out
 
 exit 0
index e9d3e4df4615dd8c5cb90f016a4354207528c082..cb796a7193e1cb73ca822ba848822a1d00c6122e 100755 (executable)
 # 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/stackprof-subr.sh
 
-. $srcdir/test-subr.sh
+set -x
+unset VALGRIND_CMD
 
 # prerequisites
 type timeout 2>/dev/null || (echo "no timeout installed"; exit 77)
-expr `whoami` = "root" || (echo "run as root"; exit 77)
+check_perf_event_open || (echo "perf_event_open fails (check kernel.perf_event_paranoid + kernel config)"; exit 77)
+expr `whoami` = "root" || (echo "not running 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
 
+# run systemwide scan, no gprof output
+testrun timeout -p --kill-after=5 10 ${abs_top_builddir}/src/stackprof -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
+grep "Starting stack profile collection systemwide" test.out || (grep "ERROR: Unsupported architecture" test.out && echo "unsupported arch" && exit 77)
+grep -E "^[0-9]+ " test.out # -- pid / sample counts entries
 
+# run systemwide scan again, with gprof output
+# reduce verbosity, bump post-processing timeout compared to the first run
+testrun timeout -p --kill-after=10 15 ${abs_top_builddir}/src/stackprof -g 2>&1 | tee test.out
 tempfiles gmon.*
-grep "^perf_event_attr configuration type=1 config=0 sample_freq=" test.out
+grep "^perf_event_attr configuration" test.out
 grep "Starting stack profile collection systemwide" test.out
 grep -E "^buildid [0-9a-f]+" test.out
 
-
 exit 0
index c3cb2121cf17a0687490542ebfa4fd6b860e2d43..9360f8b8895cdf7a0f306baf3983efade3834aee 100755 (executable)
 # 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/stackprof-subr.sh
 
-. $srcdir/test-subr.sh
+set -x
+unset VALGRIND_CMD
 
 # prerequisites
 type timeout 2>/dev/null || (echo "no timeout installed"; exit 77)
 type gprof 2>/dev/null || (echo "no gprof installed"; exit 77)
+check_perf_event_open || (echo "perf_event_open fails (check kernel.perf_event_paranoid + kernel config)"; 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
+
+# run on single executable, with gprof output
+testrun ${abs_top_builddir}/src/stackprof -v -g -- timeout 2 /bin/sh -c "while true; do true; done" 2>&1 | tee test.out
 tempfiles gmon.*
 grep "^perf_event_attr configuration" test.out
-grep "Starting stack profile collection pid" test.out
+grep "Starting stack profile collection pid" test.out || (grep "ERROR: Unsupported architecture" test.out && echo "unsupported arch" && exit 77)
 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
+stackprof_debuginfod_setup
+stackprof_check_gmon_out
 
 exit 0
index 775a95ffa02ec44fd54dbeb42ecb0fb65ec48f2e..722b7b02aa8eb51cce379432daf2198463b52adb 100755 (executable)
 # 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/stackprof-subr.sh
 
-. $srcdir/test-subr.sh
+set -x
+unset VALGRIND_CMD
 
 # prerequisites
 type timeout 2>/dev/null || (echo "no timeout installed"; exit 77)
+check_perf_event_open || (echo "perf_event_open fails (check kernel.perf_event_paranoid + kernel config)"; 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
 
+# run on single executable, no gprof output
+testrun ${abs_top_builddir}/src/stackprof -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
+grep "Starting stack profile collection pid" test.out || (grep "ERROR: Unsupported architecture" test.out && echo "unsupported arch" && exit 77)
+grep -E "^[0-9]+ sh --" test.out # -- pid / sample counts entries
 
+# run on single executable again, with gprof output
+testrun ${abs_top_builddir}/src/stackprof -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.*
-
+rm -f gmon.*
 
+# test libpfm event listing
 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
-
+    # run on single executable, with libpfm
+    testrun ${abs_top_builddir}/src/stackprof -v -e perf::BRANCHES:freq=4000 -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
index 7d3bca973fc973066499182f92b2beb77232d5a6..0b4d4e45e7862a25ec00472f74cf68d736dc5aa5 100644 (file)
@@ -17,7 +17,6 @@
 # sourced from run-stackprof-*.sh tests (must be bash scripts)
 
 . $srcdir/test-subr.sh
-# TODO . $srcdir/debuginfod-subr.sh ??
 
 check_perf_event_open() {
     tempfiles perf-test.out
@@ -30,7 +29,38 @@ check_perf_event_open() {
 }
 
 stackprof_debuginfod_setup() {
-    # TODO non networked version
+    # uncomment to test with networked debuginfod
     #export DEBUGINFOD_URLS=https://debuginfod.elfutils.org/
     return 0
 }
+
+stackprof_check_gmon_out() {
+    for f in gmon.*.out
+    do
+        exe="`basename "$f" .out`.exe"
+        if [ ! -f "$exe" ]; then
+            buildid=`echo "$f" | cut -f2 -d.`
+            if ! testrun ${abs_top_builddir}/debuginfod/debuginfod-find -v executable $buildid; then
+                echo "$exe not found, skipping"
+                continue
+            fi
+            ln -s "`${abs_top_builddir}/debuginfod/debuginfod-find executable $buildid`" "$exe"
+        fi
+        tempfiles "$exe" gprof_output.txt
+        exe_info="$exe (`readlink $exe`)"
+        # try a plain gprof run on the executable
+        if gprof "$exe" "$f" > gprof_output.txt 2>&1; then
+            echo "$exe_info"
+            cat gprof_output.txt
+            continue
+        fi
+        # else fall back to debuginfod
+        if ! testrun ${abs_top_builddir}/debuginfod/debuginfod-find -v debuginfo $exe; then
+            echo "$exe_info is a stripped binary, debuginfo not found, skipping"
+            continue
+        fi
+        debuginfo="`${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $exe`"
+        echo "$exe_info"
+        gprof "$debuginfo" "$f"
+    done
+}