[3/4] gprofng: testsuite coverage for HW-counter precision markings

Message ID 20260626113840.44715-4-claziss@gmail.com
State New
Headers
Series gprofng: Improve HW counter markings and documentation |

Commit Message

Claudiu Zissulescu June 26, 2026, 11:33 a.m. UTC
  Add two DejaGnu tests that pin the user-facing output added by the
previous two commits.

hwc_listing.exp verifies that "gprofng collect app -h" groups counters
into "Precise events" and "Standard events" sections, and that precise
counters carry the "memoryspace (precise)" type tag.

hwc_precision_marker.exp records an HW-counter experiment with the
default counter set, runs "display text", and asserts that the column
header marker "(*)" and the explanatory footnote. A marker without a
footnote, or vice versa, is a regression.

gprofng/
	* testsuite/gprofng.display/hwc_listing.exp: New test.
	* testsuite/gprofng.display/hwc_precision_marker.exp: New test.
---
 .../testsuite/gprofng.display/hwc_listing.exp | 60 ++++++++++++++++
 .../gprofng.display/hwc_precision_marker.exp  | 72 +++++++++++++++++++
 2 files changed, 132 insertions(+)
 create mode 100644 gprofng/testsuite/gprofng.display/hwc_listing.exp
 create mode 100644 gprofng/testsuite/gprofng.display/hwc_precision_marker.exp
  

Patch

diff --git a/gprofng/testsuite/gprofng.display/hwc_listing.exp b/gprofng/testsuite/gprofng.display/hwc_listing.exp
new file mode 100644
index 00000000000..c70b7ea8695
--- /dev/null
+++ b/gprofng/testsuite/gprofng.display/hwc_listing.exp
@@ -0,0 +1,60 @@ 
+# Copyright (C) 2026 Free Software Foundation, Inc.
+#
+# This file is part of the GNU Binutils.
+#
+# 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 this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
+#
+
+# Verify that "gprofng collect app -h" groups the available HW counters
+# into a "Precise events" section and a "Standard events" section, and
+# tags precise counters as "memoryspace (precise)" in the type column.
+# This pins the user-facing output added to gprofng/common/hwctable.c
+# so a future refactor cannot silently drop the section split.
+
+set gprofng $::env(GPROFNG)
+set testname "hwc_listing"
+
+set output [run_native_host_cmd "$gprofng collect app -h"]
+set out [lindex $output 1]
+
+if { [string first "not supported on this system" $out] >= 0 } then {
+    unsupported $testname
+    return
+}
+
+# Standard events block is always emitted when any counter is listed.
+if { [string first "Standard events" $out] < 0 } then {
+    send_log "missing 'Standard events' section in -h output:\n$out\n"
+    fail $testname
+    return
+}
+
+# If any precise counters are present (type column shows "memoryspace"),
+# the "(precise)" tag and the "Precise events" heading must both appear.
+if { [string first "memoryspace" $out] >= 0 } then {
+    if { [string first "memoryspace (precise)" $out] < 0 } then {
+	send_log "'memoryspace' type without '(precise)' tag:\n$out\n"
+	fail $testname
+	return
+    }
+    if { [string first "Precise events" $out] < 0 } then {
+	send_log "missing 'Precise events' heading despite memoryspace counters:\n$out\n"
+	fail $testname
+	return
+    }
+}
+
+pass $testname
diff --git a/gprofng/testsuite/gprofng.display/hwc_precision_marker.exp b/gprofng/testsuite/gprofng.display/hwc_precision_marker.exp
new file mode 100644
index 00000000000..0d38b7b3f83
--- /dev/null
+++ b/gprofng/testsuite/gprofng.display/hwc_precision_marker.exp
@@ -0,0 +1,72 @@ 
+# Copyright (C) 2026 Free Software Foundation, Inc.
+#
+# This file is part of the GNU Binutils.
+#
+# 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 this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
+#
+
+# Verify that "display text" on an HW-counter experiment marks
+# non-precise counter columns with " (*)" and emits the explanatory
+# footnote.  This pins the behavior introduced in gprofng/src/Metric.cc
+# and gprofng/src/Print.cc that addresses the most common user
+# confusion (cache misses attributed to a loop-header line because of
+# PMU skid).
+
+global srcdir CC CLOCK_GETTIME_LINK
+set gprofng $::env(GPROFNG)
+set testname "hwc_precision_marker"
+set tdir "tmpdir/hwc_precision_marker"
+
+run_native_host_cmd "mkdir -p $tdir"
+
+# Build and try to record with the default HW counter set.  If the
+# host has no PMU access the collect step will fail with a message
+# containing "not supported"; treat that as unsupported, not a fail.
+set output [run_native_host_cmd "cd $tdir && \
+  cp $srcdir/lib/smalltest.c t.c && \
+  $CC -g t.c $CLOCK_GETTIME_LINK && \
+  $gprofng collect app -p off -h on -a off -O exp.er ./a.out"]
+set status [lindex $output 0]
+set out [lindex $output 1]
+if { $status != 0 } then {
+    if { [string first "not supported" $out] >= 0 \
+	 || [string first "HW counter" $out] >= 0 \
+	 || [string first "perf_event" $out] >= 0 } then {
+	unsupported $testname
+	return
+    }
+    send_log "collect with -h on failed unexpectedly:\n$out\n"
+    fail $testname
+    return
+}
+
+set output [run_native_host_cmd "$gprofng display text -functions $tdir/exp.er"]
+set out [lindex $output 1]
+
+set have_mark	  [expr {[string first "(*)" $out] >= 0}]
+set have_footnote [expr {[string first "Non-precise HW event:" $out] >= 0}]
+
+# The marker and the footnote must be consistent.  Both present means a
+# non-precise counter was selected and explained; both absent means the
+# default set was entirely precise (rare but valid).  One without the
+# other is a regression.
+if { $have_mark != $have_footnote } then {
+    send_log "marker/footnote inconsistency (mark=$have_mark footnote=$have_footnote):\n$out\n"
+    fail $testname
+    return
+}
+
+pass $testname