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_task.h"
34
35
HwiF01(VOID)36 static VOID HwiF01(VOID)
37 {
38 ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 1, g_testCount);
39 TestHwiClear(HWI_NUM_TEST);
40 LOS_TaskYield();
41 g_testCount++;
42 }
43
TaskF02(VOID)44 static VOID TaskF02(VOID)
45 {
46 ICUNIT_GOTO_EQUAL(g_testCount, 2, g_testCount, EXIT); // 2, Here, assert that g_testCount is equal to 2.
47 g_testCount++;
48 return;
49 EXIT:
50 LOS_TaskDelete(g_testTaskID02);
51 return;
52 }
53
TaskF01(VOID)54 static VOID TaskF01(VOID)
55 {
56 UINT32 ret;
57 TSK_INIT_PARAM_S task1 = { 0 };
58 task1.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskF02;
59 task1.uwStackSize = TASK_STACK_SIZE_TEST;
60 task1.pcName = "Tsk117B";
61 task1.usTaskPrio = TASK_PRIO_TEST - 2; // 2, set new task priority, it is higher than the current task.
62 task1.uwResved = LOS_TASK_STATUS_DETACHED;
63
64 HWI_PRIOR_T hwiPrio = 3;
65 HWI_MODE_T mode = 0;
66 HwiIrqParam irqParam;
67 (void)memset_s(&irqParam, sizeof(HwiIrqParam), 0, sizeof(HwiIrqParam));
68 irqParam.pDevId = 0;
69
70 ret = LOS_TaskCreate(&g_testTaskID02, &task1);
71 ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
72
73 ICUNIT_GOTO_EQUAL(g_testCount, 0, g_testCount, EXIT);
74 g_testCount++;
75
76 ret = LOS_HwiCreate(HWI_NUM_TEST, hwiPrio, mode, (HWI_PROC_FUNC)HwiF01, &irqParam);
77 ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
78
79 TestHwiTrigger(HWI_NUM_TEST);
80
81 ICUNIT_GOTO_EQUAL(g_testCount, 3, g_testCount, EXIT); // 3, Here, assert that g_testCount is equal to 3.
82 g_testCount++;
83
84 EXIT:
85 TestHwiDelete(HWI_NUM_TEST);
86 LOS_TaskDelete(g_testTaskID02);
87 return;
88 }
89
TestCase(VOID)90 static UINT32 TestCase(VOID)
91 {
92 UINT32 ret;
93 TSK_INIT_PARAM_S task1 = { 0 };
94 task1.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskF01;
95 task1.uwStackSize = TASK_STACK_SIZE_TEST;
96 task1.pcName = "Tsk117A";
97 task1.usTaskPrio = TASK_PRIO_TEST - 2; // 2, set new task priority, it is higher than the current task.
98 task1.uwResved = LOS_TASK_STATUS_DETACHED;
99
100 g_testCount = 0;
101 ret = LOS_TaskCreate(&g_testTaskID01, &task1);
102 ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
103
104 LOS_TaskDelay(10); // 10, set delay time
105
106 ICUNIT_GOTO_EQUAL(g_testCount, 4, g_testCount, EXIT); // 4, Here, assert that g_testCount is equal to 4.
107 EXIT:
108 LOS_TaskDelete(g_testTaskID01);
109
110 return LOS_OK;
111 }
112
ItLosTask117(VOID)113 VOID ItLosTask117(VOID) // IT_Layer_ModuleORFeature_No
114 {
115 TEST_ADD_CASE("ItLosTask117", TestCase, TEST_LOS, TEST_TASK, TEST_LEVEL0, TEST_FUNCTION);
116 }
117
118