[LTP] [PATCH] syscalls: chdir02: Add test for valid buffer lenghts
Cyril Hrubis
chrubis@suse.cz
Thu Jan 22 16:05:40 CET 2026
This test tests all buffer lenghts shorter than PATH_MAX and expect the
chdir() syscall to succeed.
Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/chdir/.gitignore | 1 +
testcases/kernel/syscalls/chdir/chdir02.c | 38 ++++++++++++++++++++++
3 files changed, 40 insertions(+)
create mode 100644 testcases/kernel/syscalls/chdir/chdir02.c
diff --git a/runtest/syscalls b/runtest/syscalls
index 05bb3ceb1..2f629e4e4 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -68,6 +68,7 @@ cachestat03 cachestat03
cachestat04 cachestat04
chdir01 chdir01
+chdir02 chdir02
chdir04 chdir04
chmod01 chmod01
diff --git a/testcases/kernel/syscalls/chdir/.gitignore b/testcases/kernel/syscalls/chdir/.gitignore
index 1b15eb6b9..3475c5e54 100644
--- a/testcases/kernel/syscalls/chdir/.gitignore
+++ b/testcases/kernel/syscalls/chdir/.gitignore
@@ -1,2 +1,3 @@
/chdir01
+/chdir02
/chdir04
diff --git a/testcases/kernel/syscalls/chdir/chdir02.c b/testcases/kernel/syscalls/chdir/chdir02.c
new file mode 100644
index 000000000..fc1f80136
--- /dev/null
+++ b/testcases/kernel/syscalls/chdir/chdir02.c
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2026 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+/*\
+ * Tests that all paths shorter than PATH_MAX work fine.
+ */
+
+#include "tst_test.h"
+
+static char *path;
+
+static void verify_chdir(void)
+{
+ int i, fails = 0;
+
+ memset(path, 0, PATH_MAX);
+
+ for (i = 1; i < PATH_MAX; i++) {
+ memset(path, '/', i);
+
+ TST_EXP_PASS_SILENT(chdir(path), "chdir('/' * %i)", i);
+
+ fails += !TST_PASS;
+ }
+
+ if (!fails)
+ tst_res(TPASS, "Path lenghts <1,%i> worked correctly", PATH_MAX);
+}
+
+static struct tst_test test = {
+ .test_all = verify_chdir,
+ .bufs = (struct tst_buffers []) {
+ {&path, .size = PATH_MAX},
+ {}
+ }
+};
--
2.52.0
More information about the ltp
mailing list