y2038: testsuite/smokey/y2038: testcase for recvmmsg64
PATCH v3 3/3 y2038: testsuite/smokey/y2038: testcase for recvmmsg64
Extending the test suite for recvmmsg64 test.
---
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(+)
testsuite/smokey/y2038/syscall-tests.c +132 -0
@@ -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 ; }
Signature · 1 line
2.7.4
Hi Song,
it took some time... I'm just back from vacation.
Quoted 46 lines · Song Chen
Extending the test suite for recvmmsg64 test.
Signed-off-by Song Chen <[email protected]>---
v2:
1, rename variables
2, remove unnecessary branches
3, callsmokey_check_errno--- testsuite/smokey/y2038/syscall-tests.c | 132 +++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+)testsuite/smokey/y2038/syscall-tests.c +18
-0@@ -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 ,
testsuite/smokey/y2038/syscall-tests.c static int test_sc_cobalt_event_wait64(void) · line 1019
Quoted 10 lines
testsuite/smokey/y2038/syscall-tests.c +10
-0+ .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.
Quoted 55 lines
testsuite/smokey/y2038/syscall-tests.c +55
-0+ +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; + }
testsuite/smokey/y2038/syscall-tests.c static int test_sc_cobalt_event_wait64(void) · line 1084
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; + }
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)
Quoted 8 lines
testsuite/smokey/y2038/syscall-tests.c +8
-0+ + 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;
testsuite/smokey/y2038/syscall-tests.c static int test_sc_cobalt_event_wait64(void) · line 1102
Quoted 10 lines
testsuite/smokey/y2038/syscall-tests.c +10
-0+ } + + 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.
testsuite/smokey/y2038/syscall-tests.c static int test_sc_cobalt_event_wait64(void) · line 1111
Quoted 9 lines
testsuite/smokey/y2038/syscall-tests.c +9
-0+ + 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)
Quoted 21 lines
testsuite/smokey/y2038/syscall-tests.c +12
-0+ + 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 ; }