Files
apfstests/tests/generic/519
T
Nikolay Borisov eba73e34fd generic/519: Optimize overlap detection
Currently generic/519 takes around 5-10 minutes for me. This is
mainly due to the fact it uses a bunch of commands which spawn
processes. This, coupled by the fact the algorithm is O(n^2) in the
number of lines (624) for the sparse file and that test feels like
it's hung.

Fix this by re-implementing the existing logic in awk. This causes a
s single processes to be spawned and the rest of the processing is
done in-memory. This makes the test complete in 2 seconds for me.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
2019-08-18 23:05:45 +08:00

108 lines
2.3 KiB
Bash
Executable File

#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2018 Red Hat Inc. All Rights Reserved.
#
# FS QA Test No. 519
#
# Verify if there's physical address overlap returned by FIBMAP, cover:
# 79b3dbe4adb3 fs: fix iomap_bmap position calculation
#
seq=`basename $0`
seqres=$RESULT_DIR/$seq
echo "QA output created by $seq"
here=`pwd`
tmp=/tmp/$$
status=1 # failure is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15
_cleanup()
{
cd /
rm -f $tmp.*
}
# get standard environment, filters and checks
. ./common/rc
. ./common/filter
# remove previous $seqres.full before test
rm -f $seqres.full
# real QA test starts here
_supported_fs generic
_supported_os Linux
_require_scratch
_require_fibmap
_require_filefrag_options "es"
testfile="$SCRATCH_MNT/$seq-testfile"
# Use filefrag -B option to force the use of the older FIBMAP ioctl instead of
# the FIEMAP ioctl. Then verify if there's map overlap.
verify_filefrag()
{
# record details in .full file
${FILEFRAG_PROG} -Bes -v $testfile >> $seqres.full
# Due to physical things can't be golden image, so only output logical
# information at here
${FILEFRAG_PROG} -Be $testfile | _filter_filefrag | \
cut -d# -f1-2 > $tmp.filefrag
# Verify there's no physical address overlay
awk '
BEGIN {i=0}
{
# create a lines array of the form begin#end offsets
split($0,res,"#")
begin=res[1]
end=begin+res[2]
lines[i++]=begin"#"end
}
END {
for (i in lines) {
for (j in lines) {
# Dont check i-th line against itself
if (i == j)
continue
split(lines[i],i_line,"#")
split(lines[j],j_line,"#")
v1=i_line[1]
v2=i_line[2]
e1=j_line[1]
e2=j_line[2]
# Verify there is not:
# [ e1 ... e2 ]
# [ v1 ... v2 ]
# Or:
# [ e1 ... e2 ]
# [ v1 ... v2 ]
if (! (v1 >= e2 || v2 <= e1))
print "find physical addr overlap " lines[i] " vs " lines[j]
}
}
}
' $tmp.filefrag
}
_scratch_mkfs > $seqres.full 2>&1
_scratch_mount
# Test
echo "== FIBMAP on empty file =="
$XFS_IO_PROG -f -c "truncate 0" $testfile > /dev/null
verify_filefrag
echo "== FIBMAP on sparse file =="
$XFS_IO_PROG -f -t -c "pwrite -S 0xaa 0 1m" \
-c "pwrite -S 0xaa 2m 1m" \
-c "pwrite -S 0xaa 4m 1m" \
$testfile > /dev/null
verify_filefrag
# success, all done
status=0
exit