All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 3/3] y2038: testsuite/smokey/y2038: testcase for recvmmsg64
@ 2021-09-13  1:46 Song Chen
  2021-09-27 11:04 ` Bezdeka, Florian
  0 siblings, 1 reply; 2+ messages in thread
From: Song Chen @ 2021-09-13  1:46 UTC (permalink / raw)
  To: florian.bezdeka, xenomai

Extending the test suite for recvmmsg64 test.

Signed-off-by: Song Chen <chensong_2000@189.cn>

---
v2:
1, rename variables
2, remove unnecessary branches
3, call smokey_check_errno
---
 testsuite/smokey/y2038/syscall-tests.c | 132 +++++++++++++++++++++++++++++++++
 1 file changed, 132 insertions(+)

diff --git a/testsuite/smokey/y2038/syscall-tests.c b/testsuite/smokey/y2038/syscall-tests.c
index 8afedd7..b43a44f 100644
--- a/testsuite/smokey/y2038/syscall-tests.c
+++ b/testsuite/smokey/y2038/syscall-tests.c
@@ -12,6 +12,7 @@
 #include <asm/xenomai/syscall.h>
 #include <smokey/smokey.h>
 #include <mqueue.h>
+#include <rtdm/ipc.h>
 
 smokey_test_plugin(y2038, SMOKEY_NOARGS, "Validate correct y2038 support");
 
@@ -989,6 +990,133 @@ static int test_sc_cobalt_event_wait64(void)
 	return 0;
 }
 
+static int test_sc_cobalt_recvmmsg64(void)
+{
+	int ret = 0;
+	int sockfd;
+	int sc_nr = sc_cobalt_recvmmsg64;
+	long data;
+	struct xn_timespec64 t1, t2;
+	struct timespec ts_nat;
+	struct rtipc_port_label plabel;
+	struct sockaddr_ipc saddr;
+
+	struct iovec iov = {
+		.iov_base = &data,
+		.iov_len = sizeof(data),
+	};
+	struct msghdr msg = {
+		.msg_name = NULL,
+		.msg_namelen = 0,
+		.msg_iov = &iov,
+		.msg_iovlen = 1,
+		.msg_control = NULL,
+		.msg_controllen = 0,
+	};
+
+	sockfd = socket(AF_RTIPC, SOCK_DGRAM, IPCPROTO_XDDP);
+	if (sockfd <= 0)
+		return -errno;
+
+	strcpy(plabel.label, "y2038:recvmmsg64");
+	ret = smokey_check_errno(setsockopt(sockfd, SOL_XDDP,
+					XDDP_LABEL, &plabel, sizeof(plabel)));
+	if (ret)
+		goto out;
+
+	memset(&saddr, 0, sizeof(saddr));
+	saddr.sipc_family = AF_RTIPC;
+	saddr.sipc_port = -1;
+	ret = smokey_check_errno(bind(sockfd, (struct sockaddr *)&saddr,
+					sizeof(saddr)));
+	if (ret)
+		goto out;
+
+	/* Make sure we don't crash because of NULL pointers */
+	ret = XENOMAI_SYSCALL5(sc_nr, NULL, NULL, NULL, NULL, NULL);
+	if (ret == -ENOSYS) {
+		smokey_note("recvmmsg64: skipped. (no kernel support)");
+		goto out; // Not implemented, nothing to test, success
+	}
+	if (!smokey_assert(ret == -EADV)) {
+		ret = ret ? ret : -EINVAL;
+		goto out;
+	}
+
+	/* Providing an invalid address has to deliver EFAULT */
+	ret = XENOMAI_SYSCALL5(sc_nr, sockfd, &msg, sizeof(msg),
+				0, (void *)0xdeadbeefUL);
+	if (!smokey_assert(ret == -EFAULT)) {
+		ret = ret ? ret : -EINVAL;
+		goto out;
+	}
+
+	/*
+	 * providing an invalid timeout has to deliver EINVAL
+	 */
+	t1.tv_sec = -1;
+	ret = XENOMAI_SYSCALL5(sc_nr, sockfd, &msg, sizeof(msg), 0, &t1);
+	if (!smokey_assert(ret == -EINVAL)) {
+		ret = ret ? ret : -EINVAL;
+		goto out;
+	}
+
+	/*
+	 * providing a zero timeout,
+	 * should come back immediately with EWOULDBLOCK
+	 */
+	t1.tv_sec = 0;
+	t1.tv_nsec = 0;
+	ret = XENOMAI_SYSCALL5(sc_nr, sockfd, &msg, sizeof(msg), 0, &t1);
+	if (!smokey_assert(ret == -EWOULDBLOCK)) {
+		ret = ret ? ret : -EINVAL;
+		goto out;
+	}
+
+	/*
+	 * Providing a valid timeout, waiting for it to time out and check
+	 * that we didn't come back to early.
+	 */
+	ret = clock_gettime(CLOCK_REALTIME, &ts_nat);
+	if (ret) {
+		ret = ret ? ret : -EINVAL;
+		goto out;
+	}
+
+	t1.tv_sec = 0;
+	t1.tv_nsec = 500000;
+
+	ret = XENOMAI_SYSCALL5(sc_nr, sockfd, &msg, sizeof(msg), 0, &t1);
+	if (!smokey_assert(ret == -ETIMEDOUT)) {
+		ret = ret ? ret : -EINVAL;
+		goto out;
+	}
+
+	t1.tv_sec = ts_nat.tv_sec;
+	t1.tv_nsec = ts_nat.tv_nsec;
+
+	ret = clock_gettime(CLOCK_REALTIME, &ts_nat);
+	if (ret) {
+		ret = ret ? ret : -EINVAL;
+		goto out;
+	}
+
+	t2.tv_sec = ts_nat.tv_sec;
+	t2.tv_nsec = ts_nat.tv_nsec;
+
+	if (ts_less(&t2, &t1))
+		smokey_warning("recvmmsg64 returned to early!\n"
+			       "Expected wakeup at: %lld sec %lld nsec\n"
+			       "Back at           : %lld sec %lld nsec\n",
+			       t1.tv_sec, t1.tv_nsec, t1.tv_sec, t2.tv_nsec);
+
+	ret = 0;
+
+out:
+	close(sockfd);
+	return ret;
+}
+
 static int run_y2038(struct smokey_test *t, int argc, char *const argv[])
 {
 	int ret;
@@ -1041,5 +1169,9 @@ static int run_y2038(struct smokey_test *t, int argc, char *const argv[])
 	if (ret)
 		return ret;
 
+	ret = test_sc_cobalt_recvmmsg64();
+	if (ret)
+		return ret;
+
 	return 0;
 }
-- 
2.7.4



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

* Re: [PATCH v3 3/3] y2038: testsuite/smokey/y2038: testcase for recvmmsg64
  2021-09-13  1:46 [PATCH v3 3/3] y2038: testsuite/smokey/y2038: testcase for recvmmsg64 Song Chen
@ 2021-09-27 11:04 ` Bezdeka, Florian
  0 siblings, 0 replies; 2+ messages in thread
From: Bezdeka, Florian @ 2021-09-27 11:04 UTC (permalink / raw)
  To: xenomai, chensong_2000

Hi Song,

it took some time... I'm just back from vacation.

On Mon, 2021-09-13 at 09:46 +0800, Song Chen wrote:
> Extending the test suite for recvmmsg64 test.
> 
> Signed-off-by: Song Chen <chensong_2000@189.cn>
> 
> ---
> v2:
> 1, rename variables
> 2, remove unnecessary branches
> 3, call smokey_check_errno
> ---
>  testsuite/smokey/y2038/syscall-tests.c | 132 +++++++++++++++++++++++++++++++++
>  1 file changed, 132 insertions(+)
> 
> diff --git a/testsuite/smokey/y2038/syscall-tests.c b/testsuite/smokey/y2038/syscall-tests.c
> index 8afedd7..b43a44f 100644
> --- a/testsuite/smokey/y2038/syscall-tests.c
> +++ b/testsuite/smokey/y2038/syscall-tests.c
> @@ -12,6 +12,7 @@
>  #include <asm/xenomai/syscall.h>
>  #include <smokey/smokey.h>
>  #include <mqueue.h>
> +#include <rtdm/ipc.h>
>  
>  smokey_test_plugin(y2038, SMOKEY_NOARGS, "Validate correct y2038 support");
>  
> @@ -989,6 +990,133 @@ static int test_sc_cobalt_event_wait64(void)
>  	return 0;
>  }
>  
> +static int test_sc_cobalt_recvmmsg64(void)
> +{
> +	int ret = 0;
> +	int sockfd;
> +	int sc_nr = sc_cobalt_recvmmsg64;
> +	long data;
> +	struct xn_timespec64 t1, t2;
> +	struct timespec ts_nat;
> +	struct rtipc_port_label plabel;
> +	struct sockaddr_ipc saddr;
> +
> +	struct iovec iov = {
> +		.iov_base = &data,
> +		.iov_len = sizeof(data),
> +	};
> +	struct msghdr msg = {
> +		.msg_name = NULL,
> +		.msg_namelen = 0,
> +		.msg_iov = &iov,
> +		.msg_iovlen = 1,
> +		.msg_control = NULL,
> +		.msg_controllen = 0,
> +	};
> +
> +	sockfd = socket(AF_RTIPC, SOCK_DGRAM, IPCPROTO_XDDP);
> +	if (sockfd <= 0)
> +		return -errno;

"man socket" tells me that:
	On success, a file descriptor for the new socket is returned.
 
	On  error, -1 is returned, and errno is set appropriately.

So we should use smokey_check_errno() here as well.

> +
> +	strcpy(plabel.label, "y2038:recvmmsg64");
> +	ret = smokey_check_errno(setsockopt(sockfd, SOL_XDDP,
> +					XDDP_LABEL, &plabel, sizeof(plabel)));
> +	if (ret)
> +		goto out;
> +
> +	memset(&saddr, 0, sizeof(saddr));
> +	saddr.sipc_family = AF_RTIPC;
> +	saddr.sipc_port = -1;
> +	ret = smokey_check_errno(bind(sockfd, (struct sockaddr *)&saddr,
> +					sizeof(saddr)));
> +	if (ret)
> +		goto out;
> +
> +	/* Make sure we don't crash because of NULL pointers */
> +	ret = XENOMAI_SYSCALL5(sc_nr, NULL, NULL, NULL, NULL, NULL);
> +	if (ret == -ENOSYS) {
> +		smokey_note("recvmmsg64: skipped. (no kernel support)");
> +		goto out; // Not implemented, nothing to test, success
> +	}
> +	if (!smokey_assert(ret == -EADV)) {
> +		ret = ret ? ret : -EINVAL;
> +		goto out;
> +	}
> +
> +	/* Providing an invalid address has to deliver EFAULT */
> +	ret = XENOMAI_SYSCALL5(sc_nr, sockfd, &msg, sizeof(msg),
> +				0, (void *)0xdeadbeefUL);
> +	if (!smokey_assert(ret == -EFAULT)) {
> +		ret = ret ? ret : -EINVAL;
> +		goto out;
> +	}
> +
> +	/*
> +	 * providing an invalid timeout has to deliver EINVAL
> +	 */
> +	t1.tv_sec = -1;
> +	ret = XENOMAI_SYSCALL5(sc_nr, sockfd, &msg, sizeof(msg), 0, &t1);
> +	if (!smokey_assert(ret == -EINVAL)) {
> +		ret = ret ? ret : -EINVAL;
> +		goto out;
> +	}
> +
> +	/*
> +	 * providing a zero timeout,
> +	 * should come back immediately with EWOULDBLOCK
> +	 */
> +	t1.tv_sec = 0;
> +	t1.tv_nsec = 0;
> +	ret = XENOMAI_SYSCALL5(sc_nr, sockfd, &msg, sizeof(msg), 0, &t1);
> +	if (!smokey_assert(ret == -EWOULDBLOCK)) {
> +		ret = ret ? ret : -EINVAL;
> +		goto out;
> +	}
> +
> +	/*
> +	 * Providing a valid timeout, waiting for it to time out and check
> +	 * that we didn't come back to early.
> +	 */
> +	ret = clock_gettime(CLOCK_REALTIME, &ts_nat);
> +	if (ret) {
> +		ret = ret ? ret : -EINVAL;
> +		goto out;
> +	}

clock_gettime() returns 0 on success, -1 on failure and errno will be
set accordingly. => Use smokey_check_errno(). (If not possible for some
reason I do not see: The assignment of ret can be simplified. We know
that it is != 0, so no need for using the ? operator)

> +
> +	t1.tv_sec = 0;
> +	t1.tv_nsec = 500000;
> +
> +	ret = XENOMAI_SYSCALL5(sc_nr, sockfd, &msg, sizeof(msg), 0, &t1);
> +	if (!smokey_assert(ret == -ETIMEDOUT)) {
> +		ret = ret ? ret : -EINVAL;
> +		goto out;
> +	}
> +
> +	t1.tv_sec = ts_nat.tv_sec;
> +	t1.tv_nsec = ts_nat.tv_nsec;
> +
> +	ret = clock_gettime(CLOCK_REALTIME, &ts_nat);
> +	if (ret) {
> +		ret = ret ? ret : -EINVAL;
> +		goto out;
> +	}

See above.

> +
> +	t2.tv_sec = ts_nat.tv_sec;
> +	t2.tv_nsec = ts_nat.tv_nsec;
> +
> +	if (ts_less(&t2, &t1))
> +		smokey_warning("recvmmsg64 returned to early!\n"
> +			       "Expected wakeup at: %lld sec %lld nsec\n"
> +			       "Back at           : %lld sec %lld nsec\n",
> +			       t1.tv_sec, t1.tv_nsec, t1.tv_sec, t2.tv_nsec);

The fourth argument (t1.tv_sec) is wrong. It has to be (t2.tv_sec)

> +
> +	ret = 0;
> +
> +out:
> +	close(sockfd);
> +	return ret;
> +}
> +
>  static int run_y2038(struct smokey_test *t, int argc, char *const argv[])
>  {
>  	int ret;
> @@ -1041,5 +1169,9 @@ static int run_y2038(struct smokey_test *t, int argc, char *const argv[])
>  	if (ret)
>  		return ret;
>  
> +	ret = test_sc_cobalt_recvmmsg64();
> +	if (ret)
> +		return ret;
> +
>  	return 0;
>  }


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

end of thread, other threads:[~2021-09-27 11:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-13  1:46 [PATCH v3 3/3] y2038: testsuite/smokey/y2038: testcase for recvmmsg64 Song Chen
2021-09-27 11:04 ` Bezdeka, Florian

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.