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 <malloc.h>
17 #include <sched.h>
18 #include <signal.h>
19 #include <unistd.h>
20 #include "functionalext.h"
21
22 const int STACK_SIZE = 1024 * 8192;
23 const int SUCCESS = 0;
test(void *p)24 void *test(void *p)
25 {
26 return NULL;
27 }
28
29 /**
30 * @tc.name : clone_0100
31 * @tc.desc : Each parameter is valid, and a new thread can be created through the clone function.
32 * @tc.level : Level 0
33 */
clone_0100(void)34 void clone_0100(void)
35 {
36 void *stack = malloc(STACK_SIZE);
37 int cpid = -1;
38 cpid = clone((int (*)(void *))test, (char *)stack + STACK_SIZE, CLONE_VM | CLONE_FS | CLONE_FILES | SIGCHLD, NULL);
39 sleep(1);
40 EXPECT_NE("clone_0100", cpid, -1);
41 }
42
43 /**
44 * @tc.name : clone_0200
45 * @tc.desc : Parameter flags is 0.
46 * @tc.level : Level 2
47 */
clone_0200(void)48 void clone_0200(void)
49 {
50 void *stack = malloc(STACK_SIZE);
51 int cpid = -1;
52 cpid = clone((int (*)(void *))test, (char *)stack + STACK_SIZE, 0, NULL);
53 sleep(1);
54 EXPECT_NE("clone_0200", cpid, -1);
55 }
56
57 /**
58 * @tc.name : clone_0300
59 * @tc.desc : Parameter stack is NULL.
60 * @tc.level : Level 2
61 */
clone_0300(void)62 void clone_0300(void)
63 {
64 int cpid = -1;
65 cpid = clone((int (*)(void *))test, NULL, 0, NULL);
66 sleep(1);
67 EXPECT_NE("clone_0300", cpid, -1);
68 }
69
main(int argc, char *argv[])70 int main(int argc, char *argv[])
71 {
72 clone_0100();
73 clone_0200();
74 clone_0300();
75 return t_status;
76 }
77