[LTP] [PATCH v6 4/4] syscalls: lchown03: Merge into lchown02

Ricardo B. Marlière rbm@suse.com
Thu Sep 11 00:19:50 CEST 2025


From: Ricardo B. Marlière <rbm@suse.com>

Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
 runtest/syscalls                            |   2 -
 testcases/kernel/syscalls/lchown/.gitignore |   2 -
 testcases/kernel/syscalls/lchown/Makefile   |   5 -
 testcases/kernel/syscalls/lchown/lchown02.c |  15 +++
 testcases/kernel/syscalls/lchown/lchown03.c | 153 ----------------------------
 5 files changed, 15 insertions(+), 162 deletions(-)

diff --git a/runtest/syscalls b/runtest/syscalls
index c9b46b8efe3217150ee0740e982ea5a133b3aa46..4b284f27939d270ce920e02e2febc1fccc0fa231 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -732,9 +732,7 @@ landlock10 landlock10
 lchown01 lchown01
 lchown01_16 lchown01_16
 lchown02  lchown02
-lchown03  lchown03
 lchown02_16 lchown02_16
-lchown03_16 lchown03_16
 
 lgetxattr01 lgetxattr01
 lgetxattr02 lgetxattr02
diff --git a/testcases/kernel/syscalls/lchown/.gitignore b/testcases/kernel/syscalls/lchown/.gitignore
index e3c7bc29c32d6ef65fd8debfdb9e651dbd96364b..491ffa0815984ec68484c07696621ff668648351 100644
--- a/testcases/kernel/syscalls/lchown/.gitignore
+++ b/testcases/kernel/syscalls/lchown/.gitignore
@@ -2,5 +2,3 @@
 /lchown01_16
 /lchown02
 /lchown02_16
-/lchown03
-/lchown03_16
diff --git a/testcases/kernel/syscalls/lchown/Makefile b/testcases/kernel/syscalls/lchown/Makefile
index 7c76afea572e8ba6c5509714ba6f9f45a7b2d4d7..1a66088e3206b2073a3cac2e62a71115ece9b4e7 100644
--- a/testcases/kernel/syscalls/lchown/Makefile
+++ b/testcases/kernel/syscalls/lchown/Makefile
@@ -3,13 +3,8 @@
 
 top_srcdir		?= ../../../..
 
-# Remove after rewriting all tests to the new API.
-USE_LEGACY_COMPAT_16_H := 1
-
 include $(top_srcdir)/include/mk/testcases.mk
 
-SRCS			:= $(sort $(wildcard $(abs_srcdir)/lchown*.c))
-
 include $(abs_srcdir)/../utils/compat_16.mk
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/lchown/lchown02.c b/testcases/kernel/syscalls/lchown/lchown02.c
index aa80da143a608dbdbf34e23e00dce52ad3b54d8c..335e48ea3ace0fb19af2cd32a8e754f0cc5da893 100644
--- a/testcases/kernel/syscalls/lchown/lchown02.c
+++ b/testcases/kernel/syscalls/lchown/lchown02.c
@@ -16,6 +16,8 @@
  * - ENAMETOOLONG, if the pathname component is too long.
  * - ENOTDIR, if the directory component in pathname is not a directory.
  * - ENOENT, if the specified file does not exists.
+ * - ELOOP, if too many symbolic links were encountered in resolving path.
+ * - EROFS, if the file is on a read-only file system.
  */
 
 #include <pwd.h>
@@ -32,6 +34,8 @@
 #define TFILE3 "t_file"
 #define SFILE3 "t_file/sfile"
 #define MAXPATH (PATH_MAX + 2)
+#define EFILE1 "infinite_loop1/eloop"
+#define TEST_EROFS "mntpoint"
 
 static char *sfile1;
 static char *sfile2;
@@ -39,6 +43,8 @@ static char *bad_addr;
 static char *maxpath;
 static char *sfile3;
 static char *empty;
+static char *eloop;
+static char *erofs;
 static struct passwd *ltpuser;
 
 static struct test_case_t {
@@ -52,6 +58,8 @@ static struct test_case_t {
 	{ &maxpath, "Pathname too long", ENAMETOOLONG },
 	{ &sfile3, "Path contains regular file", ENOTDIR },
 	{ &empty, "Pathname is empty", ENOENT },
+	{ &eloop, "Too many symlinks", ELOOP },
+	{ &erofs, "Read-only filesystem", EROFS },
 };
 
 static void run(unsigned int i)
@@ -80,6 +88,9 @@ static void setup(void)
 	SAFE_SYMLINK(TFILE1, SFILE1);
 	SAFE_SETEUID(ltpuser->pw_uid);
 
+	SAFE_SYMLINK("infinite_loop1", "infinite_loop2");
+	SAFE_SYMLINK("infinite_loop2", "infinite_loop1");
+
 	SAFE_MKDIR(DIR_TEMP, 0777);
 	SAFE_TOUCH(TFILE2, 0666, NULL);
 	SAFE_SYMLINK(TFILE2, SFILE2);
@@ -94,12 +105,16 @@ static struct tst_test test = {
 	.setup = setup,
 	.needs_root = 1,
 	.needs_tmpdir = 1,
+	.mntpoint = TEST_EROFS,
+	.needs_rofs = 1,
 	.bufs = (struct tst_buffers []) {
 		{&maxpath, .size = MAXPATH},
 		{&sfile1, .str = SFILE1},
 		{&sfile2, .str = SFILE2},
 		{&sfile3, .str = SFILE3},
+		{&eloop, .str = EFILE1},
 		{&empty, .str = ""},
+		{ &erofs, .str = TEST_EROFS },
 		{}
 	},
 };
diff --git a/testcases/kernel/syscalls/lchown/lchown03.c b/testcases/kernel/syscalls/lchown/lchown03.c
deleted file mode 100644
index ecb6ed64dfd472d56abbc5a4fe5da67a48919c58..0000000000000000000000000000000000000000
--- a/testcases/kernel/syscalls/lchown/lchown03.c
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright (c) 2014 Fujitsu Ltd.
- * Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-/*
- * Test Description:
- *  Verify that,
- *   1. lchown() fails with -1 return value and sets errno to ELOOP
- *      if too many symbolic links were encountered in resolving path.
- *   2. lchown() fails with -1 return value and sets errno to EROFS
- *      if the file is on a read-only file system.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <grp.h>
-#include <pwd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <sys/mount.h>
-
-#include "test.h"
-#include "safe_macros.h"
-
-/*
- * Don't forget to remove USE_LEGACY_COMPAT_16_H from Makefile after
- * rewriting all tests to the new API.
- */
-#include "compat_16.h"
-
-#define DIR_MODE	(S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP| \
-			 S_IXGRP|S_IROTH|S_IXOTH)
-#define TEST_EROFS	"mntpoint"
-
-static char test_eloop[PATH_MAX] = ".";
-static const char *device;
-static int mount_flag;
-
-static struct test_case_t {
-	char *pathname;
-	int exp_errno;
-} test_cases[] = {
-	{test_eloop, ELOOP},
-	{TEST_EROFS, EROFS},
-};
-
-TCID_DEFINE(lchown03);
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-
-static void setup(void);
-static void lchown_verify(const struct test_case_t *);
-static void cleanup(void);
-
-int main(int argc, char *argv[])
-{
-	int lc;
-	int i;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-		for (i = 0; i < TST_TOTAL; i++)
-			lchown_verify(&test_cases[i]);
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-static void setup(void)
-{
-	int i;
-	const char *fs_type;
-
-	tst_require_root();
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	fs_type = tst_dev_fs_type();
-	device = tst_acquire_device(cleanup);
-
-	if (!device)
-		tst_brkm(TCONF, cleanup, "Failed to acquire device");
-
-	SAFE_MKDIR(cleanup, "test_eloop", DIR_MODE);
-	SAFE_SYMLINK(cleanup, "../test_eloop", "test_eloop/test_eloop");
-	for (i = 0; i < 43; i++)
-		strcat(test_eloop, "/test_eloop");
-
-	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
-	SAFE_MKDIR(cleanup, TEST_EROFS, DIR_MODE);
-	SAFE_MOUNT(cleanup, device, TEST_EROFS, fs_type, MS_RDONLY, NULL);
-	mount_flag = 1;
-}
-
-static void lchown_verify(const struct test_case_t *test)
-{
-	UID16_CHECK(geteuid(), "lchown", cleanup)
-	GID16_CHECK(getegid(), "lchown", cleanup)
-
-	TEST(LCHOWN(cleanup, test->pathname, geteuid(), getegid()));
-
-	if (TEST_RETURN != -1) {
-		tst_resm(TFAIL, "lchown() returned %ld, expected -1, errno=%d",
-			 TEST_RETURN, test->exp_errno);
-		return;
-	}
-
-	if (TEST_ERRNO == test->exp_errno) {
-		tst_resm(TPASS | TTERRNO, "lchown() failed as expected");
-	} else {
-		tst_resm(TFAIL | TTERRNO,
-			 "lchown() failed unexpectedly; expected: %d - %s",
-			 test->exp_errno,
-			 strerror(test->exp_errno));
-	}
-}
-
-static void cleanup(void)
-{
-	if (mount_flag && tst_umount(TEST_EROFS) < 0)
-		tst_resm(TWARN | TERRNO, "umount device:%s failed", device);
-
-	if (device)
-		tst_release_device(device);
-
-	tst_rmdir();
-}

-- 
2.51.0



More information about the ltp mailing list