All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Sven Schnelle <svens@linux.ibm.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v2] mmap01: fix check_file() test for file corruption
Date: Thu, 23 Jan 2025 12:35:14 +0100	[thread overview]
Message-ID: <Z5IpckANo_28f7eS@yuki.lan> (raw)
In-Reply-To: <20250122135808.3827827-1-svens@linux.ibm.com>

Hi!
> mmap01 reported random test failures. Investigation showed
> that check_file() will compare the whole buffer even if less
> bytes were read from the file. Adjust check_file() to:
> 
> - fail the test if the not the correct amount of data has been read.
> - only compare the bytes actually read
> 
> Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
> ---
> Changes in v2:
> 
> - check return value from SAFE_READ
> - only verify bytes actually read
> 
>  testcases/kernel/syscalls/mmap/mmap01.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/mmap/mmap01.c b/testcases/kernel/syscalls/mmap/mmap01.c
> index c93c37ceda52..b5798c8d2367 100644
> --- a/testcases/kernel/syscalls/mmap/mmap01.c
> +++ b/testcases/kernel/syscalls/mmap/mmap01.c
> @@ -35,15 +35,18 @@ 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));
> +	len = SAFE_READ(0, fildes, buf, sizeof(buf));
> +	if (len != strlen(STRING))
> +		tst_res(TFAIL, "Error reading from file\n");
                                                        ^
							no newline here
							please

		And possibly it would make sense to write how many
		characters were read and how many we expected so
		something as:

		tst_res(TFAIL, "Read %zi expected %zu", len, strlen(STRING));

		and we also want to do return; if we fail to read
		strlen(STRING) bytes because checking the buffer content
		does not make sense at that point, since it's possibly
		only partialy intialized

>  
> -	for (i = 0; i < buf_len; i++)
> +	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");
> -- 
> 2.47.1
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

      reply	other threads:[~2025-01-23 11:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-22 13:58 [LTP] [PATCH v2] mmap01: fix check_file() test for file corruption Sven Schnelle
2025-01-23 11:35 ` Cyril Hrubis [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=Z5IpckANo_28f7eS@yuki.lan \
    --to=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.