Skip to contentSkip to conversation

fs/acls: fix some permission issue in the testcase

PATCH In review Li Wang 2 participants 4 messages Mar 10, 2015 – Mar 12, 2015 1 message not in the archive

lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH v2 1/1 fs/acls: fix some permission issue in the testcase

* Use 'test.sh'.

* Do some cleanup.

* Remove useless changes.

* Waive the consideration of SElinux Disabled and Permitive situation.

---
 testcases/kernel/fs/acls/acl_test01 | 62 +++++++++++++++++++++----------------
 1 file changed, 35 insertions(+), 27 deletions(-)
testcases/kernel/fs/acls/acl_test01 +35 -27
index af65213..93f6d80 100755
@@ -41,6 +41,8 @@ export TCID=acltest01
 export TST_TOTAL=5
 export TST_COUNT=1
 
+. test.sh
+
 TMP=${TMP:=/tmp}
 
 TEST_USER1="acltest1"
@@ -52,18 +54,28 @@ FILE_ACL="$TMP/tacl/mount-ext3/test_file"
 FILE_ACL_LINK="$TMP/tacl/mount-ext3/test_file_link"
 TCbin=`pwd`
 
+SELINUX=$(getenforce)
+
 #-----------------------------------------------------------------------
 # FUNCTION:  do_setup
 #-----------------------------------------------------------------------
 
 do_setup(){
 
+	tst_require_root
+
 	rm -f $FILE_ACL
 	rm -f $FILE_ACL_LINK
 
+	# We couldn't consider whether the SElinux is Disable or Permissive.
+	# We only set it to Permissive when it it Enforcing.
+	if [ "$SELINUX" = "Enforcing" ]; then
+		echo "set the SElinux to Permissive."
+		setenforce 0
+	fi
+
 	if [ "x$TEST_USER1_HOMEDIR" = "x" ]; then
-		echo "Could not find user $TEST_USER1's home directory."
-		exit 1
+		tst_brkm TCONF "Could not find user $TEST_USER1's home directory."
 	fi
 
 	# XXX (garrcoop): why is cleanup junk being done in setup??? Bad test!!!
@@ -73,8 +85,7 @@ do_setup(){
 	useradd -d $TEST_USER1_HOMEDIR -m -g $TEST_USER1_GROUP $TEST_USER1 -s /bin/sh
 
 	if [ $? -ne 0 ]; then
-		echo "Could not add test user $TEST_USER1."
-		exit 1
+		tst_brkm TCONF "Could not add test user $TEST_USER1."
 	fi
 
 }
@@ -91,6 +102,12 @@ do_cleanup() {
 	mount | grep "$TMP/tacl/mount-ext3" && umount -d $TMP/tacl/mount-ext3
 	[ "x$LOOP_DEV" != x ] && losetup -d $LOOP_DEV
 	rm -rf $TMP/tacl
+
+	# We set it back to Enforcing.
+	if [ "$SELINUX" = "Enforcing" ]; then
+		echo "set the SElinux back to Enforcing."
+		setenforce 1
+	fi
 }
 
 #-----------------------------------------------------------------------
@@ -103,13 +120,11 @@ then
 	echo ""
 else
 	if [ $(id -ru) != 0 ]; then
-		tst_resm TCONF "must be root to execute this script"
-		exit 0
+		tst_brkm TCONF "Must be root to execute this script"
 	fi
 
 	if ! ( test -d $TMP/tacl || mkdir -m 777 $TMP/tacl) ; then
-		tst_resm TCONF "failed to create $TMP/tacl directory."
-		exit 1
+		tst_brkm TCONF "Failed to create $TMP/tacl directory."
 	fi
 
 	trap do_cleanup EXIT
@@ -119,21 +134,18 @@ else
 
 	dd if=/dev/zero of=$TMP/tacl/blkext3 bs=1k count=10240 && chmod 777 $TMP/tacl/blkext3
 	if [ $? -ne 0 ] ; then
-		tst_resm TCONF "Failed to create $TMP/tacl/blkext3"
-		exit 0
+		tst_brkm TCONF "Failed to create $TMP/tacl/blkext3"
 	fi
 
 	# Avoid hardcoded loopback device values (-f tries to find the first
 	# available loopback device name)!
 	if ! LOOP_DEV=$(losetup -f) || [ "x$LOOP_DEV" = x ]; then
-		tst_resm TCONF "[ losetup.1 ] Failed to find an available loopback device -- is the required support compiled in your kernel?"
-		exit 0
+		tst_brkm TCONF "[ losetup.1 ] Failed to find an available loopback device -- is the required support compiled in your kernel?"
 	fi
 
 	if ! losetup $LOOP_DEV $TMP/tacl/blkext3 2>&1 > /dev/null; then
 		echo ""
-		tst_resm TCONF "[ losetup.2 ] Failed to setup the device."
-		exit 0
+		tst_brkm TCONF "[ losetup.2 ] Failed to setup the device."
 	fi
 
 	mount | grep ext2
@@ -180,20 +192,18 @@ then
 	${TCbin}/acl_file_test $FILE_ACL
 	if [ $? -ne 0 ]
 	then
-		EXIT_CODE=1
-		echo "Extended acls for files (FAILED)"
+		tst_brkm TFAIL "Extended acls for files."
 	else
-		echo "Extended acls for files (PASSED)"
+		tst_resm TPASS "Extended acls for files."
 	fi
 
 	echo "Trying extended acls for file links"
 	${TCbin}/acl_link_test $FILE_ACL_LINK
 	if [ $? -ne 0 ]
 	then
-		EXIT_CODE=1
-		echo "Extended acls for links (FAILED)"
+		tst_brkm TFAIL "Extended acls for links."
 	else
-		echo "Extended acls for links (PASSED)"
+		tst_resm TPASS "Extended acls for links."
 	fi
 else
 	do_setup
@@ -211,20 +221,18 @@ else
 	${TCbin}/acl_file_test $FILE_ACL
 	if [ $? -ne 0 ]
 	then
-		EXIT_CODE=1
-		echo "Extended acls for files (FAILED)"
+		tst_brkm TFAIL "Extended acls for files."
 	else
-		echo "Extended acls for files (PASSED)"
+		tst_resm TPASS "Extended acls for files."
 	fi
 
 	echo "Trying extended acls for file links"
 	${TCbin}/acl_link_test $FILE_ACL_LINK
 	if [ $? -ne 0 ]
 	then
-		EXIT_CODE=1
-		echo "Extended acls for links (FAILED)"
+		tst_brkm TFAIL "Extended acls for links."
 	else
-		echo "Extended acls for links (PASSED)"
+		tst_resm TPASS "Extended acls for links."
 	fi
 
 	chown $TEST_USER1 $FILE_ACL
@@ -235,4 +243,4 @@ else
 	do_cleanup
 fi
 
-exit $EXIT_CODE
+tst_exit
Signature · 13 lines
1.8.3.1


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#1 lore raw

Hi!

Quoted 2 lines

+SELINUX=$(getenforce)

There are systems without selinux support that does not have this command available. You should check if setenforce and getenforce is present on the system first, then you can try to set the selinux to permissive.

Quoted 22 lines

do_setup(){

testcases/kernel/fs/acls/acl_test01 +10 -2
+	tst_require_root
+
 	rm -f $FILE_ACL
 	rm -f $FILE_ACL_LINK
 
+	# We couldn't consider whether the SElinux is Disable or Permissive.
+	# We only set it to Permissive when it it Enforcing.
+	if [ "$SELINUX" = "Enforcing" ]; then
+		echo "set the SElinux to Permissive."
+		setenforce 0
+	fi
+
 	if [ "x$TEST_USER1_HOMEDIR" = "x" ]; then
-		echo "Could not find user $TEST_USER1's home directory."
-		exit 1
+		tst_brkm TCONF "Could not find user $TEST_USER1's home directory."
 	fi
 
 	# XXX (garrcoop): why is cleanup junk being done in setup??? Bad test!!!

testcases/kernel/fs/acls/acl_test01 do_setup(){ · line 89

Quoted 7 lines
testcases/kernel/fs/acls/acl_test01 +1 -2
@@ -73,8 +85,7 @@ do_setup(){
 	useradd -d $TEST_USER1_HOMEDIR -m -g $TEST_USER1_GROUP $TEST_USER1 -s /bin/sh
 
 	if [ $? -ne 0 ]; then
-		echo "Could not add test user $TEST_USER1."
-		exit 1
+		tst_brkm TCONF "Could not add test user $TEST_USER1."
 	fi

I guess that these should rather rather be TBROK than TCONF. Or is the useradd failure expected to happen?

Quoted 15 lines
testcases/kernel/fs/acls/acl_test01 +6 -0
 }
@@ -91,6 +102,12 @@ do_cleanup() {
 	mount | grep "$TMP/tacl/mount-ext3" && umount -d $TMP/tacl/mount-ext3
 	[ "x$LOOP_DEV" != x ] && losetup -d $LOOP_DEV
 	rm -rf $TMP/tacl
+
+	# We set it back to Enforcing.
+	if [ "$SELINUX" = "Enforcing" ]; then
+		echo "set the SElinux back to Enforcing."
+		setenforce 1
+	fi
 }
 
 #-----------------------------------------------------------------------

testcases/kernel/fs/acls/acl_test01 then · line 124

Quoted 7 lines
testcases/kernel/fs/acls/acl_test01 +1 -2
@@ -103,13 +120,11 @@ then
 	echo ""
 else
 	if [ $(id -ru) != 0 ]; then
-		tst_resm TCONF "must be root to execute this script"
-		exit 0
+		tst_brkm TCONF "Must be root to execute this script"
 	fi

We have tst_require_root() in test.sh, please use it.

testcases/kernel/fs/acls/acl_test01 then · line 128

Quoted 5 lines
testcases/kernel/fs/acls/acl_test01 +1 -2
 	if ! ( test -d $TMP/tacl || mkdir -m 777 $TMP/tacl) ; then
-		tst_resm TCONF "failed to create $TMP/tacl directory."
-		exit 1
+		tst_brkm TCONF "Failed to create $TMP/tacl directory."
 	fi

This looks more like TBROK as well. And even better the test should use tst_tmpdir() and tst_rmdir() to create temporary directories.

testcases/kernel/fs/acls/acl_test01 else · line 138

Quoted 9 lines
testcases/kernel/fs/acls/acl_test01 +1 -2
 	trap do_cleanup EXIT
@@ -119,21 +134,18 @@ else
 
 	dd if=/dev/zero of=$TMP/tacl/blkext3 bs=1k count=10240 && chmod 777 $TMP/tacl/blkext3
 	if [ $? -ne 0 ] ; then
-		tst_resm TCONF "Failed to create $TMP/tacl/blkext3"
-		exit 0
+		tst_brkm TCONF "Failed to create $TMP/tacl/blkext3"
 	fi

Looks like TBROK to me as well.

Quoted 17 lines
testcases/kernel/fs/acls/acl_test01 +2 -4
 	# Avoid hardcoded loopback device values (-f tries to find the first
 	# available loopback device name)!
 	if ! LOOP_DEV=$(losetup -f) || [ "x$LOOP_DEV" = x ]; then
-		tst_resm TCONF "[ losetup.1 ] Failed to find an available loopback device -- is the required support compiled in your kernel?"
-		exit 0
+		tst_brkm TCONF "[ losetup.1 ] Failed to find an available loopback device -- is the required support compiled in your kernel?"
 	fi
 
 	if ! losetup $LOOP_DEV $TMP/tacl/blkext3 2>&1 > /dev/null; then
 		echo ""
-		tst_resm TCONF "[ losetup.2 ] Failed to setup the device."
-		exit 0
+		tst_brkm TCONF "[ losetup.2 ] Failed to setup the device."
 	fi
 
 	mount | grep ext2

testcases/kernel/fs/acls/acl_test01 then · line 195

Quoted 6 lines
testcases/kernel/fs/acls/acl_test01 +1 -2
@@ -180,20 +192,18 @@ then
 	${TCbin}/acl_file_test $FILE_ACL
 	if [ $? -ne 0 ]
 	then
-		EXIT_CODE=1
-		echo "Extended acls for files (FAILED)"
+		tst_brkm TFAIL "Extended acls for files."

Why tst_brkm here? It should rather be tst_resm so that the test continues with the rest of testcases. The original code didn't exit the test here.

testcases/kernel/fs/acls/acl_test01 then · line 204

Quoted 12 lines
testcases/kernel/fs/acls/acl_test01 +2 -3
 	else
-		echo "Extended acls for files (PASSED)"
+		tst_resm TPASS "Extended acls for files."
 	fi
 
 	echo "Trying extended acls for file links"
 	${TCbin}/acl_link_test $FILE_ACL_LINK
 	if [ $? -ne 0 ]
 	then
-		EXIT_CODE=1
-		echo "Extended acls for links (FAILED)"
+		tst_brkm TFAIL "Extended acls for links."

Here as well.

testcases/kernel/fs/acls/acl_test01 else · line 224

Quoted 13 lines
testcases/kernel/fs/acls/acl_test01 +2 -3
 	else
-		echo "Extended acls for links (PASSED)"
+		tst_resm TPASS "Extended acls for links."
 	fi
 else
 	do_setup
@@ -211,20 +221,18 @@ else
 	${TCbin}/acl_file_test $FILE_ACL
 	if [ $? -ne 0 ]
 	then
-		EXIT_CODE=1
-		echo "Extended acls for files (FAILED)"
+		tst_brkm TFAIL "Extended acls for files."

And here as well.

testcases/kernel/fs/acls/acl_test01 then · line 204

Quoted 12 lines
testcases/kernel/fs/acls/acl_test01 +2 -3
 	else
-		echo "Extended acls for files (PASSED)"
+		tst_resm TPASS "Extended acls for files."
 	fi
 
 	echo "Trying extended acls for file links"
 	${TCbin}/acl_link_test $FILE_ACL_LINK
 	if [ $? -ne 0 ]
 	then
-		EXIT_CODE=1
-		echo "Extended acls for links (FAILED)"
+		tst_brkm TFAIL "Extended acls for links."

Here as well.

Quoted 12 lines
testcases/kernel/fs/acls/acl_test01 +2 -2
 	else
-		echo "Extended acls for links (PASSED)"
+		tst_resm TPASS "Extended acls for links."
 	fi
 
 	chown $TEST_USER1 $FILE_ACL
@@ -235,4 +243,4 @@ else
 	do_cleanup
 fi
 
-exit $EXIT_CODE
+tst_exit
Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw

Hi!

Quoted 12 lines
Quoted 4 lines

There are systems without selinux support that does not have this command available. You should check if setenforce and getenforce is present on the system first, then you can try to set the selinux to permissive.

Hmm, how about these two ways, which one is better?
1.
if [ -x "/usr/sbin/getenforce" -a -x "/usr/sbin/setenforce" ]; then
SELINUX=getenforce
else

       SELINUX=""

fi

Quoted 7 lines

2.
COMMAND=$(command -v "getenforce" "setenforce" |wc -l) if [ $COMMAND -eq 2 ]; then

	SELINUX=$(getenforce)
else
	SELINUX=""

fi

Both looks reasonably fine. The second may be a slightly better because it does not expect the commands to live under /usr/sbin/, which may not change, but it's more robust this way.

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#4 lore raw
In reply to a message not in the archive

Hi!

Quoted 5 lines
Quoted 2 lines

This looks more like TBROK as well. And even better the test should use tst_tmpdir() and tst_rmdir() to create temporary directories.

sorry, I don't know how to replace the $TMP/tacl by tst_rmdir() function in this test.
any detail instruction here?

The tst_tmpdir() creates an unique test temporary directory and changes the working directory to it.

The testcases usually call tst_tmpdir() in the setup and then proceed with creating temporary files with local paths so that they end up creating files in the working directory.

The temporary directory is then deleted recursively with tst_rmdir() in test cleanup.

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list