From: Petr Vorel <pvorel@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v5 1/2] splice02: Generate input in C
Date: Tue, 20 Apr 2021 18:57:18 +0200 [thread overview]
Message-ID: <YH8H7gnu9FYziyGG@pevik> (raw)
In-Reply-To: <YH6c/cm9uY0QRrbu@yuki>
> Hi!
> > SAFE_CLOSE(fd);
> > + fd = SAFE_OPEN(TEST_FILENAME, O_RDONLY);
> > + to_check = st.st_size;
> > +
> > + psize = sysconf(_SC_PAGESIZE);
> > +
> > + tst_res(TINFO, "checking file content");
> > + do {
> > + i = 0;
> > + size = to_check > psize ? psize : to_check;
> > +
> > + map = SAFE_MMAP(NULL, size, PROT_READ, MAP_PRIVATE, fd,
> > + st.st_size - to_check);
> Huh, why do we loop backward over the file?
> Maybe we can just do simple loop here that would be easier to
> understand:
> blocks = LTP_ALIGN(st.st_size, page_size) / page_size;
> for (block = 0; block < blocks; block++) {
> map = SAFE_MMAP(NULL, pagesize, PROT_READ, MAP_PRIVATE, fd, block * pagesize);
> to_check = (block+1) * page_size < st.st_size ? page_size : st.st_size % page_size;
> for (i = 0; i < to_check; i++) {
> if (map[i] != get_letter(block * page_size + i))
> fail++;
> }
> SAFE_MUNMAP(map, size);
> }
> [Beware I haven't tested the code :-)]
Yep. In your code you expect that written letter change each time.
But original code writes the same letter for whole buffer (using memset()).
I guess it does not matter whether I keep writing with memset() as is
and adapt the checking code (code you proposed) or if I use your code for
checking and adapt writing code: create buffer 494 (19x 26 letters), memset() it
only once. Or do you have any preference of these?
Also I have to replace 2x return with goto cleanup (to close fd and exit the child).
Kind regards,
Petr
next prev parent reply other threads:[~2021-04-20 16:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-20 8:44 [LTP] [PATCH v5 1/2] splice02: Generate input in C Petr Vorel
2021-04-20 8:44 ` [LTP] [PATCH v5 2/2] commands: Add shell pipe test Petr Vorel
2021-04-20 9:21 ` [LTP] [PATCH v5 1/2] splice02: Generate input in C Cyril Hrubis
2021-04-20 16:57 ` Petr Vorel [this message]
2021-04-21 9:40 ` Cyril Hrubis
2021-04-21 10:04 ` 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=YH8H7gnu9FYziyGG@pevik \
--to=pvorel@suse.cz \
--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