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 "It_los_mux.h"
34 #include "los_config.h"
35
36
TaskFuncC(VOID)37 static VOID TaskFuncC(VOID)
38 {
39 UINT32 ret;
40 g_testCount++;
41
42 ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 3, g_testCount); // 3, Here, assert that g_testCount is equal to 3.
43 ret = LOS_MuxPend(g_mutexTest1, LOS_WAIT_FOREVER);
44 ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
45
46 ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 5, g_testCount); // 5, Here, assert that g_testCount is equal to 5.
47
48 ret = LOS_MuxPost(g_mutexTest1);
49 ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
50
51 // 3, Here, assert that priority is equal to 3.
52 ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, 3, g_losTask.runTask->priority);
53
54 ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 5, g_testCount); // 5, Here, assert that g_testCount is equal to 5.
55 g_testCount++;
56 }
57
TaskFuncB(VOID)58 static VOID TaskFuncB(VOID)
59 {
60 UINT32 ret;
61 g_testCount++;
62
63 ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 2, g_testCount); // 2, Here, assert that g_testCount is equal to 2.
64 ret = LOS_MuxPend(g_mutexTest1, 10); // 10, mux pend timeout.
65 ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_ERRNO_MUX_TIMEOUT, ret);
66
67 // 5, Here, assert that priority is equal to 5.
68 ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, 5, g_losTask.runTask->priority);
69 ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 3, g_testCount); // 3, Here, assert that g_testCount is equal to 3.
70 g_testCount++;
71 }
72
TaskFuncA(VOID)73 static VOID TaskFuncA(VOID)
74 {
75 UINT32 ret;
76 TSK_INIT_PARAM_S task1 = {0};
77 TSK_INIT_PARAM_S task2 = {0};
78 g_testCount++;
79
80 ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 1, g_testCount); // 1, Here, assert that g_testCount is equal to 1.
81 ret = LOS_MuxPend(g_mutexTest1, 0);
82 ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
83
84 task1.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskFuncB;
85 // 5, Set the priority according to the task purpose,a smaller number means a higher priority.
86 task1.usTaskPrio = 5;
87 task1.pcName = "TaskB";
88 task1.uwStackSize = TASK_STACK_SIZE_TEST;
89 task1.uwResved = LOS_TASK_STATUS_DETACHED;
90
91 ret = LOS_TaskCreate(&g_testTaskID02, &task1);
92 ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
93
94 task2.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskFuncC;
95 // 3, Set the priority according to the task purpose,a smaller number means a higher priority.
96 task2.usTaskPrio = 3;
97 task2.pcName = "TaskC";
98 task2.uwStackSize = TASK_STACK_SIZE_TEST;
99 task2.uwResved = LOS_TASK_STATUS_DETACHED;
100
101 ret = LOS_TaskCreate(&g_testTaskID03, &task2);
102 ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
103
104 LOS_TaskDelay(20); // 20, set delay time.
105
106 ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 4, g_testCount); // 4, Here, assert that g_testCount is equal to 4.
107 g_testCount++;
108
109 ret = LOS_MuxPost(g_mutexTest1);
110 ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
111
112 ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 6, g_testCount); // 6, Here, assert that g_testCount is equal to 6.
113 g_testCount++;
114
115 ret = LOS_MuxDelete(g_mutexTest1);
116 ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
117
118 // 10, Here, assert that priority is equal to 10.
119 ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, 10, g_losTask.runTask->priority);
120 }
121
Testcase(VOID)122 static UINT32 Testcase(VOID)
123 {
124 UINT32 ret;
125 TSK_INIT_PARAM_S task = {0};
126 g_testCount = 0;
127
128 ret = LOS_MuxCreate(&g_mutexTest1);
129 ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
130
131 task.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskFuncA;
132 // 10, Set the priority according to the task purpose,a smaller number means a higher priority.
133 task.usTaskPrio = 10;
134 task.pcName = "TaskA";
135 task.uwStackSize = TASK_STACK_SIZE_TEST;
136 task.uwResved = LOS_TASK_STATUS_DETACHED;
137
138 ret = LOS_TaskCreate(&g_testTaskID01, &task);
139 ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
140
141 ICUNIT_ASSERT_EQUAL(g_testCount, 3, g_testCount); // 3, Here, assert that g_testCount is equal to 3.
142 LOS_TaskDelay(30); // 30, set delay time.
143
144 ICUNIT_ASSERT_EQUAL(g_testCount, 7, g_testCount); // 7, Here, assert that g_testCount is equal to 7.
145 // 25, Here, assert that priority is equal to 25.
146 ICUNIT_ASSERT_EQUAL(g_losTask.runTask->priority, 25, g_losTask.runTask->priority);
147 return LOS_OK;
148 }
149
ItLosMux030(void)150 VOID ItLosMux030(void)
151 {
152 TEST_ADD_CASE("ItLosMux030", Testcase, TEST_LOS, TEST_MUX, TEST_LEVEL1, TEST_FUNCTION);
153 }
154
155