• 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 <sys/wait.h>
19 #include <unistd.h>
20 #include "functionalext.h"
21 
22 /**
23  * @tc.name      : forkpty_0100
24  * @tc.desc      : Each parameter is valid and can open a pair of pseudo-terminals for a new
25  *                 session and create a processing process.
26  * @tc.level     : Level 0
27  */
forkpty_0100(void)28 void forkpty_0100(void)
29 {
30     int master;
31     pid_t pid = forkpty(&master, NULL, NULL, NULL);
32     char *sign_r = "1";
33     char *sign_f = "0";
34     char list1[2];
35     char list2[2];
36     FILE *fp;
37     if (pid < 0) {
38         t_error("%s error in fork!", __func__);
39     } else if (pid == 0) {
40         fp = fopen("test1.txt", "w+");
41         fwrite(sign_r, sizeof(char), strlen(sign_r), fp);
42         fclose(fp);
43     } else {
44         fp = fopen("test2.txt", "w+");
45         fwrite(sign_r, sizeof(char), strlen(sign_r), fp);
46         fclose(fp);
47     }
48     sleep(1);
49     FILE *fp1 = fopen("test1.txt", "r");
50     FILE *fp2 = fopen("test2.txt", "r");
51     fread(list1, sizeof(list1), 1, fp1);
52     fread(list2, sizeof(list2), 1, fp2);
53     EXPECT_EQ("forkpty_0100", list1[0], '1');
54     EXPECT_EQ("forkpty_0100", list2[0], '1');
55     fclose(fp1);
56     fclose(fp2);
57     remove("test1.txt");
58     remove("test2.txt");
59 }
60 
main(int argc,char * argv[])61 int main(int argc, char *argv[])
62 {
63     forkpty_0100();
64     return t_status;
65 }