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
SwtmrF01(UINT32 arg)36 static VOID SwtmrF01(UINT32 arg)
37 {
38 UINT32 ret;
39 UINT32 tick = 0;
40
41 if (arg != TIMER_LOS_HANDLER_PARAMETER) {
42 return;
43 }
44
45 ret = LOS_SwtmrTimeGet(g_swtmrId1, &tick);
46 ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
47 ICUNIT_GOTO_EQUAL(tick, TIMER_LOS_EXPIRATION1 - 1, tick, EXIT);
48
49 g_testCount++;
50 return;
51 EXIT:
52 LOS_SwtmrDelete(g_swtmrId1);
53 return;
54 }
55
Testcase(VOID)56 static UINT32 Testcase(VOID)
57 {
58 UINT32 ret;
59 UINT32 tick = 0;
60
61 g_testCount = 0;
62 g_swtmrId1 = 0;
63
64 ret = LOS_SwtmrCreate(TIMER_LOS_EXPIRATION1, LOS_SWTMR_MODE_PERIOD, (SWTMR_PROC_FUNC)SwtmrF01, &g_swtmrId1,
65 TIMER_LOS_HANDLER_PARAMETER
66 #if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
67 , OS_SWTMR_ROUSES_ALLOW, OS_SWTMR_ALIGN_INSENSITIVE
68 #endif
69 );
70
71 ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
72
73 ret = LOS_SwtmrStart(g_swtmrId1);
74 ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
75
76 ret = LOS_TaskDelay(10); // 10, set delay time.
77 ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
78
79 ret = LOS_SwtmrTimeGet(g_swtmrId1, &tick);
80 ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
81
82 // 1, assert that uwTick is equal to this.
83 ICUNIT_GOTO_EQUAL(tick, 1, tick, EXIT);
84
85 // 2, Here, assert that g_testCount is equal to this .
86 ICUNIT_GOTO_EQUAL(g_testCount, 2, g_testCount, EXIT);
87
88 ret = LOS_SwtmrDelete(g_swtmrId1);
89 ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
90
91 ret = LOS_SwtmrTimeGet(g_swtmrId1, &tick);
92 ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_SWTMR_NOT_CREATED, ret, EXIT);
93
94 ret = LOS_TaskDelay(10); // 10, set delay time.
95 ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
96
97 // 2, Here, assert that g_testCount is equal to this .
98 ICUNIT_ASSERT_EQUAL(g_testCount, 2, g_testCount);
99
100 return LOS_OK;
101 EXIT:
102 LOS_SwtmrDelete(g_swtmrId1);
103 return LOS_OK;
104 }
105
ItLosSwtmr069(VOID)106 VOID ItLosSwtmr069(VOID)
107 {
108 TEST_ADD_CASE("ItLosSwtmr069", Testcase, TEST_LOS, TEST_SWTMR, TEST_LEVEL1, TEST_FUNCTION);
109 }
110
111