Add a helper checking if xattr progs are available.

Add helpers generating random strings which could be used as
key/value of xattr.

Add a helper checking if same named files under two directories have
same xattrs.

Signed-off-by: Jingbo Xu <[email protected]>
---
 tests/common/rc | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/tests/common/rc b/tests/common/rc
index a9ae369..293e556 100644
--- a/tests/common/rc
+++ b/tests/common/rc
@@ -86,6 +86,12 @@ _require_root()
        [ "$(id -u)" = "0" ] || _notrun "must be run as root"
 }
 
+_require_xattr()
+{
+       which setfattr >/dev/null 2>&1 ||
+               _notrun "attr isn't installed, skipped."
+}
+
 # this test requires erofs kernel support
 _require_erofs()
 {
@@ -315,6 +321,32 @@ _require_fssum()
        [ -x $FSSUM_PROG ] || _notrun "fssum not built"
 }
 
+# generate random string with maximum $1 length
+_random()
+{
+       head -20 /dev/urandom | base64 -w0 | head -c $1
+}
+
+# generate short random string
+_srandom()
+{
+       _random 16
+}
+
+# check xattrs of same files under two directories
+_check_xattrs()
+{
+       local dir1="$1"
+       local dir2="$2"
+       local dirs=`ls $dir1`
+
+       for d in $dirs; do
+               xattr1=`getfattr --absolute-names -d $dir1/$d | tail -n+2`
+               xattr2=`getfattr --absolute-names -d $dir2/$d | tail -n+2`
+               [ "x$xattr1" = "x$xattr2" ] || _fail "-->check xattrs FAILED"
+       done
+}
+
 _check_results()
 {
        [ -z $srcdir ] && return 0
-- 
1.8.3.1

Reply via email to