feat: added assembly atomic interface

added 32-bit assembly atomic interface:

BREAKING CHANGE:
Assembly implementation:
    ArchAtomicRead
    ArchAtomicSet
    ArchAtomicAdd
    ArchAtomicSub
    ArchAtomicInc
    ArchAtomicIncRet
    ArchAtomicDec
    ArchAtomicDecRet

https://gitee.com/openharmony/kernel_liteos_m/issues/I4O1UC
Signed-off-by: wang-shulin93 <15173259956@163.com>
This commit is contained in:
ou-yangkan
2021-12-31 13:58:12 +08:00
parent 909a18ec8f
commit 1513f50a47
31 changed files with 4288 additions and 602 deletions

View File

@@ -0,0 +1,45 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
static_library("test_atomic") {
sources = [
"it_los_atomic.c",
"it_los_atomic_001.c",
"it_los_atomic_002.c",
"it_los_atomic_003.c",
"it_los_atomic_004.c",
"it_los_atomic_005.c",
"it_los_atomic_006.c",
"it_los_atomic_007.c",
"it_los_atomic_008.c",
"it_los_atomic_009.c",
]
include_dirs = [ "." ]
configs += [ "//kernel/liteos_m/testsuites:include" ]
}

View File

@@ -0,0 +1,61 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "it_los_atomic.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
Atomic g_testAtomicID03 = 0;
Atomic64 g_testAtomicID05 = 0;
VOID ItSuiteLosAtomic(VOID)
{
ItLosAtomic001();
ItLosAtomic002();
ItLosAtomic003();
ItLosAtomic004();
ItLosAtomic005();
ItLosAtomic006();
ItLosAtomic007();
ItLosAtomic008();
ItLosAtomic009();
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@@ -0,0 +1,66 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _IT_LOS_ATOMIC_H
#define _IT_LOS_ATOMIC_H
#include "osTest.h"
#include "los_atomic.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define ATOMIC_MUTI_TASK_NUM 3
extern Atomic g_testAtomicID03;
extern Atomic64 g_testAtomicID05;
extern VOID ItLosAtomic001(VOID);
extern VOID ItLosAtomic002(VOID);
extern VOID ItLosAtomic003(VOID);
extern VOID ItLosAtomic004(VOID);
extern VOID ItLosAtomic005(VOID);
extern VOID ItLosAtomic006(VOID);
extern VOID ItLosAtomic007(VOID);
extern VOID ItLosAtomic008(VOID);
extern VOID ItLosAtomic009(VOID);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _IT_LOS_ATOMIC_H */

View File

@@ -0,0 +1,92 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "it_los_atomic.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
static UINT32 TestCase(VOID)
{
volatile INT32 value = 0;
UINTPTR ret;
ret = LOS_AtomicDecRet(&value);
ICUNIT_ASSERT_EQUAL(value, ret, value);
ICUNIT_ASSERT_EQUAL(value, -1, value);
ret = LOS_AtomicDecRet(&value);
ICUNIT_ASSERT_EQUAL(value, ret, value);
ICUNIT_ASSERT_EQUAL(value, -0x02, value);
value = 0x7fffffff;
ret = LOS_AtomicDecRet(&value);
ICUNIT_ASSERT_EQUAL(value, ret, value);
ICUNIT_ASSERT_EQUAL(value, 0x7ffffffe, value);
return LOS_OK;
}
/**
* @ingroup TEST_ATO
* @par TestCase_Number
* ItLosAtomic001
* @par TestCase_TestCase_Type
* Function test
* @brief Test interface LOS_AtomicDecRet
* @par TestCase_Pretreatment_Condition
* NA.
* @par TestCase_Test_Steps
* step1: Invoke the LOS_AtomicDecRet interface.
* @par TestCase_Expected_Result
* 1.LOS_AtomicDecRet return expected result.
* @par TestCase_Level
* Level 0
* @par TestCase_Automated
* true
* @par TestCase_Remark
* null
*/
VOID ItLosAtomic001(VOID)
{
TEST_ADD_CASE("ItLosAtomic001", TestCase, TEST_LOS, TEST_ATO, TEST_LEVEL0, TEST_FUNCTION);
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@@ -0,0 +1,100 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "it_los_atomic.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
static UINT32 TestCase(VOID)
{
volatile INT32 value = 0;
UINT32 ret;
UINT32 newVal;
newVal = 0xff;
ret = LOS_AtomicXchg32bits(&value, newVal);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(value, 0xff, value);
newVal = 0xffff;
ret = LOS_AtomicXchg32bits(&value, newVal);
ICUNIT_ASSERT_EQUAL(ret, 0xff, ret);
ICUNIT_ASSERT_EQUAL(value, 0xffff, value);
newVal = 0xffffff;
ret = LOS_AtomicXchg32bits(&value, newVal);
ICUNIT_ASSERT_EQUAL(ret, 0xffff, ret);
ICUNIT_ASSERT_EQUAL(value, 0xffffff, value);
newVal = 0xffffffff;
ret = LOS_AtomicXchg32bits(&value, newVal);
ICUNIT_ASSERT_EQUAL(ret, 0xffffff, ret);
ICUNIT_ASSERT_EQUAL(value, 0xffffffff, value);
return LOS_OK;
}
/**
* @ingroup TEST_ATO
* @par TestCase_Number
* ItLosAtomic002
* @par TestCase_TestCase_Type
* Function test
* @brief Test interface LOS_AtomicXchg32bits
* @par TestCase_Pretreatment_Condition
* NA.
* @par TestCase_Test_Steps
* step1: Invoke the LOS_AtomicXchg32bits interface.
* @par TestCase_Expected_Result
* 1.LOS_AtomicXchg32bits return expected result.
* @par TestCase_Level
* Level 0
* @par TestCase_Automated
* true
* @par TestCase_Remark
* null
*/
VOID ItLosAtomic002(VOID)
{
TEST_ADD_CASE("ItLosAtomic002", TestCase, TEST_LOS, TEST_ATO, TEST_LEVEL0, TEST_FUNCTION);
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@@ -0,0 +1,114 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "it_los_atomic.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
static UINT32 TestCase(VOID)
{
volatile INT32 value = 0;
BOOL ret;
UINT32 newVal;
UINT32 oldVal;
newVal = 0xff;
oldVal = 1;
ret = LOS_AtomicCmpXchg32bits(&value, newVal, oldVal);
ICUNIT_ASSERT_EQUAL(ret, 1, ret);
ICUNIT_ASSERT_EQUAL(value, 0, value);
oldVal = 0;
ret = LOS_AtomicCmpXchg32bits(&value, newVal, oldVal);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(value, 0xff, value);
newVal = 0xffff;
oldVal = 1;
ret = LOS_AtomicCmpXchg32bits(&value, newVal, oldVal);
ICUNIT_ASSERT_EQUAL(ret, 1, ret);
ICUNIT_ASSERT_EQUAL(value, 0xff, value);
oldVal = 0xff;
ret = LOS_AtomicCmpXchg32bits(&value, newVal, oldVal);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(value, 0xffff, value);
newVal = 0xffffffff;
oldVal = 1;
ret = LOS_AtomicCmpXchg32bits(&value, newVal, oldVal);
ICUNIT_ASSERT_EQUAL(ret, 1, ret);
ICUNIT_ASSERT_EQUAL(value, 0xffff, value);
oldVal = 0xffff;
ret = LOS_AtomicCmpXchg32bits(&value, newVal, oldVal);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(value, 0xffffffff, value);
return LOS_OK;
}
/**
* @ingroup TEST_ATO
* @par TestCase_Number
* ItLosAtomic003
* @par TestCase_TestCase_Type
* Function test
* @brief Test interface LOS_AtomicCmpXchg32bits
* @par TestCase_Pretreatment_Condition
* NA.
* @par TestCase_Test_Steps
* step1: Invoke the LOS_AtomicCmpXchg32bits interface.
* @par TestCase_Expected_Result
* 1.LOS_AtomicCmpXchg32bits return expected result.
* @par TestCase_Level
* Level 0
* @par TestCase_Automated
* true
* @par TestCase_Remark
* null
*/
VOID ItLosAtomic003(VOID)
{
TEST_ADD_CASE("ItLosAtomic003", TestCase, TEST_LOS, TEST_ATO, TEST_LEVEL0, TEST_FUNCTION);
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@@ -0,0 +1,112 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "it_los_atomic.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
static VOID TaskF01(VOID)
{
INT32 i;
UINTPTR ret;
UINTPTR count;
for (i = 0; i < 100; ++i) { // run 100 times.
count = g_testAtomicID03;
ret = LOS_AtomicIncRet(&g_testAtomicID03);
ICUNIT_ASSERT_EQUAL_VOID(ret, g_testAtomicID03, ret);
ICUNIT_ASSERT_EQUAL_VOID((count + 1), g_testAtomicID03, (count + 1));
}
ICUNIT_ASSERT_EQUAL_VOID(g_testAtomicID03, i, g_testAtomicID03);
ICUNIT_ASSERT_EQUAL_VOID(ret, g_testAtomicID03, ret);
LOS_AtomicAdd(&g_testCount, 1);
}
static UINT32 TestCase(VOID)
{
UINT32 ret;
g_testAtomicID03 = 0;
g_testCount = 0;
TSK_INIT_PARAM_S stTask1 = {0};
stTask1.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskF01;
stTask1.pcName = "Atomic_004";
stTask1.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
stTask1.usTaskPrio = TASK_PRIO_TEST - 2; // TASK_PRIO_TEST - 2 has higher priority than TASK_PRIO_TEST
stTask1.uwResved = LOS_TASK_STATUS_DETACHED;
ret = LOS_TaskCreate(&g_testTaskID01, &stTask1);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
LOS_TaskDelay(5); // delay 5 ticks.
ICUNIT_ASSERT_EQUAL(g_testCount, 1, g_testCount);
return LOS_OK;
}
/**
* @ingroup TEST_ATO
* @par TestCase_Number
* ItLosAtomic004
* @par TestCase_TestCase_Type
* Function test
* @brief Test interface LOS_AtomicIncRet 100 times.
* @par TestCase_Pretreatment_Condition
* NA.
* @par TestCase_Test_Steps
* step1: Invoke the LOS_AtomicIncRet interface 100 times in a task.
* @par TestCase_Expected_Result
* 1.LOS_AtomicIncRet return expected result.
* @par TestCase_Level
* Level 0
* @par TestCase_Automated
* true
* @par TestCase_Remark
* null
*/
VOID ItLosAtomic004(VOID)
{
TEST_ADD_CASE("ItLosAtomic004", TestCase, TEST_LOS, TEST_ATO, TEST_LEVEL0, TEST_FUNCTION);
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@@ -0,0 +1,110 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "it_los_atomic.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
static UINT32 TestCase(VOID)
{
volatile INT64 value = 0;
UINT64 ret;
UINT64 uwNewVal;
uwNewVal = 0xff;
ret = LOS_AtomicXchg64bits(&value, uwNewVal);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(value, 0xff, value);
uwNewVal = 0xffff;
ret = LOS_AtomicXchg64bits(&value, uwNewVal);
ICUNIT_ASSERT_EQUAL(ret, 0xff, ret);
ICUNIT_ASSERT_EQUAL(value, 0xffff, value);
uwNewVal = 0xffffff;
ret = LOS_AtomicXchg64bits(&value, uwNewVal);
ICUNIT_ASSERT_EQUAL(ret, 0xffff, ret);
ICUNIT_ASSERT_EQUAL(value, 0xffffff, value);
uwNewVal = 0xffffffff;
ret = LOS_AtomicXchg64bits(&value, uwNewVal);
ICUNIT_ASSERT_EQUAL(ret, 0xffffff, ret);
ICUNIT_ASSERT_EQUAL(value, 0xffffffff, value);
uwNewVal = 0xffffffffffff;
ret = LOS_AtomicXchg64bits(&value, uwNewVal);
ICUNIT_ASSERT_EQUAL(ret, 0xffffffff, ret);
ICUNIT_ASSERT_EQUAL(value, 0xffffffffffff, value);
uwNewVal = 0xffffffffffffffff;
ret = LOS_AtomicXchg64bits(&value, uwNewVal);
ICUNIT_ASSERT_EQUAL(ret, 0xffffffffffff, ret);
ICUNIT_ASSERT_EQUAL(value, 0xffffffffffffffff, value);
return LOS_OK;
}
/**
* @ingroup TEST_ATO
* @par TestCase_Number
* ItLosAtomic005
* @par TestCase_TestCase_Type
* Function test
* @brief Test interface LOS_AtomicXchg64bits
* @par TestCase_Pretreatment_Condition
* NA.
* @par TestCase_Test_Steps
* step1: Invoke the LOS_AtomicXchg64bits interface.
* @par TestCase_Expected_Result
* 1.LOS_AtomicXchg64bits return expected result.
* @par TestCase_Level
* Level 0
* @par TestCase_Automated
* true
* @par TestCase_Remark
* null
*/
VOID ItLosAtomic005(VOID)
{
TEST_ADD_CASE("ItLosAtomic005", TestCase, TEST_LOS, TEST_ATO, TEST_LEVEL0, TEST_FUNCTION);
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@@ -0,0 +1,134 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "it_los_atomic.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
static UINT32 TestCase(VOID)
{
volatile INT64 value = 0;
BOOL ret;
UINT64 newVal = 0xff;
UINT64 oldVal = 1;
ret = LOS_AtomicCmpXchg64bits(&value, newVal, oldVal);
ICUNIT_ASSERT_EQUAL(ret, 1, ret);
ICUNIT_ASSERT_EQUAL(value, 0, value);
oldVal = 0;
ret = LOS_AtomicCmpXchg64bits(&value, newVal, oldVal);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(value, 0xff, value);
newVal = 0xffff;
oldVal = 1;
ret = LOS_AtomicCmpXchg64bits(&value, newVal, oldVal);
ICUNIT_ASSERT_EQUAL(ret, 1, ret);
ICUNIT_ASSERT_EQUAL(value, 0xff, value);
oldVal = 0xff;
ret = LOS_AtomicCmpXchg64bits(&value, newVal, oldVal);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(value, 0xffff, value);
newVal = 0xffffffff;
oldVal = 1;
ret = LOS_AtomicCmpXchg64bits(&value, newVal, oldVal);
ICUNIT_ASSERT_EQUAL(ret, 1, ret);
ICUNIT_ASSERT_EQUAL(value, 0xffff, value);
oldVal = 0xffff;
ret = LOS_AtomicCmpXchg64bits(&value, newVal, oldVal);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(value, 0xffffffff, value);
newVal = 0xffffffffffff;
oldVal = 1;
ret = LOS_AtomicCmpXchg64bits(&value, newVal, oldVal);
ICUNIT_ASSERT_EQUAL(ret, 1, ret);
ICUNIT_ASSERT_EQUAL(value, 0xffffffff, value);
oldVal = 0xffffffff;
ret = LOS_AtomicCmpXchg64bits(&value, newVal, oldVal);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(value, 0xffffffffffff, value);
newVal = 0xffffffffffffffff;
oldVal = 1;
ret = LOS_AtomicCmpXchg64bits(&value, newVal, oldVal);
ICUNIT_ASSERT_EQUAL(ret, 1, ret);
ICUNIT_ASSERT_EQUAL(value, 0xffffffffffff, value);
oldVal = 0xffffffffffff;
ret = LOS_AtomicCmpXchg64bits(&value, newVal, oldVal);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(value, 0xffffffffffffffff, value);
return LOS_OK;
}
/**
* @ingroup TEST_ATO
* @par TestCase_Number
* ItLosAtomic006
* @par TestCase_TestCase_Type
* Function test
* @brief Test interface LOS_AtomicCmpXchg64bits
* @par TestCase_Pretreatment_Condition
* NA.
* @par TestCase_Test_Steps
* step1: Invoke the LOS_AtomicCmpXchg64bits interface.
* @par TestCase_Expected_Result
* 1.LOS_AtomicCmpXchg64bits return expected result.
* @par TestCase_Level
* Level 0
* @par TestCase_Automated
* true
* @par TestCase_Remark
* null
*/
VOID ItLosAtomic006(VOID)
{
TEST_ADD_CASE("ItLosAtomic006", TestCase, TEST_LOS, TEST_ATO, TEST_LEVEL0, TEST_FUNCTION);
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@@ -0,0 +1,118 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "it_los_atomic.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
static VOID TaskF01(VOID)
{
INT64 i;
for (i = 0x7fffffffffff0000; i < 0x7fffffffffff000f; ++i) {
LOS_AtomicXchg64bits(&g_testAtomicID05, i);
}
++g_testCount;
}
static UINT32 TestCase(VOID)
{
UINT32 ret, i;
UINT32 taskId[ATOMIC_MUTI_TASK_NUM];
TSK_INIT_PARAM_S task[ATOMIC_MUTI_TASK_NUM] = {0, };
CHAR taskName[ATOMIC_MUTI_TASK_NUM][20] = {"", }; // max taskName size is 20.
CHAR buf[10] = ""; // max buf size is 10.
g_testCount = 0;
g_testAtomicID05 = 0;
for (i = 0; i < ATOMIC_MUTI_TASK_NUM; i++) {
memset(buf, 0, 10); // max buf size is 10.
memset(taskName[i], 0, 20); // max taskName size is 20.
task[i].pfnTaskEntry = (TSK_ENTRY_FUNC)TaskF01;
task[i].pcName = taskName[i];
task[i].uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
task[i].usTaskPrio = TASK_PRIO_TEST - 2; // TASK_PRIO_TEST - 2 has higher priority than TASK_PRIO_TEST
task[i].uwResved = LOS_TASK_STATUS_DETACHED;
}
for (i = 0; i < ATOMIC_MUTI_TASK_NUM; i++) {
ret = LOS_TaskCreate(&taskId[i], &task[i]);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
}
LOS_TaskDelay(20); // delay 20 ticks.
ICUNIT_GOTO_EQUAL(g_testCount, ATOMIC_MUTI_TASK_NUM, g_testCount, EXIT);
ICUNIT_GOTO_EQUAL(g_testAtomicID05, 0x7fffffffffff000e, g_testAtomicID05, EXIT);
EXIT:
for (i = 0; i < ATOMIC_MUTI_TASK_NUM; i++) {
(VOID)LOS_TaskDelete(taskId[i]);
}
return LOS_OK;
}
/**
* @ingroup TEST_ATO
* @par TestCase_Number
* ItLosAtomic007
* @par TestCase_TestCase_Type
* Function test
* @brief Test interface LOS_AtomicXchg64bits
* @par TestCase_Pretreatment_Condition
* NA.
* @par TestCase_Test_Steps
* step1: Invoke the LOS_AtomicXchg64bits interface in different task.
* @par TestCase_Expected_Result
* 1.LOS_AtomicXchg64bits return expected result.
* @par TestCase_Level
* Level 0
* @par TestCase_Automated
* true
* @par TestCase_Remark
* null
*/
VOID ItLosAtomic007(VOID)
{
TEST_ADD_CASE("ItLosAtomic007", TestCase, TEST_LOS, TEST_ATO, TEST_LEVEL0, TEST_FUNCTION);
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@@ -0,0 +1,121 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "it_los_atomic.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
static VOID TaskF01(VOID)
{
INT64 i;
INT64 count;
for (i = 0x7fffffffffff0000; i < 0x7fffffffffffffff; ++i) {
count = g_testAtomicID05;
LOS_AtomicCmpXchg64bits(&g_testAtomicID05, i, count);
}
++g_testCount;
}
static UINT32 TestCase(VOID)
{
UINT32 ret, i;
UINT32 taskId[ATOMIC_MUTI_TASK_NUM];
TSK_INIT_PARAM_S task[ATOMIC_MUTI_TASK_NUM] = {0, };
CHAR taskName[ATOMIC_MUTI_TASK_NUM][20] = {"", }; // max taskName size is 20.
CHAR buf[10] = ""; // max buf size is 10.
g_testCount = 0;
g_testAtomicID05 = 0;
for (i = 0; i < ATOMIC_MUTI_TASK_NUM; i++) {
memset(buf, 0, 10); // max buf size is 10.
memset(taskName[i], 0, 20); // max taskName size is 20.
task[i].pfnTaskEntry = (TSK_ENTRY_FUNC)TaskF01;
task[i].pcName = taskName[i];
task[i].uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
task[i].usTaskPrio = TASK_PRIO_TEST - 2; // TASK_PRIO_TEST - 2 has higher priority than TASK_PRIO_TEST
task[i].uwResved = LOS_TASK_STATUS_DETACHED;
}
for (i = 0; i < ATOMIC_MUTI_TASK_NUM; i++) {
ret = LOS_TaskCreate(&taskId[i], &task[i]);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
}
LOS_TaskDelay(80); // delay 80 ticks.
ICUNIT_GOTO_EQUAL(g_testCount, ATOMIC_MUTI_TASK_NUM, g_testCount, EXIT);
ICUNIT_GOTO_EQUAL(g_testAtomicID05, (0x7fffffffffffffff - 1), g_testAtomicID05, EXIT);
EXIT:
for (i = 0; i < ATOMIC_MUTI_TASK_NUM; i++) {
(VOID)LOS_TaskDelete(taskId[i]);
}
return LOS_OK;
}
/**
* @ingroup TEST_ATO
* @par TestCase_Number
* ItLosAtomic008
* @par TestCase_TestCase_Type
* Function test
* @brief Test interface LOS_AtomicCmpXchg64bits
* @par TestCase_Pretreatment_Condition
* NA.
* @par TestCase_Test_Steps
* step1: Invoke the LOS_AtomicCmpXchg64bits interface in different task.
* @par TestCase_Expected_Result
* 1.LOS_AtomicCmpXchg64bits return expected result.
* @par TestCase_Level
* Level 0
* @par TestCase_Automated
* true
* @par TestCase_Remark
* null
*/
VOID ItLosAtomic008(VOID)
{
TEST_ADD_CASE("ItLosAtomic008", TestCase, TEST_LOS, TEST_ATO, TEST_LEVEL0, TEST_FUNCTION);
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@@ -0,0 +1,140 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "it_los_atomic.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define DB_ATOMIC_MUTI_TASK_NUM (ATOMIC_MUTI_TASK_NUM * 2) // 2 is coefficients
static VOID TaskF01(VOID)
{
UINT32 i;
for (i = 0; i < 10; ++i) { // run 10 times.
LOS_Atomic64Dec(&g_testAtomicID05);
}
++g_testCount;
}
static VOID TaskF02(VOID)
{
UINT64 i;
for (i = 0; i < 10; ++i) { // run 10 times.
LOS_AtomicCmpXchg64bits(&g_testAtomicID05, g_testAtomicID05, g_testAtomicID05);
}
++g_testCount;
}
static UINT32 TestCase(VOID)
{
UINT32 ret, i;
UINT32 taskId[DB_ATOMIC_MUTI_TASK_NUM];
TSK_INIT_PARAM_S task[DB_ATOMIC_MUTI_TASK_NUM] = {0, };
CHAR taskName[DB_ATOMIC_MUTI_TASK_NUM][20] = {"", }; // max taskName size is 20.
CHAR buf[10] = ""; // max buf size is 10.
Atomic uCount = 0;
g_testCount = 0;
g_testAtomicID05 = 0xffffffffff;
UINT32 uLoop = g_taskMaxNum - TASK_EXISTED_NUM;
if (uLoop > DB_ATOMIC_MUTI_TASK_NUM) {
uLoop = DB_ATOMIC_MUTI_TASK_NUM;
}
for (i = 0; i < uLoop; i++) {
memset(buf, 0, 10); // max buf size is 10.
memset(taskName[i], 0, 20); // max taskName size is 20.
if (i % 2 == 0) { // 2 is index.
uCount++;
task[i].pfnTaskEntry = (TSK_ENTRY_FUNC)TaskF01;
} else {
task[i].pfnTaskEntry = (TSK_ENTRY_FUNC)TaskF02;
}
task[i].pcName = taskName[i];
task[i].uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
task[i].usTaskPrio = TASK_PRIO_TEST - 2; // TASK_PRIO_TEST - 2 has higher priority than TASK_PRIO_TEST
task[i].uwResved = LOS_TASK_STATUS_DETACHED;
}
for (i = 0; i < uLoop; i++) {
ret = LOS_TaskCreate(&taskId[i], &task[i]);
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
}
LOS_TaskDelay(20); // delay 20 ticks.
ICUNIT_GOTO_EQUAL(g_testCount, uLoop, g_testCount, EXIT);
ICUNIT_GOTO_EQUAL(g_testAtomicID05, (0xffffffffff - 10 * uCount), g_testAtomicID05, EXIT); // run 10 times.
EXIT:
for (i = 0; i < uLoop; i++) {
(VOID)LOS_TaskDelete(taskId[i]);
}
return LOS_OK;
}
/**
* @ingroup TEST_ATO
* @par TestCase_Number
* ItLosAtomic009
* @par TestCase_TestCase_Type
* Function test
* @brief Test interface LOS_Atomic64Dec and LOS_AtomicCmpXchg64bits in different task.
* @par TestCase_Pretreatment_Condition
* NA.
* @par TestCase_Test_Steps
* step1: Invoke the LOS_Atomic64Dec interface in TaskF01.
* step2: Invoke the LOS_AtomicCmpXchg64bits interface in TaskF02.
* @par TestCase_Expected_Result
* 1.LOS_Atomic64Dec and LOS_AtomicCmpXchg64bits return expected result.
* @par TestCase_Level
* Level 0
* @par TestCase_Automated
* true
* @par TestCase_Remark
* null
*/
VOID ItLosAtomic009(VOID)
{
TEST_ADD_CASE("ItLosAtomic009", TestCase, TEST_LOS, TEST_ATO, TEST_LEVEL0, TEST_FUNCTION);
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */