[LTP] [PATCH v3] mmap01: fix check_file() test for file corruption
Cyril Hrubis
chrubis@suse.cz
Thu Jan 23 15:42:51 CET 2025
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.
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list