• 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_extend_cpup.h"
33 
34 #ifdef __cplusplus
35 #if __cplusplus
36 extern "C" {
37 #endif /* __cpluscplus */
38 #endif /* __cpluscplus */
39 
TaskF02(VOID)40 static UINT32 TaskF02(VOID)
41 {
42     UINT32 ret, cpupUse;
43 
44     ICUNIT_ASSERT_EQUAL(g_cpupTestCount, 2, g_cpupTestCount); // 2, Here, assert that g_cpupTestCount is equal to the expected value.
45     g_cpupTestCount++;
46 
47     cpupUse = LOS_HistoryProcessCpuUsage(g_testTaskID01, CPUP_ALL_TIME);
48     if (cpupUse > LOS_CPUP_PRECISION || cpupUse < CPU_USE_MIN) {
49         ret = LOS_NOK;
50     } else {
51         ret = LOS_OK;
52     }
53     ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
54 
55     ret = LOS_TaskDelete(g_testTaskID02);
56     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
57     return LOS_OK;
58 
59 EXIT:
60     ret = LOS_TaskDelete(g_testTaskID02);
61     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
62     return ret;
63 }
64 
TaskF01(VOID)65 static VOID TaskF01(VOID)
66 {
67     UINT32 ret;
68     TSK_INIT_PARAM_S task1 = { 0 };
69     task1.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskF02;
70     task1.uwStackSize = TASK_STACK_SIZE_TEST;
71     task1.pcName = "TskTst2";
72     task1.usTaskPrio = TASK_PRIO_TEST - 1; // 1, used to calculate the task priority.
73     task1.uwResved = TASK_STATUS_UNDETACHED;
74 #ifdef LOSCFG_KERNEL_SMP
75     task1.usCpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid());
76 #endif
77     ICUNIT_ASSERT_EQUAL_VOID(g_cpupTestCount, 0, g_cpupTestCount);
78     g_cpupTestCount++;
79 
80     g_testTaskID01 = LOS_GetCurrProcessID();
81 
82     ret = LOS_GetTaskScheduler(LOS_CurTaskIDGet());
83     // 2, used to calculate the task priority.
84     ret = LOS_SetTaskScheduler(LOS_CurTaskIDGet(), ret, TASK_PRIO_TEST - 2);
85     ICUNIT_ASSERT_EQUAL_VOID(ret, 0, ret);
86 
87     ret = LOS_TaskCreate(&g_testTaskID02, &task1);
88     ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret);
89 
90     ICUNIT_ASSERT_EQUAL_VOID(g_cpupTestCount, 1, g_cpupTestCount);
91     g_cpupTestCount++;
92 
93     LOS_TaskDelay(30); // 30, set delay time.
94 
95     ICUNIT_ASSERT_EQUAL_VOID(g_cpupTestCount, 3, g_cpupTestCount); // 3, Here, assert that g_cpupTestCount is equal to the expected value.
96     g_cpupTestCount++;
97 }
98 
Testcase(VOID)99 static UINT32 Testcase(VOID)
100 {
101     UINT32 ret, cpupUse;
102     TSK_INIT_PARAM_S task1 = { 0 };
103 
104     cpupUse = LOS_HistorySysCpuUsage(CPUP_ALL_TIME);
105     if (cpupUse > LOS_CPUP_PRECISION || cpupUse < CPU_USE_MIN) {
106         ret = LOS_NOK;
107     } else {
108         ret = LOS_OK;
109     }
110     ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
111 
112     task1.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskF01;
113     task1.uwStackSize = TASK_STACK_SIZE_TEST;
114     task1.pcName = "TskTst1";
115     task1.usTaskPrio = TASK_PRIO_TEST - 2; // 2, used to calculate the task priority.
116     task1.uwResved = TASK_STATUS_UNDETACHED;
117 #ifdef LOSCFG_KERNEL_SMP
118     task1.usCpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid());
119 #endif
120     g_cpupTestCount = 0;
121     INT32 pid = LOS_Fork(0, "TestCpupTsk1", TaskF01, TASK_STACK_SIZE_TEST);
122     if (pid < 0) {
123         ICUNIT_ASSERT_EQUAL(1, LOS_OK, 1);
124     }
125 
126     ret = LOS_Wait(pid, NULL, 0, NULL);
127     ICUNIT_ASSERT_EQUAL(pid, ret, pid);
128 
129     ICUNIT_ASSERT_EQUAL(g_cpupTestCount, 4, g_cpupTestCount); // 4, Here, assert that g_cpupTestCount is equal to the expected value.
130 
131     cpupUse = LOS_HistorySysCpuUsage(CPU_USE_MODE1);
132     if (cpupUse > LOS_CPUP_PRECISION || cpupUse < CPU_USE_MIN) {
133         ret = LOS_NOK;
134     } else {
135         ret = LOS_OK;
136     }
137     ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
138 
139     return LOS_OK;
140 
141 EXIT:
142     return ret;
143 }
144 
ItExtendCpup006(VOID)145 VOID ItExtendCpup006(VOID) // IT_Layer_ModuleORFeature_No
146 {
147     TEST_ADD_CASE("ItExtendCpup006", Testcase, TEST_EXTEND, TEST_CPUP, TEST_LEVEL2, TEST_FUNCTION);
148 }
149 #ifdef __cplusplus
150 #if __cplusplus
151 }
152 #endif /* __cpluscplus */
153 #endif /* __cpluscplus */
154