• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3  * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  * conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12  * of conditions and the following disclaimer in the documentation and/or other materials
13  * provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16  * to endorse or promote products derived from this software without specific prior written
17  * permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef IT_POSIX_PTHREAD_H
33 #define IT_POSIX_PTHREAD_H
34 
35 #include "sched.h"
36 #include "signal.h"
37 #include "semaphore.h"
38 #include "sched.h"
39 #include "osTest.h"
40 #include "pthread.h"
41 #include "pprivate.h"
42 #include "limits.h"
43 #include "unistd.h"
44 #include "mqueue.h"
45 #include "signal.h"
46 
47 #ifndef VERBOSE
48 #define VERBOSE 1
49 #endif
50 
51 /* Some routines are part of the XSI Extensions */
52 #ifndef WITHOUT_XOPEN
53 #define _XOPEN_SOURCE 600
54 #endif
55 
56 #define PTHREAD_NO_ERROR 0
57 #define PTHREAD_IS_ERROR (-1)
58 #define PTHREAD_SIGNAL_SUPPORT 0 /* 0 means that not support the signal */
59 #define PTHREAD_PRIORITY_TEST 20
60 #define PTHREAD_DEFAULT_STACK_SIZE (LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE)
61 #define PTHREAD_KEY_NUM 10
62 #define THREAD_NUM 3
63 #define PTHREAD_TIMEOUT (THREAD_NUM * 2)
64 #define PTHREAD_INTHREAD_TEST 0 /* Control going to or is already for Thread */
65 #define PTHREAD_INMAIN_TEST 1   /* Control going to or is already for Main */
66 #define INVALID_PSHARED_VALUE (-100)
67 #define NUM_OF_CONDATTR 10
68 #define RUNTIME 5
69 #define PTHREAD_THREADS_NUM 3
70 #define TCOUNT 5      // Number of single-threaded polling
71 #define COUNT_LIMIT 7 // The number of times the signal is sent
72 #define HIGH_PRIORITY 5
73 #define LOW_PRIORITY 10
74 #define PTHREAD_EXIT_VALUE ((void *)100) /* The return code of the thread when using pthread_exit(). */
75 
76 #define PTHREAD_EXISTED_NUM TASK_EXISTED_NUM
77 #define PTHREAD_EXISTED_SEM_NUM SEM_EXISTED_NUM
78 
79 /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */
80 #define _POSIX_C_SOURCE 200112L
81 
82 #define PTHREAD_MUTEX_RECURSIVE 0
83 #define PTHREAD_MUTEX_ERRORCHECK 0
84 
85 #define uart_printf_func dprintf
86 
87 #define PRIORITY_OTHER (-1)
88 #define PRIORITY_FIFO 20
89 #define PRIORITY_RR 20
90 
91 #define PTHREAD_TEST_BUG dprintf
92 
93 #define CASE(det, expl, scp, spa, sco, sta, gua, ssi, desc, res)         \
94     {                                                                    \
95         { 0 }, det, expl, scp, spa, sco, sta, gua, ssi, desc, NULL, res, \
96         {                                                                \
97             0                                                            \
98         }                                                                \
99     }
100 #define CASE_POS(det, expl, scp, spa, sco, sta, gua, ssi, desc) CASE(det, expl, scp, spa, sco, sta, gua, ssi, desc, 0)
101 #define CASE_NEG(det, expl, scp, spa, sco, sta, gua, ssi, desc) CASE(det, expl, scp, spa, sco, sta, gua, ssi, desc, 1)
102 #define CASE_UNK(det, expl, scp, spa, sco, sta, gua, ssi, desc) CASE(det, expl, scp, spa, sco, sta, gua, ssi, desc, 2)
103 
104 struct params {
105     INT32 policy;
106     INT32 priority;
107     char *policy_label;
108     INT32 status;
109 };
110 
111 typedef struct {
112     /*
113      * Object to hold the given configuration,
114      * and which will be used to create the threads
115      */
116     pthread_attr_t ta;
117 
118     /* General parameters */
119     /* 0, joinable; 1, detached */
120     INT32 detached;
121 
122     /* Scheduling parameters */
123     /*
124      * 0, sched policy is inherited;
125      * 1, sched policy from the attr param
126      */
127     INT32 explicitsched;
128     /* 0, default; 1, SCHED_FIFO; 2, SCHED_RR */
129     INT32 schedpolicy;
130     /*
131      * 0, default sched param;
132      * 1, max value for sched param;
133      * -1, min value for sched param
134      */
135     INT32 schedparam;
136     /*
137      * 0, default contension scope;
138      * 1, alternative contension scope
139      */
140     INT32 altscope;
141 
142     /* Stack parameters */
143     /* 0, system manages the stack; 1, stack is provided */
144     INT32 altstack;
145     /*
146      * 0, default guardsize;
147      * 1, guardsize is 0;
148      * 2, guard is 1 page
149      * -- this setting only affect system stacks (not user's).
150      */
151     INT32 guard;
152     /*
153      * 0, default stack size;
154      * 1, stack size specified (min value)
155      * -- ignored when stack is provided
156      */
157     INT32 altsize;
158 
159     /* Additionnal information */
160     /* object description */
161     char *descr;
162     /* Stores the stack start when an alternate stack is required */
163     void *bottom;
164     /*
165      * This thread creation is expected to:
166      * 0, succeed; 1, fail; 2, unknown
167      */
168     INT32 result;
169     /*
170      * This semaphore is used to signal the end of
171      * the detached threads execution
172      */
173     sem_t sem;
174 } ScenarIo;
175 
176 #define NSCENAR 10 // (sizeof(g_scenarii)/sizeof(g_scenarii[0]))
177 
178 extern ScenarIo g_scenarii[];
179 
180 extern _pthread_data *pthread_get_self_data(void);
181 extern _pthread_data *pthread_get_data(pthread_t id);
182 extern pthread_key_t g_key;
183 extern pthread_key_t g_pthreadKeyTest[PTHREAD_KEY_NUM];
184 extern pthread_t g_newTh;
185 extern pthread_t g_newTh2;
186 extern UINT32 g_taskMaxNum;
187 extern pthread_once_t g_onceControl;
188 extern pthread_cond_t g_pthreadCondTest1;
189 extern pthread_mutex_t g_pthreadMutexTest1;
190 extern INT32 g_startNum;
191 extern INT32 g_wakenNum;
192 extern INT32 g_t1Start;
193 extern INT32 g_signaled;
194 extern INT32 g_wokenUp;
195 extern INT32 g_lowDone;
196 extern INT32 g_pthreadSem;
197 extern INT32 g_pthreadScopeValue;
198 extern INT32 g_pthreadSchedInherit;
199 extern INT32 g_pthreadSchedPolicy;
200 
201 extern pthread_t g_pthreadTestTh;
202 
203 #ifdef LOSCFG_AARCH64
204 #define PTHREAD_STACK_MIN_TEST (PTHREAD_STACK_MIN * 3)
205 #else
206 #define PTHREAD_STACK_MIN_TEST PTHREAD_STACK_MIN
207 #endif
208 
209 static pthread_t g_testNewTh;
210 
211 static struct testdata {
212     pthread_mutex_t mutex;
213     pthread_cond_t cond;
214 } g_td;
215 
216 extern unsigned int sleep(unsigned int seconds);
217 extern unsigned int alarm(unsigned int seconds);
218 
219 extern long sysconf(int name);
220 
221 VOID ScenarInit(VOID);
222 VOID ScenarFini(VOID);
223 pthread_t TestPthreadSelf(void);
224 
225 extern UINT32 PosixPthreadInit(pthread_attr_t *attr, INT32 pri);
226 
227 #if defined(LOSCFG_TEST_SMOKE)
228 VOID ItPosixPthread003(VOID);
229 VOID ItPosixPthread004(VOID);
230 VOID ItPosixPthread005(VOID);
231 VOID ItPosixPthread006(VOID);
232 VOID ItPosixPthread009(VOID);
233 VOID ItPosixPthread018(VOID);
234 VOID ItPosixPthread019(VOID);
235 VOID ItPosixPthread021(VOID);
236 #endif
237 
238 #if defined(LOSCFG_TEST_FULL)
239 VOID ItPosixPthread001(VOID);
240 VOID ItPosixPthread002(VOID);
241 VOID ItPosixPthread007(VOID);
242 VOID ItPosixPthread008(VOID);
243 VOID ItPosixPthread010(VOID);
244 VOID ItPosixPthread011(VOID);
245 VOID ItPosixPthread013(VOID);
246 VOID ItPosixPthread023(VOID);
247 VOID ItPosixPthread028(VOID);
248 VOID ItPosixPthread029(VOID);
249 VOID ItPosixPthread030(VOID);
250 VOID ItPosixPthread031(VOID);
251 VOID ItPosixPthread032(VOID);
252 VOID ItPosixPthread033(VOID);
253 VOID ItPosixPthread034(VOID);
254 VOID ItPosixPthread035(VOID);
255 VOID ItPosixPthread039(VOID);
256 VOID ItPosixPthread040(VOID);
257 VOID ItPosixPthread041(VOID);
258 VOID ItPosixPthread042(VOID);
259 VOID ItPosixPthread044(VOID);
260 VOID ItPosixPthread045(VOID);
261 VOID ItPosixPthread046(VOID);
262 VOID ItPosixPthread048(VOID);
263 VOID ItPosixPthread049(VOID);
264 VOID ItPosixPthread050(VOID);
265 VOID ItPosixPthread051(VOID);
266 VOID ItPosixPthread056(VOID);
267 VOID ItPosixPthread057(VOID);
268 VOID ItPosixPthread058(VOID);
269 VOID ItPosixPthread060(VOID);
270 VOID ItPosixPthread066(VOID);
271 VOID ItPosixPthread068(VOID);
272 VOID ItPosixPthread069(VOID);
273 VOID ItPosixPthread071(VOID);
274 VOID ItPosixPthread072(VOID);
275 VOID ItPosixPthread073(VOID);
276 VOID ItPosixPthread074(VOID);
277 VOID ItPosixPthread075(VOID);
278 VOID ItPosixPthread078(VOID);
279 VOID ItPosixPthread079(VOID);
280 VOID ItPosixPthread080(VOID);
281 VOID ItPosixPthread081(VOID);
282 VOID ItPosixPthread082(VOID);
283 VOID ItPosixPthread083(VOID);
284 VOID ItPosixPthread084(VOID);
285 VOID ItPosixPthread085(VOID);
286 VOID ItPosixPthread087(VOID);
287 VOID ItPosixPthread088(VOID);
288 VOID ItPosixPthread089(VOID);
289 VOID ItPosixPthread092(VOID);
290 VOID ItPosixPthread095(VOID);
291 VOID ItPosixPthread098(VOID);
292 VOID ItPosixPthread101(VOID);
293 VOID ItPosixPthread102(VOID);
294 VOID ItPosixPthread103(VOID);
295 VOID ItPosixPthread107(VOID);
296 VOID ItPosixPthread108(VOID);
297 VOID ItPosixPthread110(VOID);
298 VOID ItPosixPthread112(VOID);
299 VOID ItPosixPthread116(VOID);
300 VOID ItPosixPthread121(VOID);
301 VOID ItPosixPthread123(VOID);
302 VOID ItPosixPthread124(VOID);
303 VOID ItPosixPthread125(VOID);
304 VOID ItPosixPthread127(VOID);
305 VOID ItPosixPthread128(VOID);
306 VOID ItPosixPthread129(VOID);
307 VOID ItPosixPthread132(VOID);
308 VOID ItPosixPthread133(VOID);
309 VOID ItPosixPthread134(VOID);
310 VOID ItPosixPthread136(VOID);
311 VOID ItPosixPthread138(VOID);
312 VOID ItPosixPthread141(VOID);
313 VOID ItPosixPthread142(VOID);
314 VOID ItPosixPthread144(VOID);
315 VOID ItPosixPthread150(VOID);
316 VOID ItPosixPthread152(VOID);
317 VOID ItPosixPthread154(VOID);
318 VOID ItPosixPthread166(VOID);
319 VOID ItPosixPthread167(VOID);
320 VOID ItPosixPthread173(VOID);
321 VOID ItPosixPthread175(VOID);
322 VOID ItPosixPthread176(VOID);
323 VOID ItPosixPthread177(VOID);
324 VOID ItPosixPthread182(VOID);
325 VOID ItPosixPthread185(VOID);
326 VOID ItPosixPthread186(VOID);
327 VOID ItPosixPthread187(VOID);
328 VOID ItPosixPthread188(VOID);
329 VOID ItPosixPthread193(VOID);
330 VOID ItPosixPthread194(VOID);
331 VOID ItPosixPthread197(VOID);
332 VOID ItPosixPthread198(VOID);
333 VOID ItPosixPthread200(VOID);
334 VOID ItPosixPthread204(VOID);
335 VOID ItPosixPthread205(VOID);
336 VOID ItPosixPthread206(VOID);
337 VOID ItPosixPthread208(VOID);
338 VOID ItPosixPthread209(VOID);
339 VOID ItPosixPthread211(VOID);
340 VOID ItPosixPthread213(VOID);
341 VOID ItPosixPthread214(VOID);
342 VOID ItPosixPthread215(VOID);
343 VOID ItPosixPthread217(VOID);
344 VOID ItPosixPthread218(VOID);
345 VOID ItPosixPthread219(VOID);
346 VOID ItPosixPthread221(VOID);
347 VOID ItPosixPthread224(VOID);
348 VOID ItPosixPthread226(VOID);
349 VOID ItPosixPthread233(VOID);
350 VOID ItPosixPthread237(VOID);
351 VOID ItPosixPthread238(VOID);
352 VOID ItPosixPthread239(VOID);
353 VOID ItPosixPthread240(VOID);
354 VOID ItPosixPthread241(VOID);
355 VOID ItPosixPthread246(VOID);
356 #endif
357 
358 #endif /* IT_POSIX_PTHREAD_H */
359