vgdb: Handle EAGAIN in read_buf
[valgrind.git] / none / tests / process_vm_readv_writev.c
blob63b58d31af1a7a6e7dade2f9f2c57415876c384a
1 #define _GNU_SOURCE 1
3 #include <config.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <unistd.h>
8 #include <sys/types.h>
9 #include <sys/uio.h>
11 static int status = EXIT_SUCCESS;
13 #ifdef HAVE_PROCESS_VM_READV
15 static void test_process_vm_readv()
17 char lbuf[] = "123456";
18 char rbuf[] = "ABCDEF";
20 struct iovec lvec[2];
21 struct iovec rvec[2];
23 lvec[0].iov_base = lbuf + 1;
24 lvec[0].iov_len = 1;
25 lvec[1].iov_base = lbuf + 3;
26 lvec[1].iov_len = 2;
28 rvec[0].iov_base = rbuf + 1;
29 rvec[0].iov_len = 2;
30 rvec[1].iov_base = rbuf + 4;
31 rvec[1].iov_len = 1;
33 if (process_vm_readv(getpid(),
34 lvec, 2,
35 rvec, 2,
36 0 ) < 0 ) {
37 perror("process_vm_readv");
38 status = EXIT_FAILURE;
41 if (strcmp(lbuf, "1B3CE6") != 0) {
42 fprintf(stderr, "Expected: \"1B3CE6\"; Got: \"%s\"\n", lbuf);
43 status = EXIT_FAILURE;
47 #endif /* defined( HAVE_PROCESS_VM_READV ) */
49 #ifdef HAVE_PROCESS_VM_WRITEV
51 static void test_process_vm_writev()
53 char lbuf[] = "123456";
54 char rbuf[] = "ABCDEF";
56 struct iovec lvec[2];
57 struct iovec rvec[2];
59 lvec[0].iov_base = lbuf + 1;
60 lvec[0].iov_len = 1;
61 lvec[1].iov_base = lbuf + 3;
62 lvec[1].iov_len = 2;
64 rvec[0].iov_base = rbuf + 1;
65 rvec[0].iov_len = 2;
66 rvec[1].iov_base = rbuf + 4;
67 rvec[1].iov_len = 1;
69 if (process_vm_writev(getpid(),
70 lvec, 2,
71 rvec, 2,
72 0 ) < 0 ) {
73 perror("process_vm_writev");
74 status = EXIT_FAILURE;
77 if (strcmp(rbuf, "A24D5F") != 0) {
78 fprintf(stderr, "Expected: \"A24D5F\"; Got: \"%s\"\n", rbuf);
79 status = EXIT_FAILURE;
83 #endif /* defined( HAVE_PROCESS_VM_WRITEV ) */
85 int main(int argc, char *argv[])
87 #ifdef HAVE_PROCESS_VM_READV
88 test_process_vm_readv();
89 #endif
90 #ifdef HAVE_PROCESS_VM_WRITEV
91 test_process_vm_writev();
92 #endif
93 return status;