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 <stdlib.h>
18 #include <unistd.h>
19 #include "functionalext.h"
20
21 /**
22 * @tc.name : fork_0100
23 * @tc.desc : The function call is successful and the process can be created
24 * @tc.level : Level 0
25 */
fork_0100()26 void fork_0100()
27 {
28 pid_t fpid;
29 int count = 0;
30 fpid = fork();
31 char *sign_r = "1";
32 char *sign_f = "0";
33 char list1[2];
34 char list2[2];
35 FILE *fp;
36 if (fpid < 0) {
37 t_error("%s error in fork!", __func__);
38 } else if (fpid == 0) {
39 fp = fopen("test1.txt", "w+");
40 fwrite(sign_r, sizeof(char), strlen(sign_r), fp);
41 fclose(fp);
42 } else {
43 fp = fopen("test2.txt", "w+");
44 fwrite(sign_r, sizeof(char), strlen(sign_r), fp);
45 fclose(fp);
46 }
47 sleep(1);
48 FILE *fp1 = fopen("test1.txt", "r");
49 FILE *fp2 = fopen("test2.txt", "r");
50 fread(list1, sizeof(list1), 1, fp1);
51 fread(list2, sizeof(list2), 1, fp2);
52 EXPECT_EQ("fork_0100", list1[0], '1');
53 EXPECT_EQ("fork_0100", list2[0], '1');
54
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 fork_0100();
64 return t_status;
65 }