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_swtmr.h"
34 
35 
Case1(UINT32 arg)36 static VOID Case1(UINT32 arg)
37 {
38     // 20, Here, assert that g_testCount is equal to this .
39     ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 20, g_testCount);
40     // 30, Set the number to determine whether the process is as expected.
41     g_testCount = 30;
42 }
43 
Case2null44 static VOID Case2(VOID)
45 {
46     // 10, Here, assert that g_testCount is equal to this .
47     ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 10, g_testCount);
48     // 20, Set the number to determine whether the process is as expected.
49     g_testCount = 20;
50 }
51 
Case3null52 static VOID Case3(VOID)
53 {
54     // 10, Set the number to determine whether the process is as expected.
55     g_testCount = 10;
56 }
57 
Testcasenull58 static UINT32 Testcase(VOID)
59 {
60     UINT32 ret;
61     UINT32 swtmrId1;
62     UINT32 swtmrId2;
63     UINT32 swtmrId3;
64 
65     g_testCount = 0;
66 
67     // 5, Timeout interval of a periodic software timer.
68     ret = LOS_SwtmrCreate(5, LOS_SWTMR_MODE_PERIOD, (SWTMR_PROC_FUNC)Case3, &swtmrId1, 0xffff
69 #if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
70         , OS_SWTMR_ROUSES_ALLOW, OS_SWTMR_ALIGN_INSENSITIVE
71 #endif
72     );
73     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
74     // 6, Timeout interval of a periodic software timer.
75     ret = LOS_SwtmrCreate(6, LOS_SWTMR_MODE_PERIOD, (SWTMR_PROC_FUNC)Case2, &swtmrId2, 0xffff
76 #if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
77         , OS_SWTMR_ROUSES_ALLOW, OS_SWTMR_ALIGN_INSENSITIVE
78 #endif
79     );
80     ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
81     // 7, Timeout interval of a periodic software timer.
82     ret = LOS_SwtmrCreate(7, LOS_SWTMR_MODE_PERIOD, (SWTMR_PROC_FUNC)Case1, &swtmrId3, 0xffff
83 #if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
84         , OS_SWTMR_ROUSES_ALLOW, OS_SWTMR_ALIGN_INSENSITIVE
85 #endif
86     );
87     ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
88 
89     LOS_SwtmrStart(swtmrId1);
90     LOS_SwtmrStart(swtmrId2);
91     LOS_SwtmrStart(swtmrId3);
92 
93     LOS_TaskDelay(19); // 19, set delay time.
94 
95     LOS_SwtmrDelete(swtmrId1);
96     LOS_SwtmrDelete(swtmrId2);
97     LOS_SwtmrDelete(swtmrId3);
98 
99     return LOS_OK;
100 EXIT:
101     LOS_SwtmrDelete(swtmrId1);
102     LOS_SwtmrDelete(swtmrId2);
103     LOS_SwtmrDelete(swtmrId3);
104     return LOS_OK;
105 }
106 
ItLosSwtmr031null107 VOID ItLosSwtmr031(VOID) // IT_Layer_ModuleORFeature_No
108 {
109     TEST_ADD_CASE("ItLosSwtmr031", Testcase, TEST_LOS, TEST_SWTMR, TEST_LEVEL1, TEST_FUNCTION);
110 }
111 
112