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