• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <config.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <unistd.h>
6 #include <sys/types.h>
7 #include <sys/uio.h>
8 
9 static int status = EXIT_SUCCESS;
10 
11 #ifdef HAVE_PROCESS_VM_READV
12 
test_process_vm_readv()13 static void test_process_vm_readv()
14 {
15    char lbuf[] = "123456";
16    char rbuf[] = "ABCDEF";
17 
18    struct iovec lvec[2];
19    struct iovec rvec[2];
20 
21    lvec[0].iov_base = lbuf + 1;
22    lvec[0].iov_len = 1;
23    lvec[1].iov_base = lbuf + 3;
24    lvec[1].iov_len = 2;
25 
26    rvec[0].iov_base = rbuf + 1;
27    rvec[0].iov_len = 2;
28    rvec[1].iov_base = rbuf + 4;
29    rvec[1].iov_len = 1;
30 
31    if (process_vm_readv(getpid(),
32                         lvec, 2,
33                         rvec, 2,
34                         0 ) < 0 ) {
35       perror("process_vm_readv");
36       status = EXIT_FAILURE;
37    }
38 
39    if (strcmp(lbuf, "1B3CE6") != 0) {
40       fprintf(stderr, "Expected: \"1B3CE6\"; Got: \"%s\"\n", lbuf);
41       status = EXIT_FAILURE;
42    }
43 }
44 
45 #endif /* defined( HAVE_PROCESS_VM_READV ) */
46 
47 #ifdef HAVE_PROCESS_VM_WRITEV
48 
test_process_vm_writev()49 static void test_process_vm_writev()
50 {
51    char lbuf[] = "123456";
52    char rbuf[] = "ABCDEF";
53 
54    struct iovec lvec[2];
55    struct iovec rvec[2];
56 
57    lvec[0].iov_base = lbuf + 1;
58    lvec[0].iov_len = 1;
59    lvec[1].iov_base = lbuf + 3;
60    lvec[1].iov_len = 2;
61 
62    rvec[0].iov_base = rbuf + 1;
63    rvec[0].iov_len = 2;
64    rvec[1].iov_base = rbuf + 4;
65    rvec[1].iov_len = 1;
66 
67    if (process_vm_writev(getpid(),
68                          lvec, 2,
69                          rvec, 2,
70                          0 ) < 0 ) {
71       perror("process_vm_writev");
72       status = EXIT_FAILURE;
73    }
74 
75    if (strcmp(rbuf, "A24D5F") != 0) {
76       fprintf(stderr, "Expected: \"A24D5F\"; Got: \"%s\"\n", rbuf);
77       status = EXIT_FAILURE;
78    }
79 }
80 
81 #endif /* defined( HAVE_PROCESS_VM_WRITEV ) */
82 
main(int argc,char * argv[])83 int main(int argc, char *argv[])
84 {
85 #ifdef HAVE_PROCESS_VM_READV
86    test_process_vm_readv();
87 #endif
88 #ifdef HAVE_PROCESS_VM_WRITEV
89    test_process_vm_writev();
90 #endif
91    return status;
92 }
93