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