linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	 Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	 Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>,  Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	 James Clark <james.clark@linaro.org>,
	Collin Funk <collin.funk1@gmail.com>,
	 Dmitry Vyukov <dvyukov@google.com>,
	Andi Kleen <ak@linux.intel.com>,
	 Thomas Falcon <thomas.falcon@intel.com>,
	Leo Yan <leo.yan@arm.com>,
	 Yicong Yang <yangyicong@hisilicon.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	 "Masami Hiramatsu (Google)" <mhiramat@kernel.org>,
	Stephen Brennan <stephen.s.brennan@oracle.com>,
	 Haibo Xu <haibo1.xu@intel.com>,
	linux-kernel@vger.kernel.org,  linux-perf-users@vger.kernel.org
Subject: [PATCH v1 11/17] perf tests buildid: Add purge and remove testing
Date: Sat, 22 Nov 2025 00:19:23 -0800	[thread overview]
Message-ID: <20251122081929.7588-12-irogers@google.com> (raw)
In-Reply-To: <20251122081929.7588-1-irogers@google.com>

Add testing for the purge and remove commands. Use the noploop
workload rather than just a return to avoid missing samples in the
workload in perf record. Tidy up the cleanup code to cleanup when
signals happen.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/tests/shell/buildid.sh | 203 ++++++++++++++++++++++++++----
 1 file changed, 177 insertions(+), 26 deletions(-)

diff --git a/tools/perf/tests/shell/buildid.sh b/tools/perf/tests/shell/buildid.sh
index d2eb213da01d..102808cca9db 100755
--- a/tools/perf/tests/shell/buildid.sh
+++ b/tools/perf/tests/shell/buildid.sh
@@ -36,16 +36,69 @@ if [ ${run_pe} -eq 1 ]; then
 	unset WAYLAND_DISPLAY
 fi
 
-ex_md5=$(mktemp /tmp/perf.ex.MD5.XXX)
-ex_sha1=$(mktemp /tmp/perf.ex.SHA1.XXX)
+build_id_dir=
+ex_source=$(mktemp /tmp/perf_buildid_test.ex.XXX.c)
+ex_md5=$(mktemp /tmp/perf_buildid_test.ex.MD5.XXX)
+ex_sha1=$(mktemp /tmp/perf_buildid_test.ex.SHA1.XXX)
 ex_pe=$(dirname $0)/../pe-file.exe
+data=$(mktemp /tmp/perf_buildid_test.data.XXX)
+log_out=$(mktemp /tmp/perf_buildid_test.log.out.XXX)
+log_err=$(mktemp /tmp/perf_buildid_test.log.err.XXX)
 
-echo 'int main(void) { return 0; }' | cc -Wl,--build-id=sha1 -o ${ex_sha1} -x c -
-echo 'int main(void) { return 0; }' | cc -Wl,--build-id=md5 -o ${ex_md5} -x c -
+cleanup() {
+	rm -f ${ex_source} ${ex_md5} ${ex_sha1} ${data} ${log_out} ${log_err}
+	if [ ${run_pe} -eq 1 ]; then
+		rm -r ${wineprefix}
+	fi
+        if [ -d ${build_id_dir} ]; then
+		rm -rf ${build_id_dir}
+        fi
+	trap - EXIT TERM INT
+}
+
+trap_cleanup() {
+	echo "Unexpected signal in ${FUNCNAME[1]}"
+	cleanup
+	exit 1
+}
+trap trap_cleanup EXIT TERM INT
+
+# Test program based on the noploop workload.
+cat <<EOF > ${ex_source}
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
 
+static volatile sig_atomic_t done;
+
+static void sighandler(int sig)
+{
+	(void)sig;
+	done = 1;
+}
+
+int main(int argc, const char **argv)
+{
+	int sec = 1;
+
+	if (argc > 1)
+		sec = atoi(argv[1]);
+
+	signal(SIGINT, sighandler);
+	signal(SIGALRM, sighandler);
+	alarm(sec);
+
+	while (!done)
+		continue;
+
+	return 0;
+}
+EOF
+cc -Wl,--build-id=sha1 ${ex_source} -o ${ex_sha1} -x c -
+cc -Wl,--build-id=md5 ${ex_source} -o ${ex_md5} -x c -
 echo "test binaries: ${ex_sha1} ${ex_md5} ${ex_pe}"
 
-check()
+get_build_id()
 {
 	case $1 in
 	*.exe)
@@ -64,6 +117,15 @@ check()
 		id=`readelf -n ${1} 2>/dev/null | grep 'Build ID' | awk '{print $3}'`
 		;;
 	esac
+	echo ${id}
+}
+
+check()
+{
+	file=$1
+	perf_data=$2
+
+	id=$(get_build_id $file)
 	echo "build id: ${id}"
 
 	id_file=${id#??}
@@ -76,45 +138,53 @@ check()
 		exit 1
 	fi
 
-	file=${build_id_dir}/.build-id/$id_dir/`readlink ${link}`/elf
-	echo "file: ${file}"
+	cached_file=${build_id_dir}/.build-id/$id_dir/`readlink ${link}`/elf
+	echo "file: ${cached_file}"
 
 	# Check for file permission of original file
 	# in case of pe-file.exe file
 	echo $1 | grep ".exe"
 	if [ $? -eq 0 ]; then
-		if [ -x $1 ] && [ ! -x $file ]; then
-			echo "failed: file ${file} executable does not exist"
+		if [ -x $1 ] && [ ! -x $cached_file ]; then
+			echo "failed: file ${cached_file} executable does not exist"
 			exit 1
 		fi
 
-		if [ ! -x $file ] && [ ! -e $file ]; then
-			echo "failed: file ${file} does not exist"
+		if [ ! -x $cached_file ] && [ ! -e $cached_file ]; then
+			echo "failed: file ${cached_file} does not exist"
 			exit 1
 		fi
-	elif [ ! -x $file ]; then
-		echo "failed: file ${file} does not exist"
+	elif [ ! -x $cached_file ]; then
+		echo "failed: file ${cached_file} does not exist"
 		exit 1
 	fi
 
-	diff ${file} ${1}
+	diff ${cached_file} ${1}
 	if [ $? -ne 0 ]; then
-		echo "failed: ${file} do not match"
+		echo "failed: ${cached_file} do not match"
 		exit 1
 	fi
 
-	${perf} buildid-cache -l | grep ${id}
+	${perf} buildid-cache -l | grep -q ${id}
 	if [ $? -ne 0 ]; then
 		echo "failed: ${id} is not reported by \"perf buildid-cache -l\""
 		exit 1
 	fi
 
+	if [ -n "${perf_data}" ]; then
+		${perf} buildid-list -i ${perf_data} | grep -q ${id}
+		if [ $? -ne 0 ]; then
+			echo "failed: ${id} is not reported by \"perf buildid-list -i ${perf_data}\""
+			exit 1
+		fi
+	fi
+
 	echo "OK for ${1}"
 }
 
 test_add()
 {
-	build_id_dir=$(mktemp -d /tmp/perf.debug.XXX)
+	build_id_dir=$(mktemp -d /tmp/perf_buildid_test.debug.XXX)
 	perf="perf --buildid-dir ${build_id_dir}"
 
 	${perf} buildid-cache -v -a ${1}
@@ -128,12 +198,88 @@ test_add()
 	rm -rf ${build_id_dir}
 }
 
+test_remove()
+{
+	build_id_dir=$(mktemp -d /tmp/perf_buildid_test.debug.XXX)
+	perf="perf --buildid-dir ${build_id_dir}"
+
+	${perf} buildid-cache -v -a ${1}
+	if [ $? -ne 0 ]; then
+		echo "failed: add ${1} to build id cache"
+		exit 1
+	fi
+
+	id=$(get_build_id ${1})
+	if ! ${perf} buildid-cache -l | grep -q ${id}; then
+		echo "failed: ${id} not in cache"
+		exit 1
+	fi
+
+	${perf} buildid-cache -v -r ${1}
+	if [ $? -ne 0 ]; then
+		echo "failed: remove ${id} from build id cache"
+		exit 1
+	fi
+
+	if ${perf} buildid-cache -l | grep -q ${id}; then
+		echo "failed: ${id} still in cache after remove"
+		exit 1
+	fi
+
+	echo "remove: OK"
+	rm -rf ${build_id_dir}
+}
+
+test_purge()
+{
+	build_id_dir=$(mktemp -d /tmp/perf_buildid_test.debug.XXX)
+	perf="perf --buildid-dir ${build_id_dir}"
+
+	id1=$(get_build_id ${ex_sha1})
+	${perf} buildid-cache -v -a ${ex_sha1}
+	if ! ${perf} buildid-cache -l | grep -q ${id1}; then
+		echo "failed: ${id1} not in cache"
+		exit 1
+	fi
+
+	id2=$(get_build_id ${ex_md5})
+	${perf} buildid-cache -v -a ${ex_md5}
+	if ! ${perf} buildid-cache -l | grep -q ${id2}; then
+		echo "failed: ${id2} not in cache"
+		exit 1
+	fi
+
+	# Purge by path
+	${perf} buildid-cache -v -p ${ex_sha1}
+	if [ $? -ne 0 ]; then
+		echo "failed: purge build id cache of ${ex_sha1}"
+		exit 1
+	fi
+
+	${perf} buildid-cache -v -p ${ex_md5}
+	if [ $? -ne 0 ]; then
+		echo "failed: purge build id cache of ${ex_md5}"
+		exit 1
+	fi
+
+	# Verify both are gone
+	if ${perf} buildid-cache -l | grep -q ${id1}; then
+		echo "failed: ${id1} still in cache after purge"
+		exit 1
+	fi
+
+	if ${perf} buildid-cache -l | grep -q ${id2}; then
+		echo "failed: ${id2} still in cache after purge"
+		exit 1
+	fi
+
+	echo "purge: OK"
+	rm -rf ${build_id_dir}
+}
+
 test_record()
 {
-	data=$(mktemp /tmp/perf.data.XXX)
-	build_id_dir=$(mktemp -d /tmp/perf.debug.XXX)
-	log_out=$(mktemp /tmp/perf.log.out.XXX)
-	log_err=$(mktemp /tmp/perf.log.err.XXX)
+	build_id_dir=$(mktemp -d /tmp/perf_buildid_test.debug.XXX)
 	perf="perf --buildid-dir ${build_id_dir}"
 
 	echo "running: perf record $*"
@@ -145,7 +291,7 @@ test_record()
 	fi
 
 	args="$*"
-	check ${args##* }
+	check ${args##* } ${data}
 
 	rm -f ${log_out} ${log_err}
 	rm -rf ${build_id_dir}
@@ -166,10 +312,15 @@ if [ ${run_pe} -eq 1 ]; then
 	test_record wine ${ex_pe}
 fi
 
-# cleanup
-rm ${ex_sha1} ${ex_md5}
-if [ ${run_pe} -eq 1 ]; then
-	rm -r ${wineprefix}
+# remove binaries manually via perf buildid-cache -r
+test_remove ${ex_sha1}
+test_remove ${ex_md5}
+if [ ${add_pe} -eq 1 ]; then
+	test_remove ${ex_pe}
 fi
 
+# purge binaries manually via perf buildid-cache -p
+test_purge
+
+cleanup
 exit 0
-- 
2.52.0.rc2.455.g230fcf2819-goog


  parent reply	other threads:[~2025-11-22  8:19 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-22  8:19 [PATCH v1 00/17] perf: Small fixes and new tests Ian Rogers
2025-11-22  8:19 ` [PATCH v1 01/17] perf kvm: Fix debug assertion Ian Rogers
2025-11-26  6:33   ` Namhyung Kim
2025-11-22  8:19 ` [PATCH v1 02/17] perf timechart: Add record support for output perf.data path Ian Rogers
2025-11-26  6:38   ` Namhyung Kim
2025-11-22  8:19 ` [PATCH v1 03/17] perf symbol-elf: Add missing puts on error path Ian Rogers
2025-12-01 18:04   ` Arnaldo Carvalho de Melo
2025-11-22  8:19 ` [PATCH v1 04/17] perf symbol: Add missed dso__put Ian Rogers
2025-11-22  8:19 ` [PATCH v1 05/17] perf probe-event: Ensure probe event nsinfo is always cleared Ian Rogers
2025-11-26  6:58   ` Namhyung Kim
2025-11-22  8:19 ` [PATCH v1 06/17] perf hist: In init, ensure mem_info is put on error paths Ian Rogers
2025-12-01 17:05   ` Arnaldo Carvalho de Melo
2025-12-01 17:14   ` Arnaldo Carvalho de Melo
2025-12-01 17:52     ` Ian Rogers
2025-11-22  8:19 ` [PATCH v1 07/17] perf mem-events: Don't leak online CPU map Ian Rogers
2025-12-01 17:01   ` Arnaldo Carvalho de Melo
2025-11-22  8:19 ` [PATCH v1 08/17] perf jitdump: Fix missed dso__put Ian Rogers
2025-12-01 17:00   ` Arnaldo Carvalho de Melo
2025-11-22  8:19 ` [PATCH v1 09/17] perf c2c: Clean up some defensive gets and make asan clean Ian Rogers
2025-12-01 17:45   ` Arnaldo Carvalho de Melo
2025-11-22  8:19 ` [PATCH v1 10/17] perf tests c2c: Add a basic c2c Ian Rogers
2025-11-22  8:19 ` Ian Rogers [this message]
2025-11-22  8:19 ` [PATCH v1 12/17] perf tests top: Add basic perf top coverage test Ian Rogers
2025-11-22  8:19 ` [PATCH v1 13/17] perf tests timechart: Add a perf timechart test Ian Rogers
2025-11-22  8:19 ` [PATCH v1 14/17] perf tests kallsyms: Add basic kallsyms test Ian Rogers
2025-11-22  8:19 ` [PATCH v1 15/17] perf tests script dlfilter: Add a dlfilter test Ian Rogers
2025-11-22  8:19 ` [PATCH v1 16/17] perf tests evlist: Add basic evlist test Ian Rogers
2025-11-26  7:19   ` Namhyung Kim
2025-11-22  8:19 ` [PATCH v1 17/17] perf test kvm: Add some basic perf kvm test coverage Ian Rogers
2025-11-26  7:21   ` Namhyung Kim
2025-11-27 11:53     ` Ian Rogers
2025-11-27 20:55       ` Namhyung Kim
2025-11-28  9:06         ` Ian Rogers
2025-12-03 19:03           ` Namhyung Kim
2025-12-04 19:10 ` [PATCH v1 00/17] perf: Small fixes and new tests Namhyung Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251122081929.7588-12-irogers@google.com \
    --to=irogers@google.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=collin.funk1@gmail.com \
    --cc=dvyukov@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=haibo1.xu@intel.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=leo.yan@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=stephen.s.brennan@oracle.com \
    --cc=thomas.falcon@intel.com \
    --cc=yangyicong@hisilicon.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).