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 <fcntl.h>
17 #include <sys/statvfs.h>
18 #include "test.h"
19
20 /**
21 * @tc.name : fstatvfs_0100
22 * @tc.desc : Returns the same information about an open file referenced by descriptor fd
23 * @tc.level : Level 0
24 */
fstatvfs_0100(void)25 void fstatvfs_0100(void)
26 {
27 struct statvfs sts;
28 int fd = open("/proc", O_RDONLY);
29 if (fd < 0) {
30 t_error("%s open failed\n", __func__);
31 }
32
33 int result = fstatvfs(fd, &sts);
34 if (result != 0) {
35 t_error("%s fstatvfs failed\n", __func__);
36 }
37
38 close(fd);
39
40 if (sts.f_bsize != 4096U) {
41 t_error("%s f_bsize invalid\n", __func__);
42 }
43 if (sts.f_bfree != 0U) {
44 t_error("%s f_bfree invalid\n", __func__);
45 }
46 if (sts.f_ffree != 0U) {
47 t_error("%s f_ffree invalid\n", __func__);
48 }
49 if (sts.f_fsid != 0U) {
50 t_error("%s f_fsid invalid\n", __func__);
51 }
52 if (sts.f_namemax != 255U) {
53 t_error("%s f_namemax invalid\n", __func__);
54 }
55 }
56
57 /**
58 * @tc.name : fstatvfs_0200
59 * @tc.desc : Test case when parameter is invalid
60 * @tc.level : Level 2
61 */
fstatvfs_0200(void)62 void fstatvfs_0200(void)
63 {
64 struct statvfs sts;
65 int result = fstatvfs(-1, &sts);
66 if (result != -1) {
67 t_error("%s fstatvfs should be failed\n", __func__);
68 }
69 }
70
main(int argc,char * argv[])71 int main(int argc, char *argv[])
72 {
73 fstatvfs_0100();
74 fstatvfs_0200();
75 return t_status;
76 }