1 /*
2 * Copyright (C) 2013 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/statvfs.h>
20
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <fcntl.h>
24
TEST(statvfs,statvfs)25 TEST(statvfs, statvfs) {
26 struct statvfs sb;
27 memset(&sb, 0, sizeof(sb));
28
29 ASSERT_EQ(0, statvfs("/", &sb));
30 #if __BIONIC__
31 ASSERT_EQ(0U, sb.f_bfree);
32 ASSERT_EQ(0U, sb.f_ffree);
33 ASSERT_EQ(0U, sb.f_fsid);
34 ASSERT_TRUE((sb.f_flag & ST_RDONLY) != 0);
35 #endif
36
37 #if __BIONIC__
38 ASSERT_EQ(0, statvfs("/data/local/tmp", &sb));
39 ASSERT_NE(0U, sb.f_bfree);
40 ASSERT_NE(0U, sb.f_ffree);
41 ASSERT_NE(0U, sb.f_fsid);
42 ASSERT_FALSE((sb.f_flag & ST_RDONLY) != 0);
43 ASSERT_TRUE((sb.f_flag & ST_NOSUID) != 0);
44 #endif
45 }
46
TEST(statvfs,fstatvfs)47 TEST(statvfs, fstatvfs) {
48 struct statvfs sb;
49 memset(&sb, 0, sizeof(sb));
50
51 int fd = open("/", O_RDONLY);
52 ASSERT_EQ(0, fstatvfs(fd, &sb));
53 close(fd);
54 #if __BIONIC__
55 ASSERT_EQ(0U, sb.f_bfree);
56 ASSERT_EQ(0U, sb.f_ffree);
57 ASSERT_EQ(0U, sb.f_fsid);
58 ASSERT_TRUE((sb.f_flag & ST_RDONLY) != 0);
59 #endif
60
61 #if __BIONIC__
62 fd = open("/data/local/tmp", O_RDONLY);
63 ASSERT_EQ(0, fstatvfs(fd, &sb));
64 close(fd);
65 ASSERT_NE(0U, sb.f_bfree);
66 ASSERT_NE(0U, sb.f_ffree);
67 ASSERT_NE(0U, sb.f_fsid);
68 ASSERT_FALSE((sb.f_flag & ST_RDONLY) != 0);
69 ASSERT_TRUE((sb.f_flag & ST_NOSUID) != 0);
70 #endif
71 }
72