From 7d06a7e561b72e04691b985be3b67221eb32e19b Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 15 Sep 2022 16:02:09 +0200 Subject: [PATCH] btrfs-progs: tests: use _mktemp_local for temporary files Signed-off-by: David Sterba --- tests/cli-tests/012-defrag-recursion/test.sh | 4 +--- .../031-metadatadump-check-data-csum/test.sh | 3 +-- tests/fsck-tests/059-shrunk-device/test.sh | 3 +-- tests/misc-tests/016-send-clone-src/test.sh | 3 +-- tests/misc-tests/018-recv-end-of-stream/test.sh | 14 ++++++-------- .../026-image-non-printable-chars/test.sh | 5 +++-- .../035-receive-common-mount-point-prefix/test.sh | 9 +++------ tests/misc-tests/037-fi-show-on-new-file/test.sh | 10 ++++------ .../041-subvolume-delete-during-send/test.sh | 4 +--- tests/misc-tests/050-receive-prop-ro-to-rw/test.sh | 4 ++-- .../051-warning-rw-subvol-received-uuid/test.sh | 4 ++-- tests/misc-tests/053-receive-write-encoded/test.sh | 3 +-- tests/misc-tests/054-receive-dump-newlines/test.sh | 3 +-- .../005-long-device-name-for-ssd/test.sh | 4 +--- tests/mkfs-tests/006-partitioned-loopdev/test.sh | 4 +--- .../test.sh | 3 +-- 16 files changed, 30 insertions(+), 50 deletions(-) diff --git a/tests/cli-tests/012-defrag-recursion/test.sh b/tests/cli-tests/012-defrag-recursion/test.sh index d7f6b80c..a5737cf6 100755 --- a/tests/cli-tests/012-defrag-recursion/test.sh +++ b/tests/cli-tests/012-defrag-recursion/test.sh @@ -13,9 +13,7 @@ prepare_test_dev run_check_mkfs_test_dev run_check_mount_test_dev -run_check truncate -s 0 img2 -run_check truncate -s 1G img2 -chmod a+w img2 +_mktemp_local img2 1G # create second mount with btrfs, create a file in the target mount path, the # mount must hide that diff --git a/tests/fsck-tests/031-metadatadump-check-data-csum/test.sh b/tests/fsck-tests/031-metadatadump-check-data-csum/test.sh index 1590ce6d..b4b27d39 100755 --- a/tests/fsck-tests/031-metadatadump-check-data-csum/test.sh +++ b/tests/fsck-tests/031-metadatadump-check-data-csum/test.sh @@ -16,8 +16,7 @@ run_check_mount_test_dev run_check $SUDO_HELPER dd if=/dev/urandom of="$TEST_MNT/file" bs=4k count=16 run_check_umount_test_dev -touch restored_image -chmod a+w restored_image +_mktemp_local restored_image run_check $SUDO_HELPER "$TOP/btrfs-image" "$TEST_DEV" "restored_image" # use prepare_test_dev() to wipe all existing data on $TEST_DEV diff --git a/tests/fsck-tests/059-shrunk-device/test.sh b/tests/fsck-tests/059-shrunk-device/test.sh index d770f3d3..140ee3a4 100755 --- a/tests/fsck-tests/059-shrunk-device/test.sh +++ b/tests/fsck-tests/059-shrunk-device/test.sh @@ -10,8 +10,7 @@ setup_root_helper file="img" # Allocate an initial 1G file for testing. -truncate -s0 "$file" -truncate -s1g "$file" +_mktemp_local "$file" 1g dev=$(run_check_stdout $SUDO_HELPER losetup --find --show "$file") diff --git a/tests/misc-tests/016-send-clone-src/test.sh b/tests/misc-tests/016-send-clone-src/test.sh index 1dbad6f4..a0ed6f30 100755 --- a/tests/misc-tests/016-send-clone-src/test.sh +++ b/tests/misc-tests/016-send-clone-src/test.sh @@ -29,8 +29,7 @@ for i in 1 2 3; do run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r subv-parent2 subv-snap2_$i done -truncate -s0 "$here"/send-stream.img -chmod a+w "$here"/send-stream.img +_mktemp_local "$here/send-stream.img" run_check $SUDO_HELPER "$TOP/btrfs" send -f "$here"/send-stream.img \ -c subv-snap1_1 -c subv-snap2_1 subv-snap1_[23] subv-snap2_[23] diff --git a/tests/misc-tests/018-recv-end-of-stream/test.sh b/tests/misc-tests/018-recv-end-of-stream/test.sh index 1acb2ad7..ea0dacf8 100755 --- a/tests/misc-tests/018-recv-end-of-stream/test.sh +++ b/tests/misc-tests/018-recv-end-of-stream/test.sh @@ -27,8 +27,7 @@ test_full_empty_stream() { run_check $SUDO_HELPER "$TOP/btrfs" subvolume create subv1 run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r subv1 subv1-snap - truncate -s0 "$str" - chmod a+w "$str" + _mktemp_local "$str" run_check $SUDO_HELPER "$TOP/btrfs" send -f "$str" subv1-snap cd "$here" || _fail "cannot chdir back to test directory" @@ -58,8 +57,7 @@ test_full_simple_stream() { run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r subv1 subv1-snap - truncate -s0 "$str" - chmod a+w "$str" + _mktemp_local "$str" run_check $SUDO_HELPER "$TOP/btrfs" send -f "$str" subv1-snap cd "$here" || _fail "cannot chdir back to test directory" @@ -88,8 +86,8 @@ test_incr_empty_stream() { run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r subv1 subv1-snap run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r subv1 subv2-snap - truncate -s0 "$fstr" "$istr" - chmod a+w "$fstr" "$istr" + _mktemp_local "$fstr" + _mktemp_local "$istr" run_check $SUDO_HELPER "$TOP/btrfs" send -f "$fstr" subv1-snap run_check $SUDO_HELPER "$TOP/btrfs" send -p subv1-snap -f "$istr" subv2-snap @@ -128,8 +126,8 @@ test_incr_simple_stream() { run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r subv1 subv2-snap - truncate -s0 "$fstr" "$istr" - chmod a+w "$fstr" "$istr" + _mktemp_local "$fstr" + _mktemp_local "$istr" run_check $SUDO_HELPER "$TOP/btrfs" send -f "$fstr" subv1-snap run_check $SUDO_HELPER "$TOP/btrfs" send -p subv1-snap -f "$istr" subv2-snap diff --git a/tests/misc-tests/026-image-non-printable-chars/test.sh b/tests/misc-tests/026-image-non-printable-chars/test.sh index 5a25183c..23ec515e 100755 --- a/tests/misc-tests/026-image-non-printable-chars/test.sh +++ b/tests/misc-tests/026-image-non-printable-chars/test.sh @@ -18,8 +18,9 @@ touch "$TEST_MNT/|5gp!" run_check_umount_test_dev -run_check touch img img.restored img.dump -run_check chmod a+w img img.restored img.dump +_mktemp_local img +_mktemp_local img.restored +_mktemp_local img.dump run_check $SUDO_HELPER "$TOP/btrfs-image" -ss "$TEST_DEV" img run_check $SUDO_HELPER "$TOP/btrfs-image" -r img img.restored run_check_stdout $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-tree img.restored > img.dump diff --git a/tests/misc-tests/035-receive-common-mount-point-prefix/test.sh b/tests/misc-tests/035-receive-common-mount-point-prefix/test.sh index 538549a3..6617bd53 100755 --- a/tests/misc-tests/035-receive-common-mount-point-prefix/test.sh +++ b/tests/misc-tests/035-receive-common-mount-point-prefix/test.sh @@ -14,10 +14,8 @@ check_prereq mkfs.btrfs setup_root_helper -rm -f dev1 dev2 -run_check truncate -s 1G dev1 -run_check truncate -s 1G dev2 -chmod a+w dev1 dev2 +_mktemp_local dev1 1G +_mktemp_local dev2 1G loop1=$(run_check_stdout $SUDO_HELPER losetup --find --show dev1) loop2=$(run_check_stdout $SUDO_HELPER losetup --find --show dev2) @@ -35,8 +33,7 @@ echo "some data" | $SUDO_HELPER tee "$TEST_MNT/ddis/file" > /dev/null run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r \ "$TEST_MNT/ddis" "$TEST_MNT/ddis/snap" -run_check truncate -s 0 send.data -chmod a+w send.data +_mktemp_local send.data run_check $SUDO_HELPER "$TOP/btrfs" send -f send.data "$TEST_MNT/ddis/snap" # The following receive used to fail because it incorrectly determined the mount diff --git a/tests/misc-tests/037-fi-show-on-new-file/test.sh b/tests/misc-tests/037-fi-show-on-new-file/test.sh index 9a5b9857..37182feb 100755 --- a/tests/misc-tests/037-fi-show-on-new-file/test.sh +++ b/tests/misc-tests/037-fi-show-on-new-file/test.sh @@ -6,10 +6,8 @@ source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs -IMAGE=$(mktemp -u btrfs-progs-image.XXXXXX) +_mktemp_local img 3g +run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f img +run_check $SUDO_HELPER "$TOP/btrfs" filesystem show img -run_check truncate -s3g "$IMAGE" -run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$IMAGE" -run_check $SUDO_HELPER "$TOP/btrfs" filesystem show "$IMAGE" - -rm -f "$IMAGE" +rm -f img diff --git a/tests/misc-tests/041-subvolume-delete-during-send/test.sh b/tests/misc-tests/041-subvolume-delete-during-send/test.sh index 723d528a..f6649678 100755 --- a/tests/misc-tests/041-subvolume-delete-during-send/test.sh +++ b/tests/misc-tests/041-subvolume-delete-during-send/test.sh @@ -20,9 +20,7 @@ done run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r "$TEST_MNT/subv1" "$TEST_MNT/snap1" stream="stream$RANDOM.out" -rm -f -- "$stream" -touch -- "$stream" -chmod a+rw -- "$stream" +_mktemp_local "$stream" run_check "$TOP/btrfs" filesystem sync "$TEST_MNT" # Output to file must be slow run_check $SUDO_HELPER "$TOP/btrfs" send -f "$stream" "$TEST_MNT/snap1" & diff --git a/tests/misc-tests/050-receive-prop-ro-to-rw/test.sh b/tests/misc-tests/050-receive-prop-ro-to-rw/test.sh index fb1e0e64..cc826af9 100755 --- a/tests/misc-tests/050-receive-prop-ro-to-rw/test.sh +++ b/tests/misc-tests/050-receive-prop-ro-to-rw/test.sh @@ -21,8 +21,8 @@ for i in `seq 10`; do done run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r "$TEST_MNT/src/subvol1" "$TEST_MNT/src/snap2" -touch send1.stream send2.stream -chmod a+w send1.stream send2.stream +_mktemp_local send1.stream +_mktemp_local send2.stream run_check $SUDO_HELPER "$TOP/btrfs" send -f send1.stream "$TEST_MNT/src/snap1" run_check $SUDO_HELPER "$TOP/btrfs" send -f send2.stream -p "$TEST_MNT/src/snap1" "$TEST_MNT/src/snap2" diff --git a/tests/misc-tests/051-warning-rw-subvol-received-uuid/test.sh b/tests/misc-tests/051-warning-rw-subvol-received-uuid/test.sh index e1f44946..dc732b1a 100755 --- a/tests/misc-tests/051-warning-rw-subvol-received-uuid/test.sh +++ b/tests/misc-tests/051-warning-rw-subvol-received-uuid/test.sh @@ -34,9 +34,9 @@ if run_check_stdout $SUDO_HELPER "$TOP/btrfs" subvolume show "$TEST_MNT/snap1" | grep -q "WARNING.*received_uuid"; then _fail "unexpected warning" fi + run_check $SUDO_HELPER mkdir "$TEST_MNT/recv" -touch send.stream -chmod a+w send.stream +_mktemp_local send.stream run_check $SUDO_HELPER "$TOP/btrfs" send -f send.stream "$TEST_MNT/snap1" run_check $SUDO_HELPER "$TOP/btrfs" receive -f send.stream -m "$TEST_MNT" "$TEST_MNT/recv" if run_check_stdout $SUDO_HELPER "$TOP/btrfs" subvolume show "$TEST_MNT/recv/snap1" | diff --git a/tests/misc-tests/053-receive-write-encoded/test.sh b/tests/misc-tests/053-receive-write-encoded/test.sh index 75cfe9a1..790c95eb 100755 --- a/tests/misc-tests/053-receive-write-encoded/test.sh +++ b/tests/misc-tests/053-receive-write-encoded/test.sh @@ -31,8 +31,7 @@ send_one() { run_check_mount_test_dev "-o" "compress-force=$algorithm" cd "$TEST_MNT" || _fail "cannot chdir to TEST_MNT" - trucate -s0 "$file" - chmod a+w "$file" + _mktemp_local "$file" run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$subv" run_check $SUDO_HELPER dd if=/dev/zero of="$subv/file1" bs=1M count=1 diff --git a/tests/misc-tests/054-receive-dump-newlines/test.sh b/tests/misc-tests/054-receive-dump-newlines/test.sh index 0bb245a8..93d11bb7 100755 --- a/tests/misc-tests/054-receive-dump-newlines/test.sh +++ b/tests/misc-tests/054-receive-dump-newlines/test.sh @@ -28,8 +28,7 @@ failed link source" "$TEST_MNT/subv1/file failed link target" run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r "$TEST_MNT/subv1" "$TEST_MNT/snap1" -touch send.stream -chmod a+w send.stream +_mktemp_local send.stream run_check $SUDO_HELPER "$TOP/btrfs" send -f send.stream "$TEST_MNT/snap1" run_check_stdout "$TOP/btrfs" receive --dump -f send.stream | diff --git a/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh b/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh index bd89696e..2c011b6e 100755 --- a/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh +++ b/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh @@ -18,9 +18,7 @@ dmname=\ btrfs-test-with-very-long-name-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA$rand dmdev="/dev/mapper/$dmname" -run_check truncate -s0 img -chmod a+w img -run_check truncate -s2g img +_mktemp_local img 2g loopdev=`run_check_stdout $SUDO_HELPER losetup --find --show img` run_check $SUDO_HELPER dmsetup create "$dmname" --table "0 1048576 linear $loopdev 0" diff --git a/tests/mkfs-tests/006-partitioned-loopdev/test.sh b/tests/mkfs-tests/006-partitioned-loopdev/test.sh index 5d972a78..c5a3be86 100755 --- a/tests/mkfs-tests/006-partitioned-loopdev/test.sh +++ b/tests/mkfs-tests/006-partitioned-loopdev/test.sh @@ -12,8 +12,7 @@ check_prereq mkfs.btrfs setup_root_helper -run_check truncate -s0 img -chmod a+w img +_mktemp_local img cp partition-1g-1g img run_check truncate -s2g img @@ -28,5 +27,4 @@ done # cleanup run_check $SUDO_HELPER losetup -d "$loopdev" -run_check truncate -s0 img rm img diff --git a/tests/mkfs-tests/017-small-backing-size-thin-provision-device/test.sh b/tests/mkfs-tests/017-small-backing-size-thin-provision-device/test.sh index 0a9b3ff6..38b9b28e 100755 --- a/tests/mkfs-tests/017-small-backing-size-thin-provision-device/test.sh +++ b/tests/mkfs-tests/017-small-backing-size-thin-provision-device/test.sh @@ -54,8 +54,7 @@ fi meta_dev_offset=0 total_data_dev_size=$(($meta_dev_offset + $meta_dev_size + $data_dev_size)) -run_check truncate -s0 img -chmod a+w img +_mktemp_local img run_check truncate -s"$(($total_data_dev_size * $sector_size))" img dm_backing_dev=`run_check_stdout $SUDO_HELPER losetup --find --show img`