Hi!
It looks (at least for me) that fs_perms tests are broken for a long time (as
they are trying to find binaries in working directory instead of LTPROOT).

Attached patch fixes fs_perm.c to look for test binary in
$LTPROOT/testcases/bin/ rather than in ./ and converts silly and broken
fs_perms_simple.sh script into runtest file that is also added into runltp
script.


The way how now fs_perm is copying test file into temporary directory is not
ideall either because the test fails when executed by hand. I could think of
creating file with a such line:

#!/bin/true

Or maybe more robust:

#!/bin/sh
true

But I'm not sure if there is always /bin/true (as it's buildin in most of the
shells) or if I it's good idea to add dependecy for /bin/sh. But this would
avoid compiling dummy C program and copying it from $LTPROOT/testcases/bin/.

Or we could do some trickery to embed the "dummy" binary file into the code as
array.

Any ideas here?


However the problem discussed above fs_perms tests are at least working with
this patch.

Signed-off-by: Cyril Hrubis [email protected]

-- 
Cyril Hrubis
[email protected]
diff --git a/runltp b/runltp
index b848a7f..097e32e 100755
--- a/runltp
+++ b/runltp
@@ -557,6 +557,7 @@ main()
 
         for SCENFILES in ${LTPROOT}/runtest/syscalls                \
                          ${LTPROOT}/runtest/fs                      \
+                         ${LTPROOT}/runtest/fs_perms_simple         \
                          ${LTPROOT}/runtest/fsx                     \
                          ${LTPROOT}/runtest/dio                     \
                          ${LTPROOT}/runtest/io                      \
diff --git a/runtest/fs b/runtest/fs
index 75c5e38..2de871d 100644
--- a/runtest/fs
+++ b/runtest/fs
@@ -64,9 +64,6 @@ writetest01	writetest
 #Also run the fs_di (Data Integrity tests)
 fs_di fs_di -d $TMPDIR
 
-#Also run the fs_perms (File System Permission Tests)
-fs_perms fs_perms_simpletest.sh
-
 # Read every file in /proc. Not likely to crash, but does enough 
 # to disturb the kernel. A good kernel latency killer too.
 # Was not sure why it should reside in runtest/crashme and won´t get tested ever
diff --git a/runtest/fs_perms_simple b/runtest/fs_perms_simple
new file mode 100644
index 0000000..cc986bd
--- /dev/null
+++ b/runtest/fs_perms_simple
@@ -0,0 +1,26 @@
+#
+# These tests are setting file permissions/group/uid and are trying to
+# open/write/execute the file.
+#
+#
+#
+# fs_perms file_mode file_uid file_gid test_uid test_gid mode (r|w|x) expected_result
+#
+fs_perms01 fs_perms 001 99 99 12 100 x 0
+fs_perms02 fs_perms 010 99 99 200 99 x 0
+fs_perms03 fs_perms 100 99 99 99 500 x 0
+fs_perms04 fs_perms 002 99 99 12 100 w 0
+fs_perms05 fs_perms 020 99 99 200 99 w 0
+fs_perms06 fs_perms 200 99 99 99 500 w 0
+fs_perms07 fs_perms 004 99 99 12 100 r 0
+fs_perms08 fs_perms 040 99 99 200 99 r 0
+fs_perms09 fs_perms 400 99 99 99 500 r 0
+fs_perms10 fs_perms 000 99 99 99 99  r 1
+fs_perms11 fs_perms 000 99 99 99 99  w 1
+fs_perms12 fs_perms 000 99 99 99 99  x 1
+fs_perms13 fs_perms 010 99 99 99 500 x 1
+fs_perms14 fs_perms 100 99 99 200 99 x 1
+fs_perms15 fs_perms 020 99 99 99 500 w 1
+fs_perms16 fs_perms 200 99 99 200 99 w 1
+fs_perms17 fs_perms 040 99 99 99 500 r 1
+fs_perms18 fs_perms 400 99 99 200 99 r 1
diff --git a/testcases/kernel/fs/fs_perms/fs_perms.c b/testcases/kernel/fs/fs_perms/fs_perms.c
index ad44028..274988d 100644
--- a/testcases/kernel/fs/fs_perms/fs_perms.c
+++ b/testcases/kernel/fs/fs_perms/fs_perms.c
@@ -1,5 +1,6 @@
 /*
  *   Copyright (c) International Business Machines  Corp., 2000
+ *   Copyright (c) 2010 Cyril Hrubis [email protected]
  *
  *   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
@@ -42,111 +43,132 @@
 char *TCID = "fs_perms";
 int TST_TOTAL = 1;
 
-static int testsetup(mode_t mode, int cuserId, int cgroupId)
+void cleanup(void)
+{
+	tst_rmdir();
+	tst_exit();
+}
+
+/*
+ * Create temporary directory and copy binary file equivalent to /bin/true into
+ * it as test.file.
+ */
+static int testsetup(mode_t mode, int user_id, int group_id)
 {
 	int ret;
-	char cmd_str[256];
+	char *ltp_root = getenv("LTPROOT");
+	char cmd_str[1024];
 
-	sprintf(cmd_str, "cp %s/testx test.file", getcwd(NULL, 0));
 	tst_tmpdir();
 
-	ret = unlink("test.file");
-	if (ret && errno != ENOENT)
-		goto done;
+	if (ltp_root == NULL)
+		tst_brkm(TBROK, cleanup, "LTPROOT variable is not exported"); 
+
+	snprintf(cmd_str, sizeof(cmd_str), "cp %s/testcases/bin/fs_perms_testx test.file",
+                 ltp_root);
+
 	ret = system(cmd_str);
+	
 	if (ret)
-		goto done;
+		return ret;
+
 	ret = chmod("test.file", mode);
+	
 	if (ret)
-		goto done;
-	ret = chown("test.file", cuserId, cgroupId);
+		return ret;
 
- done:
+	ret = chown("test.file", user_id, group_id);
+	
 	return ret;
 }
 
-void cleanup(void)
+static int testfperm(int user_id, int group_id, char *fperm)
 {
-	tst_rmdir();
-	tst_exit();
-}
-
-static int testfperm(int userId, int groupId, char *fperm)
-{
-	/* SET CURRENT USER/GROUP PERMISSIONS */
-	if (setegid(groupId)) {
-		tst_brkm(TBROK, cleanup, "could not setegid to %d: %s", groupId, strerror(errno));
+	FILE *testfile;
+	int ret;
+	
+	if (setegid(group_id)) {
+		tst_brkm(TBROK, cleanup, "could not setegid to %d: %s", group_id, strerror(errno));
 		seteuid(0);
 		setegid(0);
 		return -1;
 	}
-	if (seteuid(userId)) {
-		tst_brkm(TBROK, cleanup, "could not seteuid to %d: %s", userId, strerror(errno));
+
+	if (seteuid(user_id)) {
+		tst_brkm(TBROK, cleanup, "could not seteuid to %d: %s", user_id, strerror(errno));
 		seteuid(0);
 		setegid(0);
 		return -1;
 	}
 
-	switch (tolower(fperm[0])) {
-	case 'x': {
+	if (tolower(fperm[0]) == 'x') {
 		int status;
+		
 		if (fork() == 0) {
 			execlp("./test.file", "test.file", NULL);
 			exit(1);
 		}
+		
 		wait(&status);
+		
 		seteuid(0);
 		setegid(0);
+		
 		return WEXITSTATUS(status);
 	}
-	default: {
-		FILE *testfile;
-		if ((testfile = fopen("test.file", fperm))) {
-			fclose(testfile);
-			seteuid(0);
-			setegid(0);
-			return 0;
-		} else {
-			seteuid(0);
-			setegid(0);
-			return 1;
-		}
-	}
-	}
+
+	if ((testfile = fopen("test.file", fperm))) {
+		fclose(testfile);
+		ret = 0;
+	} else
+		ret = 1;	
+
+	seteuid(0);
+	setegid(0);
+
+	return ret;
+}
+
+static void print_usage(const char *bname)
+{
+	char *usage = "<file mode> <file UID> <file GID> "
+                      "<tester UID> <tester GID> <permission "
+                      "to test r|w|x> <expected result 0|1>";
+
+	printf("Usage: %s %s\n", bname, usage);
 }
 
 int main(int argc, char *argv[])
 {
 	char *fperm;
-	int result, exresult = 0, cuserId = 0, cgroupId = 0, userId = 0, groupId = 0;
+	int result, exresult, cuser_id, cgroup_id, user_id, group_id;
 	mode_t mode;
 
 	tst_require_root(tst_exit);
 
-	switch (argc) {
-	case 8:
-		mode = strtol(argv[1], (char **)NULL, 010);
-		cuserId = atoi(argv[2]);
-		cgroupId = atoi(argv[3]);
-		userId = atoi(argv[4]);
-		groupId = atoi(argv[5]);
-		fperm = argv[6];
-		exresult = atoi(argv[7]);
-		break;
-	default:
-		printf("Usage: %s <mode of file> <UID of file> <GID of file> <UID of tester> <GID of tester> <permission to test r|w|x> <expected result as 0|1>\n", argv[0]);
+	if (argc != 8) {
+		print_usage(argv[0]);
 		return 1;
 	}
 
-	result = testsetup(mode, cuserId, cgroupId);
-	if (result) {
+	mode      = strtol(argv[1], NULL, 010);
+	cuser_id  = atoi(argv[2]);
+	cgroup_id = atoi(argv[3]);
+	user_id   = atoi(argv[4]);
+	group_id  = atoi(argv[5]);
+	fperm     = argv[6];
+	exresult  = atoi(argv[7]);
+
+	result = testsetup(mode, cuser_id, cgroup_id);
+
+	if (result)
 		tst_brkm(TBROK, cleanup, "testsetup() failed: %s", strerror(errno));
-	}
 
-	result = testfperm(userId, groupId, fperm);
-	unlink("test.file");
+	result = testfperm(user_id, group_id, fperm);
+
 	tst_resm(exresult == result ? TPASS : TFAIL, "%c a %03o file owned by (%d/%d) as user/group(%d/%d)",
-		fperm[0], mode, cuserId, cgroupId, userId, groupId);
-	cleanup();
-	return 0;
+		fperm[0], mode, cuser_id, cgroup_id, user_id, group_id);
+
+	tst_rmdir();
+	tst_exit();
 }
diff --git a/testcases/kernel/fs/fs_perms/fs_perms_simpletest.sh b/testcases/kernel/fs/fs_perms/fs_perms_simpletest.sh
deleted file mode 100755
index 5a8df8b..0000000
--- a/testcases/kernel/fs/fs_perms/fs_perms_simpletest.sh
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/bin/sh
-
-Code=0
-
-test()
-{
-    arg=${1}; shift
-    res=${1}
-
-    ./fs_perms ${arg} ${res}
-    if [ $? -ne 0 ]; then
-       Code=$((Code + 1))
-    fi
-}
-
-test "001 99 99 12 100 x" 0
-test "010 99 99 200 99 x" 0
-test "100 99 99 99 500 x" 0
-test "002 99 99 12 100 w" 0
-test "020 99 99 200 99 w" 0
-test "200 99 99 99 500 w" 0
-test "004 99 99 12 100 r" 0
-test "040 99 99 200 99 r" 0
-test "400 99 99 99 500 r" 0
-test "000 99 99 99 99 r" 1
-test "000 99 99 99 99 w" 1
-test "000 99 99 99 99 x" 1
-test "010 99 99 99 500 x" 1
-test "100 99 99 200 99 x" 1
-test "020 99 99 99 500 w" 1
-test "200 99 99 200 99 w" 1
-test "040 99 99 99 500 r" 1
-test "400 99 99 200 99 r" 1
-
-exit ${Code}
diff --git a/testcases/kernel/fs/fs_perms/fs_perms_testx.c b/testcases/kernel/fs/fs_perms/fs_perms_testx.c
new file mode 100644
index 0000000..4af2aea
--- /dev/null
+++ b/testcases/kernel/fs/fs_perms/fs_perms_testx.c
@@ -0,0 +1,29 @@
+/*
+ *   Copyright (c) 2010 Cyril Hrubis [email protected]
+ *
+ *   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
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ *   the GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program;  if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+ /*
+  * This program just mimics /bin/true behaviour (as the main test tries to
+  * execute this).
+  */
+
+#include <stdio.h>
+
+int main(void)
+{
+	return 0;
+}
diff --git a/testcases/kernel/fs/fs_perms/testx.c b/testcases/kernel/fs/fs_perms/testx.c
deleted file mode 100644
index 5944ce0..0000000
--- a/testcases/kernel/fs/fs_perms/testx.c
+++ /dev/null
@@ -1,4 +0,0 @@
-#include <stdio.h>
-int main(void) {
-	return 0;
-}
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to