fstests: filter test and scratch together safely
authorMisono, Tomohiro <misono.tomohiro@jp.fujitsu.com>
Fri, 1 Sep 2017 05:39:44 +0000 (14:39 +0900)
committerEryu Guan <eguan@redhat.com>
Sun, 3 Sep 2017 04:20:00 +0000 (12:20 +0800)
Several tests uses both _filter_test_dir and _filter_scratch
concatenated by pipe to filter $TEST_DIR and $SCRATCH_MNT. However,
this would fail if the shorter string is a substring of the other
(like "/mnt" and "/mnt2").

This patch introduces new common filter function to safely call both
_filter_test_dir and _filter_scratch, and update tests and functions
to use this new function.

I checked this with btrfs/029, generic/409,410,411, and
generic/381,383, xfs/106,108 (which calls _filter_quota). Thanks
Eryu for advice.

[eguan: folded 2nd patch into 1st patch and update commit log a bit]

Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>
Reviewed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
common/filter
tests/btrfs/029
tests/generic/409
tests/generic/410
tests/generic/411

index 1ef342b59726e2b31fc19be13e26a8d550f68b74..39ea140cb60fabc36f22299893282023ab435f81 100644 (file)
@@ -295,6 +295,17 @@ _filter_scratch()
            -e "/.use_space/d"
 }
 
+_filter_testdir_and_scratch()
+{
+       # filter both $TEST_DIR and $SCRATCH_MNT, but always filter the longer
+       # string first if the other string is a substring of the first one
+       if echo "$TEST_DIR" | grep -q "$SCRATCH_MNT"; then
+               _filter_test_dir | _filter_scratch
+       else
+               _filter_scratch | _filter_test_dir
+       fi
+}
+
 # Turn any device in the scratch pool into SCRATCH_DEV
 _filter_scratch_pool()
 {
@@ -311,7 +322,7 @@ _filter_quota()
 {
        # Long dev name might be split onto its own line; last
        # seds remove that newline if present
-       _filter_scratch | _filter_test_dir | _filter_spaces | \
+       _filter_testdir_and_scratch | _filter_spaces | \
        sed -e 'N;s/SCRATCH_DEV\n/SCRATCH_DEV/g' | \
        sed -e 'N;s/TEST_DEV\n/TEST_DEV/g'
 }
index c390c95f58848eb666705f9134d4d550cc0d084c..b6e2dbb04ecb66d2763cfc3fd2e3fe830ebc0f03 100755 (executable)
@@ -66,19 +66,14 @@ _scratch_mkfs > /dev/null 2>&1
 _scratch_mount
 $XFS_IO_PROG -f -c 'pwrite -S 0x61 0 9000' $SCRATCH_MNT/original >> $seqres.full
 
-_filter_testdirs()
-{
-    _filter_test_dir | _filter_scratch
-}
-
 _create_reflinks()
 {
     # auto reflink, should fall back to non-reflink
     rm -rf $2
     echo "reflink=auto:"
     cp --reflink=auto $1 $2
-    md5sum $1 | _filter_testdirs
-    md5sum $2 | _filter_testdirs
+    md5sum $1 | _filter_testdir_and_scratch
+    md5sum $2 | _filter_testdir_and_scratch
 
     # always reflink, should fail outright
     rm -rf $2
@@ -86,7 +81,7 @@ _create_reflinks()
     cp --reflink=always $1 $2 >> $seqres.full 2>&1 || echo "cp reflink failed"
 
     # The failed target actually gets created by cp:
-    ls $2 | _filter_testdirs
+    ls $2 | _filter_testdir_and_scratch
 }
 
 echo "test reflinks across different devices"
index 22af44c8a06c241a473a637e5166a4dd40c89dab..3ad65c91647f87416ffd2074a8ed2d3815fbe6d0 100755 (executable)
@@ -104,8 +104,7 @@ find_mnt()
                    -e "s;$mpB;mpB;g" \
                    -e "s;$mpC;mpC;g" \
                    -e "s;$mpD;mpD;g" | \
-               _filter_spaces | _filter_scratch | \
-               _filter_test_dir | sort
+               _filter_spaces | _filter_testdir_and_scratch | sort
        echo "======"
 }
 
index 18cb0c1c16ee827034f62696599bc303c7e85155..63ab716204628df6fd8ff6b8e02ec5861c1d1482 100755 (executable)
@@ -110,8 +110,7 @@ find_mnt()
                sed -e "s;$mpA;mpA;g" \
                    -e "s;$mpB;mpB;g" \
                    -e "s;$mpC;mpC;g" | \
-               _filter_spaces | _filter_scratch | \
-               _filter_test_dir | sort
+               _filter_spaces | _filter_testdir_and_scratch | sort
        echo "======"
 }
 
index 5db49a4486c6a964bef207e2e751f212b20bd4e7..83f6d26165ac6a626a35afa165eadf3c6ee30069 100755 (executable)
@@ -93,8 +93,7 @@ find_mnt()
                sed -e "s;$mpA;mpA;g" \
                    -e "s;$mpB;mpB;g" \
                    -e "s;$mpC;mpC;g" | \
-               _filter_spaces | _filter_scratch | \
-               _filter_test_dir | sort
+               _filter_spaces | _filter_testdir_and_scratch | sort
        echo "======"
 }