From: Andrea Cervesato <andrea.cervesato@suse.de>
To: Linux Test Project <ltp@lists.linux.it>
Subject: [LTP] [PATCH v2 4/7] fs: rewrite stream02 test using new API
Date: Thu, 16 Apr 2026 16:33:38 +0200 [thread overview]
Message-ID: <20260416-stream_refactoring-v2-4-8321b1ec6f68@suse.com> (raw)
In-Reply-To: <20260416-stream_refactoring-v2-0-8321b1ec6f68@suse.com>
From: Andrea Cervesato <andrea.cervesato@suse.com>
Old LTP API is deprecated. Convert stream02 to new tst_test.h-based
API. Use TST_EXP_PASS_PTR_NULL() for fopen() calls so that a failure
reports TFAIL instead of TBROK.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
testcases/kernel/fs/stream/stream02.c | 134 ++++++++--------------------------
1 file changed, 30 insertions(+), 104 deletions(-)
diff --git a/testcases/kernel/fs/stream/stream02.c b/testcases/kernel/fs/stream/stream02.c
index 98473d86aab686eea2212c0e005a46e950f74ae8..9486ce85ac2472803ed873e0d626ac1fd759c674 100644
--- a/testcases/kernel/fs/stream/stream02.c
+++ b/testcases/kernel/fs/stream/stream02.c
@@ -1,119 +1,45 @@
+// 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();
+ SAFE_MKNOD(FILENAME, (S_IFIFO | 0666), 0);
- for (lc = 0; TEST_LOOPING(lc); lc++) {
+ for (size_t i = 0; i < ARRAY_SIZE(modes); i++) {
+ TST_EXP_PASS_PTR_NULL(fopen(FILENAME, modes[i]),
+ "fopen(%s, %s)", FILENAME, modes[i]);
- 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;
- }
- 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;
+ if (TST_PASS)
+ SAFE_FCLOSE(TST_RET_PTR);
+ }
- /*--------------------------------------------------------------------*/
-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.");
- }
-
- /*--------------------------------------------------------------------*/
- } /* 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-04-16 14:34 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-16 14:33 [LTP] [PATCH v2 0/7] Rewrite fs stream testing suite Andrea Cervesato
2026-04-16 14:33 ` [LTP] [PATCH v2 1/7] lib: add safe macros for " Andrea Cervesato
2026-04-16 15:34 ` [LTP] " linuxtestproject.agent
2026-04-16 14:33 ` [LTP] [PATCH v2 2/7] fs: rewrite stream01 test using new API Andrea Cervesato
2026-04-16 15:26 ` Cyril Hrubis
2026-04-16 14:33 ` [LTP] [PATCH v2 3/7] lib: add TST_EXP_PASS_PTR_NULL() macro Andrea Cervesato
2026-04-16 15:15 ` Cyril Hrubis
2026-04-16 14:33 ` Andrea Cervesato [this message]
2026-04-16 15:32 ` [LTP] [PATCH v2 4/7] fs: rewrite stream02 test using new API Cyril Hrubis
2026-04-16 14:33 ` [LTP] [PATCH v2 5/7] fs: rewrite stream03 " Andrea Cervesato
2026-04-16 14:33 ` [LTP] [PATCH v2 6/7] fs: rewrite stream04 " Andrea Cervesato
2026-04-16 14:33 ` [LTP] [PATCH v2 7/7] fs: rewrite stream05 " Andrea Cervesato
2026-04-16 18:21 ` [LTP] [PATCH v2 0/7] Rewrite fs stream testing suite 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=20260416-stream_refactoring-v2-4-8321b1ec6f68@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