Skip to contentSkip to conversation

y2038: testsuite/smokey/y2038: testcase for recvmmsg64

PATCH Superseded Song Chen 2 participants 2 messages Sep 7, 2021

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Song Chen

author
#0 lore raw

PATCH 3/3 y2038: testsuite/smokey/y2038: testcase for recvmmsg64

Extending the test suite for recvmmsg64 test.

---
 testsuite/smokey/y2038/syscall-tests.c | 135 +++++++++++++++++++++++++++++++++
 1 file changed, 135 insertions(+)
testsuite/smokey/y2038/syscall-tests.c +135 -0
index 8afedd7..7b68021 100644
@@ -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,136 @@ 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 ts64, ts_wu;
+	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 = setsockopt(sockfd, SOL_XDDP, XDDP_LABEL, &plabel, sizeof(plabel));
+	if (ret) {
+		ret = -errno;
+		goto out;
+	}
+
+	memset(&saddr, 0, sizeof(saddr));
+	saddr.sipc_family = AF_RTIPC;
+	saddr.sipc_port = -1;
+	ret = bind(sockfd, (struct sockaddr *)&saddr, sizeof(saddr));
+	if (ret) {
+		ret = -errno;
+		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
+	 */
+	ts64.tv_sec = -1;
+	ret = XENOMAI_SYSCALL5(sc_nr, sockfd, &msg, sizeof(msg), 0, &ts64);
+	if (!smokey_assert(ret == -EINVAL)) {
+		ret = ret ? ret : -EINVAL;
+		goto out;
+	}
+
+	/*
+	 * providing a zero timeout,
+	 * should come back immediately with EWOULDBLOCK
+	 */
+	ts64.tv_sec = 0;
+	ts64.tv_nsec = 0;
+	ret = XENOMAI_SYSCALL5(sc_nr, sockfd, &msg, sizeof(msg), 0, &ts64);
+	if (!smokey_assert(ret == -EWOULDBLOCK)) {
+		ret = ret ? ret : -EINVAL;
+		goto out;
+	} else
+		ret = 0;
+
+	/*
+	 * 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;
+	}
+
+	ts64.tv_sec = 0;
+	ts64.tv_nsec = 500000;
+
+	ret = XENOMAI_SYSCALL5(sc_nr, sockfd, &msg, sizeof(msg), 0, &ts64);
+	if (!smokey_assert(ret == -ETIMEDOUT)) {
+		ret = ret ? ret : -EINVAL;
+		goto out;
+	} else
+		ret = 0;
+
+	ts64.tv_sec = ts_nat.tv_sec;
+	ts64.tv_nsec = ts_nat.tv_nsec;
+
+	ret = clock_gettime(CLOCK_REALTIME, &ts_nat);
+	if (ret) {
+		ret = ret ? ret : -EINVAL;
+		goto out;
+	}
+
+	ts_wu.tv_sec = ts_nat.tv_sec;
+	ts_wu.tv_nsec = ts_nat.tv_nsec;
+
+	if (ts_less(&ts_wu, &ts64))
+		smokey_warning("event_wait64 returned to early!\n"
+			       "Expected wakeup at: %lld sec %lld nsec\n"
+			       "Back at           : %lld sec %lld nsec\n",
+			       ts64.tv_sec, ts64.tv_nsec, ts_wu.tv_sec,
+			       ts_wu.tv_nsec);
+
+out:
+	close(sockfd);
+	return ret;
+}
+
 static int run_y2038(struct smokey_test *t, int argc, char *const argv[])
 {
 	int ret;
@@ -1041,5 +1172,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;
 }
Signature · 1 line
2.7.4
#1 lore raw

Hi Song!

Quoted 47 lines · Song Chen

Extending the test suite for recvmmsg64 test.

---
 testsuite/smokey/y2038/syscall-tests.c | 135 +++++++++++++++++++++++++++++++++
 1 file changed, 135 insertions(+)
testsuite/smokey/y2038/syscall-tests.c +25 -0
index 8afedd7..7b68021 100644
@@ -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,136 @@ 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 ts64, ts_wu;
+	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,
+	};
+

testsuite/smokey/y2038/syscall-tests.c static int test_sc_cobalt_event_wait64(void) · line 1026

Quoted 10 lines
testsuite/smokey/y2038/syscall-tests.c +10 -0
+	sockfd = socket(AF_RTIPC, SOCK_DGRAM, IPCPROTO_XDDP);
+	if (sockfd <= 0)
+		return -errno;
+
+	strcpy(plabel.label, "y2038:recvmmsg64");
+	ret = setsockopt(sockfd, SOL_XDDP, XDDP_LABEL, &plabel, sizeof(plabel));
+	if (ret) {
+		ret = -errno;
+		goto out;
+	}

Looks like smokey_check_errno() could be used for the setsockopt() call and for similar calls like bind() below and socket() above.

Quoted 41 lines
testsuite/smokey/y2038/syscall-tests.c +41 -0
+
+	memset(&saddr, 0, sizeof(saddr));
+	saddr.sipc_family = AF_RTIPC;
+	saddr.sipc_port = -1;
+	ret = bind(sockfd, (struct sockaddr *)&saddr, sizeof(saddr));
+	if (ret) {
+		ret = -errno;
+		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
+	 */
+	ts64.tv_sec = -1;
+	ret = XENOMAI_SYSCALL5(sc_nr, sockfd, &msg, sizeof(msg), 0, &ts64);
+	if (!smokey_assert(ret == -EINVAL)) {
+		ret = ret ? ret : -EINVAL;
+		goto out;
+	}
+
+	/*
+	 * providing a zero timeout,

testsuite/smokey/y2038/syscall-tests.c static int test_sc_cobalt_event_wait64(void) · line 1077

Quoted 10 lines
testsuite/smokey/y2038/syscall-tests.c +10 -0
+	 * should come back immediately with EWOULDBLOCK
+	 */
+	ts64.tv_sec = 0;
+	ts64.tv_nsec = 0;
+	ret = XENOMAI_SYSCALL5(sc_nr, sockfd, &msg, sizeof(msg), 0, &ts64);
+	if (!smokey_assert(ret == -EWOULDBLOCK)) {
+		ret = ret ? ret : -EINVAL;
+		goto out;
+	} else
+		ret = 0;

Can't we remove the else branch here (and in similar tests below)? If ret == -EWOULDBLOCK it will be overwritten below, so no need to reset it, right?

Quoted 10 lines
testsuite/smokey/y2038/syscall-tests.c +10 -0
+
+	/*
+	 * 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;
+	}

testsuite/smokey/y2038/syscall-tests.c static int test_sc_cobalt_event_wait64(void) · line 1097

Quoted 10 lines
testsuite/smokey/y2038/syscall-tests.c +10 -0
+
+	ts64.tv_sec = 0;
+	ts64.tv_nsec = 500000;
+
+	ret = XENOMAI_SYSCALL5(sc_nr, sockfd, &msg, sizeof(msg), 0, &ts64);
+	if (!smokey_assert(ret == -ETIMEDOUT)) {
+		ret = ret ? ret : -EINVAL;
+		goto out;
+	} else
+		ret = 0;

Unnecessary else branch?

Quoted 9 lines
testsuite/smokey/y2038/syscall-tests.c +9 -0
+
+	ts64.tv_sec = ts_nat.tv_sec;
+	ts64.tv_nsec = ts_nat.tv_nsec;
+
+	ret = clock_gettime(CLOCK_REALTIME, &ts_nat);
+	if (ret) {
+		ret = ret ? ret : -EINVAL;
+		goto out;
+	}

testsuite/smokey/y2038/syscall-tests.c static int test_sc_cobalt_event_wait64(void) · line 1116

Quoted 10 lines
testsuite/smokey/y2038/syscall-tests.c +10 -0
+
+	ts_wu.tv_sec = ts_nat.tv_sec;
+	ts_wu.tv_nsec = ts_nat.tv_nsec;
+
+	if (ts_less(&ts_wu, &ts64))
+		smokey_warning("event_wait64 returned to early!\n"
+			       "Expected wakeup at: %lld sec %lld nsec\n"
+			       "Back at           : %lld sec %lld nsec\n",
+			       ts64.tv_sec, ts64.tv_nsec, ts_wu.tv_sec,
+			       ts_wu.tv_nsec);

Nope, it's not event_wait64 that returned to early. Copy paste error...

I renamed ts_wu to t2 in similar tests. I forgot about the "wakeup" meaning of "wu" some time ago and decided that t1 and t2 are sufficient.

Quoted 19 lines
testsuite/smokey/y2038/syscall-tests.c +10 -0
+
+out:
+	close(sockfd);
+	return ret;
+}
+
 static int run_y2038(struct smokey_test *t, int argc, char *const argv[])
 {
 	int ret;
@@ -1041,5 +1172,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;
 }