Skip to contentSkip to conversation

syscalls: chdir02: Add test for valid buffer lenghts

PATCH In review Cyril Hrubis 3 participants 4 messages Jan 22 – Feb 17

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 syscalls: chdir02: Add test for valid buffer lenghts

This test tests all buffer lenghts shorter than PATH_MAX and expect the chdir() syscall to succeed.

---
 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
runtest/syscalls +1 -0
index 05bb3ceb1..2f629e4e4 100644
@@ -68,6 +68,7 @@ cachestat03 cachestat03
 cachestat04 cachestat04
 
 chdir01 chdir01
+chdir02 chdir02
 chdir04 chdir04
 
 chmod01 chmod01
testcases/kernel/syscalls/chdir/.gitignore +1 -0
index 1b15eb6b9..3475c5e54 100644
@@ -1,2 +1,3 @@
 /chdir01
+/chdir02
 /chdir04
testcases/kernel/syscalls/chdir/chdir02.c new file +38 -0
new file mode 100644
index 000000000..fc1f80136
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2026 Cyril Hrubis <[email protected]>
+ */
+
+/*\
+ * 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},
+		{}
+	}
+};
Signature · 5 lines
2.52.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v1 1/1
#1 lore raw

Hi Cyril,

Quoted 2 lines

This test tests all buffer lenghts shorter than PATH_MAX and expect the chdir() syscall to succeed.

Thanks for quickly implementing this test. IMHO it should be merged before the release.

nit: I'd slightly prefer not to reuse the name of previously deleted test, but no big deal.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by Andrea Cervesato on v1 1/1
#2 lore raw
In reply to Cyril Hrubis

Hi!

A few typos below.

Quoted 1 line · Cyril Hrubis

This test tests all buffer lenghts shorter than PATH_MAX and expect the

                               ^
			      lengths

testcases/kernel/syscalls/chdir/chdir02.c line 29

Quoted 2 lines
testcases/kernel/syscalls/chdir/chdir02.c new file +2 -0
+	if (!fails)
+		tst_res(TPASS, "Path lenghts <1,%i> worked correctly", PATH_MAX);
                                       ^
				       lengths

The rest LGTM. Feel free to merge.

Signature · 7 lines
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Hi!

Quoted 1 line

The rest LGTM. Feel free to merge.

Typos fixed and patch pushed, thanks.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp