1 // SPDX-License-Identifier: GPL-2.0-or-later
2
3 /*\
4 * Tests sendmmsg() failures:
5 *
6 * - EBADF Bad socket file descriptor
7 * - EFAULT Bad message vector address
8 */
9
10 #define _GNU_SOURCE
11 #include "sendmmsg.h"
12
13 #define VLEN 1
14
15 static int send_sockfd;
16 static struct mmsghdr *snd_msg;
17
18 static void *bad_addr;
19 static int bad_fd = -1;
20
21 struct test_case {
22 const char *desc;
23 int *fd;
24 int exp_errno;
25 struct mmsghdr **msg_vec;
26 };
27
28 static struct test_case tcase[] = {
29 {
30 .desc = "bad file descriptor",
31 .fd = &bad_fd,
32 .msg_vec = &snd_msg,
33 .exp_errno = EBADF,
34 },
35 {
36 .desc = "invalid msgvec address",
37 .fd = &send_sockfd,
38 .msg_vec = (void*)&bad_addr,
39 .exp_errno = EFAULT,
40 },
41 };
42
do_test(unsigned int i)43 static void do_test(unsigned int i)
44 {
45 struct time64_variants *tv = &variants[tst_variant];
46 struct test_case *tc = &tcase[i];
47
48 TST_EXP_FAIL(tv->sendmmsg(*tc->fd, *tc->msg_vec, VLEN, 0),
49 tc->exp_errno, "sendmmsg() %s", tc->desc);
50 }
51
setup(void)52 static void setup(void)
53 {
54 send_sockfd = SAFE_SOCKET(AF_INET, SOCK_DGRAM, 0);
55
56 tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
57 }
58
cleanup(void)59 static void cleanup(void)
60 {
61 if (send_sockfd > 0)
62 SAFE_CLOSE(send_sockfd);
63 }
64
65 static struct tst_test test = {
66 .test = do_test,
67 .tcnt = ARRAY_SIZE(tcase),
68 .setup = setup,
69 .cleanup = cleanup,
70 .test_variants = ARRAY_SIZE(variants),
71 .bufs = (struct tst_buffers []) {
72 {&snd_msg, .size = VLEN * sizeof(*snd_msg)},
73 {},
74 }
75 };
76