Although my OpenSuSE system has e2fsprogs installed, the test
fiemap-perf cannot use it, because /usr/sbin is missing in
my (non-root) user's PATH:

  fiemap-perf: skipped test: the `filefrag` utility is missing
  SKIP: cp/fiemap-perf

This is similar to the matter in commit
5eeaca942ab8fc090cd6b0ae2fede698dc9a6f5d.

The attached patch fixing it (although I feel that we may
need a more generic function require_sbin_tool_).

Have a nice day,
Berny


>From dcf45199a9ae5c573e8de3f4deba753f6e276b33 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <[email protected]>
Date: Wed, 23 Nov 2011 09:54:26 +0100
Subject: [PATCH] tests: adjust PATH to include /usr/sbin for filefrag-using tests

* tests/init.cfg (require_filefrag_PATH_): New function to test whether
filefrag is in PATH, otherwise adding /usr/sbin to PATH.  Needed for
distributions (OpenSuSE) in which sudo does not include /usr/sbin in
PATH.
* tests/cp/fiemap-empty: Use require_filefrag_PATH_.
* tests/cp/fiemap-perf: Likewise.
* tests/cp/sparse-fiemap: Likewise.
---
 tests/cp/fiemap-empty  |    2 ++
 tests/cp/fiemap-perf   |    2 ++
 tests/cp/sparse-fiemap |    1 +
 tests/init.cfg         |   19 +++++++++++++++++++
 4 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/tests/cp/fiemap-empty b/tests/cp/fiemap-empty
index 6ce5957..762360d 100755
--- a/tests/cp/fiemap-empty
+++ b/tests/cp/fiemap-empty
@@ -29,6 +29,8 @@ fiemap_capable_ fiemap_chk ||
   skip_ 'this file system lacks FIEMAP support'
 rm fiemap_chk
 
+require_filefrag_PATH_
+
 # TODO: rather than requiring `fallocate`, possible add
 # this functionality to truncate --alloc
 fallocate --help >/dev/null || skip_ 'The fallocate utility is required'
diff --git a/tests/cp/fiemap-perf b/tests/cp/fiemap-perf
index b17360e..8e310b9 100755
--- a/tests/cp/fiemap-perf
+++ b/tests/cp/fiemap-perf
@@ -24,6 +24,8 @@ touch fiemap_chk
 fiemap_capable_ fiemap_chk ||
   skip_ "this file system lacks FIEMAP support"
 
+require_filefrag_PATH_
+
 # Exclude ext3 (or unknown fs types)
 # as the emulated extent scanning is slow
 df -t ext3 . >/dev/null &&
diff --git a/tests/cp/sparse-fiemap b/tests/cp/sparse-fiemap
index 831bf0b..93b103a 100755
--- a/tests/cp/sparse-fiemap
+++ b/tests/cp/sparse-fiemap
@@ -33,6 +33,7 @@ else
   # It's not;  we need to create one, hence we need root access.
   require_root_
   require_mkfs_PATH_
+  require_filefrag_PATH_
 
   cwd=$PWD
   cleanup_() { cd /; umount "$cwd/mnt"; }
diff --git a/tests/init.cfg b/tests/init.cfg
index 9b05b34..bbe086b 100644
--- a/tests/init.cfg
+++ b/tests/init.cfg
@@ -212,6 +212,25 @@ require_mkfs_PATH_()
   export PATH
 }
 
+# Some versions of sudo do not include /usr/sbin in PATH.
+# Test if filefrag is in PATH, otherwise try to adapt PATH.
+require_filefrag_PATH_()
+{
+  type filefrag && return
+
+  case ":$PATH:" in
+    *:/usr/sbin:*) skip_ "no usable filefrag found" ;;
+  esac
+
+  test -x /usr/sbin/filefrag \
+    || skip_ "no usable filefrag found"
+
+  PATH="$PATH:/usr/sbin"
+  export PATH
+}
+
+
+
 get_process_status_()
 {
   sed -n '/^State:[	 ]*\([[:alpha:]]\).*/s//\1/p' /proc/$1/status
-- 
1.7.3.4

Reply via email to