]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: require root only if current partition is neither btrfs nor xfs
authorJim Meyering <meyering@redhat.com>
Sat, 22 May 2010 08:22:58 +0000 (10:22 +0200)
committerJim Meyering <meyering@redhat.com>
Fri, 11 Jun 2010 12:10:57 +0000 (14:10 +0200)
* tests/cp/sparse-fiemap: Don't require root access if current
partition is btrfs or xfs.
Use init.sh, not test-lib.sh.

tests/cp/sparse-fiemap

index 3608db3fd342659a89622a5f588ed732b8313d21..1f78671ce504f701304d0f45f72c67b2458e1f20 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 # Test cp --sparse=always through fiemap copy
 
-# Copyright (C) 2006-2010 Free Software Foundation, Inc.
+# Copyright (C) 2010 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
@@ -21,29 +21,34 @@ if test "$VERBOSE" = yes; then
   cp --version
 fi
 
-. $srcdir/test-lib.sh
-require_root_
-
-cwd=`pwd`
-cleanup_() { cd /; umount "$cwd/mnt"; }
-
-skip=0
-# Create an ext4 loopback file system
-dd if=/dev/zero of=blob bs=8192 count=1000 || skip=1
-mkdir mnt
-mkfs -t ext4 -F blob ||
-  skip_test_ "failed to create ext4 file system"
-mount -oloop blob mnt   || skip=1
-cd mnt                  || skip=1
-echo test > f           || skip=1
-test -s f               || skip=1
-
-test $skip = 1 &&
-  skip_test_ "insufficient mount/ext4 support"
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+
+if df -T -t btrfs -t xfs . ; then
+  : # Current dir is on a partition with working extents.  Good!
+else
+  # It's not;  we need to create one, hence we need root access.
+  require_root_
+
+  cwd=$PWD
+  cleanup_() { cd /; umount "$cwd/mnt"; }
+
+  skip=0
+  # Create an XFS loopback file system
+  dd if=/dev/zero of=blob bs=32k count=1000 || skip=1
+  mkdir mnt
+  mkfs -t xfs blob ||
+    skip_test_ "failed to create XFS file system"
+  mount -oloop blob mnt   || skip=1
+  cd mnt                  || skip=1
+  echo test > f           || skip=1
+  test -s f               || skip=1
+
+  test $skip = 1 &&
+    skip_test_ "insufficient mount/XFS support"
+fi
 
 # Create a 1TiB sparse file
-dd if=/dev/zero of=mnt/sparse bs=1k count=1 seek=1G || framework_failure
-
+dd if=/dev/zero of=sparse bs=1k count=1 seek=1G || framework_failure
 
 # It takes many minutes to copy this sparse file using the old method.
 # By contrast, it takes far less than 1 second using FIEMAP-copy.