public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Andrea Cervesato <andrea.cervesato@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v4 4/4] Add open15 test
Date: Thu, 11 Jul 2024 09:43:56 +0200	[thread overview]
Message-ID: <20240711-stat04-v4-4-d30c26fdaf5a@suse.com> (raw)
In-Reply-To: <20240711-stat04-v4-0-d30c26fdaf5a@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.

Reviewed-by: Li Wang <liwang@redhat.com>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 runtest/syscalls                          |  2 +-
 testcases/kernel/syscalls/open/.gitignore |  1 +
 testcases/kernel/syscalls/open/open15.c   | 75 +++++++++++++++++++++++++++++++
 3 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/runtest/syscalls b/runtest/syscalls
index 40c0dd070..4dfdf3782 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..09d7a1f3b
--- /dev/null
+++ b/testcases/kernel/syscalls/open/open15.c
@@ -0,0 +1,75 @@
+// 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. We generate a file via symlink, then we read both from file
+ * and symlink, comparing that data has been correctly written.
+ */
+
+#include "tst_test.h"
+
+#define FILENAME "myfile.txt"
+#define SYMBNAME "myfile_symlink"
+#define BIG_STRING "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
+
+static char buff_file[128];
+static char buff_symb[128];
+static int str_size;
+
+static void run(void)
+{
+	int fd_file, fd_symb;
+
+	memset(buff_file, 0, sizeof(buff_file));
+	memset(buff_symb, 0, sizeof(buff_symb));
+
+	tst_res(TINFO, "Create symlink");
+	SAFE_TOUCH(FILENAME, 0777, NULL);
+	SAFE_SYMLINK(FILENAME, SYMBNAME);
+
+	fd_file = SAFE_OPEN(FILENAME, O_RDONLY, 0777);
+	fd_symb = SAFE_OPEN(SYMBNAME, O_RDWR, 0777);
+
+	tst_res(TINFO, "Write data via symlink");
+	SAFE_WRITE(SAFE_WRITE_ALL, fd_symb, BIG_STRING, str_size);
+	SAFE_LSEEK(fd_symb, 0, 0);
+
+	tst_res(TINFO, "Read data via file");
+	SAFE_READ(1, fd_file, buff_file, str_size);
+	SAFE_LSEEK(fd_file, 0, 0);
+
+	tst_res(TINFO, "Read data via symlink");
+	SAFE_READ(1, fd_symb, buff_symb, str_size);
+	SAFE_LSEEK(fd_symb, 0, 0);
+
+	TST_EXP_EXPR(!strncmp(buff_file, BIG_STRING, str_size),
+		"file data has been correctly written");
+
+	TST_EXP_EXPR(!strncmp(buff_file, buff_symb, str_size),
+		"file data is the equivalent to symlink generated file data");
+
+	SAFE_CLOSE(fd_file);
+	SAFE_CLOSE(fd_symb);
+
+	SAFE_UNLINK(SYMBNAME);
+	SAFE_UNLINK(FILENAME);
+}
+
+static void setup(void)
+{
+	str_size = strlen(BIG_STRING);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.needs_tmpdir = 1,
+};

-- 
2.43.0


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

  parent reply	other threads:[~2024-07-11  7:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-11  7:43 [LTP] [PATCH v4 0/4] symlink01 split Andrea Cervesato
2024-07-11  7:43 ` [LTP] [PATCH v4 1/4] Add stat04 test Andrea Cervesato
2024-07-11  7:43 ` [LTP] [PATCH v4 2/4] Add lstat03 test Andrea Cervesato
2024-07-11  8:33   ` Cyril Hrubis
2024-07-11  7:43 ` [LTP] [PATCH v4 3/4] Add chmod08 test Andrea Cervesato
2024-07-11  8:43   ` Cyril Hrubis
2024-07-11  9:17     ` Andrea Cervesato via ltp
2024-07-11  7:43 ` Andrea Cervesato [this message]
2024-07-11  8:50   ` [LTP] [PATCH v4 4/4] Add open15 test Cyril Hrubis
2024-07-11 12:12     ` Petr Vorel

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=20240711-stat04-v4-4-d30c26fdaf5a@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