• 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 <sys/stat.h>
18 #include "functionalext.h"
19 
20 #define TEST_FIFO_MODE 0666
21 
22 /**
23  * @tc.name      : mknodat_0100
24  * @tc.desc      : Verify mknodat process success. Create named pipe with correct parameters.
25  *                 The pathname given in pathname is absolute.
26  * @tc.level     : Level 0
27  */
mknodat_0100(void)28 void mknodat_0100(void)
29 {
30     struct stat sb;
31     const char *path = "/data/mknodat_0100";
32     int ret = mknodat(-1, path, S_IFIFO | TEST_FIFO_MODE, 0);
33     EXPECT_EQ("mknodat_0100", ret, 0);
34     ret = stat(path, &sb);
35     EXPECT_EQ("mknodat_0100", ret, 0);
36     EXPECT_TRUE("mknodat_0100", S_ISFIFO(sb.st_mode));
37     unlink(path);
38 }
39 
40 /**
41  * @tc.name      : mknodat_0200
42  * @tc.desc      : Verify mknodat process fail. Because pathname already exists.
43  * @tc.level     : Level 0
44  */
mknodat_0200(void)45 void mknodat_0200(void)
46 {
47     struct stat sb;
48     const char *path = "/data/mknodat_0200";
49     int ret = mknodat(-1, path, S_IFIFO | TEST_FIFO_MODE, 0);
50     EXPECT_EQ("mknodat_0200", ret, 0);
51     ret = stat(path, &sb);
52     EXPECT_EQ("mknodat_0200", ret, 0);
53     EXPECT_TRUE("mknodat_0200", S_ISFIFO(sb.st_mode));
54     ret = mknodat(-1, path, S_IFIFO | TEST_FIFO_MODE, 0);
55     EXPECT_EQ("mknodat_0200", ret, -1);
56     unlink(path);
57 }
58 
main(void)59 int main(void)
60 {
61     mknodat_0100();
62     mknodat_0200();
63     return t_status;
64 }