1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific prior written
16 * permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "It_posix_mutex.h"
32
PosixPthreadDestroy(pthread_attr_t *attr, pthread_t thread)33 UINT32 PosixPthreadDestroy(pthread_attr_t *attr, pthread_t thread)
34 {
35 UINT32 uwRet = 0;
36
37 uwRet = pthread_join(thread, NULL);
38 ICUNIT_GOTO_EQUAL(uwRet, 0, uwRet, NOK);
39
40 uwRet = pthread_attr_destroy(attr);
41 ICUNIT_GOTO_EQUAL(uwRet, 0, uwRet, NOK);
42
43 return LOS_OK;
44 NOK:
45 return LOS_NOK;
46 }
47
PosixPthreadInit(pthread_attr_t *attr, int pri)48 UINT32 PosixPthreadInit(pthread_attr_t *attr, int pri)
49 {
50 UINT32 uwRet = 0;
51 struct sched_param sp;
52
53 uwRet = pthread_attr_init(attr);
54 ICUNIT_GOTO_EQUAL(uwRet, 0, uwRet, NOK);
55
56 uwRet = pthread_attr_setinheritsched(attr, PTHREAD_EXPLICIT_SCHED);
57 ICUNIT_GOTO_EQUAL(uwRet, 0, uwRet, NOK);
58
59 sp.sched_priority = pri;
60 uwRet = pthread_attr_setschedparam(attr, &sp);
61 ICUNIT_GOTO_EQUAL(uwRet, 0, uwRet, NOK);
62
63 return LOS_OK;
64 NOK:
65 return LOS_NOK;
66 }
67
TestExtraTaskDelay(UINT32 uwTick)68 VOID TestExtraTaskDelay(UINT32 uwTick)
69 {
70 #ifdef LOSCFG_KERNEL_SMP
71 // trigger task schedule may occor on another core
72 // needs adding delay and checking status later
73 LosTaskDelay(uwTick);
74 #else
75 // do nothing
76 #endif
77 }
78
ItSuitePosixMutex(void)79 VOID ItSuitePosixMutex(void)
80 {
81 PRINTF("*********** Begin sample posix mutex test ************\n");
82 ItPosixMux001();
83 ItPosixMux002();
84 ItPosixMux003();
85 ItPosixMux004();
86 ItPosixMux005();
87 ItPosixMux006();
88 ItPosixMux007();
89 ItPosixMux008();
90 ItPosixMux009();
91 ItPosixMux010();
92 ItPosixMux011();
93 ItPosixMux012();
94 ItPosixMux013();
95 ItPosixMux014();
96 ItPosixMux015();
97 ItPosixMux016();
98 ItPosixMux017();
99 ItPosixMux018();
100 ItPosixMux019();
101 ItPosixMux020();
102 ItPosixMux021();
103 ItPosixMux022();
104 ItPosixMux023();
105 ItPosixMux024();
106 ItPosixMux025();
107 ItPosixMux026();
108 ItPosixMux027();
109 ItPosixMux028();
110 ItPosixMux029();
111 ItPosixMux030();
112 ItPosixMux031();
113 ItPosixMux032();
114 ItPosixMux033();
115 ItPosixMux034();
116 ItPosixMux035();
117 ItPosixMux036();
118 ItPosixMux037();
119 ItPosixMux038();
120 ItPosixMux039();
121 ItPosixMux040();
122 ItPosixMux041();
123 ItPosixMux042();
124 ItPosixMux043();
125 ItPosixMux044();
126 ItPosixMux045();
127 ItPosixMux046();
128 ItPosixMux047();
129 ItPosixMux048();
130 #ifndef LOSCFG_KERNEL_SMP
131 ItPosixMux049();
132 #endif
133 }
134