• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *   http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <errno.h>
17 #include <stdlib.h>
18 #include <sys/uio.h>
19 #include "functionalext.h"
20 
21 #define __VALUE_BUFFER_SIZE__ 256
22 #define __VALUE_DATA_SIZE__ 2
23 
24 /**
25  * @tc.name      : process_vm_writev_0100
26  * @tc.desc      : Single data inter-process data transfer
27  * @tc.level     : Level 0
28  */
process_vm_writev_0100(void)29 void process_vm_writev_0100(void)
30 {
31     char src[__VALUE_BUFFER_SIZE__] = "This is process_vm_writev_0100.";
32     char dst[__VALUE_BUFFER_SIZE__] = "";
33     struct iovec local = {.iov_base = dst, .iov_len = sizeof(dst)};
34     struct iovec remote = {.iov_base = src, .iov_len = sizeof(src)};
35 
36     ssize_t rev = process_vm_readv(getpid(), &local, 1, &remote, 1, 0);
37     EXPECT_EQ("process_vm_writev_0100", rev, sizeof(dst));
38     EXPECT_STREQ("process_vm_writev_0100", dst, src);
39 }
40 
41 /**
42  * @tc.name      : process_vm_writev_0200
43  * @tc.desc      : Data transfer between multiple data processes
44  * @tc.level     : Level 0
45  */
process_vm_writev_0200(void)46 void process_vm_writev_0200(void)
47 {
48     char src1[__VALUE_BUFFER_SIZE__] = "This is process_vm_writev_0200_1.";
49     char src2[__VALUE_BUFFER_SIZE__] = "This is process_vm_writev_0200_2.";
50     char dst1[__VALUE_BUFFER_SIZE__] = "";
51     char dst2[__VALUE_BUFFER_SIZE__] = "";
52     struct iovec local[__VALUE_DATA_SIZE__] = {
53         {.iov_base = dst1, .iov_len = sizeof(dst1)},
54         {.iov_base = dst2, .iov_len = sizeof(dst2)},
55     };
56     struct iovec remote[__VALUE_DATA_SIZE__] = {
57         {.iov_base = src1, .iov_len = sizeof(src1)},
58         {.iov_base = src2, .iov_len = sizeof(src2)},
59     };
60 
61     ssize_t rev = process_vm_readv(getpid(), local, 2, remote, 2, 0);
62     EXPECT_EQ("process_vm_writev_0200", rev, sizeof(dst1) + sizeof(dst2));
63     int i;
64     for (i = 0; i < __VALUE_DATA_SIZE__; i++) {
65         EXPECT_STREQ("process_vm_writev_0200", local[i].iov_base, remote[i].iov_base);
66     }
67 }
68 
69 /**
70  * @tc.name      : process_vm_writev_0300
71  * @tc.desc      : Provide the correct template, create a temporary file
72  * @tc.level     : Level 2
73  */
process_vm_writev_0300(void)74 void process_vm_writev_0300(void)
75 {
76     char src[__VALUE_BUFFER_SIZE__] = "This is process_vm_writev_0300.";
77     struct iovec local = {
78         .iov_base = NULL,
79         .iov_len = 0,
80     };
81     struct iovec remote = {.iov_base = src, .iov_len = sizeof(src)};
82 
83     ssize_t rev = process_vm_readv(getpid(), &local, 1, &remote, 1, 0);
84     EXPECT_EQ("process_vm_writev_0300", rev, 0);
85 }
86 
87 /**
88  * @tc.name      : process_vm_readv_0100
89  * @tc.desc      : Transfers data from the remote process to the local process
90  * @tc.level     : Level 0
91  */
process_vm_readv_0100(void)92 void process_vm_readv_0100(void)
93 {
94     char src[__VALUE_BUFFER_SIZE__] = "This is process_vm_readv_0100.";
95     char dst[__VALUE_BUFFER_SIZE__] = "";
96     struct iovec remote, local;
97     remote.iov_base = src;
98     remote.iov_len = __VALUE_BUFFER_SIZE__;
99 
100     local.iov_base = dst;
101     local.iov_len = __VALUE_BUFFER_SIZE__;
102 
103     int ret = process_vm_readv(getpid(), &local, 1, &remote, 1, 0);
104     EXPECT_EQ("process_vm_readv_0100", ret, sizeof(src));
105     EXPECT_STREQ("process_vm_readv_0100", dst, src);
106 }
107 
108 /**
109  * @tc.name      : process_vm_readv_0200
110  * @tc.desc      : No remote instance data specified, transfer data from remote process to local process
111  * @tc.level     : Level 2
112  */
process_vm_readv_0200(void)113 void process_vm_readv_0200(void)
114 {
115     char dst[__VALUE_BUFFER_SIZE__] = "";
116     struct iovec remote, local;
117     remote.iov_base = NULL;
118     remote.iov_len = __VALUE_BUFFER_SIZE__;
119 
120     local.iov_base = dst;
121     local.iov_len = __VALUE_BUFFER_SIZE__;
122 
123     int ret = process_vm_readv(getpid(), &local, 1, &remote, 1, 0);
124     EXPECT_EQ("process_vm_readv_0200", ret, ERREXPECT);
125     EXPECT_EQ("process_vm_readv_0200", errno, EFAULT);
126 }
127 
128 /**
129  * @tc.name      : process_vm_readv_0300
130  * @tc.desc      : No local instance data specified, transfer data from remote process to local process
131  * @tc.level     : Level 2
132  */
process_vm_readv_0300(void)133 void process_vm_readv_0300(void)
134 {
135     char src[__VALUE_BUFFER_SIZE__] = "This is process_vm_readv_0300.";
136     struct iovec remote, local;
137     remote.iov_base = src;
138     remote.iov_len = __VALUE_BUFFER_SIZE__;
139 
140     local.iov_base = NULL;
141     local.iov_len = __VALUE_BUFFER_SIZE__;
142 
143     int ret = process_vm_readv(getpid(), &local, 1, &remote, 1, 0);
144     EXPECT_EQ("process_vm_readv_0300", ret, ERREXPECT);
145     EXPECT_EQ("process_vm_readv_0300", errno, EFAULT);
146 }
147 
main(void)148 int main(void)
149 {
150     process_vm_writev_0100();
151     process_vm_writev_0200();
152     process_vm_writev_0300();
153     process_vm_readv_0100();
154     process_vm_readv_0200();
155     process_vm_readv_0300();
156     return t_status;
157 }