Elliott Hughes | 1d18e9c | 2014-02-18 15:48:56 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 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 |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 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. |
| 15 | */ |
| 16 | |
| 17 | #include <gtest/gtest.h> |
| 18 | |
| 19 | #include <sys/vfs.h> |
| 20 | |
| 21 | #include <sys/types.h> |
| 22 | #include <sys/stat.h> |
| 23 | #include <fcntl.h> |
| 24 | |
| 25 | #include <string> |
| 26 | |
| 27 | template <typename StatFsT> void Check(StatFsT& sb) { |
| 28 | EXPECT_EQ(4096, static_cast<int>(sb.f_bsize)); |
| 29 | EXPECT_EQ(0U, sb.f_bfree); |
| 30 | EXPECT_EQ(0U, sb.f_ffree); |
| 31 | EXPECT_EQ(0, sb.f_fsid.__val[0]); |
| 32 | EXPECT_EQ(0, sb.f_fsid.__val[1]); |
| 33 | EXPECT_EQ(255, static_cast<int>(sb.f_namelen)); |
Elliott Hughes | fa495d5 | 2015-03-18 15:46:48 -0700 | [diff] [blame^] | 34 | |
| 35 | // The kernel sets a private bit to indicate that f_flags is valid. |
| 36 | // This flag is not supposed to be exposed to libc clients. |
| 37 | static const uint32_t ST_VALID = 0x0020; |
| 38 | EXPECT_TRUE((sb.f_flags & ST_VALID) == 0) << sb.f_flags; |
Elliott Hughes | 1d18e9c | 2014-02-18 15:48:56 -0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | TEST(sys_vfs, statfs) { |
| 42 | struct statfs sb; |
| 43 | ASSERT_EQ(0, statfs("/proc", &sb)); |
| 44 | Check(sb); |
| 45 | } |
| 46 | |
| 47 | TEST(sys_vfs, statfs64) { |
| 48 | struct statfs64 sb; |
| 49 | ASSERT_EQ(0, statfs64("/proc", &sb)); |
| 50 | Check(sb); |
| 51 | } |
| 52 | |
| 53 | TEST(sys_vfs, fstatfs) { |
| 54 | struct statfs sb; |
| 55 | int fd = open("/proc", O_RDONLY); |
| 56 | ASSERT_EQ(0, fstatfs(fd, &sb)); |
| 57 | close(fd); |
| 58 | Check(sb); |
| 59 | } |
Elliott Hughes | fa495d5 | 2015-03-18 15:46:48 -0700 | [diff] [blame^] | 60 | |
Elliott Hughes | 1d18e9c | 2014-02-18 15:48:56 -0800 | [diff] [blame] | 61 | TEST(sys_vfs, fstatfs64) { |
| 62 | struct statfs64 sb; |
| 63 | int fd = open("/proc", O_RDONLY); |
| 64 | ASSERT_EQ(0, fstatfs64(fd, &sb)); |
| 65 | close(fd); |
| 66 | Check(sb); |
| 67 | } |