[LTP] [PATCH v2] Add lstat03 test

Andrea Cervesato andrea.cervesato@suse.de
Mon Feb 19 16:49:09 CET 2024


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

This test has been extracted from symlink01 test and it checks that
lstat() executed on file provide the same information of symlink
linking to it.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
Remove test_lstat_no_path() test
TST_EXP_PASS for lstat() and SAFE_SYMLINK for symlink()
Removed memory leak using tst_get_tmpdir()

 runtest/syscalls                           |  4 +-
 testcases/kernel/syscalls/lstat/.gitignore |  2 +
 testcases/kernel/syscalls/lstat/lstat03.c  | 50 ++++++++++++++++++++++
 3 files changed, 54 insertions(+), 2 deletions(-)
 create mode 100644 testcases/kernel/syscalls/lstat/lstat03.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 7794f1465..a7f22d907 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -723,12 +723,12 @@ lseek02 lseek02
 lseek07 lseek07
 lseek11 lseek11
 
-lstat01A symlink01 -T lstat01
-lstat01A_64 symlink01 -T lstat01_64
 lstat01 lstat01
 lstat01_64 lstat01_64
 lstat02 lstat02
 lstat02_64 lstat02_64
+lstat03 lstat03
+lstat03_64 lstat03_64
 
 mallinfo02 mallinfo02
 
diff --git a/testcases/kernel/syscalls/lstat/.gitignore b/testcases/kernel/syscalls/lstat/.gitignore
index a497a445f..72cba871f 100644
--- a/testcases/kernel/syscalls/lstat/.gitignore
+++ b/testcases/kernel/syscalls/lstat/.gitignore
@@ -2,3 +2,5 @@
 /lstat01_64
 /lstat02
 /lstat02_64
+/lstat03
+/lstat03_64
diff --git a/testcases/kernel/syscalls/lstat/lstat03.c b/testcases/kernel/syscalls/lstat/lstat03.c
new file mode 100644
index 000000000..30932f1fa
--- /dev/null
+++ b/testcases/kernel/syscalls/lstat/lstat03.c
@@ -0,0 +1,50 @@
+// 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 checks that lstat() executed on file provide the same information
+ * of symlink linking to it.
+ */
+
+#include "tst_test.h"
+
+static void run(void)
+{
+	char *symname = "my_symlink0";
+	char *tmpdir = tst_get_tmpdir();
+
+	SAFE_SYMLINK(tmpdir, symname);
+
+	struct stat path_stat;
+	struct stat link_stat;
+
+	TST_EXP_PASS(lstat(tmpdir, &path_stat));
+	TST_EXP_PASS(lstat(symname, &link_stat));
+
+	TST_EXP_EQ_LI(path_stat.st_dev, link_stat.st_dev);
+	TST_EXP_EQ_LI(path_stat.st_nlink, link_stat.st_nlink);
+	TST_EXP_EQ_LI(path_stat.st_uid, link_stat.st_uid);
+	TST_EXP_EQ_LI(path_stat.st_gid, link_stat.st_gid);
+	TST_EXP_EQ_LI(path_stat.st_atime, link_stat.st_atime);
+	TST_EXP_EQ_LI(path_stat.st_mtime, link_stat.st_mtime);
+	TST_EXP_EQ_LI(path_stat.st_ctime, link_stat.st_ctime);
+
+	TST_EXP_EXPR(path_stat.st_mode != link_stat.st_mode,
+		"object and symbolic link have different st_mode");
+	TST_EXP_EXPR(path_stat.st_size != link_stat.st_size,
+		"object and symbolic link have different st_size");
+
+	SAFE_UNLINK(symname);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.needs_tmpdir = 1,
+};
-- 
2.35.3



More information about the ltp mailing list