• 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 #include "It_los_mux.h"
33 
34 #ifdef __cplusplus
35 #if __cplusplus
36 extern "C" {
37 #endif /* __cplusplus */
38 #endif /* __cplusplus */
39 
TaskD5Func(VOID)40 static VOID TaskD5Func(VOID)
41 {
42     UINT32 ret;
43     g_testCount++;
44 
45     ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 4, g_testCount); // 4, here assert the result.
46 
47     ret = LOS_MuxLock(&g_mutexTest2, LOS_WAIT_FOREVER);
48     ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
49 
50     ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 5, g_testCount); // 5, here assert the result.
51 
52     ret = LOS_MuxUnlock(&g_mutexTest2);
53     ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
54 
55     UINT16 priority = LOS_TaskPriGet(OsCurrTaskGet()->taskID);
56     ICUNIT_ASSERT_EQUAL_VOID(priority, 2, priority); // 2, here assert the result.
57     ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 5, g_testCount);                             // 5, here assert the result.
58     g_testCount++;
59 }
60 
TaskC5Func(VOID)61 static VOID TaskC5Func(VOID)
62 {
63     UINT32 ret;
64     g_testCount++;
65 
66     ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 3, g_testCount); // 3, here assert the result.
67 
68     ret = LOS_MuxLock(&g_mutexTest2, LOS_WAIT_FOREVER);
69     ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
70 
71     ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 6, g_testCount); // 6, here assert the result.
72 
73     ret = LOS_MuxUnlock(&g_mutexTest2);
74     ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
75 
76     UINT16 priority = LOS_TaskPriGet(OsCurrTaskGet()->taskID);
77     ICUNIT_ASSERT_EQUAL_VOID(priority, 3, priority); // 3, here assert the result.
78 
79     ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 6, g_testCount); // 6, here assert the result.
80     g_testCount++;
81 }
82 
TaskB5Func(VOID)83 static VOID TaskB5Func(VOID)
84 {
85     UINT32 ret;
86     g_testCount++;
87 
88     ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 2, g_testCount); // 2, here assert the result.
89 
90     ret = LOS_MuxLock(&g_mutexTest1, LOS_WAIT_FOREVER);
91     ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
92 
93     ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 7, g_testCount); // 7, here assert the result.
94 
95     ret = LOS_MuxUnlock(&g_mutexTest1);
96     ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
97 
98     UINT16 priority = LOS_TaskPriGet(OsCurrTaskGet()->taskID);
99     ICUNIT_ASSERT_EQUAL_VOID(priority, 5, priority); // 5, here assert the result.
100 
101     g_testCount++;
102 }
103 
TaskA5Func(VOID)104 static VOID TaskA5Func(VOID)
105 {
106     UINT32 ret;
107     TSK_INIT_PARAM_S task1 = { 0 };
108     TSK_INIT_PARAM_S task2 = { 0 };
109     TSK_INIT_PARAM_S task3 = { 0 };
110     g_testCount++;
111 
112     ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 1, g_testCount);
113 
114     ret = LOS_MuxLock(&g_mutexTest1, 0);
115     ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
116 
117     ret = LOS_MuxLock(&g_mutexTest2, 0);
118     ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
119 
120     task1.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskB5Func;
121     task1.usTaskPrio = 5; // 5, set reasonable priority.
122     task1.pcName = "TaskB";
123     task1.uwStackSize = TASK_STACK_SIZE_TEST;
124     task1.uwResved = LOS_TASK_STATUS_DETACHED;
125 #ifdef LOSCFG_KERNEL_SMP
126     task1.usCpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid());
127 #endif
128     ret = LOS_TaskCreate(&g_testTaskID02, &task1);
129     ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
130 
131     task2.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskC5Func;
132     task2.usTaskPrio = 3; // 3, set reasonable priority.
133     task2.pcName = "TaskC";
134     task2.uwStackSize = TASK_STACK_SIZE_TEST;
135     task2.uwResved = LOS_TASK_STATUS_DETACHED;
136 #ifdef LOSCFG_KERNEL_SMP
137     task2.usCpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid());
138 #endif
139     ret = LOS_TaskCreate(&g_testTaskID03, &task2);
140     ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
141 
142     task3.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskD5Func;
143     task3.usTaskPrio = 2; // 2, set reasonable priority.
144     task3.pcName = "TaskD";
145     task3.uwStackSize = TASK_STACK_SIZE_TEST;
146     task3.uwResved = LOS_TASK_STATUS_DETACHED;
147 #ifdef LOSCFG_KERNEL_SMP
148     task3.usCpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid());
149 #endif
150     ret = LOS_TaskCreate(&g_testTaskID04, &task3);
151     ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
152 
153     g_testCount++;
154     ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 5, g_testCount); // 5, here assert the result.
155 
156     ret = LOS_MuxUnlock(&g_mutexTest2);
157     ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
158 
159     ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 7, g_testCount); // 5, here assert the result.
160 
161     ret = LOS_MuxUnlock(&g_mutexTest1);
162     ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
163 
164     UINT16 priority = LOS_TaskPriGet(OsCurrTaskGet()->taskID);
165     ICUNIT_ASSERT_EQUAL_VOID(priority, 10, priority); // 10, here assert the result.
166     ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 8, g_testCount); // 8, here assert the result.
167     g_testCount++;
168 }
169 
Testcase(VOID)170 static UINT32 Testcase(VOID)
171 {
172     UINT32 ret;
173     TSK_INIT_PARAM_S task = {0};
174     g_testCount = 0;
175 
176     ret = LosMuxCreate(&g_mutexTest1);
177     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
178 
179     ret = LosMuxCreate(&g_mutexTest2);
180     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
181 
182     task.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskA5Func;
183     task.usTaskPrio = 10; // 10, set reasonable priority.
184     task.pcName = "TaskA";
185     task.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
186     task.uwResved = LOS_TASK_STATUS_DETACHED;
187 #ifdef LOSCFG_KERNEL_SMP
188     task.usCpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid());
189 #endif
190     ret = LOS_TaskCreate(&g_testTaskID01, &task);
191     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
192 
193     ret = LOS_MuxDestroy(&g_mutexTest1);
194     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
195 
196     ret = LOS_MuxDestroy(&g_mutexTest2);
197     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
198 
199     ICUNIT_ASSERT_EQUAL(g_testCount, 9, g_testCount); // 9, here assert the result.
200 
201     UINT16 priority = LOS_TaskPriGet(OsCurrTaskGet()->taskID);
202     ICUNIT_ASSERT_EQUAL(priority, 25, priority); // 25, here assert the result.
203     return LOS_OK;
204 }
205 
ItLosMux031(void)206 VOID ItLosMux031(void)
207 {
208     TEST_ADD_CASE("ItLosMux031", Testcase, TEST_LOS, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
209 }
210 
211 #ifdef __cplusplus
212 #if __cplusplus
213 }
214 #endif /* __cplusplus */
215 #endif
216