• 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 <pty.h>
17 #include <stdlib.h>
18 #include <unistd.h>
19 #include <fcntl.h>
20 #include "functionalext.h"
21 
22 #define PTMPATH "/dev/ptmx"
23 
24 /**
25  * @tc.name      : ptsname_0100
26  * @tc.desc      : Open the ptm file to establish a pseudo terminal, and judge
27  *                 whether the function successfully obtains the terminal name
28  * @tc.level     : Level 0
29  */
ptsname_0100(void)30 void ptsname_0100(void)
31 {
32     char *mastername = NULL;
33 
34     int masterfd = open(PTMPATH, O_RDONLY);
35     if (masterfd == -1) {
36         perror("open failed");
37         exit(EXIT_FAILURE);
38     }
39     mastername = ptsname(masterfd);
40     EXPECT_PTRNE("ptsname_0100", mastername, NULL);
41 
42     close(masterfd);
43 }
44 
45 /**
46  * @tc.name      : ptsname_0200
47  * @tc.desc      : Pass in a non-existing terminal descriptor to determine whether the function returns NULL
48  * @tc.level     : Level 2
49  */
ptsname_0200(void)50 void ptsname_0200(void)
51 {
52     int aslave = -1;
53     char *aslavename = NULL;
54 
55     aslavename = ptsname(aslave);
56     EXPECT_PTREQ("ptsname_0200", aslavename, NULL);
57 }
58 
main(void)59 int main(void)
60 {
61     ptsname_0100();
62     ptsname_0200();
63     return t_status;
64 }