From: Cyril Hrubis <chrubis@suse.cz>
To: Andrea Cervesato <andrea.cervesato@suse.de>
Cc: Linux Test Project <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH v2 2/6] fs: rewrite stream01 test using new API
Date: Tue, 7 Apr 2026 16:57:03 +0200 [thread overview]
Message-ID: <adUbPyRUYPPzh38a@yuki.lan> (raw)
In-Reply-To: <20260304-stream_refactoring-v2-2-3e48ada8ff1a@suse.com>
Hi!
> +static void read_file(const char *file, const char *str, size_t n)
> +{
> + char buf[n];
> + FILE *stream;
> + size_t len;
>
> -#define PASSED 1
> -#define FAILED 0
> + memset(buf, 0, sizeof(buf));
>
> -/* XXX: add setup and cleanup. */
> + stream = SAFE_FOPEN(file, "r");
> + len = SAFE_FREAD(buf, n, n, stream);
Huh, we pass buffer of size n but ask it to read n * n bytes? That does
not seem to be right.
Also the buffer must always be bigger than n to allow the fread() to
read more bytes that we wrote, in a case that the file was written into
intcorrectly. So we need something like:
char buf[128];
...
len = SAFE_FREAD(buf, 1, sizeof(buf), stream);
> + SAFE_FCLOSE(stream);
>
> -char progname[] = "stream01()";
> -char tempfile1[40] = "";
> -char tempfile2[40] = "";
> + TST_EXP_EXPR(len == n, "Read the entire %s file buffer", file);
> + TST_EXP_EQ_STRN(buf, str, len);
> +}
>
> -/*--------------------------------------------------------------------*/
> -int main(int ac, char *av[])
> +static void run(void)
> {
> FILE *stream;
> - char buf[10];
> - int i;
> - int lc;
> -
> - /*
> - * parse standard options
> - */
> - tst_parse_opts(ac, av, NULL, NULL);
>
> - local_flag = PASSED;
> - tst_tmpdir();
> - for (lc = 0; TEST_LOOPING(lc); lc++) {
> + tst_res(TINFO, "Write %s file", FILENAME1);
> + stream = SAFE_FOPEN(FILENAME1, "a+");
> + SAFE_FWRITE(buff_file1, strlen(buff_file1), 3, stream);
>
> - sprintf(tempfile1, "stream011.%d", getpid());
> - sprintf(tempfile2, "stream012.%d", getpid());
> - /*--------------------------------------------------------------------*/
> - //block0:
> - if ((stream = fopen(tempfile1, "a+")) == NULL) {
> - tst_brkm(TFAIL, NULL, "fopen(%s) a+ failed: %s",
> - tempfile1,
> - strerror(errno));
> - }
> - fwrite("a", 1, 1, stream);
> - if ((stream = freopen(tempfile2, "a+", stream)) == NULL) {
> - tst_brkm(TFAIL | TERRNO, NULL, "freopen(%s) a+ failed",
> - tempfile2);
> - }
> - fwrite("a", 1, 1, stream);
> - fclose(stream);
> + tst_res(TINFO, "Write %s file streaming into %s file", FILENAME2, FILENAME1);
> + stream = SAFE_FREOPEN(FILENAME2, "a+", stream);
> + SAFE_FWRITE(buff_file2, strlen(buff_file2), 3, stream);
And here as well we ask to write strlen(buff_fiel2) * 3
bytes but the buff_file2 is only 3 characters.
> + SAFE_FCLOSE(stream);
>
> - local_flag = PASSED;
> + read_file(FILENAME1, buff_file1, 3);
> + read_file(FILENAME2, buff_file2, 3);
>
> - /*--------------------------------------------------------------------*/
> - unlink(tempfile1);
> - unlink(tempfile2);
> -
> - } /* end for */
> - tst_rmdir();
> - tst_exit();
> + SAFE_UNLINK(FILENAME1);
> + SAFE_UNLINK(FILENAME2);
> }
> +
> +static struct tst_test test = {
> + .test_all = run,
> + .needs_tmpdir = 1,
> +};
>
> --
> 2.51.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-04-07 14:57 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 [this message]
2026-03-04 13:25 ` [LTP] [PATCH v2 3/6] fs: rewrite stream02 " Andrea Cervesato
2026-04-07 14:59 ` 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=adUbPyRUYPPzh38a@yuki.lan \
--to=chrubis@suse.cz \
--cc=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