From: Petr Vorel <pvorel@suse.cz>
To: Cyril Hrubis <chrubis@suse.cz>
Cc: Sven Schnelle <svens@linux.ibm.com>, ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v3] mmap01: fix check_file() test for file corruption
Date: Thu, 23 Jan 2025 19:12:40 +0100 [thread overview]
Message-ID: <20250123181240.GA134067@pevik> (raw)
In-Reply-To: <Z5JVa6MgafKoBiyt@yuki.lan>
Hi all,
Reviewed-by: Petr Vorel <pvorel@suse.cz>
> Hi!
> > diff --git a/testcases/kernel/syscalls/mmap/mmap01.c b/testcases/kernel/syscalls/mmap/mmap01.c
> > index c93c37ceda52..ffbe6485a09c 100644
> > --- a/testcases/kernel/syscalls/mmap/mmap01.c
> > +++ b/testcases/kernel/syscalls/mmap/mmap01.c
> > @@ -35,19 +35,23 @@ static void check_file(void)
> > {
> > int i, fildes, buf_len = sizeof(STRING) + 3;
> > char buf[buf_len];
> > + ssize_t len;
> > fildes = SAFE_OPEN(TEMPFILE, O_RDONLY);
> > - SAFE_READ(0, fildes, buf, sizeof(buf));
> > -
> > - for (i = 0; i < buf_len; i++)
> > + len = SAFE_READ(0, fildes, buf, sizeof(buf));
> > + if (len != strlen(STRING)) {
> > + tst_res(TFAIL, "Read %zi expected %zu", len, strlen(STRING));
> > + goto out;
> > + }
> > + for (i = 0; i < len; i++)
> > if (buf[i] == 'X' || buf[i] == 'Y' || buf[i] == 'Z')
> > break;
> > - if (i == buf_len)
> > + if (i == len)
> > tst_res(TPASS, "Specified pattern not found in file");
> > else
> > tst_res(TFAIL, "Specified pattern found in file");
> > -
> > +out:
> > SAFE_CLOSE(fildes);
> We could close the file right after the read, that would have avoided
> the goto, but I guess that the patch is good enough now.
Good point. If you don't mind, I would merge it as following.
Kind regards,
Petr
+++ testcases/kernel/syscalls/mmap/mmap01.c
@@ -39,10 +39,13 @@ static void check_file(void)
fildes = SAFE_OPEN(TEMPFILE, O_RDONLY);
len = SAFE_READ(0, fildes, buf, sizeof(buf));
+ SAFE_CLOSE(fildes);
+
if (len != strlen(STRING)) {
tst_res(TFAIL, "Read %zi expected %zu", len, strlen(STRING));
- goto out;
+ return;
}
+
for (i = 0; i < len; i++)
if (buf[i] == 'X' || buf[i] == 'Y' || buf[i] == 'Z')
break;
@@ -51,8 +54,6 @@ static void check_file(void)
tst_res(TPASS, "Specified pattern not found in file");
else
tst_res(TFAIL, "Specified pattern found in file");
-out:
- SAFE_CLOSE(fildes);
}
static void set_file(void)
--
Mailing list info: https://lists.linux.it/listinfo/ltp
prev parent reply other threads:[~2025-01-23 18:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-23 14:36 [LTP] [PATCH v3] mmap01: fix check_file() test for file corruption Sven Schnelle
2025-01-23 14:42 ` Cyril Hrubis
2025-01-23 18:12 ` Petr Vorel [this message]
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=20250123181240.GA134067@pevik \
--to=pvorel@suse.cz \
--cc=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
--cc=svens@linux.ibm.com \
/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