From 83086b59737352e38e66fbfa0f203405cff5dd90 Mon Sep 17 00:00:00 2001 From: Michal Berger Date: Wed, 29 Jan 2020 00:45:16 +0100 Subject: [PATCH] test/blobfs: Refactor exit behavior The on_error_exit() function was being called via the local ERR trap to cleanup after the tests in case any failure occurred during the execution. However, this was masking the backtrace trap so the on_error_exit() had to also call print_backtrace() to compensate - this was resulting in an additional function being unnecessarily placed onto the stack and included in the actual backtrace. Avoid the above by refactoring on_error_exit() into simple cleanup() function called upon exit()ing from the script. The rationale is that cleanup has to happen regardless if the script failed or not and elements like $conf_file are always created from the very scratch by the script itself anyway prior running the tests. Change-Id: I6bb8f4155525037624f0bd5aab288f8c502141f6 Signed-off-by: Michal Berger Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/456 Tested-by: SPDK CI Jenkins Reviewed-by: Darek Stojaczyk Reviewed-by: Ben Walker Reviewed-by: Shuhei Matsumoto --- test/blobfs/blobfs.sh | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/test/blobfs/blobfs.sh b/test/blobfs/blobfs.sh index 3e3cf3372..820818325 100755 --- a/test/blobfs/blobfs.sh +++ b/test/blobfs/blobfs.sh @@ -18,16 +18,14 @@ test_cache_size=512 source $rootdir/test/common/autotest_common.sh -function on_error_exit() { - if [ -n "$blobfs_pid" ]; then +function cleanup() { + if [[ -n $blobfs_pid && -e /proc/$blobfs_pid ]]; then killprocess $blobfs_pid fi rm -rf $mount_dir rm -f $tmp_file rm -f $conf_file - print_backtrace - exit 1 } function blobfs_start_app { @@ -122,7 +120,7 @@ function blobfs_fuse_test() { killprocess $blobfs_pid } -trap 'on_error_exit;' ERR +trap 'cleanup' EXIT # Create one temp file as test bdev dd if=/dev/zero of=${tmp_file} bs=4k count=1M @@ -139,7 +137,3 @@ blobfs_create_test # Create dir for FUSE mount mkdir -p $mount_dir blobfs_fuse_test - - -rm -rf $mount_dir -rm -f $tmp_file