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 INT64 i;
38 INT64 count;
39 for (i = 0x7fffffffffff0000; i < 0x7fffffffffffffff; ++i) {
40 count = g_testAtomicID05;
41 LOS_AtomicCmpXchg64bits(&g_testAtomicID05, i, count);
42 }
43
44 ++g_testCount;
45 }
46
TestCase(VOID)47 static UINT32 TestCase(VOID)
48 {
49 UINT32 ret, i;
50 UINT32 taskId[ATOMIC_MUTI_TASK_NUM];
51 TSK_INIT_PARAM_S task[ATOMIC_MUTI_TASK_NUM] = {0, };
52 CHAR taskName[ATOMIC_MUTI_TASK_NUM][20] = {"", }; // max taskName size is 20.
53 CHAR buf[10] = ""; // max buf size is 10.
54
55 g_testCount = 0;
56 g_testAtomicID05 = 0;
57
58 for (i = 0; i < ATOMIC_MUTI_TASK_NUM; i++) {
59 ret = memset_s(buf, 10, 0, 10); // max buf size is 10.
60 ICUNIT_ASSERT_EQUAL(ret, 0, ret);
61 ret = memset_s(taskName[i], 20, 0, 20); // max taskName size is 20.
62 ICUNIT_ASSERT_EQUAL(ret, 0, ret);
63 task[i].pfnTaskEntry = (TSK_ENTRY_FUNC)TaskF01;
64 task[i].pcName = taskName[i];
65 task[i].uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
66 task[i].usTaskPrio = TASK_PRIO_TEST - 2; // TASK_PRIO_TEST - 2 has higher priority than TASK_PRIO_TEST
67 task[i].uwResved = LOS_TASK_STATUS_DETACHED;
68 }
69
70 for (i = 0; i < ATOMIC_MUTI_TASK_NUM; i++) {
71 ret = LOS_TaskCreate(&taskId[i], &task[i]);
72 ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
73 }
74
75 LOS_TaskDelay(80); // delay 80 ticks.
76
77 ICUNIT_GOTO_EQUAL(g_testCount, ATOMIC_MUTI_TASK_NUM, g_testCount, EXIT);
78 ICUNIT_GOTO_EQUAL(g_testAtomicID05, (0x7fffffffffffffff - 1), g_testAtomicID05, EXIT);
79 EXIT:
80 for (i = 0; i < ATOMIC_MUTI_TASK_NUM; i++) {
81 (VOID)LOS_TaskDelete(taskId[i]);
82 }
83 return LOS_OK;
84 }
85
86 /**
87 * @ingroup TEST_ATO
88 * @par TestCase_Number
89 * ItLosAtomic008
90 * @par TestCase_TestCase_Type
91 * Function test
92 * @brief Test interface LOS_AtomicCmpXchg64bits
93 * @par TestCase_Pretreatment_Condition
94 * NA.
95 * @par TestCase_Test_Steps
96 * step1: Invoke the LOS_AtomicCmpXchg64bits interface in different task.
97 * @par TestCase_Expected_Result
98 * 1.LOS_AtomicCmpXchg64bits return expected result.
99 * @par TestCase_Level
100 * Level 0
101 * @par TestCase_Automated
102 * true
103 * @par TestCase_Remark
104 * null
105 */
106
ItLosAtomic008(VOID)107 VOID ItLosAtomic008(VOID)
108 {
109 TEST_ADD_CASE("ItLosAtomic008", TestCase, TEST_LOS, TEST_ATO, TEST_LEVEL0, TEST_FUNCTION);
110 }
111