common/fuzzy: if the fuzz verb is random, keep fuzzing until we get a new value
[xfstests-dev.git] / common / filter
index a7d2aa932f1487937fbefdc34b303ee9bbf21ddb..0cb458b0051f9d360ec449841249f88042c6fe6b 100644 (file)
@@ -143,6 +143,7 @@ _filter_mkfs()
        return ;;
     esac
 
+    echo "_fs_has_crcs=0" >&2
     set -
     perl -ne '
     if (/^meta-data=([\w,|\/.-]+)\s+isize=(\d+)\s+agcount=(\d+), agsize=(\d+) blks/) {
@@ -220,7 +221,16 @@ common_line_filter()
 
 _filter_xfs_io()
 {
-    sed -e "s/[0-9/.]* [GMKiBbytes]*, [0-9]* ops\; [0-9/:. sec]* ([inf0-9/.]* [EPGMKiBbytes]*\/sec and [inf0-9/.]* ops\/sec)/XXX Bytes, X ops\; XX:XX:XX.X (XXX YYY\/sec and XXX ops\/sec)/"
+    # Apart from standard numeric values, we also filter out 'inf' and 'nan'
+    # which can result from division in some cases
+    sed -e "s/[0-9/.]* [GMKiBbytes]*, [0-9]* ops\; [0-9/:. sec]* ([infa0-9/.]* [EPGMKiBbytes]*\/sec and [infa0-9/.]* ops\/sec)/XXX Bytes, X ops\; XX:XX:XX.X (XXX YYY\/sec and XXX ops\/sec)/"
+}
+
+# stderr filter for xfs_io to handle change of error output format (e.g.
+# pwrite64 -> pwrite).
+_filter_xfs_io_error()
+{
+       sed -e "s/^\(.*\)64\(: .*$\)/\1\2/"
 }
 
 _filter_xfs_io_unique()
@@ -228,18 +238,74 @@ _filter_xfs_io_unique()
     common_line_filter | _filter_xfs_io
 }
 
+_filter_xfs_io_units_modified()
+{
+       UNIT=$1
+       UNIT_SIZE=$2
+
+       $AWK_PROG -v unit="$UNIT" -v unit_size=$UNIT_SIZE '
+               /wrote/ {
+                       split($2, bytes, "/")
+
+                       bytes_written = strtonum(bytes[1])
+
+                       offset = strtonum($NF)
+
+                       unit_start = offset / unit_size
+                       unit_start = int(unit_start)
+                       unit_end = (offset + bytes_written - 1) / unit_size
+                       unit_end = int(unit_end)
+
+                       printf("%ss modified: [%d - %d]\n", unit, unit_start, unit_end)
+
+                       next
+               }
+       '
+}
+
+_filter_xfs_io_blocks_modified()
+{
+       BLOCK_SIZE=$(_get_block_size $SCRATCH_MNT)
+
+       _filter_xfs_io_units_modified "Block" $BLOCK_SIZE
+}
+
+_filter_xfs_io_pages_modified()
+{
+       PAGE_SIZE=$(get_page_size)
+
+       _filter_xfs_io_units_modified "Page" $PAGE_SIZE
+}
+
+
 _filter_test_dir()
 {
-       sed -e "s,$TEST_DEV,TEST_DEV,g" -e "s,$TEST_DIR,TEST_DIR,g"
+       # TEST_DEV may be a prefix of TEST_DIR (e.g. /mnt, /mnt/ovl-mnt)
+       # so substitute TEST_DIR first
+       sed -e "s,\B$TEST_DIR,TEST_DIR,g" \
+           -e "s,\B$TEST_DEV,TEST_DEV,g"
 }
 
 _filter_scratch()
 {
-       sed -e "s,$SCRATCH_DEV,SCRATCH_DEV,g" \
-           -e "s,$SCRATCH_MNT,SCRATCH_MNT,g" \
+       # SCRATCH_DEV may be a prefix of SCRATCH_MNT (e.g. /mnt, /mnt/ovl-mnt)
+       # so substitute SCRATCH_MNT first
+       sed -e "s,\B$SCRATCH_MNT,SCRATCH_MNT,g" \
+           -e "s,\B$SCRATCH_DEV,SCRATCH_DEV,g" \
            -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()
 {
@@ -249,18 +315,27 @@ _filter_scratch_pool()
 
 _filter_spaces()
 {
-       sed -e 's/ [ ]*/ /g'
+       sed -e "s/\s\+/ /g"
 }
 
 _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'
 }
 
+_filter_project_quota()
+{
+       # Project ID 0 is always present on disk but was not reported
+       # until the GETNEXTQUOTA ioctl came into use.  Filter it out.
+       # But if you specify a name for ID 0, that means you want to
+       # deal with it by yourself, this function won't filter it out.
+       _filter_quota | grep -v "^\#0 \|^(null) "
+}
+
 # Account for different "ln" failure messages
 _filter_ln()
 {
@@ -274,9 +349,9 @@ _filter_uuid()
 {
        if [ ! -z $1 ]; then
                UUID=$1
-               sed -e "s/\(uuid:\) $UUID/\1 <EXACTUUID>/i"
+               sed -e "s/\(uuid[ :=]\+\) $UUID/\1 <EXACTUUID>/i"
        else
-               sed -e "s/\(uuid:\) *[0-9a-f-][0-9a-f-]*/\1 <UUID>/i"
+               sed -e "s/\(uuid[ :=]\+\) [0-9a-f-][0-9a-f-]*/\1 <UUID>/ig"
        fi
 }
 
@@ -322,5 +397,81 @@ _filter_ro_mount() {
            -e "s/mount: cannot mount block device/mount: cannot mount/g"
 }
 
+_filter_od()
+{
+       BLOCK_SIZE=$(_get_block_size $SCRATCH_MNT)
+       $AWK_PROG -v block_size=$BLOCK_SIZE '
+               /^[0-9]+/ {
+                       offset = strtonum("0"$1);
+                       $1 = sprintf("%o", offset / block_size);
+                       print $0;
+               }
+               /\*/
+       '
+}
+
+# Remove quotes from failed mknod calls. Starting with Coreutils v8.25,
+# mknod errors print unquoted filenames
+_filter_mknod()
+{
+       sed -e "s/mknod: [\`']\(.*\)': File exists/mknod: \1: File exists/"
+}
+
+_filter_lostfound()
+{
+       sed -e '/^lost+found$/d'
+}
+
+_filter_ovl_dirs()
+{
+       sed -e "s,$OVL_LOWER,OVL_LOWER,g" \
+           -e "s,$OVL_UPPER,OVL_UPPER,g" \
+           -e "s,$OVL_WORK,OVL_WORK,g"
+}
+
+# interpret filefrag output,
+# eg. "physical 1234, length 10, logical 5678" -> "1234#10#5678"
+_filter_filefrag()
+{
+       perl -ne '
+       if (/blocks? of (\d+) bytes/) {
+               $blocksize = $1;
+               next
+       }
+       ($ext, $logical, $physical, $length) =
+               (/^\s*(\d+):\s+(\d+)..\s+\d+:\s+(\d+)..\s+\d+:\s+(\d+):/)
+       or next;
+       ($flags) = /.*:\s*(\S*)$/;
+       print $physical * $blocksize, "#",
+             $length * $blocksize, "#",
+             $logical * $blocksize, "#",
+             $flags, "\n"'
+}
+
+# We generate WARNINGs on purpose when applications mix buffered/mmap IO with
+# direct IO on the same file. This is a helper for _check_dmesg() to filter out
+# such warnings.
+_filter_aiodio_dmesg()
+{
+       local warn1="WARNING:.*fs/xfs/xfs_file\.c:.*xfs_file_dio_aio_write.*"
+       local warn2="WARNING:.*fs/xfs/xfs_file\.c:.*xfs_file_dio_aio_read.*"
+       local warn3="WARNING:.*fs/xfs/xfs_file\.c:.*xfs_file_read_iter.*"
+       local warn4="WARNING:.*fs/xfs/xfs_file\.c:.*xfs_file_aio_read.*"
+       local warn5="WARNING:.*fs/iomap\.c:.*iomap_dio_rw.*"
+       local warn6="WARNING:.*fs/xfs/xfs_aops\.c:.*__xfs_get_blocks.*"
+       local warn7="WARNING:.*fs/iomap\.c:.*iomap_dio_actor.*"
+       local warn8="WARNING:.*fs/iomap\.c:.*iomap_dio_complete.*"
+       local warn9="WARNING:.*fs/direct-io\.c:.*dio_complete.*"
+       sed -e "s#$warn1#Intentional warnings in xfs_file_dio_aio_write#" \
+           -e "s#$warn2#Intentional warnings in xfs_file_dio_aio_read#" \
+           -e "s#$warn3#Intentional warnings in xfs_file_read_iter#" \
+           -e "s#$warn4#Intentional warnings in xfs_file_aio_read#" \
+           -e "s#$warn5#Intentional warnings in iomap_dio_rw#" \
+           -e "s#$warn6#Intentional warnings in __xfs_get_blocks#" \
+           -e "s#$warn7#Intentional warnings in iomap_dio_actor#" \
+           -e "s#$warn8#Intentional warnings in iomap_dio_complete#" \
+           -e "s#$warn9#Intentional warnings in dio_complete#"
+}
+
 # make sure this script returns success
 /bin/true