• 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 "osTest.h"
33 
34 #if (LOS_KERNEL_MULTI_HWI_TEST == 1)
35 #include "It_los_task.h"
36 
TaskF01(VOID)37 static VOID TaskF01(VOID)
38 {
39     return;
40 }
41 
TaskF03(VOID)42 static VOID TaskF03(VOID)
43 {
44     ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 6, g_testCount); // 6, Here, assert that g_testCount is equal to 6.
45 
46     LOS_TaskDelete(g_testTaskID01);
47     LOS_TaskDelete(g_testTaskID02);
48 }
49 
TaskF02(VOID)50 static VOID TaskF02(VOID)
51 {
52     ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 1, g_testCount);
53     g_testCount++;
54 
55     TestHwiTrigger(HWI_NUM_TEST2);
56     ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 2, g_testCount); // 2, Here, assert that g_testCount is equal to 2.
57     g_testCount++;
58 
59     LOS_TaskDelete(g_testTaskID03);
60 }
61 
HwiF03(VOID)62 static VOID HwiF03(VOID)
63 {
64     TestHwiClear(HWI_NUM_TEST2);
65 
66     ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 3, g_testCount); // 3, Here, assert that g_testCount is equal to 3.
67     g_testCount++;
68 
69     TestHwiTrigger(HWI_NUM_TEST1);
70     ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 4, g_testCount); // 4, Here, assert that g_testCount is equal to 4.
71     g_testCount++;
72 
73     TestHwiDelete(HWI_NUM_TEST2);
74 }
75 
HwiF02(VOID)76 static VOID HwiF02(VOID)
77 {
78     TestHwiClear(HWI_NUM_TEST2);
79 
80     ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 3, g_testCount); // 3, Here, assert that g_testCount is equal to 3.
81     g_testCount++;
82 
83     TestHwiDelete(HWI_NUM_TEST2);
84 }
85 
HwiF01(VOID)86 static VOID HwiF01(VOID)
87 {
88     UINT32 ret;
89     TSK_INIT_PARAM_S task1 = { 0 };
90     task1.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskF01;
91     task1.usTaskPrio = TASK_PRIO_TEST - 1;
92     task1.pcName = "Tsk084A";
93     task1.uwStackSize = TASK_STACK_SIZE_TEST;
94 
95     TestHwiClear(HWI_NUM_TEST);
96 
97     g_testCount++;
98 
99     ret = LOS_TaskCreate(&g_testTaskID01, &task1);
100     ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
101 
102     task1.usTaskPrio = TASK_PRIO_TEST - 2; // 2, set new task priority, it is higher than the current task.
103     task1.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskF02;
104     task1.pcName = "Tsk084B";
105     ret = LOS_TaskCreate(&g_testTaskID02, &task1);
106     ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
107 
108     task1.usTaskPrio = TASK_PRIO_TEST - 3; // 3, set new task priority base on testsuite task`s priority.
109     task1.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskF03;
110     task1.pcName = "Tsk084C";
111     ret = LOS_TaskCreate(&g_testTaskID03, &task1);
112     ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
113 
114     TestHwiDelete(HWI_NUM_TEST);
115 }
116 
TestCase(VOID)117 static UINT32 TestCase(VOID)
118 {
119     UINT32 loop;
120     UINT32 ret;
121 
122     for (loop = 0; loop < IT_TASK_LOOP; loop++) {
123         g_testCount = 0;
124 
125         ret = LOS_HwiCreate(HWI_NUM_TEST, 1, 0, HwiF01, 0);
126         ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
127 
128         ret = LOS_HwiCreate(HWI_NUM_TEST1, 1, 0, HwiF02, 0);
129         ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
130 
131         ret = LOS_HwiCreate(HWI_NUM_TEST2, 1, 0, HwiF03, 0);
132         ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
133 
134         TestHwiTrigger(HWI_NUM_TEST1);
135 
136         LOS_TaskDelay(2); // 2, set delay time
137 
138         TestHwiDelete(HWI_NUM_TEST);
139         TestHwiDelete(HWI_NUM_TEST1);
140         TestHwiDelete(HWI_NUM_TEST2);
141     }
142 
143     return LOS_OK;
144 }
145 
ItLosTask084(VOID)146 VOID ItLosTask084(VOID) // IT_Layer_ModuleORFeature_No
147 {
148     TEST_ADD_CASE("ItLosTask084", TestCase, TEST_LOS, TEST_TASK, TEST_LEVEL2, TEST_PRESSURE);
149 }
150 #endif
151 
152