Thread (9 messages) 9 messages, 3 authors, 2021-09-23

Re: [PATCH 3/3] perf tests: Improve temp file cleanup in test_arm_coresight.sh

From: James Clark <hidden>
Date: 2021-09-22 13:41:14
Also in: lkml


On 22/09/2021 12:00, Leo Yan wrote:
On Tue, Sep 21, 2021 at 02:10:09PM +0100, James Clark wrote:
quoted
Cleanup perf.data.old files which are also dropped by perf, handle
sigint and propagate it to the parent in case the test is run in a bash
while loop and don't create the temp files if the test will be skipped.

Signed-off-by: James Clark <redacted>
---
 tools/perf/tests/shell/test_arm_coresight.sh | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/tools/perf/tests/shell/test_arm_coresight.sh b/tools/perf/tests/shell/test_arm_coresight.sh
index c9eef0bba6f1..6de53b7ef5ff 100755
--- a/tools/perf/tests/shell/test_arm_coresight.sh
+++ b/tools/perf/tests/shell/test_arm_coresight.sh
@@ -9,8 +9,6 @@
 # SPDX-License-Identifier: GPL-2.0
 # Leo Yan <leo.yan@linaro.org>, 2020
 
-perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
-file=$(mktemp /tmp/temporary_file.XXXXX)
 glb_err=0
 
 skip_if_no_cs_etm_event() {
@@ -22,13 +20,20 @@ skip_if_no_cs_etm_event() {
 
 skip_if_no_cs_etm_event || exit 2
 
+perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
+file=$(mktemp /tmp/temporary_file.XXXXX)
+
 cleanup_files()
 {
 	rm -f ${perfdata}
 	rm -f ${file}
+	rm -f "${perfdata}.old"
+	trap - exit term int
+	kill -2 $$
Here it always sends signal SIGINT to current PID with $$, another
choice is to send signal based on the incoming signal type, like below:

  [[ "$1" = "int" ]] || kill -SIGINT $$
  [[ "$1" = "term" ]] || kill -SIGTERM $$
Yes I thought that this might be an issue, but I tested it in a few different
scenarios. Especially when running it under the normal ./perf test command and
it didn't seem to cause an issue whether it passed or failed. So I'm not sure
if it's worth changing or not. Maybe it is in case it gets copy pasted into
another shell test?

James
If you think the current change is sufficient to meet the testing
requirement, then this patch would be fine for me either:

Reviewed-by: Leo Yan <redacted>
quoted
+	exit $glb_err
 }
 
-trap cleanup_files exit
+trap cleanup_files exit term int
 
 record_touch_file() {
 	echo "Recording trace (only user mode) with path: CPU$2 => $1"
-- 
2.28.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help