Skip to content

Commit

Permalink
mmap01: fix check_file() test for file corruption
Browse files Browse the repository at this point in the history
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

Link: https://lore.kernel.org/ltp/[email protected]/
Reviewed-by: Cyril Hrubis <[email protected]>
Reviewed-by: Petr Vorel <[email protected]>
Signed-off-by: Sven Schnelle <[email protected]>
[ pvorel: replace goto with return ]
Signed-off-by: Petr Vorel <[email protected]>
  • Loading branch information
svens-s390 authored and pevik committed Jan 24, 2025
1 parent de17245 commit 6e58212
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions testcases/kernel/syscalls/mmap/mmap01.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,25 @@ 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));
SAFE_CLOSE(fildes);

if (len != strlen(STRING)) {
tst_res(TFAIL, "Read %zi expected %zu", len, strlen(STRING));
return;
}

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");

SAFE_CLOSE(fildes);
}

static void set_file(void)
Expand Down

0 comments on commit 6e58212

Please sign in to comment.