• 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 
33 #include "it_los_atomic.h"
34 
TaskF01(VOID)35 static VOID TaskF01(VOID)
36 {
37     INT32 i;
38     UINTPTR ret;
39     UINTPTR count;
40     for (i = 0; i < 100; ++i) { // run 100 times.
41         count = g_testAtomicID03;
42         ret = LOS_AtomicIncRet(&g_testAtomicID03);
43         ICUNIT_ASSERT_EQUAL_VOID(ret, g_testAtomicID03, ret);
44         ICUNIT_ASSERT_EQUAL_VOID((count + 1), g_testAtomicID03, (count + 1));
45     }
46     ICUNIT_ASSERT_EQUAL_VOID(g_testAtomicID03, i, g_testAtomicID03);
47     ICUNIT_ASSERT_EQUAL_VOID(ret, g_testAtomicID03, ret);
48 
49     LOS_AtomicAdd(&g_testCount, 1);
50 }
51 
TestCase(VOID)52 static UINT32 TestCase(VOID)
53 {
54     UINT32 ret;
55 
56     g_testAtomicID03 = 0;
57 
58     g_testCount = 0;
59 
60     TSK_INIT_PARAM_S stTask1 = {0};
61     stTask1.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskF01;
62     stTask1.pcName       = "Atomic_004";
63     stTask1.uwStackSize  = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
64     stTask1.usTaskPrio   = TASK_PRIO_TEST - 2; // TASK_PRIO_TEST - 2 has higher priority than TASK_PRIO_TEST
65     stTask1.uwResved     = LOS_TASK_STATUS_DETACHED;
66 
67     ret = LOS_TaskCreate(&g_testTaskID01, &stTask1);
68     ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
69     LOS_TaskDelay(5); // delay 5 ticks.
70 
71     ICUNIT_ASSERT_EQUAL(g_testCount, 1, g_testCount);
72 
73     return LOS_OK;
74 }
75 
76 /**
77  * @ingroup TEST_ATO
78  * @par TestCase_Number
79  * ItLosAtomic004
80  * @par TestCase_TestCase_Type
81  * Function test
82  * @brief Test interface LOS_AtomicIncRet 100 times.
83  * @par TestCase_Pretreatment_Condition
84  * NA.
85  * @par TestCase_Test_Steps
86  * step1: Invoke the LOS_AtomicIncRet interface 100 times in a task.
87  * @par TestCase_Expected_Result
88  * 1.LOS_AtomicIncRet return expected result.
89  * @par TestCase_Level
90  * Level 0
91  * @par TestCase_Automated
92  * true
93  * @par TestCase_Remark
94  * null
95  */
96 
ItLosAtomic004(VOID)97 VOID ItLosAtomic004(VOID)
98 {
99     TEST_ADD_CASE("ItLosAtomic004", TestCase, TEST_LOS, TEST_ATO, TEST_LEVEL0, TEST_FUNCTION);
100 }
101