• 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 <fcntl.h>
17 #include <stdio.h>
18 #include <sys/vfs.h>
19 #include "test.h"
20 
21 /**
22  * @tc.name      : fstatfs_0100
23  * @tc.desc      : Validation failed to get file status (parameter invalid file does not exist)
24  * @tc.level     : Level 0
25  */
fstatfs_0100(void)26 void fstatfs_0100(void)
27 {
28     struct statfs st;
29     int fd = open("/proc", O_RDONLY);
30     if (fd < 0) {
31         t_error("%s open failed\n", __func__);
32     }
33 
34     int result = fstatfs(fd, &st);
35     if (result != 0) {
36         t_error("%s fstatfs failed, result is %d\n", __func__, result);
37     }
38 
39     close(fd);
40 
41     if ((int)st.f_bsize != 4096) {
42         t_error("%s st.f_bsize invalid\n", __func__);
43     }
44 
45     if (st.f_bfree != 0U) {
46         t_error("%s st.f_bfree invalid\n"), __func__;
47     }
48 
49     if (st.f_ffree != 0U) {
50         t_error("%s st.f_ffree invalid\n"), __func__;
51     }
52 
53     if (st.f_fsid.__val[0] != 0) {
54         t_error("%s st.f_fsid.__val[0] invalid\n"), __func__;
55     }
56 
57     if (st.f_fsid.__val[1] != 0) {
58         t_error("%s st.f_fsid.__val[1] invalid\n"), __func__;
59     }
60 
61     if ((int)st.f_namelen != 255) {
62         t_error("%s st.f_namelen invalid\n"), __func__;
63     }
64 }
65 
66 /**
67  * @tc.name      : fstatfs_0200
68  * @tc.desc      : Validation failed to get file status (parameter invalid file does not exist)
69  * @tc.level     : Level 2
70  */
fstatfs_0200(void)71 void fstatfs_0200(void)
72 {
73     struct statfs st;
74     int result = fstatfs(-1, &st);
75     if (result != -1) {
76         t_error("%s fstatfs should be failed\n", __func__);
77     }
78 }
79 
main(int argc,char * argv[])80 int main(int argc, char *argv[])
81 {
82     fstatfs_0100();
83     fstatfs_0200();
84     return t_status;
85 }