Re: [LTP] [PATCH] Added test for mmap() with MAP_SHARED_VALIDATE.

Petr Vorel
2023-03-27T10:51:27Z

Hi,

> +static void test_mmap(void)
> +{
> + mapped_address = mmap(NULL, TEST_FILE_SIZE, PROT_READ | PROT_WRITE,
> + (1 << 7) | MAP_SHARED_VALIDATE, fd_file, 0);
> + if (mapped_address != MAP_FAILED)
> + tst_res(TFAIL | TERRNO, "mmap() is successful, but it should have failed.");
> + else if (errno == EOPNOTSUPP)
> + tst_res(TPASS, "mmap() failed with errno set to EOPNOTSUPP.");
> + else
> + tst_res(TFAIL | TERRNO, "mmap() failed with unexpected error.");
> +}

FYI we have various helpers in include/tst_test_macros.h, e.g. TST_EXP_FAIL()
for expected failures where return is just classical syscalls result
(0 for pass, -1 for error) or TST_EXP_FD() for file descriptors.

But these cannot be used here, because mmap returns pointer to void.
We might want to write helpers which use TEST_VOID() instead of TEST(),
after tests for mmap() are rewritten to new API, they could use it.