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