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

Li Wang liwang@redhat.com
Tue Mar 28 05:39:54 CEST 2023


On Mon, Mar 27, 2023 at 6:51 PM Petr Vorel <pvorel@suse.cz> wrote:
>
> 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.

Sounds good, but we can do this in later refactoring work on mmap tests.
Now I'm slightly OK with not using TEST_ macros for everything:).


-- 
Regards,
Li Wang



More information about the ltp mailing list