• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this list of
8  * conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11  * of conditions and the following disclaimer in the documentation and/or other materials
12  * provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15  * to endorse or promote products derived from this software without specific prior written
16  * permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include "osTest.h"
32 #include "It_los_pm.h"
33 
DeviceSuspend(UINT32 mode)34 static UINT32 DeviceSuspend(UINT32 mode)
35 {
36     return LOS_OK;
37 }
38 
DeviceResume(UINT32 mode)39 static VOID DeviceResume(UINT32 mode)
40 {
41     return;
42 }
43 
44 static LosPmDevice g_device1 = {
45     .suspend = NULL,
46     .resume = NULL,
47 };
48 
SysResume(VOID)49 static VOID SysResume(VOID)
50 {
51 }
52 
53 static LosPmSysctrl g_sysctrl = {
54     .normalSuspend = NULL,
55     .normalResume = SysResume,
56 };
57 
TimerStart(UINT64 timer)58 static VOID TimerStart(UINT64 timer)
59 {
60 
61 }
62 
GetTimerCycle(VOID)63 static UINT64 GetTimerCycle(VOID)
64 {
65     return 0;
66 }
67 
TickLock(VOID)68 static VOID TickLock(VOID)
69 {
70     return;
71 }
72 
TickUnlock(VOID)73 static VOID TickUnlock(VOID)
74 {
75     return;
76 }
77 
78 static LosPmTickTimer g_tickTimer = {
79     .tickLock = NULL,
80     .tickUnlock = NULL,
81     .timerStart = NULL,
82     .timerStop = NULL,
83     .timerCycleGet = NULL,
84     .freq = 0,
85 };
86 
TestCase(VOID)87 static UINT32 TestCase(VOID)
88 {
89     UINT32 ret;
90 
91     ret = LOS_PmRegister(LOS_PM_TYPE_DEVICE, NULL);
92     ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_PM_INVALID_PARAM, ret);
93 
94     ret = LOS_PmRegister(LOS_PM_TYPE_DEVICE, &g_device1);
95     ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_PM_INVALID_PARAM, ret);
96 
97     g_device1.suspend = DeviceSuspend;
98     ret = LOS_PmRegister(LOS_PM_TYPE_DEVICE, &g_device1);
99     ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_PM_INVALID_PARAM, ret);
100 
101     g_device1.suspend = NULL;
102     g_device1.resume = DeviceResume;
103     ret = LOS_PmRegister(LOS_PM_TYPE_DEVICE, &g_device1);
104     ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_PM_INVALID_PARAM, ret);
105 
106     g_device1.suspend = DeviceSuspend;
107     g_device1.resume = DeviceResume;
108     ret = LOS_PmRegister(LOS_PM_TYPE_DEVICE, &g_device1);
109     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
110 
111     ret = LOS_PmRegister(LOS_PM_TYPE_TICK_TIMER, NULL);
112     ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_PM_INVALID_PARAM, ret);
113 
114     ret = LOS_PmRegister(LOS_PM_TYPE_TICK_TIMER, &g_tickTimer);
115     ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_PM_INVALID_PARAM, ret);
116 
117     g_tickTimer.tickLock = TickLock;
118     ret = LOS_PmRegister(LOS_PM_TYPE_TICK_TIMER, &g_tickTimer);
119     ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_PM_INVALID_PARAM, ret);
120 
121     g_tickTimer.tickLock = NULL;
122     g_tickTimer.tickUnlock = TickUnlock;
123     ret = LOS_PmRegister(LOS_PM_TYPE_TICK_TIMER, &g_tickTimer);
124     ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_PM_INVALID_PARAM, ret);
125 
126     g_tickTimer.tickLock = TickLock;
127     g_tickTimer.tickUnlock = TickUnlock;
128     ret = LOS_PmRegister(LOS_PM_TYPE_TICK_TIMER, &g_tickTimer);
129     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
130 
131     ret = LOS_PmUnregister(LOS_PM_TYPE_TICK_TIMER, &g_tickTimer);
132     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
133 
134     g_tickTimer.tickLock = TickLock;
135     g_tickTimer.tickUnlock = TickUnlock;
136     g_tickTimer.timerStart = TimerStart;
137     ret = LOS_PmRegister(LOS_PM_TYPE_TICK_TIMER, &g_tickTimer);
138     ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_PM_INVALID_PARAM, ret);
139 
140     g_tickTimer.timerStop = TickLock;
141     ret = LOS_PmRegister(LOS_PM_TYPE_TICK_TIMER, &g_tickTimer);
142     ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_PM_INVALID_PARAM, ret);
143 
144     g_tickTimer.timerCycleGet = GetTimerCycle;
145     ret = LOS_PmRegister(LOS_PM_TYPE_TICK_TIMER, &g_tickTimer);
146     ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_PM_INVALID_PARAM, ret);
147 
148     g_tickTimer.freq = 32000; /* 32000HZ */
149     ret = LOS_PmRegister(LOS_PM_TYPE_TICK_TIMER, &g_tickTimer);
150     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
151 
152     ret = LOS_PmUnregister(LOS_PM_TYPE_TICK_TIMER, &g_tickTimer);
153     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
154 
155     ret = LOS_PmUnregister(LOS_PM_TYPE_SYSCTRL, &g_sysctrl);
156     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
157 
158     ret = LOS_PmUnregister(LOS_PM_TYPE_DEVICE, &g_device1);
159     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
160     return LOS_OK;
161 }
162 
ItLosPm001(VOID)163 VOID ItLosPm001(VOID) // IT_Layer_ModuleORFeature_No
164 {
165     TEST_ADD_CASE("ItLosPm001", TestCase, TEST_LOS, TEST_TASK, TEST_LEVEL0, TEST_FUNCTION);
166 }
167