Skip to content

Commit

Permalink
syscalls: sendmmsg: Reuse struct time64_variants
Browse files Browse the repository at this point in the history
Lets reuse the common structure here.

Signed-off-by: Viresh Kumar <[email protected]>
Reviewed-by: Cyril Hrubis <[email protected]>
  • Loading branch information
vireshk authored and metan-ucw committed Sep 17, 2020
1 parent b4ae2cb commit 8ff0357
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions testcases/kernel/syscalls/sendmmsg/sendmmsg01.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <string.h>
#include <sys/types.h>

#include "time64_variants.h"
#include "tst_test.h"
#include "lapi/socket.h"
#include "tst_safe_macros.h"
Expand All @@ -24,32 +25,25 @@ static int receive_sockfd;
static struct mmsghdr *snd_msg, *rcv_msg;
static struct iovec *snd1, *snd2, *rcv1, *rcv2;

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"},
static struct time64_variants variants[] = {
{ .recvmmsg = libc_recvmmsg, .sendmmsg = libc_sendmmsg, .ts_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"},
{ .recvmmsg = sys_recvmmsg, .sendmmsg = sys_sendmmsg, .ts_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"},
{ .recvmmsg = sys_recvmmsg64, .sendmmsg = sys_sendmmsg, .ts_type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"},
#endif
};

static void run(void)
{
struct test_variants *tv = &variants[tst_variant];
struct time64_variants *tv = &variants[tst_variant];
struct tst_ts timeout;
int retval;

retval = tv->send(send_sockfd, snd_msg, VLEN, 0);
retval = tv->sendmmsg(send_sockfd, snd_msg, VLEN, 0);
if (retval < 0 || snd_msg[0].msg_len != 6 || snd_msg[1].msg_len != 6) {
tst_res(TFAIL | TERRNO, "sendmmsg() failed");
return;
Expand All @@ -58,11 +52,11 @@ static void run(void)
memset(rcv1->iov_base, 0, rcv1->iov_len);
memset(rcv2->iov_base, 0, rcv2->iov_len);

timeout.type = tv->type;
timeout.type = tv->ts_type;
tst_ts_set_sec(&timeout, 1);
tst_ts_set_nsec(&timeout, 0);

retval = tv->receive(receive_sockfd, rcv_msg, VLEN, 0, tst_ts_get(&timeout));
retval = tv->recvmmsg(receive_sockfd, rcv_msg, VLEN, 0, tst_ts_get(&timeout));

if (retval == -1) {
tst_res(TFAIL | TERRNO, "recvmmsg() failed");
Expand Down

0 comments on commit 8ff0357

Please sign in to comment.