All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v2 0/3] testcases/kernel/syscalls: Adding new testcases for existing tests
@ 2020-08-07 11:39 Filip Bozuta
  2020-08-07 11:39 ` [LTP] [PATCH v2 1/3] syscalls/mq_timed{send|receive}: Add test cases for bad address Filip Bozuta
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Filip Bozuta @ 2020-08-07 11:39 UTC (permalink / raw)
  To: ltp

This series introduces new test cases for existing tests for syscalls

    * mq_timedsend()        * sendmmsg()
    * mq_timedreceive()     * recvmmsg()
    * clock_nanosleep()

* First patch in the series introduces bad address test cases for
  'mq_timedsend()' and 'mq_timedreceive()'

* Second patch in the series introduces bad timespec address cases
  for 'clock_nanosleep()'

* Third patch in the series introduces a timeout case and an errno
  test for 'sendmmsg()' and 'recvmmsg()'

More detailed descriptions of these newly added test cases and the
implementation details can be found in this series patch commit
messages.

These new test cases are part of my work of implementation for 2038
safe variants of the above mentioned syscalls in QEMU:

    * mq_timedsend_time64()
    * mq_timedreceive_time64()
    * clock_nanosleep_time64()
    * recvmmsg_time64()

These test cases are needed to make sure that QEMU implementations of
the above mentioned time64 syscalls work properly.

These test cases are also used to fix some minor issues with already
existing implementations of regular variants of these syscalls.

v2:

    * Changed bad address values from (void *)1 to using function
      'tst_get_bad_addr()'
    * Removed unnecessary implementation descriptions that can be
      seen from the patches

Filip Bozuta (3):
  syscalls/mq_timed{send|receive}: Add test cases for bad address
  syscalls/clock_nanosleep: add a test case for bad timespec address
  syscalls/{send|recv}mmsg: add a test case for timeout and errno test

 runtest/syscalls                              |   1 +
 .../clock_nanosleep/clock_nanosleep01.c       |  35 ++-
 .../mq_timedreceive/mq_timedreceive01.c       |  15 +-
 .../syscalls/mq_timedsend/mq_timedsend01.c    |  29 ++-
 testcases/kernel/syscalls/sendmmsg/.gitignore |   1 +
 .../kernel/syscalls/sendmmsg/sendmmsg01.c     |  68 ++++--
 .../kernel/syscalls/sendmmsg/sendmmsg02.c     | 231 ++++++++++++++++++
 testcases/kernel/syscalls/utils/mq_timed.h    |   2 +
 8 files changed, 362 insertions(+), 20 deletions(-)
 create mode 100644 testcases/kernel/syscalls/sendmmsg/sendmmsg02.c

-- 
2.25.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [LTP] [PATCH v2 1/3] syscalls/mq_timed{send|receive}: Add test cases for bad address
  2020-08-07 11:39 [LTP] [PATCH v2 0/3] testcases/kernel/syscalls: Adding new testcases for existing tests Filip Bozuta
@ 2020-08-07 11:39 ` Filip Bozuta
  2020-08-10 12:42   ` Cyril Hrubis
  2020-08-07 11:39 ` [LTP] [PATCH v2 2/3] syscalls/clock_nanosleep: add a test case for bad timespec address Filip Bozuta
  2020-08-07 11:39 ` [LTP] [PATCH v2 3/3] syscalls/{send|recv}mmsg: add a test case for timeout and errno test Filip Bozuta
  2 siblings, 1 reply; 7+ messages in thread
From: Filip Bozuta @ 2020-08-07 11:39 UTC (permalink / raw)
  To: ltp

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(-)

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;
 };
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [LTP] [PATCH v2 2/3] syscalls/clock_nanosleep: add a test case for bad timespec address
  2020-08-07 11:39 [LTP] [PATCH v2 0/3] testcases/kernel/syscalls: Adding new testcases for existing tests Filip Bozuta
  2020-08-07 11:39 ` [LTP] [PATCH v2 1/3] syscalls/mq_timed{send|receive}: Add test cases for bad address Filip Bozuta
@ 2020-08-07 11:39 ` Filip Bozuta
  2020-08-10 12:57   ` Cyril Hrubis
  2020-08-07 11:39 ` [LTP] [PATCH v2 3/3] syscalls/{send|recv}mmsg: add a test case for timeout and errno test Filip Bozuta
  2 siblings, 1 reply; 7+ messages in thread
From: Filip Bozuta @ 2020-08-07 11:39 UTC (permalink / raw)
  To: ltp

This patch introduces test cases for already existing test
for syscall 'clock_nanosleep()' (clock_nanosleep01). These test
cases are for situations when bad timespec addresses are passed
for arguments 'request' and 'remain' in which case errno
EFAULT ('Bad address') is expected to be set.

Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
---
 .../clock_nanosleep/clock_nanosleep01.c       | 35 +++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c b/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c
index 4542995f2..66108ed8e 100644
--- a/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c
+++ b/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c
@@ -20,6 +20,8 @@ static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
 enum test_type {
 	NORMAL,
 	SEND_SIGINT,
+	BAD_TS_ADDR_REQ,
+	BAD_TS_ADDR_REM,
 };
 
 #define TYPE_NAME(x) .ttype = x, .desc = #x
@@ -78,6 +80,22 @@ static struct test_case tcase[] = {
 		.exp_ret = -1,
 		.exp_err = EINTR,
 	},
+	{
+		TYPE_NAME(BAD_TS_ADDR_REQ),
+		.clk_id = CLOCK_REALTIME,
+		.flags = 0,
+		.exp_ret = -1,
+		.exp_err = EFAULT,
+	},
+	{
+		TYPE_NAME(BAD_TS_ADDR_REM),
+		.clk_id = CLOCK_REALTIME,
+		.flags = 0,
+		.tv_sec = 10,
+		.tv_nsec = 0,
+		.exp_ret = -1,
+		.exp_err = EFAULT,
+	},
 };
 
 static struct tst_ts *rq;
@@ -106,24 +124,37 @@ void setup(void)
 	SAFE_SIGNAL(SIGINT, sighandler);
 }
 
+void cleanup(void) {}
+
 static void do_test(unsigned int i)
 {
 	struct test_variants *tv = &variants[tst_variant];
 	struct test_case *tc = &tcase[i];
 	pid_t pid = 0;
+	void *request, *remain;
 
 	memset(rm, 0, sizeof(*rm));
 	rm->type = rq->type;
 
 	tst_res(TINFO, "case %s", tc->desc);
 
-	if (tc->ttype == SEND_SIGINT)
+	if (tc->ttype == SEND_SIGINT || tc->ttype == BAD_TS_ADDR_REM)
 		pid = create_sig_proc(SIGINT, 40, 500000);
 
 	tst_ts_set_sec(rq, tc->tv_sec);
 	tst_ts_set_nsec(rq, tc->tv_nsec);
 
-	TEST(tv->func(tc->clk_id, tc->flags, tst_ts_get(rq), tst_ts_get(rm)));
+	if (tc->ttype == BAD_TS_ADDR_REQ)
+		request = tst_get_bad_addr(cleanup);
+	else
+		request = tst_ts_get(rq);
+
+	if (tc->ttype == BAD_TS_ADDR_REM)
+		remain = tst_get_bad_addr(cleanup);
+	else
+		remain = tst_ts_get(rm);
+
+	TEST(tv->func(tc->clk_id, tc->flags, request, remain));
 
 	if (tv->func == libc_clock_nanosleep) {
 		/*
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [LTP] [PATCH v2 3/3] syscalls/{send|recv}mmsg: add a test case for timeout and errno test
  2020-08-07 11:39 [LTP] [PATCH v2 0/3] testcases/kernel/syscalls: Adding new testcases for existing tests Filip Bozuta
  2020-08-07 11:39 ` [LTP] [PATCH v2 1/3] syscalls/mq_timed{send|receive}: Add test cases for bad address Filip Bozuta
  2020-08-07 11:39 ` [LTP] [PATCH v2 2/3] syscalls/clock_nanosleep: add a test case for bad timespec address Filip Bozuta
@ 2020-08-07 11:39 ` Filip Bozuta
  2 siblings, 0 replies; 7+ messages in thread
From: Filip Bozuta @ 2020-08-07 11:39 UTC (permalink / raw)
  To: ltp

This patch introduces a test case for the already existing test for
syscalls 'sendmmsg()' and 'recvmmsg()' (sendmmsg01). This test
case is meant to check whether the timeout is reached aproppriately
after the first message is received. The timeout is set to 1 nsec as to
make sure that it has to be reached. In this case the expected return
value is 1 as the second message is not supposed be received after the
timeout is reached.

* Note: No matter how small the timeout is, one message is always gonna
have to be received because the timeout is checked only after a received
message. This is an existing bug for syscall 'recvmmsg()':
https://man7.org/linux/man-pages/man2/recvmmsg.2.html#BUGS

This patch introduces a new test file for these syscalls (sendmmsg02.c).
This test file is meant to check whether the aproppriate errno is set in
some sitautions when these syscalls fail. These situations include:
bad socket file descriptor (EBADF), bad message vector address (EFAULT),
bad timeout value (EINVAL), bad timeout address (EFAULT).

Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
---
 runtest/syscalls                              |   1 +
 testcases/kernel/syscalls/sendmmsg/.gitignore |   1 +
 .../kernel/syscalls/sendmmsg/sendmmsg01.c     |  68 ++++--
 .../kernel/syscalls/sendmmsg/sendmmsg02.c     | 231 ++++++++++++++++++
 4 files changed, 286 insertions(+), 15 deletions(-)
 create mode 100644 testcases/kernel/syscalls/sendmmsg/sendmmsg02.c

diff --git a/runtest/syscalls b/runtest/syscalls
index c2bfc6df3..7c2f71e0c 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1200,6 +1200,7 @@ sendmsg02 sendmsg02
 sendmsg03 sendmsg03
 
 sendmmsg01 sendmmsg01
+sendmmsg02 sendmmsg02
 
 sendto01 sendto01
 sendto02 sendto02
diff --git a/testcases/kernel/syscalls/sendmmsg/.gitignore b/testcases/kernel/syscalls/sendmmsg/.gitignore
index b703ececd..42693c44d 100644
--- a/testcases/kernel/syscalls/sendmmsg/.gitignore
+++ b/testcases/kernel/syscalls/sendmmsg/.gitignore
@@ -1 +1,2 @@
 sendmmsg01
+sendmmsg02
diff --git a/testcases/kernel/syscalls/sendmmsg/sendmmsg01.c b/testcases/kernel/syscalls/sendmmsg/sendmmsg01.c
index 54febf661..d7d5d33cc 100644
--- a/testcases/kernel/syscalls/sendmmsg/sendmmsg01.c
+++ b/testcases/kernel/syscalls/sendmmsg/sendmmsg01.c
@@ -24,6 +24,36 @@ static int receive_sockfd;
 static struct mmsghdr *snd_msg, *rcv_msg;
 static struct iovec *snd1, *snd2, *rcv1, *rcv2;
 
+enum test_type {
+	NORMAL,
+	TIMEOUT,
+};
+
+#define TYPE_NAME(x) .ttype = x, .desc = #x
+
+struct test_case {
+	int ttype;
+	const char *desc;
+	long tv_sec;
+	long tv_nsec;
+	int exp_ret;
+};
+
+static struct test_case tcase[] = {
+	{
+		TYPE_NAME(NORMAL),
+		.tv_sec = 1,
+		.tv_nsec = 0,
+		.exp_ret = 2,
+	},
+	{
+		TYPE_NAME(TIMEOUT),
+		.tv_sec = 0,
+		.tv_nsec = 1,
+		.exp_ret = 1,
+	},
+};
+
 static struct test_variants {
 	int (*receive)(int sockfd, struct mmsghdr *msgvec, unsigned int vlen,
 		       unsigned int flags, void *timeout);
@@ -43,14 +73,17 @@ static struct test_variants {
 #endif
 };
 
-static void run(void)
+static void do_test(unsigned int i)
 {
 	struct test_variants *tv = &variants[tst_variant];
+	struct test_case *tc = &tcase[i];
 	struct tst_ts timeout;
-	int retval;
 
-	retval = tv->send(send_sockfd, snd_msg, VLEN, 0);
-	if (retval < 0 || snd_msg[0].msg_len != 6 || snd_msg[1].msg_len != 6) {
+	tst_res(TINFO, "case %s", tc->desc);
+
+	TEST(tv->send(send_sockfd, snd_msg, VLEN, 0));
+
+	if (TST_RET < 0 || snd_msg[0].msg_len != 6 || snd_msg[1].msg_len != 6) {
 		tst_res(TFAIL | TERRNO, "sendmmsg() failed");
 		return;
 	}
@@ -59,18 +92,18 @@ static void run(void)
 	memset(rcv2->iov_base, 0, rcv2->iov_len);
 
 	timeout.type = tv->type;
-	tst_ts_set_sec(&timeout, 1);
-	tst_ts_set_nsec(&timeout, 0);
+	tst_ts_set_sec(&timeout, tc->tv_sec);
+	tst_ts_set_nsec(&timeout, tc->tv_nsec);
 
-	retval = tv->receive(receive_sockfd, rcv_msg, VLEN, 0, tst_ts_get(&timeout));
+	TEST(tv->receive(receive_sockfd, rcv_msg, VLEN, 0, tst_ts_get(&timeout)));
 
-	if (retval == -1) {
+	if (TST_RET == -1) {
 		tst_res(TFAIL | TERRNO, "recvmmsg() failed");
 		return;
 	}
-	if (retval != 2) {
+	if (tc->exp_ret != TST_RET) {
 		tst_res(TFAIL, "Received unexpected number of messages (%d)",
-			retval);
+			TST_RET);
 		return;
 	}
 
@@ -79,10 +112,14 @@ static void run(void)
 	else
 		tst_res(TPASS, "First message received successfully");
 
-	if (memcmp(rcv2->iov_base, "three", 5))
-		tst_res(TFAIL, "Error in second received message");
-	else
-		tst_res(TPASS, "Second message received successfully");
+	if (tc->ttype == NORMAL) {
+		if (memcmp(rcv2->iov_base, "three", 5))
+			tst_res(TFAIL, "Error in second received message");
+		else
+			tst_res(TPASS, "Second message received successfully");
+	} else {
+		tst_res(TPASS, "Timeout successfully reached before second message");
+	}
 }
 
 static void setup(void)
@@ -128,7 +165,8 @@ static void cleanup(void)
 }
 
 static struct tst_test test = {
-	.test_all = run,
+	.tcnt = ARRAY_SIZE(tcase),
+	.test = do_test,
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_variants = ARRAY_SIZE(variants),
diff --git a/testcases/kernel/syscalls/sendmmsg/sendmmsg02.c b/testcases/kernel/syscalls/sendmmsg/sendmmsg02.c
new file mode 100644
index 000000000..d7501beef
--- /dev/null
+++ b/testcases/kernel/syscalls/sendmmsg/sendmmsg02.c
@@ -0,0 +1,231 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#define _GNU_SOURCE
+#include <netinet/ip.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include "tst_test.h"
+#include "lapi/socket.h"
+#include "tst_safe_macros.h"
+#include "sendmmsg_var.h"
+
+#define BUFSIZE 16
+#define VLEN 2
+
+static int send_sockfd;
+static int receive_sockfd;
+static struct mmsghdr *snd_msg, *rcv_msg;
+static struct iovec *snd1, *snd2, *rcv1, *rcv2;
+static struct tst_ts ts;
+
+enum test_type {
+	BAD_SEND_FD,
+	BAD_RECV_FD,
+	BAD_SEND_MSGVEC,
+	BAD_RECV_MSGVEC,
+	BAD_TS_VALUE_1,
+	BAD_TS_VALUE_2,
+	BAD_TS_ADDR,
+};
+
+#define TYPE_NAME(x) .ttype = x, .desc = #x
+
+struct test_case {
+	int ttype;
+	const char *desc;
+	int send_fd;
+	int recv_fd;
+	long tv_sec;
+	long tv_nsec;
+	int exp_send_ret;
+	int exp_send_errno;
+	int exp_recv_errno;
+};
+
+static struct test_case tcase[] = {
+	{
+		TYPE_NAME(BAD_SEND_FD),
+		.send_fd = -1,
+		.exp_send_ret = -1,
+		.exp_send_errno = EBADF,
+	},
+	{
+		TYPE_NAME(BAD_RECV_FD),
+		.exp_send_ret = VLEN,
+		.recv_fd = -1,
+		.exp_recv_errno = EBADF,
+	},
+	{
+		TYPE_NAME(BAD_SEND_MSGVEC),
+		.exp_send_ret = -1,
+		.exp_send_errno = EFAULT,
+	},
+	{
+		TYPE_NAME(BAD_RECV_MSGVEC),
+		.exp_send_ret = VLEN,
+		.exp_recv_errno = EFAULT,
+	},
+	{
+		TYPE_NAME(BAD_TS_VALUE_1),
+		.exp_send_ret = VLEN,
+		.tv_sec = -1,
+		.tv_nsec = 0,
+		.exp_recv_errno = EINVAL,
+	},
+	{
+		TYPE_NAME(BAD_TS_VALUE_2),
+		.exp_send_ret = VLEN,
+		.tv_sec = 1,
+		.tv_nsec = 1000000001,
+		.exp_recv_errno = EINVAL,
+	},
+	{
+		TYPE_NAME(BAD_TS_ADDR),
+		.exp_send_ret = VLEN,
+		.exp_recv_errno = EFAULT,
+	}
+};
+
+static struct test_variants {
+	int (*receive)(int sockfd, struct mmsghdr *msgvec, unsigned int vlen,
+		       unsigned int flags, void *timeout);
+	int (*send)(int sockfd, struct mmsghdr *msgvec, unsigned int vlen,
+		    unsigned int flags);
+	enum tst_ts_type type;
+	char *desc;
+} variants[] = {
+	{ .receive = libc_recvmmsg, .send = libc_sendmmsg, .type = TST_LIBC_TIMESPEC, .desc = "vDSO or syscall with libc spec"},
+
+#if (__NR_recvmmsg != __LTP__NR_INVALID_SYSCALL)
+	{ .receive = sys_recvmmsg, .send = sys_sendmmsg, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"},
+#endif
+
+#if (__NR_recvmmsg_time64 != __LTP__NR_INVALID_SYSCALL)
+	{ .receive = sys_recvmmsg64, .send = sys_sendmmsg, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"},
+#endif
+};
+
+static void cleanup(void)
+{
+	if (send_sockfd > 0)
+		SAFE_CLOSE(send_sockfd);
+	if (receive_sockfd > 0)
+		SAFE_CLOSE(receive_sockfd);
+}
+
+static void do_test(unsigned int i)
+{
+	struct test_variants *tv = &variants[tst_variant];
+	struct test_case *tc = &tcase[i];
+	void *snd_msgvec, *rcv_msgvec, *timeout;
+
+	tst_res(TINFO, "case %s", tc->desc);
+
+	if (tc->ttype != BAD_SEND_FD)
+		tc->send_fd = send_sockfd;
+	if (tc->ttype != BAD_RECV_FD)
+		tc->recv_fd = receive_sockfd;
+
+	if (tc->ttype == BAD_SEND_MSGVEC)
+		snd_msgvec = tst_get_bad_addr(cleanup);
+	else
+		snd_msgvec = snd_msg;
+
+	TEST(tv->send(tc->send_fd, snd_msgvec, VLEN, 0));
+
+	if (TST_RET < 0) {
+		if (tc->exp_send_ret != TST_RET || errno != tc->exp_send_errno)
+			tst_res(TFAIL | TERRNO, "sendmmsg() failed unexpectedly");
+		else
+			tst_res(TPASS | TERRNO, "sendmmg() failed successfully");
+		return;
+	}
+
+	if (tc->exp_send_ret != TST_RET || snd_msg[0].msg_len != 6 ||
+	    snd_msg[1].msg_len != 6) {
+		tst_res(TFAIL | TERRNO, "sendmmsg() failed");
+		return;
+	}
+
+	memset(rcv1->iov_base, 0, rcv1->iov_len);
+	memset(rcv2->iov_base, 0, rcv2->iov_len);
+
+	ts.type = tv->type;
+	tst_ts_set_sec(&ts, tc->tv_sec);
+	tst_ts_set_nsec(&ts, tc->tv_nsec);
+
+	if (tc->ttype == BAD_RECV_MSGVEC)
+		rcv_msgvec = tst_get_bad_addr(cleanup);
+	else
+		rcv_msgvec = rcv_msg;
+
+	if (tc->ttype == BAD_TS_ADDR)
+		timeout = tst_get_bad_addr(cleanup);
+	else
+		timeout = tst_ts_get(&ts);
+
+	TEST(tv->receive(tc->recv_fd, rcv_msgvec, VLEN, 0, timeout));
+
+	if (TST_RET < 0) {
+		if (tc->exp_recv_errno == errno)
+			tst_res(TPASS | TERRNO, "receivemmsg() failed successfully");
+		else
+			tst_res(TFAIL | TERRNO, "receivemmsg() failed unexpectedly");
+	} else {
+		tst_res(TFAIL | TERRNO, "receivemmsg() succeded unexpectedly");
+	}
+}
+
+static void setup(void)
+{
+	struct sockaddr_in addr;
+	unsigned int port = TST_GET_UNUSED_PORT(AF_INET, SOCK_DGRAM);
+
+	send_sockfd = SAFE_SOCKET(AF_INET, SOCK_DGRAM, 0);
+	receive_sockfd = SAFE_SOCKET(AF_INET, SOCK_DGRAM, 0);
+
+	addr.sin_family = AF_INET;
+	addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+	addr.sin_port = port;
+
+	SAFE_BIND(receive_sockfd, (struct sockaddr *)&addr, sizeof(addr));
+	SAFE_CONNECT(send_sockfd, (struct sockaddr *)&addr, sizeof(addr));
+
+	memcpy(snd1[0].iov_base, "one", snd1[0].iov_len);
+	memcpy(snd1[1].iov_base, "two", snd1[1].iov_len);
+	memcpy(snd2->iov_base, "three3", snd2->iov_len);
+
+	memset(snd_msg, 0, VLEN * sizeof(*snd_msg));
+	snd_msg[0].msg_hdr.msg_iov = snd1;
+	snd_msg[0].msg_hdr.msg_iovlen = 2;
+	snd_msg[1].msg_hdr.msg_iov = snd2;
+	snd_msg[1].msg_hdr.msg_iovlen = 1;
+
+	memset(rcv_msg, 0, VLEN * sizeof(*rcv_msg));
+	rcv_msg[0].msg_hdr.msg_iov = rcv1;
+	rcv_msg[0].msg_hdr.msg_iovlen = 1;
+	rcv_msg[1].msg_hdr.msg_iov = rcv2;
+	rcv_msg[1].msg_hdr.msg_iovlen = 1;
+
+	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcase),
+	.test = do_test,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_variants = ARRAY_SIZE(variants),
+	.bufs = (struct tst_buffers []) {
+		{&snd1, .iov_sizes = (int[]){3, 3, -1}},
+		{&snd2, .iov_sizes = (int[]){6, -1}},
+		{&rcv1, .iov_sizes = (int[]){6, -1}},
+		{&rcv2, .iov_sizes = (int[]){5, -1}},
+		{&snd_msg, .size = VLEN * sizeof(*snd_msg)},
+		{&rcv_msg, .size = VLEN * sizeof(*rcv_msg)},
+		{},
+	}
+};
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [LTP] [PATCH v2 1/3] syscalls/mq_timed{send|receive}: Add test cases for bad address
  2020-08-07 11:39 ` [LTP] [PATCH v2 1/3] syscalls/mq_timed{send|receive}: Add test cases for bad address Filip Bozuta
@ 2020-08-10 12:42   ` Cyril Hrubis
  0 siblings, 0 replies; 7+ messages in thread
From: Cyril Hrubis @ 2020-08-10 12:42 UTC (permalink / raw)
  To: ltp

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);
 

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [LTP] [PATCH v2 2/3] syscalls/clock_nanosleep: add a test case for bad timespec address
  2020-08-07 11:39 ` [LTP] [PATCH v2 2/3] syscalls/clock_nanosleep: add a test case for bad timespec address Filip Bozuta
@ 2020-08-10 12:57   ` Cyril Hrubis
  2020-08-10 13:56     ` Filip Bozuta
  0 siblings, 1 reply; 7+ messages in thread
From: Cyril Hrubis @ 2020-08-10 12:57 UTC (permalink / raw)
  To: ltp

Hi!
> This patch introduces test cases for already existing test
> for syscall 'clock_nanosleep()' (clock_nanosleep01). These test
> cases are for situations when bad timespec addresses are passed
> for arguments 'request' and 'remain' in which case errno
> EFAULT ('Bad address') is expected to be set.
> 
> Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
> ---
>  .../clock_nanosleep/clock_nanosleep01.c       | 35 +++++++++++++++++--
>  1 file changed, 33 insertions(+), 2 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c b/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c
> index 4542995f2..66108ed8e 100644
> --- a/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c
> +++ b/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c
> @@ -20,6 +20,8 @@ static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
>  enum test_type {
>  	NORMAL,
>  	SEND_SIGINT,
> +	BAD_TS_ADDR_REQ,
> +	BAD_TS_ADDR_REM,
>  };
>  
>  #define TYPE_NAME(x) .ttype = x, .desc = #x
> @@ -78,6 +80,22 @@ static struct test_case tcase[] = {
>  		.exp_ret = -1,
>  		.exp_err = EINTR,
>  	},
> +	{
> +		TYPE_NAME(BAD_TS_ADDR_REQ),
> +		.clk_id = CLOCK_REALTIME,
> +		.flags = 0,
> +		.exp_ret = -1,
> +		.exp_err = EFAULT,
> +	},
> +	{
> +		TYPE_NAME(BAD_TS_ADDR_REM),
> +		.clk_id = CLOCK_REALTIME,
> +		.flags = 0,
> +		.tv_sec = 10,
> +		.tv_nsec = 0,
> +		.exp_ret = -1,
> +		.exp_err = EFAULT,
> +	},
>  };
>  
>  static struct tst_ts *rq;
> @@ -106,24 +124,37 @@ void setup(void)
>  	SAFE_SIGNAL(SIGINT, sighandler);
>  }
>  
> +void cleanup(void) {}

Please just pass NULL to the tst_get_bad_addr() instead.

Also it should be called only once in the test setup, as I explained for
the previous patch.

>  static void do_test(unsigned int i)
>  {
>  	struct test_variants *tv = &variants[tst_variant];
>  	struct test_case *tc = &tcase[i];
>  	pid_t pid = 0;
> +	void *request, *remain;
>  
>  	memset(rm, 0, sizeof(*rm));
>  	rm->type = rq->type;
>  
>  	tst_res(TINFO, "case %s", tc->desc);
>  
> -	if (tc->ttype == SEND_SIGINT)
> +	if (tc->ttype == SEND_SIGINT || tc->ttype == BAD_TS_ADDR_REM)
>  		pid = create_sig_proc(SIGINT, 40, 500000);

Does the kernel access the remaining time only if the call gets
interrupted by a signal?

I guess that this would be better written down in comment.

Generally LTP testcases usually have short documentation in a comment
just after the license and copyright. In this case it should be
something as:

/*
 * EINVAL - negative tv_nsec
 * EINVAL - tv_nsec > 1s
 * ...
 * EFAULT - invalid request pointer
 * EFAULT - invalid remain pointer while interrupted by a signal
 */

>  	tst_ts_set_sec(rq, tc->tv_sec);
>  	tst_ts_set_nsec(rq, tc->tv_nsec);
>  
> -	TEST(tv->func(tc->clk_id, tc->flags, tst_ts_get(rq), tst_ts_get(rm)));
> +	if (tc->ttype == BAD_TS_ADDR_REQ)
> +		request = tst_get_bad_addr(cleanup);
> +	else
> +		request = tst_ts_get(rq);
> +
> +	if (tc->ttype == BAD_TS_ADDR_REM)
> +		remain = tst_get_bad_addr(cleanup);
> +	else
> +		remain = tst_ts_get(rm);
> +
> +	TEST(tv->func(tc->clk_id, tc->flags, request, remain));
>  
>  	if (tv->func == libc_clock_nanosleep) {
>  		/*
> -- 
> 2.25.1
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [LTP] [PATCH v2 2/3] syscalls/clock_nanosleep: add a test case for bad timespec address
  2020-08-10 12:57   ` Cyril Hrubis
@ 2020-08-10 13:56     ` Filip Bozuta
  0 siblings, 0 replies; 7+ messages in thread
From: Filip Bozuta @ 2020-08-10 13:56 UTC (permalink / raw)
  To: ltp

Hello,

thanks for the review!

On 10.8.20. 14:57, Cyril Hrubis wrote:
> Hi!
>> This patch introduces test cases for already existing test
>> for syscall 'clock_nanosleep()' (clock_nanosleep01). These test
>> cases are for situations when bad timespec addresses are passed
>> for arguments 'request' and 'remain' in which case errno
>> EFAULT ('Bad address') is expected to be set.
>>
>> Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
>> ---
>>   .../clock_nanosleep/clock_nanosleep01.c       | 35 +++++++++++++++++--
>>   1 file changed, 33 insertions(+), 2 deletions(-)
>>
>> diff --git a/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c b/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c
>> index 4542995f2..66108ed8e 100644
>> --- a/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c
>> +++ b/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c
>> @@ -20,6 +20,8 @@ static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
>>   enum test_type {
>>   	NORMAL,
>>   	SEND_SIGINT,
>> +	BAD_TS_ADDR_REQ,
>> +	BAD_TS_ADDR_REM,
>>   };
>>   
>>   #define TYPE_NAME(x) .ttype = x, .desc = #x
>> @@ -78,6 +80,22 @@ static struct test_case tcase[] = {
>>   		.exp_ret = -1,
>>   		.exp_err = EINTR,
>>   	},
>> +	{
>> +		TYPE_NAME(BAD_TS_ADDR_REQ),
>> +		.clk_id = CLOCK_REALTIME,
>> +		.flags = 0,
>> +		.exp_ret = -1,
>> +		.exp_err = EFAULT,
>> +	},
>> +	{
>> +		TYPE_NAME(BAD_TS_ADDR_REM),
>> +		.clk_id = CLOCK_REALTIME,
>> +		.flags = 0,
>> +		.tv_sec = 10,
>> +		.tv_nsec = 0,
>> +		.exp_ret = -1,
>> +		.exp_err = EFAULT,
>> +	},
>>   };
>>   
>>   static struct tst_ts *rq;
>> @@ -106,24 +124,37 @@ void setup(void)
>>   	SAFE_SIGNAL(SIGINT, sighandler);
>>   }
>>   
>> +void cleanup(void) {}
> Please just pass NULL to the tst_get_bad_addr() instead.
>
> Also it should be called only once in the test setup, as I explained for
> the previous patch.

Yes I will change this and send v3 for this patch soon. I will pass NULL 
and move the tst_get_bad_addr() in test setup() same as in the first 
patch. Thanks for the explanation!

>
>>   static void do_test(unsigned int i)
>>   {
>>   	struct test_variants *tv = &variants[tst_variant];
>>   	struct test_case *tc = &tcase[i];
>>   	pid_t pid = 0;
>> +	void *request, *remain;
>>   
>>   	memset(rm, 0, sizeof(*rm));
>>   	rm->type = rq->type;
>>   
>>   	tst_res(TINFO, "case %s", tc->desc);
>>   
>> -	if (tc->ttype == SEND_SIGINT)
>> +	if (tc->ttype == SEND_SIGINT || tc->ttype == BAD_TS_ADDR_REM)
>>   		pid = create_sig_proc(SIGINT, 40, 500000);
> Does the kernel access the remaining time only if the call gets
> interrupted by a signal?
Yes, the the 'remain' argument is accessed only in a case when call gets 
interrupted by a signal and in case it is not NULL and if flag 
TIMER_ABSTIME is not set, the argument gets updated with the remaining 
time from the timeout. For that reason a signal should be set in this 
test case so that the test fails with expected errno (EFAULT) when 
kernel tries to access the argument.
>
> I guess that this would be better written down in comment.
>
> Generally LTP testcases usually have short documentation in a comment
> just after the license and copyright. In this case it should be
> something as:
>
> /*
>   * EINVAL - negative tv_nsec
>   * EINVAL - tv_nsec > 1s
>   * ...
>   * EFAULT - invalid request pointer
>   * EFAULT - invalid remain pointer while interrupted by a signal
>   */

Thanks for pointing this out. I will put these short comment 
explanations in my v3 version of this patch.

Best regards,

Filip

>>   	tst_ts_set_sec(rq, tc->tv_sec);
>>   	tst_ts_set_nsec(rq, tc->tv_nsec);
>>   
>> -	TEST(tv->func(tc->clk_id, tc->flags, tst_ts_get(rq), tst_ts_get(rm)));
>> +	if (tc->ttype == BAD_TS_ADDR_REQ)
>> +		request = tst_get_bad_addr(cleanup);
>> +	else
>> +		request = tst_ts_get(rq);
>> +
>> +	if (tc->ttype == BAD_TS_ADDR_REM)
>> +		remain = tst_get_bad_addr(cleanup);
>> +	else
>> +		remain = tst_ts_get(rm);
>> +
>> +	TEST(tv->func(tc->clk_id, tc->flags, request, remain));
>>   
>>   	if (tv->func == libc_clock_nanosleep) {
>>   		/*
>> -- 
>> 2.25.1
>>
>>
>> -- 
>> Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-08-10 13:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-07 11:39 [LTP] [PATCH v2 0/3] testcases/kernel/syscalls: Adding new testcases for existing tests Filip Bozuta
2020-08-07 11:39 ` [LTP] [PATCH v2 1/3] syscalls/mq_timed{send|receive}: Add test cases for bad address Filip Bozuta
2020-08-10 12:42   ` Cyril Hrubis
2020-08-07 11:39 ` [LTP] [PATCH v2 2/3] syscalls/clock_nanosleep: add a test case for bad timespec address Filip Bozuta
2020-08-10 12:57   ` Cyril Hrubis
2020-08-10 13:56     ` Filip Bozuta
2020-08-07 11:39 ` [LTP] [PATCH v2 3/3] syscalls/{send|recv}mmsg: add a test case for timeout and errno test Filip Bozuta

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.