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