[LTP] [PATCH v1] Add lstat03 test
Andrea Cervesato
andrea.cervesato@suse.de
Thu Jan 18 16:24:38 CET 2024
From: Andrea Cervesato <andrea.cervesato@suse.com>
This test has been extracted from symlink01 test and it verifies
lstat() syscall functionalities on symlink generated file.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 4 +-
testcases/kernel/syscalls/lstat/.gitignore | 2 +
testcases/kernel/syscalls/lstat/lstat03.c | 69 ++++++++++++++++++++++
3 files changed, 73 insertions(+), 2 deletions(-)
create mode 100644 testcases/kernel/syscalls/lstat/lstat03.c
diff --git a/runtest/syscalls b/runtest/syscalls
index 6e2407879..69ac20b49 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..86efed348
--- /dev/null
+++ b/testcases/kernel/syscalls/lstat/lstat03.c
@@ -0,0 +1,69 @@
+// 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 lstat() is working correctly on symlink()
+ * generated files.
+ */
+
+#include "tst_test.h"
+
+static void test_lstat(void)
+{
+ char *symname = "my_symlink0";
+
+ TST_EXP_PASS(symlink(tst_get_tmpdir(), symname));
+
+ struct stat path_stat;
+ struct stat link_stat;
+
+ SAFE_LSTAT(tst_get_tmpdir(), &path_stat);
+ SAFE_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 void test_lstat_no_path(void)
+{
+ char *symname = "my_symlink1";
+ struct stat link_stat;
+
+ TST_EXP_PASS(symlink("bc+eFhi!k", symname));
+
+ SAFE_LSTAT(symname, &link_stat);
+ TST_EXP_EXPR((link_stat.st_mode & S_IFMT) == S_IFLNK,
+ "can read symlink file information");
+
+ SAFE_UNLINK(symname);
+}
+
+static void run(void)
+{
+ test_lstat();
+ test_lstat_no_path();
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .needs_tmpdir = 1,
+};
--
2.35.3
More information about the ltp
mailing list