2 * Copyright (C) 2015 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <gtest/gtest.h>
21 #include "TemporaryFile.h"
23 TEST(sys_uio, readv_writev) {
26 char buf1[] = "hello";
27 char buf2[] = "world";
28 iovec ios[] = { { buf1, 5 }, { buf2, 5 } };
30 ASSERT_EQ(10, writev(tf.fd, ios, 2));
32 ASSERT_EQ(0, lseek(tf.fd, 0, SEEK_SET));
34 memset(buf1, '1', sizeof(buf1));
35 memset(buf2, '2', sizeof(buf2));
37 ASSERT_EQ(10, readv(tf.fd, ios, 2));
38 buf1[5] = buf2[5] = '\0';
39 ASSERT_STREQ("hello", buf1);
40 ASSERT_STREQ("world", buf2);
43 template <typename ReadFn, typename WriteFn>
44 void TestPreadVPwriteV(ReadFn read_fn, WriteFn write_fn) {
48 iovec ios[] = { { buf, 5 } };
50 ASSERT_EQ(5, write_fn(tf.fd, ios, 1, 5));
51 ASSERT_EQ(0, lseek(tf.fd, 0, SEEK_CUR));
54 ASSERT_EQ(5, write_fn(tf.fd, ios, 1, 0));
55 ASSERT_EQ(0, lseek(tf.fd, 0, SEEK_CUR));
57 ASSERT_EQ(5, read_fn(tf.fd, ios, 1, 5));
58 ASSERT_STREQ("world", buf);
59 ASSERT_EQ(5, read_fn(tf.fd, ios, 1, 0));
60 ASSERT_STREQ("hello", buf);
63 TEST(sys_uio, preadv_pwritev) {
64 TestPreadVPwriteV(preadv, pwritev);
67 TEST(sys_uio, preadv64_pwritev64) {
68 TestPreadVPwriteV(preadv64, pwritev64);
71 TEST(sys_uio, process_vm_readv) {
72 ASSERT_EQ(0, process_vm_readv(0, nullptr, 0, nullptr, 0, 0));
75 TEST(sys_uio, process_vm_writev) {
76 ASSERT_EQ(0, process_vm_writev(0, nullptr, 0, nullptr, 0, 0));