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 #define TEST_AT_FDCWD -100
22
23 /**
24 * @tc.name : mkfifoat_0100
25 * @tc.desc : Verify mkfifoat process success. Create named pipe with correct parameters.
26 * The pathname given in pathname is absolute.
27 * @tc.level : Level 0
28 */
mkfifoat_0100(void)29 void mkfifoat_0100(void)
30 {
31 struct stat sb;
32 const char *path = "/data/mkfifoat_0100";
33 int ret = mkfifoat(-1, path, S_IFIFO | TEST_FIFO_MODE);
34 EXPECT_EQ("mkfifoat_0100", ret, 0);
35 ret = stat(path, &sb);
36 EXPECT_EQ("mkfifoat_0100", ret, 0);
37 EXPECT_TRUE("mkfifoat_0100", S_ISFIFO(sb.st_mode));
38 unlink(path);
39 }
40
41 /**
42 * @tc.name : mkfifoat_0200
43 * @tc.desc : Verify mkfifoat process success. Create named pipe with correct parameters.
44 * The pathname given in pathname is relative.
45 * @tc.level : Level 0
46 */
mkfifoat_0200(void)47 void mkfifoat_0200(void)
48 {
49 struct stat sb;
50 const char *path = "mkfifoat_0200";
51 int ret = mkfifoat(TEST_AT_FDCWD, path, S_IFIFO | TEST_FIFO_MODE);
52 EXPECT_EQ("mkfifoat_0200", ret, 0);
53 ret = stat(path, &sb);
54 EXPECT_EQ("mkfifoat_0200", ret, 0);
55 EXPECT_TRUE("mkfifoat_0200", S_ISFIFO(sb.st_mode));
56 unlink(path);
57 }
58
59 /**
60 * @tc.name : mkfifoat_0300
61 * @tc.desc : Verify mkfifoat process fail. Create named pipe with exception argument.
62 * @tc.level : Level 2
63 */
mkfifoat_0300(void)64 void mkfifoat_0300(void)
65 {
66 int ret = mkfifoat(-1, "mkfifoat_0300", S_IFIFO | TEST_FIFO_MODE);
67 EXPECT_EQ("mkfifoat_0300", ret, -1);
68 }
69
main(void)70 int main(void)
71 {
72 mkfifoat_0100();
73 mkfifoat_0200();
74 mkfifoat_0300();
75 return t_status;
76 }