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 "multithread_constructor.h"
17
18 #include <pthread.h>
19 #include <stdio.h>
20 #include <unistd.h>
21 #include "stdio.h"
22 #include "stdlib.h"
23
24 const static int ARGUMENT_LIMIT = 2;
25 const static unsigned int SLEEP_TIMEOUT = 360000;
26
CreateThread(int * argv)27 void CreateThread(int *argv)
28 {
29 int threadID = *argv;
30 printf("create MultiThread %d\n", threadID);
31 TestFunc1();
32 return;
33 }
34
MultiThreadConstructor(const int threadNum)35 NOINLINE int MultiThreadConstructor(const int threadNum)
36 {
37 pthread_t t[threadNum];
38 int threadID[threadNum];
39
40 for (int i = 0; i < threadNum; ++i) {
41 threadID[i] = i;
42 pthread_create(&t[i], NULL, (void *(*)(void *))CreateThread, &threadID[i]);
43 pthread_detach(t[i]);
44 }
45
46 while (1) {
47 continue;
48 }
49
50 return 0;
51 }
52
TestFunc70(void)53 NOINLINE int TestFunc70(void)
54 {
55 sleep(SLEEP_TIMEOUT);
56 return 0;
57 }
58
59 #ifndef UNITTEST
main(int argc,char * argv[])60 int main(int argc, char* argv[])
61 {
62 if (argc != ARGUMENT_LIMIT) {
63 printf("invalid input argument.\n");
64 return 0;
65 }
66 MultiThreadConstructor(atoi(argv[1]));
67 return 0;
68 }
69 #endif
70
71 // auto gen function
72 GEN_TEST_FUNCTION(0, 1)
73 GEN_TEST_FUNCTION(1, 2)
74 GEN_TEST_FUNCTION(2, 3)
75 GEN_TEST_FUNCTION(3, 4)
76 GEN_TEST_FUNCTION(4, 5)
77 GEN_TEST_FUNCTION(5, 6)
78 GEN_TEST_FUNCTION(6, 7)
79 GEN_TEST_FUNCTION(7, 8)
80 GEN_TEST_FUNCTION(8, 9)
81 GEN_TEST_FUNCTION(9, 10)
82
83 GEN_TEST_FUNCTION(10, 11)
84 GEN_TEST_FUNCTION(11, 12)
85 GEN_TEST_FUNCTION(12, 13)
86 GEN_TEST_FUNCTION(13, 14)
87 GEN_TEST_FUNCTION(14, 15)
88 GEN_TEST_FUNCTION(15, 16)
89 GEN_TEST_FUNCTION(16, 17)
90 GEN_TEST_FUNCTION(17, 18)
91 GEN_TEST_FUNCTION(18, 19)
92 GEN_TEST_FUNCTION(19, 20)
93
94 GEN_TEST_FUNCTION(20, 21)
95 GEN_TEST_FUNCTION(21, 22)
96 GEN_TEST_FUNCTION(22, 23)
97 GEN_TEST_FUNCTION(23, 24)
98 GEN_TEST_FUNCTION(24, 25)
99 GEN_TEST_FUNCTION(25, 26)
100 GEN_TEST_FUNCTION(26, 27)
101 GEN_TEST_FUNCTION(27, 28)
102 GEN_TEST_FUNCTION(28, 29)
103 GEN_TEST_FUNCTION(29, 30)
104
105 GEN_TEST_FUNCTION(30, 31)
106 GEN_TEST_FUNCTION(31, 32)
107 GEN_TEST_FUNCTION(32, 33)
108 GEN_TEST_FUNCTION(33, 34)
109 GEN_TEST_FUNCTION(34, 35)
110 GEN_TEST_FUNCTION(35, 36)
111 GEN_TEST_FUNCTION(36, 37)
112 GEN_TEST_FUNCTION(37, 38)
113 GEN_TEST_FUNCTION(38, 39)
114 GEN_TEST_FUNCTION(39, 40)
115
116 GEN_TEST_FUNCTION(40, 41)
117 GEN_TEST_FUNCTION(41, 42)
118 GEN_TEST_FUNCTION(42, 43)
119 GEN_TEST_FUNCTION(43, 44)
120 GEN_TEST_FUNCTION(44, 45)
121 GEN_TEST_FUNCTION(45, 46)
122 GEN_TEST_FUNCTION(46, 47)
123 GEN_TEST_FUNCTION(47, 48)
124 GEN_TEST_FUNCTION(48, 49)
125 GEN_TEST_FUNCTION(49, 50)
126
127 GEN_TEST_FUNCTION(50, 51)
128 GEN_TEST_FUNCTION(51, 52)
129 GEN_TEST_FUNCTION(52, 53)
130 GEN_TEST_FUNCTION(53, 54)
131 GEN_TEST_FUNCTION(54, 55)
132 GEN_TEST_FUNCTION(55, 56)
133 GEN_TEST_FUNCTION(56, 57)
134 GEN_TEST_FUNCTION(57, 58)
135 GEN_TEST_FUNCTION(58, 59)
136 GEN_TEST_FUNCTION(59, 60)
137
138 GEN_TEST_FUNCTION(60, 61)
139 GEN_TEST_FUNCTION(61, 62)
140 GEN_TEST_FUNCTION(62, 63)
141 GEN_TEST_FUNCTION(63, 64)
142 GEN_TEST_FUNCTION(64, 65)
143 GEN_TEST_FUNCTION(65, 66)
144 GEN_TEST_FUNCTION(66, 67)
145 GEN_TEST_FUNCTION(67, 68)
146 GEN_TEST_FUNCTION(68, 69)
147 GEN_TEST_FUNCTION(69, 70)
148