All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avinesh Kumar <akumar@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] syscalls/mmap06: Add testcases for EINVAL scenarios
Date: Fri,  1 Sep 2023 11:27:51 +0530	[thread overview]
Message-ID: <20230901055756.7057-1-akumar@suse.de> (raw)
In-Reply-To: <ZPCLZ5eIPQZ8sWoX@yuki>

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

  reply	other threads:[~2023-09-01  5:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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   ` Avinesh Kumar [this message]
2023-09-08 14:35     ` [LTP] [PATCH] syscalls/mmap06: Add testcases for " Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230901055756.7057-1-akumar@suse.de \
    --to=akumar@suse.de \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.