• 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 <errno.h>
17 #include <fcntl.h>
18 #include <stdio.h>
19 #include <unistd.h>
20 #include "test.h"
21 
22 const char *path = "/data/tests/libc-test/src/syncfs.txt";
23 
24 /**
25  * @tc.name      : syncfs_0100
26  * @tc.desc      : Commit filesystem caches to disk
27  * @tc.level     : Level 0
28  */
syncfs_0100(void)29 void syncfs_0100(void)
30 {
31     errno = 0;
32     int fd = open(path, O_RDWR | O_CREAT);
33     if (fd == -1) {
34         t_error("%s open failed\n", __func__);
35         return;
36     }
37 
38     int result = syncfs(fd);
39     if (result == -1) {
40         t_error("%s syncfs failed, result is %d\n", __func__, result);
41     }
42     if (errno == EBADF) {
43         t_error("%s errno is %d\n", __func__, errno);
44     }
45     close(fd);
46     remove(path);
47 }
48 
49 /**
50  * @tc.name      : syncfs_0200
51  * @tc.desc      : Can't sync an invalid fd
52  * @tc.level     : Level 2
53  */
syncfs_0200(void)54 void syncfs_0200(void)
55 {
56     errno = 0;
57     int result = syncfs(-1);
58     if (result != -1) {
59         t_error("%s syncfs should failed, resuly is %d\n", __func__, result);
60     }
61     if (errno != EBADF) {
62         t_error("%s errno is %d\n", errno);
63     }
64 }
65 
main(int argc,char * argv[])66 int main(int argc, char *argv[])
67 {
68     syncfs_0100();
69     syncfs_0200();
70     return t_status;
71 }
72