From: Andrea Cervesato <andrea.cervesato@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 5/5] Add open15 test
Date: Tue, 02 Jul 2024 16:12:51 +0200 [thread overview]
Message-ID: <20240702-stat04-v1-5-e27d9953210d@suse.com> (raw)
In-Reply-To: <20240702-stat04-v1-0-e27d9953210d@suse.com>
From: Andrea Cervesato <andrea.cervesato@suse.com>
This test has been extracted from symlink01 and it verifies that
open() is working correctly on symlink() generated files.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 2 +-
testcases/kernel/syscalls/open/.gitignore | 1 +
testcases/kernel/syscalls/open/open15.c | 86 +++++++++++++++++++++++++++++++
3 files changed, 88 insertions(+), 1 deletion(-)
diff --git a/runtest/syscalls b/runtest/syscalls
index 928e75f9b..47efac158 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -923,7 +923,6 @@ nice04 nice04
nice05 nice05
open01 open01
-open01A symlink01 -T open01
open02 open02
open03 open03
open04 open04
@@ -936,6 +935,7 @@ open11 open11
open12 open12
open13 open13
open14 open14
+open15 open15
openat01 openat01
openat02 openat02
diff --git a/testcases/kernel/syscalls/open/.gitignore b/testcases/kernel/syscalls/open/.gitignore
index 001d874d6..af5997572 100644
--- a/testcases/kernel/syscalls/open/.gitignore
+++ b/testcases/kernel/syscalls/open/.gitignore
@@ -12,3 +12,4 @@
/open12_child
/open13
/open14
+/open15
diff --git a/testcases/kernel/syscalls/open/open15.c b/testcases/kernel/syscalls/open/open15.c
new file mode 100644
index 000000000..cbe2d62a4
--- /dev/null
+++ b/testcases/kernel/syscalls/open/open15.c
@@ -0,0 +1,86 @@
+// 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 open() is working correctly on symlink()
+ * generated files.
+ */
+
+#include "tst_test.h"
+
+#define FILENAME "myfile.txt"
+#define BIG_STRING "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
+
+static void test_open_symlink(void)
+{
+ int fd;
+ int str_size;
+ char buff[128];
+ char *symname = "my_symlink0";
+
+ str_size = strlen(BIG_STRING);
+
+ SAFE_SYMLINK(FILENAME, symname);
+
+ fd = SAFE_OPEN(symname, O_CREAT | O_RDWR, 0777);
+ SAFE_WRITE(SAFE_WRITE_ALL, fd, BIG_STRING, str_size);
+ SAFE_LSEEK(fd, 0, 0);
+ SAFE_READ(1, fd, buff, str_size);
+ SAFE_CLOSE(fd);
+
+ TST_EXP_EXPR(!strncmp(buff, BIG_STRING, str_size),
+ "symlink generated file can be opened to write data");
+
+ SAFE_UNLINK(symname);
+ SAFE_UNLINK(FILENAME);
+}
+
+static void test_open_compare(void)
+{
+ int fd_file, fd_symlink;
+ int str_size;
+ char buff_file[128];
+ char buff_symlink[128];
+ char *symname = "my_symlink1";
+
+ str_size = strlen(BIG_STRING);
+
+ fd_file = SAFE_OPEN(FILENAME, O_CREAT | O_RDWR, 0777);
+ SAFE_WRITE(SAFE_WRITE_ALL, fd_file, BIG_STRING, str_size);
+
+ SAFE_SYMLINK(FILENAME, symname);
+
+ SAFE_LSEEK(fd_file, 0, 0);
+ SAFE_READ(1, fd_file, buff_file, str_size);
+
+ fd_symlink = SAFE_OPEN(symname, O_RDWR, 0777);
+ SAFE_LSEEK(fd_symlink, 0, 0);
+ SAFE_READ(1, fd_symlink, buff_symlink, str_size);
+
+ TST_EXP_EXPR(!strncmp(buff_file, buff_symlink, str_size),
+ "file data is the equivalent to symlink generated file data");
+
+ SAFE_CLOSE(fd_file);
+ SAFE_CLOSE(fd_symlink);
+
+ SAFE_UNLINK(symname);
+ SAFE_UNLINK(FILENAME);
+}
+
+static void run(void)
+{
+ test_open_symlink();
+ test_open_compare();
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .needs_tmpdir = 1,
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2024-07-02 14:14 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-02 14:12 [LTP] [PATCH 0/5] symlink01 split Andrea Cervesato
2024-07-02 14:12 ` [LTP] [PATCH 1/5] Add stat04 test Andrea Cervesato
2024-07-04 7:06 ` Li Wang
2024-07-04 9:17 ` Cyril Hrubis
2024-07-04 9:23 ` Cyril Hrubis
2024-07-04 11:27 ` Li Wang
2024-07-04 11:55 ` Cyril Hrubis
2024-07-04 12:02 ` Li Wang
2024-07-02 14:12 ` [LTP] [PATCH 2/5] Fix TST_EXP_EXTR() stringification Andrea Cervesato
2024-07-04 7:11 ` Li Wang
2024-07-04 9:19 ` Cyril Hrubis
2024-07-02 14:12 ` [LTP] [PATCH 3/5] Add lstat03 test Andrea Cervesato
2024-07-04 6:36 ` Li Wang
2024-07-04 6:56 ` Li Wang
2024-07-02 14:12 ` [LTP] [PATCH 4/5] Add chmod08 test Andrea Cervesato
2024-07-04 7:12 ` Li Wang
2024-07-02 14:12 ` Andrea Cervesato [this message]
2024-07-04 7:18 ` [LTP] [PATCH 5/5] Add open15 test Li Wang
2024-07-04 7:32 ` Li Wang
2024-07-09 10:31 ` Andrea Cervesato via ltp
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240702-stat04-v1-5-e27d9953210d@suse.com \
--to=andrea.cervesato@suse.de \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox