* [LTP] [PATCH] syscalls/mmap22: Add new test for validating mmap's EINVAL scenarios @ 2023-08-31 11:28 Avinesh Kumar 2023-08-31 12:45 ` Cyril Hrubis 0 siblings, 1 reply; 4+ messages in thread From: Avinesh Kumar @ 2023-08-31 11:28 UTC (permalink / raw) To: ltp Signed-off-by: Avinesh Kumar <akumar@suse.de> --- testcases/kernel/syscalls/mmap/mmap22.c | 73 +++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 testcases/kernel/syscalls/mmap/mmap22.c diff --git a/testcases/kernel/syscalls/mmap/mmap22.c b/testcases/kernel/syscalls/mmap/mmap22.c new file mode 100644 index 000000000..98e8b05e2 --- /dev/null +++ b/testcases/kernel/syscalls/mmap/mmap22.c @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2023 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com> + */ + +/*\ + * [Description] + * + * Verify that, mmap() call fails with errno EINVAL when + * + * - length argument is 0. + * - flags contains none of MAP_PRIVATE, MAP_SHARED, or MAP_SHARED_VALIDATE. + */ + +#include <stdlib.h> +#include "tst_test.h" + +#define TEMPFILE "mmapfile" +#define MMAPSIZE 1024 +static size_t page_sz; +static int fd; + +static struct tcase { + size_t length; + int prot; + int flags; +} tcases[] = { + {0, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED}, + {MMAPSIZE, PROT_READ | PROT_WRITE, MAP_FILE}, +}; + +static void setup(void) +{ + char *buf; + + page_sz = getpagesize(); + buf = SAFE_MALLOC(page_sz); + memset(buf, 'A', page_sz); + + fd = SAFE_OPEN(TEMPFILE, O_RDWR | O_CREAT, 0666); + SAFE_WRITE(SAFE_WRITE_ALL, fd, buf, page_sz); + free(buf); +} + +static void run(unsigned int i) +{ + struct tcase *tc = &tcases[i]; + + TESTPTR(mmap(0, tc->length, tc->prot, tc->flags, fd, 0)); + + if (TST_RET_PTR != MAP_FAILED) { + tst_res(TFAIL | TERRNO, "mmap() was successful unexpectedly"); + SAFE_MUNMAP(TST_RET_PTR, page_sz); + } else if (TST_ERR == EINVAL) { + tst_res(TPASS, "mmap() failed with errno EINVAL"); + } else { + tst_res(TFAIL | TERRNO, "mmap() failed but unexpected errno"); + } +} + +static void cleanup(void) +{ + if (fd > 0) + SAFE_CLOSE(fd); +} + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test = run, + .tcnt = ARRAY_SIZE(tcases), + .needs_tmpdir = 1 +}; -- 2.41.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH] syscalls/mmap22: Add new test for validating mmap's EINVAL scenarios 2023-08-31 11:28 [LTP] [PATCH] syscalls/mmap22: Add new test for validating mmap's EINVAL scenarios Avinesh Kumar @ 2023-08-31 12:45 ` Cyril Hrubis 2023-09-01 5:57 ` [LTP] [PATCH] syscalls/mmap06: Add testcases for " Avinesh Kumar 0 siblings, 1 reply; 4+ messages in thread From: Cyril Hrubis @ 2023-08-31 12:45 UTC (permalink / raw) To: Avinesh Kumar; +Cc: ltp Hi! If we add exp_errno to the struct tcase we can as well put these two EINVAL testcasese into mmap06.c instead. -- Cyril Hrubis chrubis@suse.cz -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 4+ messages in thread
* [LTP] [PATCH] syscalls/mmap06: Add testcases for EINVAL scenarios 2023-08-31 12:45 ` Cyril Hrubis @ 2023-09-01 5:57 ` Avinesh Kumar 2023-09-08 14:35 ` Cyril Hrubis 0 siblings, 1 reply; 4+ messages in thread From: Avinesh Kumar @ 2023-09-01 5:57 UTC (permalink / raw) To: ltp Signed-off-by: Avinesh Kumar <akumar@suse.de> --- testcases/kernel/syscalls/mmap/mmap06.c | 32 +++++++++++++++---------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/testcases/kernel/syscalls/mmap/mmap06.c b/testcases/kernel/syscalls/mmap/mmap06.c index 012e7de41..1a0c8e3cf 100644 --- a/testcases/kernel/syscalls/mmap/mmap06.c +++ b/testcases/kernel/syscalls/mmap/mmap06.c @@ -8,27 +8,35 @@ /*\ * [Description] * - * Verify that, mmap() call fails when a file mapping is requested but the - * file descriptor is not open for reading, and errno is set to EACCES. + * Verify that, mmap() call fails with errno: + * + * - EACCES, when a file mapping is requested but the file descriptor is not open for reading. + * - EINVAL, when length argument is 0. + * - EINVAL, when flags contains none of MAP_PRIVATE, MAP_SHARED, or MAP_SHARED_VALIDATE. */ #include <stdlib.h> #include "tst_test.h" +#define MMAPSIZE 1024 #define TEMPFILE "mmapfile" static size_t page_sz; static int fd; static struct tcase { + size_t length; int prot; int flags; + int exp_errno; } tcases[] = { - {PROT_WRITE, MAP_FILE | MAP_PRIVATE}, - {PROT_WRITE, MAP_FILE | MAP_SHARED}, - {PROT_READ, MAP_FILE | MAP_PRIVATE}, - {PROT_READ, MAP_FILE | MAP_SHARED}, - {PROT_READ | PROT_WRITE, MAP_FILE | MAP_PRIVATE}, - {PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED} + {MMAPSIZE, PROT_WRITE, MAP_FILE | MAP_PRIVATE, EACCES}, + {MMAPSIZE, PROT_WRITE, MAP_FILE | MAP_SHARED, EACCES}, + {MMAPSIZE, PROT_READ, MAP_FILE | MAP_PRIVATE, EACCES}, + {MMAPSIZE, PROT_READ, MAP_FILE | MAP_SHARED, EACCES}, + {MMAPSIZE, PROT_READ | PROT_WRITE, MAP_FILE | MAP_PRIVATE, EACCES}, + {MMAPSIZE, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, EACCES}, + {0, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, EINVAL}, + {MMAPSIZE, PROT_READ | PROT_WRITE, MAP_FILE, EINVAL} }; static void setup(void) @@ -48,13 +56,13 @@ static void run(unsigned int i) { struct tcase *tc = &tcases[i]; - TESTPTR(mmap(NULL, page_sz, tc->prot, tc->flags, fd, 0)); + TESTPTR(mmap(NULL, tc->length, tc->prot, tc->flags, fd, 0)); if (TST_RET_PTR != MAP_FAILED) { tst_res(TFAIL, "mmap() was successful unexpectedly"); - SAFE_MUNMAP(TST_RET_PTR, page_sz); - } else if (TST_ERR == EACCES) { - tst_res(TPASS, "mmap() failed with errno EACCES"); + SAFE_MUNMAP(TST_RET_PTR, MMAPSIZE); + } else if (TST_ERR == tc->exp_errno) { + tst_res(TPASS, "mmap() failed with expected errno"); } else { tst_res(TFAIL | TERRNO, "mmap() failed but unexpected errno"); } -- 2.41.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH] syscalls/mmap06: Add testcases for EINVAL scenarios 2023-09-01 5:57 ` [LTP] [PATCH] syscalls/mmap06: Add testcases for " Avinesh Kumar @ 2023-09-08 14:35 ` Cyril Hrubis 0 siblings, 0 replies; 4+ messages in thread From: Cyril Hrubis @ 2023-09-08 14:35 UTC (permalink / raw) To: Avinesh Kumar; +Cc: ltp Hi! Pushed with a minor change, thanks. I did change the messages a bit so that we have sligtly nicer output with: diff --git a/testcases/kernel/syscalls/mmap/mmap06.c b/testcases/kernel/syscalls/mmap/mmap06.c index 1a0c8e3cf..615743fa7 100644 --- a/testcases/kernel/syscalls/mmap/mmap06.c +++ b/testcases/kernel/syscalls/mmap/mmap06.c @@ -62,9 +62,9 @@ static void run(unsigned int i) tst_res(TFAIL, "mmap() was successful unexpectedly"); SAFE_MUNMAP(TST_RET_PTR, MMAPSIZE); } else if (TST_ERR == tc->exp_errno) { - tst_res(TPASS, "mmap() failed with expected errno"); + tst_res(TPASS | TERRNO, "mmap() failed with"); } else { - tst_res(TFAIL | TERRNO, "mmap() failed but unexpected errno"); + tst_res(TFAIL | TERRNO, "mmap() failed unexpectedly"); } } -- Cyril Hrubis chrubis@suse.cz -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-09-08 14:35 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-08-31 11:28 [LTP] [PATCH] syscalls/mmap22: Add new test for validating mmap's EINVAL scenarios Avinesh Kumar 2023-08-31 12:45 ` Cyril Hrubis 2023-09-01 5:57 ` [LTP] [PATCH] syscalls/mmap06: Add testcases for " Avinesh Kumar 2023-09-08 14:35 ` Cyril Hrubis
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox