[LTP] [PATCH v1] Add chdir05 test
Andrea Cervesato
andrea.cervesato@suse.de
Fri Jan 19 09:59:39 CET 2024
From: Andrea Cervesato <andrea.cervesato@suse.com>
This test has been extracted from symlink01 and it verifies that
chdir() is working correctly on symlink() generated files.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 2 +-
testcases/kernel/syscalls/chdir/.gitignore | 1 +
testcases/kernel/syscalls/chdir/chdir05.c | 58 ++++++++++++++++++++++
3 files changed, 60 insertions(+), 1 deletion(-)
create mode 100644 testcases/kernel/syscalls/chdir/chdir05.c
diff --git a/runtest/syscalls b/runtest/syscalls
index 6e2407879..68460de0b 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -61,8 +61,8 @@ capset04 capset04
cacheflush01 cacheflush01
chdir01 chdir01
-chdir01A symlink01 -T chdir01
chdir04 chdir04
+chdir05 chdir05
chmod01 chmod01
chmod01A symlink01 -T chmod01
diff --git a/testcases/kernel/syscalls/chdir/.gitignore b/testcases/kernel/syscalls/chdir/.gitignore
index 1b15eb6b9..96dc538f1 100644
--- a/testcases/kernel/syscalls/chdir/.gitignore
+++ b/testcases/kernel/syscalls/chdir/.gitignore
@@ -1,2 +1,3 @@
/chdir01
/chdir04
+/chdir05
diff --git a/testcases/kernel/syscalls/chdir/chdir05.c b/testcases/kernel/syscalls/chdir/chdir05.c
new file mode 100644
index 000000000..d9fa94a13
--- /dev/null
+++ b/testcases/kernel/syscalls/chdir/chdir05.c
@@ -0,0 +1,58 @@
+// 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 chdir() is working correctly on symlink()
+ * generated files.
+ */
+
+#include "tst_test.h"
+
+static void test_chdir(void)
+{
+ char *symname = "my_symlink0";
+
+ SAFE_SYMLINK(tst_get_tmpdir(), symname);
+ TST_EXP_PASS(chdir(symname));
+
+ SAFE_UNLINK(symname);
+}
+
+static void test_chdir_no_path(void)
+{
+ char *symname = "my_symlink1";
+
+ SAFE_SYMLINK("bc+eFhi!k", symname);
+ TST_EXP_FAIL(chdir(symname), ENOENT);
+
+ SAFE_UNLINK(symname);
+}
+
+static void test_chdir_loop(void)
+{
+ char *symname = "my_symlink2";
+
+ TST_EXP_PASS(symlink(symname, symname));
+ TST_EXP_FAIL(chdir(symname), ELOOP);
+
+ SAFE_UNLINK(symname);
+}
+
+static void run(void)
+{
+ test_chdir();
+ test_chdir_no_path();
+ test_chdir_loop();
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .needs_tmpdir = 1,
+};
--
2.35.3
More information about the ltp
mailing list