(root)/
strace-6.5/
tests-m32/
umovestr_cached_adjacent.c
       1  /*
       2   * Check effectiveness of umovestr memory caching.
       3   *
       4   * Copyright (c) 2019-2020 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  	const size_t size = get_page_size() + (DEFAULT_STRLEN - 1);
      21  	char *const buf = tail_alloc(size);
      22  	fill_memory_ex(buf, DEFAULT_STRLEN * 2, 'a', 'z' - 'a' + 1);
      23  
      24  	struct iovec *const io = tail_alloc(sizeof(*io) * DEFAULT_STRLEN);
      25  	for (unsigned int i = 0; i < DEFAULT_STRLEN; ++i) {
      26  		io[i].iov_base = buf + i;
      27  		io[i].iov_len = DEFAULT_STRLEN;
      28  	}
      29  
      30  	tprintf("%s", "");
      31  
      32  	int rc = writev(-1, io, DEFAULT_STRLEN);
      33  	const char *errstr = sprintrc(rc);
      34  
      35  	tprintf("writev(-1, [");
      36  	for (unsigned int i = 0; i < DEFAULT_STRLEN; ++i) {
      37  		if (i)
      38  			tprintf(", ");
      39  		tprintf("{iov_base=\"%.*s\", iov_len=%u}",
      40  			(int) io[i].iov_len,
      41  			(char *) io[i].iov_base,
      42  			(unsigned int) io[i].iov_len);
      43  	}
      44  	tprintf("], %u) = %s\n", DEFAULT_STRLEN, errstr);
      45  
      46  	tprintf("+++ exited with 0 +++\n");
      47  	return 0;
      48  }