diff mbox series

[v2,1/3] syscalls/mq_timed{send|receive}: Add test cases for bad address

Message ID 20200807113950.69052-2-Filip.Bozuta@syrmia.com
State Accepted
Headers show
Series testcases/kernel/syscalls: Adding new testcases for existing tests | expand

Commit Message

Filip Bozuta Aug. 7, 2020, 11:39 a.m. UTC
This patch introduces test cases for already existing
tests for syscalls 'mq_timedsend()' and 'mq_timedreceive()'
(mq_timedsend01, mq_timedreceive01). These test cases are for
situations when bad addresses are passed for arguments 'msg_ptr'
and 'abs_timeout' in which case errno 'EFAULT' is expected to be set.

Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
---
 .../mq_timedreceive/mq_timedreceive01.c       | 15 +++++++++-
 .../syscalls/mq_timedsend/mq_timedsend01.c    | 29 +++++++++++++++++--
 testcases/kernel/syscalls/utils/mq_timed.h    |  2 ++
 3 files changed, 43 insertions(+), 3 deletions(-)

Comments

Cyril Hrubis Aug. 10, 2020, 12:42 p.m. UTC | #1
Hi!
Pushed with a minor change, thanks.

I've moved the tst_get_bad_addr() to the setup since that funciton
allocates memory, which would cause failures with large enough -i test
parameter. The diff is:

diff --git a/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c b/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c
index d99538e4b..de0505106 100644
--- a/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c
+++ b/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c
@@ -17,6 +17,7 @@ static int fd, fd_root, fd_nonblock, fd_maxint = INT_MAX - 1, fd_invalid = -1;
 #include "mq_timed.h"
 
 static struct tst_ts ts;
+static void *bad_addr;
 
 static struct test_case tcase[] = {
 	{
@@ -139,6 +140,8 @@ static void setup(void)
 	tst_res(TINFO, "Testing variant: %s", tv->desc);
 	ts.type = tv->type;
 
+	bad_addr = tst_get_bad_addr(NULL);
+
 	setup_common();
 }
 
@@ -173,7 +176,7 @@ static void do_test(unsigned int i)
 		len -= 1;
 
 	if (tc->bad_ts_addr)
-		abs_timeout = tst_get_bad_addr(cleanup_common);
+		abs_timeout = bad_addr;
 	else
 		abs_timeout = tst_ts_get(tc->rq);
 
diff --git a/testcases/kernel/syscalls/mq_timedsend/mq_timedsend01.c b/testcases/kernel/syscalls/mq_timedsend/mq_timedsend01.c
index 7e220f297..d72f5d41a 100644
--- a/testcases/kernel/syscalls/mq_timedsend/mq_timedsend01.c
+++ b/testcases/kernel/syscalls/mq_timedsend/mq_timedsend01.c
@@ -17,6 +17,7 @@ static int fd, fd_root, fd_nonblock, fd_maxint = INT_MAX - 1, fd_invalid = -1;
 #include "mq_timed.h"
 
 static struct tst_ts ts;
+static void *bad_addr;
 
 static struct test_case tcase[] = {
 	{
@@ -152,6 +153,8 @@ static void setup(void)
 	tst_res(TINFO, "Testing variant: %s", tv->desc);
 	ts.type = tv->type;
 
+	bad_addr = tst_get_bad_addr(cleanup_common);
+
 	setup_common();
 }
 
@@ -184,12 +187,12 @@ static void do_test(unsigned int i)
 	}
 
 	if (tc->bad_msg_addr)
-		msg_ptr = tst_get_bad_addr(cleanup_common);
+		msg_ptr = bad_addr;
 	else
 		msg_ptr = smsg;
 
 	if (tc->bad_ts_addr)
-		abs_timeout = tst_get_bad_addr(cleanup_common);
+		abs_timeout = bad_addr;
 	else
 		abs_timeout = tst_ts_get(tc->rq);
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c b/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c
index 8e24651c9..d99538e4b 100644
--- a/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c
+++ b/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c
@@ -123,6 +123,13 @@  static struct test_case tcase[] = {
 		.ret = -1,
 		.err = EINTR,
 	},
+	{
+		.fd = &fd,
+		.len = 16,
+		.bad_ts_addr = 1,
+		.ret = -1,
+		.err = EFAULT,
+	}
 };
 
 static void setup(void)
@@ -144,6 +151,7 @@  static void do_test(unsigned int i)
 	size_t len = MAX_MSGSIZE;
 	char rmsg[len];
 	pid_t pid = -1;
+	void *abs_timeout;
 
 	tst_ts_set_sec(&ts, tc->tv_sec);
 	tst_ts_set_nsec(&ts, tc->tv_nsec);
@@ -164,7 +172,12 @@  static void do_test(unsigned int i)
 	if (tc->invalid_msg)
 		len -= 1;
 
-	TEST(tv->receive(*tc->fd, rmsg, len, &prio, tst_ts_get(tc->rq)));
+	if (tc->bad_ts_addr)
+		abs_timeout = tst_get_bad_addr(cleanup_common);
+	else
+		abs_timeout = tst_ts_get(tc->rq);
+
+	TEST(tv->receive(*tc->fd, rmsg, len, &prio, abs_timeout));
 
 	if (pid > 0)
 		kill_pid(pid);
diff --git a/testcases/kernel/syscalls/mq_timedsend/mq_timedsend01.c b/testcases/kernel/syscalls/mq_timedsend/mq_timedsend01.c
index f7fc2c533..7e220f297 100644
--- a/testcases/kernel/syscalls/mq_timedsend/mq_timedsend01.c
+++ b/testcases/kernel/syscalls/mq_timedsend/mq_timedsend01.c
@@ -129,6 +129,20 @@  static struct test_case tcase[] = {
 		.ret = -1,
 		.err = EINTR,
 	},
+	{
+		.fd = &fd,
+		.len = 16,
+		.bad_msg_addr = 1,
+		.ret = -1,
+		.err = EFAULT,
+	},
+	{
+		.fd = &fd,
+		.len = 16,
+		.bad_ts_addr = 1,
+		.ret = -1,
+		.err = EFAULT,
+	}
 };
 
 static void setup(void)
@@ -150,6 +164,7 @@  static void do_test(unsigned int i)
 	size_t len = MAX_MSGSIZE;
 	char rmsg[len];
 	pid_t pid = -1;
+	void *msg_ptr, *abs_timeout;
 
 	tst_ts_set_sec(&ts, tc->tv_sec);
 	tst_ts_set_nsec(&ts, tc->tv_nsec);
@@ -168,7 +183,17 @@  static void do_test(unsigned int i)
 			}
 	}
 
-	TEST(tv->send(*tc->fd, smsg, tc->len, tc->prio, tst_ts_get(tc->rq)));
+	if (tc->bad_msg_addr)
+		msg_ptr = tst_get_bad_addr(cleanup_common);
+	else
+		msg_ptr = smsg;
+
+	if (tc->bad_ts_addr)
+		abs_timeout = tst_get_bad_addr(cleanup_common);
+	else
+		abs_timeout = tst_ts_get(tc->rq);
+
+	TEST(tv->send(*tc->fd, msg_ptr, tc->len, tc->prio, abs_timeout));
 
 	if (pid > 0)
 		kill_pid(pid);
@@ -179,7 +204,7 @@  static void do_test(unsigned int i)
 				"mq_timedsend() failed unexpectedly, expected %s",
 				tst_strerrno(tc->err));
 		else
-			tst_res(TPASS | TTERRNO, "mq_timedreceive() failed expectedly");
+			tst_res(TPASS | TTERRNO, "mq_timedsend() failed expectedly");
 
 		if (*tc->fd == fd)
 			cleanup_queue(fd);
diff --git a/testcases/kernel/syscalls/utils/mq_timed.h b/testcases/kernel/syscalls/utils/mq_timed.h
index 3a99d9eef..a217e864e 100644
--- a/testcases/kernel/syscalls/utils/mq_timed.h
+++ b/testcases/kernel/syscalls/utils/mq_timed.h
@@ -41,6 +41,8 @@  struct test_case {
 	int send;
 	int signal;
 	int timeout;
+	int bad_msg_addr;
+	int bad_ts_addr;
 	int ret;
 	int err;
 };