[PATCH v2 5/7] xfstest: Add test case to check various corner cases for collapsing range

2013-09-02 Thread Namjae Jeon
From: Namjae Jeon 

This patch checks various corner cases for collapsing a range.
This patch is based on generic/255 test case which checks various corner
cases for punch hole.

Signed-off-by: Namjae Jeon 
Signed-off-by: Ashish Sangwan 
---
 common/collapse  |  264 ++
 common/rc|   14 +++
 tests/shared/316 |   70 +
 tests/shared/316.out |  221 ++
 tests/shared/group   |2 +-
 5 files changed, 570 insertions(+), 1 deletion(-)
 create mode 100644 common/collapse
 create mode 100644 tests/shared/316
 create mode 100644 tests/shared/316.out

diff --git a/common/collapse b/common/collapse
new file mode 100644
index 000..dd3be5e
--- /dev/null
+++ b/common/collapse
@@ -0,0 +1,264 @@
+##/bin/bash
+#
+# Copyright (c) 2013 Samsung Electronics.  All Rights Reserved.
+#
+# 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.
+#
+# This program is distributed in the hope that it would 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 the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+# Test procedure for checking collapse range feature
+
+# Test different corner cases for collapsing a range:
+#
+#  1. into a hole
+#  2. into allocated space
+#  3. into unwritten space
+#  4. hole -> data
+#  5. hole -> unwritten
+#  6. data -> hole
+#  7. data -> unwritten
+#  8. unwritten -> hole
+#  9. unwritten -> data
+#  10. hole -> data -> hole
+#  11. data -> hole -> data
+#  12. unwritten -> data -> unwritten
+#  13. data -> unwritten -> data
+#  14. data -> hole @ EOF
+#  15. data -> hole @ 0
+#  16. data -> cache cold ->hole
+#
+# Test file is removed, created and sync'd between tests.
+#
+# Use -k flag to keep the file between tests.  This will
+# test the handling of pre-existing holes.
+#
+# Use the -d flag to not sync the file between tests.
+# This will test the handling of delayed extents
+#
+_test_generic_collapse()
+{
+
+   remove_testfile=1
+   sync_cmd="-c fsync"
+   OPTIND=1
+   while getopts 'dk' OPTION
+   do
+   case $OPTION in
+   k)  remove_testfile=
+   ;;
+   d)  sync_cmd=
+   ;;
+   ?)  echo Invalid flag
+   exit 1
+   ;;
+   esac
+   done
+   shift $(($OPTIND - 1))
+
+   alloc_cmd=$1
+   collapse_cmd=$2
+   punch_cmd=$3
+   map_cmd=$4
+   filter_cmd=$5
+   testfile=$6
+
+   echo "  1. into a hole"
+   if [ "$remove_testfile" ]; then
+   rm -f $testfile
+   fi
+   $XFS_IO_PROG -f -c "truncate 80k" \
+   -c "$collapse_cmd 16k 32k" \
+   -c "$map_cmd -v" $testfile | $filter_cmd
+   [ $? -ne 0 ] && die_now
+   _md5_checksum $testfile
+
+   echo "  2. into allocated space"
+   if [ "$remove_testfile" ]; then
+   rm -f $testfile
+   fi
+   $XFS_IO_PROG -f -c "truncate 80k" \
+   -c "pwrite 0 80k" $sync_cmd \
+   -c "$collapse_cmd 16k 32k" \
+   -c "$map_cmd -v" $testfile | $filter_cmd
+   [ $? -ne 0 ] && die_now
+   _md5_checksum $testfile
+
+   echo "  3. into unwritten space"
+   if [ "$remove_testfile" ]; then
+   rm -f $testfile
+   fi
+   $XFS_IO_PROG -f -c "truncate 80k" \
+   -c "$alloc_cmd 0 80k" \
+   -c "$collapse_cmd 16k 32k" \
+   -c "$map_cmd -v" $testfile | $filter_cmd
+   [ $? -ne 0 ] && die_now
+   _md5_checksum $testfile
+
+   echo "  4. hole -> data"
+   if [ "$remove_testfile" ]; then
+   rm -f $testfile
+   fi
+   $XFS_IO_PROG -f -c "truncate 80k" \
+   -c "pwrite 32k 32k" $sync_cmd \
+   -c "$collapse_cmd 16k 32k" \
+   -c "$map_cmd -v" $testfile | $filter_cmd
+   [ $? -ne 0 ] && die_now
+   _md5_checksum $testfile
+
+   echo "  5. hole -> unwritten"
+   if [ "$remove_testfile" ]; then
+   rm -f $testfile
+   fi
+   $XFS_IO_PROG -f -c "truncate 80k" \
+   -c "$alloc_cmd 32k 32k" \
+   -c "$collapse_cmd 16k 32k" \
+   -c "$map_cmd -v" $testfile | $filter_cmd
+   [ $? -ne 0 ] && die_now
+   _md5_checksum $testfile
+
+   echo "  6. data -> hole"
+   if [ "$remove_testfile" ]; then
+   rm -f $testfile
+   fi
+   $XFS_IO_PROG -f -c "truncate 80k" \
+

[PATCH v2 5/7] xfstest: Add test case to check various corner cases for collapsing range

2013-09-02 Thread Namjae Jeon
From: Namjae Jeon namjae.j...@samsung.com

This patch checks various corner cases for collapsing a range.
This patch is based on generic/255 test case which checks various corner
cases for punch hole.

Signed-off-by: Namjae Jeon namjae.j...@samsung.com
Signed-off-by: Ashish Sangwan a.sang...@samsung.com
---
 common/collapse  |  264 ++
 common/rc|   14 +++
 tests/shared/316 |   70 +
 tests/shared/316.out |  221 ++
 tests/shared/group   |2 +-
 5 files changed, 570 insertions(+), 1 deletion(-)
 create mode 100644 common/collapse
 create mode 100644 tests/shared/316
 create mode 100644 tests/shared/316.out

diff --git a/common/collapse b/common/collapse
new file mode 100644
index 000..dd3be5e
--- /dev/null
+++ b/common/collapse
@@ -0,0 +1,264 @@
+##/bin/bash
+#
+# Copyright (c) 2013 Samsung Electronics.  All Rights Reserved.
+#
+# 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.
+#
+# This program is distributed in the hope that it would 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 the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+# Test procedure for checking collapse range feature
+
+# Test different corner cases for collapsing a range:
+#
+#  1. into a hole
+#  2. into allocated space
+#  3. into unwritten space
+#  4. hole - data
+#  5. hole - unwritten
+#  6. data - hole
+#  7. data - unwritten
+#  8. unwritten - hole
+#  9. unwritten - data
+#  10. hole - data - hole
+#  11. data - hole - data
+#  12. unwritten - data - unwritten
+#  13. data - unwritten - data
+#  14. data - hole @ EOF
+#  15. data - hole @ 0
+#  16. data - cache cold -hole
+#
+# Test file is removed, created and sync'd between tests.
+#
+# Use -k flag to keep the file between tests.  This will
+# test the handling of pre-existing holes.
+#
+# Use the -d flag to not sync the file between tests.
+# This will test the handling of delayed extents
+#
+_test_generic_collapse()
+{
+
+   remove_testfile=1
+   sync_cmd=-c fsync
+   OPTIND=1
+   while getopts 'dk' OPTION
+   do
+   case $OPTION in
+   k)  remove_testfile=
+   ;;
+   d)  sync_cmd=
+   ;;
+   ?)  echo Invalid flag
+   exit 1
+   ;;
+   esac
+   done
+   shift $(($OPTIND - 1))
+
+   alloc_cmd=$1
+   collapse_cmd=$2
+   punch_cmd=$3
+   map_cmd=$4
+   filter_cmd=$5
+   testfile=$6
+
+   echo   1. into a hole
+   if [ $remove_testfile ]; then
+   rm -f $testfile
+   fi
+   $XFS_IO_PROG -f -c truncate 80k \
+   -c $collapse_cmd 16k 32k \
+   -c $map_cmd -v $testfile | $filter_cmd
+   [ $? -ne 0 ]  die_now
+   _md5_checksum $testfile
+
+   echo   2. into allocated space
+   if [ $remove_testfile ]; then
+   rm -f $testfile
+   fi
+   $XFS_IO_PROG -f -c truncate 80k \
+   -c pwrite 0 80k $sync_cmd \
+   -c $collapse_cmd 16k 32k \
+   -c $map_cmd -v $testfile | $filter_cmd
+   [ $? -ne 0 ]  die_now
+   _md5_checksum $testfile
+
+   echo   3. into unwritten space
+   if [ $remove_testfile ]; then
+   rm -f $testfile
+   fi
+   $XFS_IO_PROG -f -c truncate 80k \
+   -c $alloc_cmd 0 80k \
+   -c $collapse_cmd 16k 32k \
+   -c $map_cmd -v $testfile | $filter_cmd
+   [ $? -ne 0 ]  die_now
+   _md5_checksum $testfile
+
+   echo   4. hole - data
+   if [ $remove_testfile ]; then
+   rm -f $testfile
+   fi
+   $XFS_IO_PROG -f -c truncate 80k \
+   -c pwrite 32k 32k $sync_cmd \
+   -c $collapse_cmd 16k 32k \
+   -c $map_cmd -v $testfile | $filter_cmd
+   [ $? -ne 0 ]  die_now
+   _md5_checksum $testfile
+
+   echo   5. hole - unwritten
+   if [ $remove_testfile ]; then
+   rm -f $testfile
+   fi
+   $XFS_IO_PROG -f -c truncate 80k \
+   -c $alloc_cmd 32k 32k \
+   -c $collapse_cmd 16k 32k \
+   -c $map_cmd -v $testfile | $filter_cmd
+   [ $? -ne 0 ]  die_now
+   _md5_checksum $testfile
+
+   echo   6. data - hole
+   if [ $remove_testfile ]; then
+   rm -f $testfile
+   fi
+   $XFS_IO_PROG -f -c truncate 80k \
+   -c pwrite 0 32k