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 "osTest.h"
33 #include "los_config.h"
34 #include "los_bitmap.h"
35 #include "It_los_mux.h"
36
37 #ifdef __cplusplus
38 #if __cplusplus
39 extern "C" {
40 #endif /* __cplusplus */
41 #endif /* __cplusplus */
42
43 static LosMux g_testMux1;
44 static LosMux g_testMux2;
45 static UINT32 g_mainTaskID;
TaskFe4Func(VOID)46 static VOID TaskFe4Func(VOID)
47 {
48 UINT32 ret;
49
50 ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 4, g_testCount); // 4, here assert the result.
51 g_testCount++;
52
53 ret = LOS_MuxLock(&g_testMux2, LOS_WAIT_FOREVER);
54 ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
55
56 UINT16 priority = LOS_TaskPriGet(g_mainTaskID);
57 ICUNIT_ASSERT_EQUAL_VOID(priority, 10, priority); // 10, here assert the result.
58 ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 6, g_testCount); // 6, here assert the result.
59 g_testCount++;
60
61 ret = LOS_MuxUnlock(&g_testMux2);
62 ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
63
64 return;
65 }
66
TaskMisc10Func(VOID)67 static VOID TaskMisc10Func(VOID)
68 {
69 UINT32 ret;
70 g_testCount++;
71
72 ret = LOS_MuxLock(&g_testMux1, LOS_WAIT_FOREVER);
73 ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
74
75 ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 8, g_testCount); // 8, here assert the result.
76 g_testCount++;
77
78 ret = LOS_MuxUnlock(&g_testMux1);
79 ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
80
81 return;
82 }
83
Testcase(VOID)84 static UINT32 Testcase(VOID)
85 {
86 UINT32 ret;
87 TSK_INIT_PARAM_S taskParam = { 0 };
88 g_testCount = 0;
89 LosTaskCB *task = NULL;
90 LosMuxAttr attr = { 0 };
91
92 UINT16 prio = LOS_TaskPriGet(OsCurrTaskGet()->taskID);
93 g_mainTaskID = OsCurrTaskGet()->taskID;
94
95 ret = LosMuxCreate(&g_testMux1);
96 ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
97
98 ret = LOS_MuxAttrInit(&attr);
99 ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
100
101 ret = LOS_MuxAttrSetProtocol(&attr, LOS_MUX_PRIO_NONE);
102 ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
103
104 ret = LOS_MuxInit(&g_testMux2, &attr);
105 ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
106
107 ret = LOS_MuxLock(&g_testMux1, LOS_WAIT_FOREVER);
108 ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
109
110 ret = LOS_MuxLock(&g_testMux2, LOS_WAIT_FOREVER);
111 ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
112
113 g_testCount++;
114 g_testCount++;
115
116 taskParam.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskMisc10Func;
117 taskParam.usTaskPrio = 10; // 10, set reasonable priority.
118 taskParam.pcName = "TaskMisc_10";
119 taskParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
120 taskParam.uwResved = LOS_TASK_STATUS_DETACHED;
121 #ifdef LOSCFG_KERNEL_SMP
122 taskParam.usCpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid());
123 #endif
124
125 ret = LOS_TaskCreate(&g_testTaskID01, &taskParam);
126 ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
127
128 UINT16 priority = LOS_TaskPriGet(OsCurrTaskGet()->taskID);
129 ICUNIT_GOTO_EQUAL(priority, 10, priority, EXIT); // 10, here assert the result.
130 ICUNIT_GOTO_EQUAL(g_testCount, 3, g_testCount, EXIT); // 3, here assert the result.
131 g_testCount++;
132
133 taskParam.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskFe4Func;
134 taskParam.usTaskPrio = 4; // 4, set reasonable priority.
135 taskParam.pcName = "TaskFe_4";
136 taskParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
137 taskParam.uwResved = LOS_TASK_STATUS_DETACHED;
138 #ifdef LOSCFG_KERNEL_SMP
139 taskParam.usCpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid());
140 #endif
141
142 ret = LOS_TaskCreate(&g_testTaskID03, &taskParam);
143 ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
144
145 priority = LOS_TaskPriGet(OsCurrTaskGet()->taskID);
146 ICUNIT_GOTO_EQUAL(priority, 10, priority, EXIT); // 10, here assert the result.
147 ICUNIT_GOTO_EQUAL(g_testCount, 5, g_testCount, EXIT); // 5, here assert the result.
148 g_testCount++;
149
150 ret = LOS_MuxUnlock(&g_testMux2);
151 ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
152
153 ICUNIT_GOTO_EQUAL(g_testCount, 7, g_testCount, EXIT); // 7, here assert the result.
154 g_testCount++;
155
156 ret = LOS_MuxUnlock(&g_testMux1);
157 ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
158
159 priority = LOS_TaskPriGet(OsCurrTaskGet()->taskID);
160 ICUNIT_GOTO_EQUAL(priority, prio, priority, EXIT);
161
162 ICUNIT_GOTO_EQUAL(g_testCount, 9, g_testCount, EXIT); // 9, here assert the result.
163
164 EXIT:
165 ret = LOS_MuxDestroy(&g_testMux1);
166 ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
167
168 ret = LOS_MuxDestroy(&g_testMux2);
169 ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
170
171 return LOS_OK;
172 }
173
ItLosMux043(void)174 VOID ItLosMux043(void)
175 {
176 TEST_ADD_CASE("ItLosMux043", Testcase, TEST_LOS, TEST_MUX, TEST_LEVEL2, TEST_FUNCTION);
177 }
178
179 #ifdef __cplusplus
180 #if __cplusplus
181 }
182 #endif /* __cplusplus */
183 #endif /* __cplusplus */
184