• 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_lmk.h"
33 #include "los_list.h"
34 
release_OK_First(VOID)35 STATIC UINT32 release_OK_First(VOID)
36 {
37     return LOS_OK;
38 }
39 
restore_OK_First(VOID)40 STATIC UINT32 restore_OK_First(VOID)
41 {
42     return LOS_OK;
43 }
44 
release_OK_Another(VOID)45 STATIC UINT32 release_OK_Another(VOID)
46 {
47     return LOS_OK;
48 }
49 
restore_OK_Another(VOID)50 STATIC UINT32 restore_OK_Another(VOID)
51 {
52     return LOS_OK;
53 }
54 
release_OK_Third(VOID)55 STATIC UINT32 release_OK_Third(VOID)
56 {
57     return LOS_OK;
58 }
59 
restore_OK_Third(VOID)60 STATIC UINT32 restore_OK_Third(VOID)
61 {
62     return LOS_OK;
63 }
64 
TestCase(VOID)65 STATIC UINT32 TestCase(VOID)
66 {
67     UINT32 ret;
68 
69     LosLmkOpsNode firstOpsNode = {
70         .priority = LMK_PRIORITY_LOW,
71         .freeMem = release_OK_First,
72         .restoreTask = restore_OK_First,
73     };
74 
75     LosLmkOpsNode anotherOpsNode = {
76         .priority = LMK_PRIORITY_MEDIUM,
77         .freeMem = release_OK_Another,
78         .restoreTask = restore_OK_Another,
79     };
80 
81     LosLmkOpsNode thirdOpsNode = {
82         .priority = LMK_PRIORITY_HIGH,
83         .freeMem = release_OK_Third,
84         .restoreTask = restore_OK_Third,
85     };
86 
87     ret = LOS_LmkOpsNodeRegister(&firstOpsNode);
88     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
89     ret = LOS_LmkOpsNodeRegister(&thirdOpsNode);
90     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
91     ret = LOS_LmkOpsNodeRegister(&anotherOpsNode);
92     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
93 #if (LOSCFG_KERNEL_LMK_DEBUG == 1)
94     (VOID)LOS_LmkOpsNodeInfoShow();
95 #endif
96     (VOID)LOS_LmkOpsNodeUnregister(&firstOpsNode);
97     (VOID)LOS_LmkOpsNodeUnregister(&anotherOpsNode);
98     (VOID)LOS_LmkOpsNodeUnregister(&thirdOpsNode);
99 
100     ret = LOS_LmkOpsNodeRegister(&firstOpsNode);
101     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
102     ret = LOS_LmkOpsNodeRegister(&anotherOpsNode);
103     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
104     ret = LOS_LmkOpsNodeRegister(&thirdOpsNode);
105     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
106 #if (LOSCFG_KERNEL_LMK_DEBUG == 1)
107     (VOID)LOS_LmkOpsNodeInfoShow();
108 #endif
109     (VOID)LOS_LmkOpsNodeUnregister(&firstOpsNode);
110     (VOID)LOS_LmkOpsNodeUnregister(&anotherOpsNode);
111     (VOID)LOS_LmkOpsNodeUnregister(&thirdOpsNode);
112 
113     ret = LOS_LmkOpsNodeRegister(&anotherOpsNode);
114     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
115     ret = LOS_LmkOpsNodeRegister(&thirdOpsNode);
116     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
117     ret = LOS_LmkOpsNodeRegister(&firstOpsNode);
118     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
119 #if (LOSCFG_KERNEL_LMK_DEBUG == 1)
120     (VOID)LOS_LmkOpsNodeInfoShow();
121 #endif
122     (VOID)LOS_LmkOpsNodeUnregister(&firstOpsNode);
123     (VOID)LOS_LmkOpsNodeUnregister(&anotherOpsNode);
124     (VOID)LOS_LmkOpsNodeUnregister(&thirdOpsNode);
125 
126     return LOS_OK;
127 }
128 
ItLosLmk004(VOID)129 VOID ItLosLmk004(VOID)
130 {
131     TEST_ADD_CASE("ItLosLmk004", TestCase, TEST_LOS, TEST_COMP, TEST_LEVEL0, TEST_FUNCTION);
132 }
133