common/rc: Add _require_{chown,chmod}()
authorPavel Reichl <preichl@redhat.com>
Mon, 19 Apr 2021 22:04:03 +0000 (00:04 +0200)
committerEryu Guan <guaneryu@gmail.com>
Sun, 25 Apr 2021 04:53:55 +0000 (12:53 +0800)
Add helper functions that ensure that test is only executed on file
systems that implement chown, chmod and symbolic links.

Fixed test are: generic/{87,88,125,126,128,193,314,317,355,597,598}

[Eryu: remove _require_test and declare variable as local]

Signed-off-by: Pavel Reichl <preichl@redhat.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
12 files changed:
common/rc
tests/generic/087
tests/generic/088
tests/generic/125
tests/generic/126
tests/generic/128
tests/generic/193
tests/generic/314
tests/generic/317
tests/generic/355
tests/generic/597
tests/generic/598

index 11ff763..bed322f 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -2185,6 +2185,40 @@ _require_user()
     [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
 }
 
     [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
 }
 
+# check for a chown support
+#
+_require_chown()
+{
+       local rnd_uid=4242
+       local file="$TEST_DIR/chown_testfile"
+
+       rm -f $file
+       touch $file
+       chown ${rnd_uid}:${rnd_uid} $file >/dev/null 2>&1 \
+               || _notrun "chown is not supported ${FSTYP}"
+}
+
+
+# check for a chmod support
+# Since chmod sometimes fails silently actual functionality test is done
+#
+_require_chmod()
+{
+       local file="$TEST_DIR/chmod_testfile"
+
+       rm -f $file
+       touch $file
+
+       # get original file mode
+       local mode=`stat --format="0%a" $file`
+       # flip the user's read bit
+       let mode^=0400
+       chmod `printf '%o' "$mode"` $file
+       # check that the chmod actually flipped the bit
+       [ `stat --format="0%a" $file` == `printf '0%o' "$mode"` ] \
+               || _notrun "chmod is not supported ${FSTYP}"
+}
+
 # check for a group on the machine, fsgqa as default
 #
 _require_group()
 # check for a group on the machine, fsgqa as default
 #
 _require_group()
index 1f30dbf..c357611 100755 (executable)
@@ -37,6 +37,7 @@ _cleanup()
 # real QA test starts here
 _supported_fs generic
 _require_test
 # real QA test starts here
 _supported_fs generic
 _require_test
+_require_chown
 
 QA_FS_PERMS=$here/src/fs_perms
 
 
 QA_FS_PERMS=$here/src/fs_perms
 
index 9388a08..ad99bd7 100755 (executable)
@@ -29,6 +29,7 @@ _filter()
 # real QA test starts here
 _supported_fs generic
 _require_test
 # real QA test starts here
 _supported_fs generic
 _require_test
+_require_chown
 
 path=$TEST_DIR/t_access
 $here/src/t_access_root $path | tee $seqres.full | _filter
 
 path=$TEST_DIR/t_access
 $here/src/t_access_root $path | tee $seqres.full | _filter
index e84248d..8c8f5cd 100755 (executable)
@@ -25,6 +25,7 @@ _supported_fs generic
 _require_test
 _require_user
 _require_odirect
 _require_test
 _require_user
 _require_odirect
+_require_chmod
 
 TESTDIR=$TEST_DIR/ftrunc
 TESTFILE=$TESTDIR/ftrunc.tmp
 
 TESTDIR=$TEST_DIR/ftrunc
 TESTFILE=$TESTDIR/ftrunc.tmp
index ac25d29..636ca00 100755 (executable)
@@ -27,6 +27,7 @@ _cleanup()
 # real QA test starts here
 _supported_fs generic
 _require_test
 # real QA test starts here
 _supported_fs generic
 _require_test
+_require_chown
 
 QA_FS_PERMS=$here/src/fs_perms
 
 
 QA_FS_PERMS=$here/src/fs_perms
 
index b3e49ef..c1eae77 100755 (executable)
@@ -24,6 +24,7 @@ _supported_fs generic
 
 _require_scratch
 _require_user
 
 _require_scratch
 _require_user
+_require_chmod
 
 _scratch_mkfs >/dev/null 2>&1
 _scratch_mount "-o nosuid"
 
 _scratch_mkfs >/dev/null 2>&1
 _scratch_mount "-o nosuid"
index 3125efd..fd0ebbf 100755 (executable)
@@ -56,6 +56,7 @@ _supported_fs generic
 
 _require_test
 _require_user
 
 _require_test
 _require_user
+_require_chown
 
 test_root=$TEST_DIR/$seq.$$.root
 test_user=$TEST_DIR/$seq.$$.user
 
 test_root=$TEST_DIR/$seq.$$.root
 test_user=$TEST_DIR/$seq.$$.user
index 03df81c..540f0fe 100755 (executable)
@@ -29,6 +29,7 @@ _cleanup()
 _supported_fs generic
 _require_test
 _require_user
 _supported_fs generic
 _require_test
 _require_user
+_require_chown
 
 rm -rf $TEST_DIR/$seq-dir
 
 
 rm -rf $TEST_DIR/$seq-dir
 
index 29c37a5..289dfab 100755 (executable)
@@ -45,6 +45,7 @@ _require_scratch
 _require_user
 _require_ugid_map
 _require_userns
 _require_user
 _require_ugid_map
 _require_userns
+_require_chown
 qa_user_id=`id -u $qa_user`
 
 _filter_output()
 qa_user_id=`id -u $qa_user`
 
 _filter_output()
index 161dd04..74fba0f 100755 (executable)
@@ -32,6 +32,7 @@ _supported_fs generic
 _require_test
 _require_user
 _require_odirect
 _require_test
 _require_user
 _require_odirect
+_require_chown
 
 testfile=$TEST_DIR/$seq.test
 rm -f $testfile
 
 testfile=$TEST_DIR/$seq.test
 rm -f $testfile
index ba769d7..6602dc7 100755 (executable)
@@ -43,6 +43,7 @@ _require_sysctl_variable fs.protected_hardlinks
 _require_user fsgqa2
 # Do this SECOND so that qa_user is fsgqa, and _user_do uses that account
 _require_user fsgqa
 _require_user fsgqa2
 # Do this SECOND so that qa_user is fsgqa, and _user_do uses that account
 _require_user fsgqa
+_require_symlinks
 
 OWNER=fsgqa2
 OTHER=fsgqa
 
 OWNER=fsgqa2
 OTHER=fsgqa
index 6b76527..230c3ac 100755 (executable)
@@ -43,6 +43,7 @@ _require_sysctl_variable fs.protected_fifos
 _require_user fsgqa2
 # Do this SECOND so that qa_user is fsgqa, and _user_do uses that account
 _require_user fsgqa
 _require_user fsgqa2
 # Do this SECOND so that qa_user is fsgqa, and _user_do uses that account
 _require_user fsgqa
+_require_chmod
 
 USER1=fsgqa2
 USER2=fsgqa
 
 USER1=fsgqa2
 USER2=fsgqa