[LTP] [PATCH v1] Add link01 test

Andrea Cervesato andrea.cervesato@suse.de
Fri Jan 19 10:07:13 CET 2024


From: Andrea Cervesato <andrea.cervesato@suse.com>

This test verifies that link() is working correctly on symlink()
generated files, renaming the symbolic link and checking that
stat() information are preserved.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 runtest/syscalls                        |  2 +-
 testcases/kernel/syscalls/link/link01.c | 47 +++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 1 deletion(-)
 create mode 100644 testcases/kernel/syscalls/link/link01.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 68460de0b..00a0dd87e 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -692,7 +692,7 @@ lchown03_16 lchown03_16
 lgetxattr01 lgetxattr01
 lgetxattr02 lgetxattr02
 
-link01 symlink01 -T link01
+link01 link01
 link02 link02
 link04 link04
 link05 link05
diff --git a/testcases/kernel/syscalls/link/link01.c b/testcases/kernel/syscalls/link/link01.c
new file mode 100644
index 000000000..e1cda7054
--- /dev/null
+++ b/testcases/kernel/syscalls/link/link01.c
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
+ *    Author: David Fenner
+ *    Copilot: Jon Hendrickson
+ * Copyright (C) 2024 Andrea Cervesato andrea.cervesato@suse.com
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies that link() is working correctly on symlink()
+ * generated files, renaming the symbolic link and checking that
+ * stat() information are preserved.
+ */
+
+#include "tst_test.h"
+
+static void run(void)
+{
+	struct stat oldlink_stat;
+	struct stat newlink_stat;
+	char *symname0 = "my_symlink0";
+	char *symname1 = "my_symlink1";
+
+	SAFE_SYMLINK(tst_get_tmpdir(), symname0);
+	SAFE_STAT(symname0, &oldlink_stat);
+
+	SAFE_LINK(symname0, symname1);
+	SAFE_STAT(symname1, &newlink_stat);
+
+	TST_EXP_EQ_LI(oldlink_stat.st_ino, newlink_stat.st_ino);
+	TST_EXP_EQ_LI(oldlink_stat.st_nlink, newlink_stat.st_nlink);
+
+	if (TST_RET == -1) {
+		SAFE_UNLINK(symname0);
+		remove(symname1);
+	} else {
+		SAFE_UNLINK(symname1);
+		remove(symname0);
+	}
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.needs_tmpdir = 1,
+};
-- 
2.35.3



More information about the ltp mailing list