]> granicus.if.org Git - strace/blob - tests/vmsplice.c
c339953f010c5ceec6c6c91b30d05506e0ecdc4e
[strace] / tests / vmsplice.c
1 /*
2  * This file is part of vmsplice strace test.
3  *
4  * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
5  * Copyright (c) 2016-2017 The strace developers.
6  * All rights reserved.
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10
11 #include "tests.h"
12 #include <asm/unistd.h>
13
14 #if defined __NR_vmsplice
15
16 # include <assert.h>
17 # include <stdio.h>
18 # include <unistd.h>
19 # include <sys/uio.h>
20
21 int
22 main(void)
23 {
24         tprintf("%s", "");
25
26         int fds[2];
27         if (pipe(fds))
28                 perror_msg_and_fail("pipe");
29         assert(0 == fds[0]);
30         assert(1 == fds[1]);
31
32         static const char w0_c[] = "012";
33         const char *w0_d = hexdump_strdup(w0_c);
34         void *w0 = tail_memdup(w0_c, LENGTH_OF(w0_c));
35
36         static const char w1_c[] = "34567";
37         const char *w1_d = hexdump_strdup(w1_c);
38         void *w1 = tail_memdup(w1_c, LENGTH_OF(w1_c));
39
40         static const char w2_c[] = "89abcde";
41         const char *w2_d = hexdump_strdup(w2_c);
42         void *w2 = tail_memdup(w2_c, LENGTH_OF(w2_c));
43
44         const struct iovec iov_[] = {
45                 {
46                         .iov_base = w0,
47                         .iov_len = LENGTH_OF(w0_c)
48                 }, {
49                         .iov_base = w1,
50                         .iov_len = LENGTH_OF(w1_c)
51                 }, {
52                         .iov_base = w2,
53                         .iov_len = LENGTH_OF(w2_c)
54                 }
55         };
56         const struct iovec *iov = tail_memdup(iov_, sizeof(iov_));
57         const unsigned int len =
58                 LENGTH_OF(w0_c) + LENGTH_OF(w1_c) + LENGTH_OF(w2_c);
59
60         tprintf("vmsplice(1, [{iov_base=\"%s\", iov_len=%u}"
61                 ", {iov_base=\"%s\", iov_len=%u}"
62                 ", {iov_base=\"%s\", iov_len=%u}], %u, %s) = %u\n"
63                 " * %u bytes in buffer 0\n"
64                 " | 00000 %-49s  %-16s |\n"
65                 " * %u bytes in buffer 1\n"
66                 " | 00000 %-49s  %-16s |\n"
67                 " * %u bytes in buffer 2\n"
68                 " | 00000 %-49s  %-16s |\n",
69                 w0_c, LENGTH_OF(w0_c), w1_c, LENGTH_OF(w1_c),
70                 w2_c, LENGTH_OF(w2_c), (unsigned int) ARRAY_SIZE(iov_),
71                 "SPLICE_F_NONBLOCK", len,
72                 LENGTH_OF(w0_c), w0_d, w0_c,
73                 LENGTH_OF(w1_c), w1_d, w1_c, LENGTH_OF(w2_c), w2_d, w2_c);
74
75         const long rc = syscall(__NR_vmsplice, 1, iov, ARRAY_SIZE(iov_), 2);
76         if (rc < 0)
77                 perror_msg_and_skip("vmsplice");
78         assert(rc == (int) len);
79
80         tprintf("+++ exited with 0 +++\n");
81         return 0;
82 }
83
84 #else
85
86 SKIP_MAIN_UNDEFINED("__NR_vmsplice")
87
88 #endif