From: Andrea Cervesato <andrea.cervesato@suse.de>
To: Linux Test Project <ltp@lists.linux.it>
Subject: [LTP] [PATCH v2 3/6] fs: rewrite stream02 test using new API
Date: Wed, 04 Mar 2026 14:25:41 +0100 [thread overview]
Message-ID: <20260304-stream_refactoring-v2-3-3e48ada8ff1a@suse.com> (raw)
In-Reply-To: <20260304-stream_refactoring-v2-0-3e48ada8ff1a@suse.com>
From: Andrea Cervesato <andrea.cervesato@suse.com>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
testcases/kernel/fs/stream/stream02.c | 136 +++++++++-------------------------
1 file changed, 33 insertions(+), 103 deletions(-)
diff --git a/testcases/kernel/fs/stream/stream02.c b/testcases/kernel/fs/stream/stream02.c
index 98473d86aab686eea2212c0e005a46e950f74ae8..c08bdbed0754453c6ab666fe5e733d31383587fb 100644
--- a/testcases/kernel/fs/stream/stream02.c
+++ b/testcases/kernel/fs/stream/stream02.c
@@ -1,119 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
+ * Copyright (c) International Business Machines Corp., 2002
+ * ported from SPIE section2/filesuite/stream2.c, by Airong Zhang
*
- * Copyright (c) International Business Machines Corp., 2002
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) 2026 Andrea Cervesato <andrea.cervesato@suse.com>
*/
-/* ported from SPIE section2/filesuite/stream2.c, by Airong Zhang */
-
-/*======================================================================
- =================== TESTPLAN SEGMENT ===================
->KEYS: < fseek() mknod() fopen()
->WHAT: < 1)
->HOW: < 1)
->BUGS: <
-======================================================================*/
-#include <stdio.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include "test.h"
-
-char *TCID = "stream02";
-int TST_TOTAL = 1;
-int local_flag;
+/*\
+ * Verify that it's possible to `fopen()` a file that has been created by
+ * `mknod()` using different modes.
+ */
-#define PASSED 1
-#define FAILED 0
+#include "tst_test.h"
+#include "tst_safe_stdio.h"
-char progname[] = "stream02()";
-char tempfile1[40] = "";
+#define FILENAME "ltp_file_node"
-/* XXX: add cleanup + setup. */
+static const char *const modes[] = {
+ "r+",
+ "w+",
+ "a+",
+};
-/*--------------------------------------------------------------------*/
-int main(int ac, char *av[])
+static void run(void)
{
FILE *stream;
- int fd;
- int lc;
-
- /*
- * parse standard options
- */
- tst_parse_opts(ac, av, NULL, NULL);
-
- local_flag = PASSED;
- tst_tmpdir();
- for (lc = 0; TEST_LOOPING(lc); lc++) {
+ SAFE_MKNOD(FILENAME, (S_IFIFO | 0666), 0);
- sprintf(tempfile1, "stream1.%d", getpid());
- /*--------------------------------------------------------------------*/
- //block0:
- if (mknod(tempfile1, (S_IFIFO | 0666), 0) != 0) {
- tst_resm(TFAIL, "mknod failed in block0: %s",
- strerror(errno));
- local_flag = FAILED;
- goto block1;
+ for (size_t i = 0; i < ARRAY_SIZE(modes); i++) {
+ stream = SAFE_FOPEN(FILENAME, modes[i]);
+ if (!stream) {
+ tst_res(TFAIL, "fopen(%s) returned NULL pointer", modes[i]);
+ return;
}
- if ((stream = fopen(tempfile1, "w+")) == NULL) {
- tst_resm(TFAIL, "fopen(%s) w+ failed for pipe file: %s",
- tempfile1, strerror(errno));
- local_flag = FAILED;
- } else {
- fclose(stream);
- }
- if ((stream = fopen(tempfile1, "a+")) == NULL) {
- tst_resm(TFAIL, "fopen(%s) a+ failed: %s", tempfile1,
- strerror(errno));
- local_flag = FAILED;
- } else {
- fclose(stream);
- unlink(tempfile1);
- }
- if (local_flag == PASSED) {
- tst_resm(TPASS, "Test passed in block0.");
- } else {
- tst_resm(TFAIL, "Test failed in block0.");
- }
- local_flag = PASSED;
- /*--------------------------------------------------------------------*/
-block1:
- if ((fd = open("/dev/tty", O_WRONLY)) >= 0) {
- close(fd);
- if ((stream = fopen("/dev/tty", "w")) == NULL) {
- tst_resm(TFAIL | TERRNO,
- "fopen(/dev/tty) write failed");
- local_flag = FAILED;
- } else {
- fclose(stream);
- }
- }
- if (local_flag == PASSED) {
- tst_resm(TPASS, "Test passed in block1.");
- } else {
- tst_resm(TFAIL, "Test failed in block1.");
- }
+ SAFE_FCLOSE(stream);
+
+ tst_res(TPASS, "Opened file using '%s' mode", modes[i]);
+ }
- /*--------------------------------------------------------------------*/
- } /* end for */
- tst_rmdir();
- tst_exit();
+ SAFE_UNLINK(FILENAME);
}
+
+static struct tst_test test = {
+ .test_all = run,
+ .needs_tmpdir = 1,
+};
--
2.51.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-03-04 13:27 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-04 13:25 [LTP] [PATCH v2 0/6] Rewrite fs stream testing suite Andrea Cervesato
2026-03-04 13:25 ` [LTP] [PATCH v2 1/6] Add safe macros for " Andrea Cervesato
2026-03-04 13:25 ` [LTP] [PATCH v2 2/6] fs: rewrite stream01 test using new API Andrea Cervesato
2026-04-07 14:57 ` Cyril Hrubis
2026-03-04 13:25 ` Andrea Cervesato [this message]
2026-04-07 14:59 ` [LTP] [PATCH v2 3/6] fs: rewrite stream02 " Cyril Hrubis
2026-03-04 13:25 ` [LTP] [PATCH v2 4/6] fs: rewrite stream03 " Andrea Cervesato
2026-03-04 13:25 ` [LTP] [PATCH v2 5/6] fs: rewrite stream04 " Andrea Cervesato
2026-03-04 13:25 ` [LTP] [PATCH v2 6/6] fs: rewrite stream05 " Andrea Cervesato
2026-04-07 15:30 ` Cyril Hrubis
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=20260304-stream_refactoring-v2-3-3e48ada8ff1a@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