Create archives with and without --reflink and then check for differences before and after extraction. tests/reflink-sparse matches tests/reflink except that all source files are sparse, generated with truncate(1).
Signed-off-by: David Disseldorp <dd...@suse.de> --- tests/reflink-sparse.at | 67 +++++++++++++++++++++++++++ tests/reflink.at | 100 ++++++++++++++++++++++++++++++++++++++++ tests/testsuite.at | 2 + 3 files changed, 169 insertions(+) create mode 100644 tests/reflink-sparse.at create mode 100644 tests/reflink.at diff --git a/tests/reflink-sparse.at b/tests/reflink-sparse.at new file mode 100644 index 0000000..5bf69b2 --- /dev/null +++ b/tests/reflink-sparse.at @@ -0,0 +1,67 @@ +# Process this file with autom4te to create testsuite. -*- Autotest -*- +# Copyright (C) 2004, 2006-2007, 2010, 2014-2015, 2017 Free Software +# Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301 USA. + +AT_SETUP([reflink-sparse]) + +AT_DATA([filelist],[a 3872 +b 16384 +c 3872 +d 4096 +e 0 +f 5 +g 4096 +]) + +# same as reflink test, except use sparse files instead of genfile +AT_CHECK([ +cpio --help | grep reflink >/dev/null || AT_SKIP_TEST +diff filelist filelist || AT_SKIP_TEST +truncate --help >/dev/null || AT_SKIP_TEST + +while read NAME LENGTH +do + rm -f $NAME + truncate --size=$LENGTH $NAME + echo $NAME +done < filelist > filelist_raw + +for format in bin odc newc crc tar ustar hpbin hpodc +do + cpio --reflink --format=$format --quiet -o -O sparse_reflink.$format < filelist_raw + # 'xfs_io -c "fiemap -v" sparse_reflink.$format' may show hole extents + cpio --format=$format --quiet -o < filelist_raw > archive.$format + diff sparse_reflink.$format archive.$format + + for archive in archive.$format sparse_reflink.$format + do + rm -rf output.* + mkdir "output.$archive" && cd "output.$archive" + cpio -i --quiet < "../$archive" + + while read file + do + test -f $file || echo "$file not found in $archive" + done < ../filelist_raw + + cd .. + done +done +]) + +AT_CLEANUP diff --git a/tests/reflink.at b/tests/reflink.at new file mode 100644 index 0000000..ca513c4 --- /dev/null +++ b/tests/reflink.at @@ -0,0 +1,100 @@ +# Process this file with autom4te to create testsuite. -*- Autotest -*- +# Copyright (C) 2004, 2006-2007, 2010, 2014-2015, 2017 Free Software +# Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301 USA. + +AT_SETUP([reflink]) + +# The copy_file_range() syscall on XFS and Btrfs requires filesystem +# alignment to actually perform extent sharing (reflink), otherwise +# the kernel may fallback to splice. In an effort to trigger both +# reflink and splice, mix the archive with aligned and unaligned file +# data. +# hdr(crc/newc) = 110 +# filename(a) + 2 +# data + 3872 +# hdr(crc/newc) + 110 +# filename(b) + 2 +# = 4096 (common XFS / Btrfs FS block size) +AT_DATA([filelist],[a 3872 +b 16384 +c 3872 +d 4096 +e 0 +f 5 +g 4096 +]) + +AT_CHECK([ +# check that cpio is built with copy_file_range syscall support +cpio --help | grep reflink >/dev/null || AT_SKIP_TEST +# this test requires diff +diff filelist filelist || AT_SKIP_TEST + +while read NAME LENGTH +do + genfile --length $LENGTH > $NAME + echo $NAME +done < filelist > filelist_raw + +for format in bin odc newc crc tar ustar hpbin hpodc +do + cpio --reflink --format=$format --quiet -o -O reflink.$format < filelist_raw + # 'xfs_io -c "fiemap -v" reflink.$format' should show shared extents + cpio --format=$format --quiet -o < filelist_raw > archive.$format + diff reflink.$format archive.$format + + for archive in archive.$format reflink.$format + do + rm -rf output.* + mkdir "output.$archive" && cd "output.$archive" + cpio -i --quiet < "../$archive" + + while read file + do + test -f $file || echo "$file not found in $archive" + done < ../filelist_raw + + cd .. + done +done +]) + +AT_CHECK([ + cpio --help | grep reflink >/dev/null || AT_SKIP_TEST + # reflink without output file should throw an error + echo "filelist" | cpio --format=newc --quiet --reflink -o > a.cpio +], +[2], +[], +[cpio: --reflink is used but no archive file name is given (use -F or -O options) +Try 'cpio --help' or 'cpio --usage' for more information. +]) + +AT_CHECK([ + cpio --help | grep reflink >/dev/null || AT_SKIP_TEST + echo "filelist" | cpio --format=newc --quiet --reflink -o -O a.cpio + # copyin with reflink should throw an error + cpio --extract --reflink --file a.cpio +], +[2], +[], +[cpio: --reflink is meaningless with --extract +Try 'cpio --help' or 'cpio --usage' for more information. +]) + +AT_CLEANUP diff --git a/tests/testsuite.at b/tests/testsuite.at index 8716296..2d4958d 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -36,6 +36,8 @@ m4_include([symlink-long.at]) m4_include([symlink-to-stdout.at]) m4_include([interdir.at]) m4_include([chain.at]) +m4_include([reflink.at]) +m4_include([reflink-sparse.at]) m4_include([setstat01.at]) m4_include([setstat02.at]) -- 2.26.2