1 /*
2 * Check effectiveness of umovestr memory caching.
3 *
4 * Copyright (c) 2019-2021 Dmitry V. Levin <ldv@strace.io>
5 * All rights reserved.
6 *
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
10 #include "tests.h"
11
12 #include <stdio.h>
13 #include <string.h>
14 #include <unistd.h>
15 #include <sys/uio.h>
16
17 int
18 main(void)
19 {
20 char *const buf = tail_alloc(DEFAULT_STRLEN);
21 fill_memory_ex(buf, DEFAULT_STRLEN, 'a', 'z' - 'a' + 1);
22
23 struct iovec *const io = tail_alloc(sizeof(*io) * DEFAULT_STRLEN);
24 for (unsigned int i = 0; i < DEFAULT_STRLEN; ++i) {
25 io[i].iov_base = buf + DEFAULT_STRLEN - i;
26 io[i].iov_len = i;
27 }
28
29 tprintf("%s", "");
30
31 int rc = writev(-1, io, DEFAULT_STRLEN);
32 const char *errstr = sprintrc(rc);
33
34 tprintf("writev(-1, [");
35 for (unsigned int i = 0; i < DEFAULT_STRLEN; ++i) {
36 if (i)
37 tprintf(", ");
38 tprintf("{iov_base=\"%.*s\", iov_len=%u}",
39 (int) io[i].iov_len,
40 (char *) io[i].iov_base,
41 (unsigned int) io[i].iov_len);
42 }
43 tprintf("], %u) = %s\n", DEFAULT_STRLEN, errstr);
44
45 tprintf("+++ exited with 0 +++\n");
46 return 0;
47 }