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