feat: 支持native动态加载组件

1.【需求描述】
动态库开发部分:
gcc的sample code。
提供生成暴露接口生成机制,并允许产品新增需要暴露的接口。
提供可以判断库允许资源大小的能力,并提供相关工具辅助开发者确定开发的库要求的资源是否可以满足。

动态库运行部分:
提供elf load的api,可以加载指定路径下的库,并完成符号重映射等运行准备。
提供elf 暴露符号调用的api,用于调用库的api。
elf加载&链接异常时,有明确错误记录,返回明确错误类型。
提供elf 卸载的api。

2.【方案描述】
(1) 通过灌段的形式记录需要导出符号的地址信息,用于暴露内核对外的接口,在加载链接器中通过查询
对应的符号信息获取符号地址。
(2) 加载链接时,解析共享库并将共享库中可加载段通过文件系统读入内存中,并对共享库中未定义的、
需要重定位的符号进行重定位。需要调用符号时,根据符号名通过哈希表即可查询共享库提供的对应符号
的地址。

BREAKING CHANGE:
新增4个对外接口,声明在los_dynlink.h文件中,分别为:
(1) LOS_DynlinkInit: 动态加载模块初始化。
(2) LOS_SoLoad: 加载指定路径的共享库。
(3) LOS_FindSym: 根据共享库句柄查找指定符号。
(4) LOS_SoUnload: 卸载共享库。

close #I418HJ

Signed-off-by: Haryslee <lihao189@huawei.com>
Change-Id: I7669b7ef20096294f9d1094c85ac6602fefad354
This commit is contained in:
Haryslee
2021-07-18 16:47:24 +08:00
parent 7fe9cc9aa0
commit d75383400e
56 changed files with 3160 additions and 65 deletions

View File

@@ -0,0 +1,38 @@
# Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
static_library("test_dynlink") {
sources = [
"It_los_dynlink.c",
"It_los_dynlink_001.c",
"It_los_dynlink_002.c",
"It_los_dynlink_003.c",
"It_los_dynlink_004.c",
"It_los_dynlink_005.c",
"It_los_dynlink_006.c",
"It_los_dynlink_007.c",
"It_los_dynlink_008.c",
"It_los_dynlink_009.c",
"It_los_dynlink_010.c",
"It_los_dynlink_011.c",
"It_los_dynlink_012.c",
"It_los_dynlink_013.c",
"It_los_dynlink_014.c",
"It_los_dynlink_015.c",
"It_los_dynlink_016.c",
"It_los_dynlink_017.c",
"It_los_dynlink_018.c",
"It_los_dynlink_019.c",
"It_los_dynlink_020.c",
]
include_dirs = [
"../../../../kernel/include",
"../../../../kernel/arch/include",
"../../../include",
"../../../../utils",
"../../../../components/dynlink",
".",
"../../../../components/cpup",
"//third_party/bounds_checking_function/include",
]
}

View File

@@ -0,0 +1,54 @@
/*
* Copyright (c) 2021-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_dynlink.h"
VOID ItSuiteLosDynlink(VOID)
{
ItLosDynlink001();
ItLosDynlink002();
ItLosDynlink003();
ItLosDynlink004();
ItLosDynlink005();
ItLosDynlink006();
ItLosDynlink007();
ItLosDynlink008();
ItLosDynlink009();
ItLosDynlink010();
ItLosDynlink011();
ItLosDynlink012();
ItLosDynlink013();
ItLosDynlink014();
ItLosDynlink015();
ItLosDynlink016();
ItLosDynlink017();
ItLosDynlink018();
ItLosDynlink019();
ItLosDynlink020();
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 2021-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_DYNLINK_H
#define IT_LOS_DYNLINK_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#include "iCunit.h"
#define DSO_PATH "/music/"
#define DSO_FULL_PATH(p) DSO_PATH p
VOID ItLosDynlink001(VOID);
VOID ItLosDynlink002(VOID);
VOID ItLosDynlink003(VOID);
VOID ItLosDynlink004(VOID);
VOID ItLosDynlink005(VOID);
VOID ItLosDynlink006(VOID);
VOID ItLosDynlink007(VOID);
VOID ItLosDynlink008(VOID);
VOID ItLosDynlink009(VOID);
VOID ItLosDynlink010(VOID);
VOID ItLosDynlink012(VOID);
VOID ItLosDynlink013(VOID);
VOID ItLosDynlink014(VOID);
VOID ItLosDynlink015(VOID);
VOID ItLosDynlink016(VOID);
VOID ItLosDynlink017(VOID);
VOID ItLosDynlink018(VOID);
VOID ItLosDynlink019(VOID);
VOID ItLosDynlink020(VOID);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _IT_LOS_DYNLINK_H */

View File

@@ -0,0 +1,55 @@
/*
* Copyright (c) 2021-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 "los_dynlink.h"
#include "It_los_dynlink.h"
/* Test invalid param */
STATIC UINT32 TestCase(VOID)
{
INT32 ret;
VOID *handle = NULL;
INT32 (*func)(INT32 ,INT32) = NULL;
handle = (VOID *)LOS_SoLoad(NULL, NULL);
ICUNIT_ASSERT_EQUAL(handle, NULL, handle);
func = (INT32 (*)(INT32, INT32))LOS_FindSym(NULL, NULL);
ICUNIT_ASSERT_EQUAL(func, NULL, func);
ret = LOS_SoUnload(NULL);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
return LOS_OK;
}
VOID ItLosDynlink001(VOID)
{
TEST_ADD_CASE("ItLosDynlink001", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright (c) 2021-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 "los_dynlink.h"
#include "It_los_dynlink.h"
/* Test invalide params */
STATIC UINT32 TestCase(VOID)
{
VOID *handle = NULL;
VOID *invalHandle = NULL;
INT32 (*func)(INT32, INT32) = NULL;
CHAR *symbolName = "test_api";
CHAR *dsoName = DSO_FULL_PATH("Align4_dynamic_align4.so");
INT32 ret;
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle);
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, NULL);
ICUNIT_GOTO_EQUAL(func, NULL, func, EXIT);
func = (INT32 (*)(INT32, INT32))LOS_FindSym(NULL, symbolName);
ICUNIT_GOTO_EQUAL(func, NULL, func, EXIT);
invalHandle = handle + 1;
func = (INT32 (*)(INT32, INT32))LOS_FindSym(invalHandle, symbolName);
ICUNIT_GOTO_EQUAL(func, NULL, func, EXIT);
ret = LOS_SoUnload(invalHandle);
ICUNIT_GOTO_NOT_EQUAL(ret, 0, ret, EXIT);
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, symbolName);
ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT);
EXIT:
ret = LOS_SoUnload(handle);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return LOS_OK;
}
VOID ItLosDynlink002(VOID)
{
TEST_ADD_CASE("ItLosDynlink002", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright (c) 2021-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 "los_dynlink.h"
#include "It_los_dynlink.h"
/* Test dso name of too long length */
STATIC UINT32 TestCase(VOID)
{
VOID *handle = NULL;
CHAR name[PATH_MAX + 2];
(VOID)memset_s(name, PATH_MAX + 1, 'a', PATH_MAX + 1);
name[PATH_MAX + 1] = '\0';
handle = (VOID *)LOS_SoLoad(name, NULL);
ICUNIT_ASSERT_EQUAL(handle, NULL, handle);
return LOS_OK;
}
VOID ItLosDynlink003(VOID)
{
TEST_ADD_CASE("ItLosDynlink003", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright (c) 2021-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 "los_dynlink.h"
#include "It_los_dynlink.h"
/* Test shell script, shared library with ET_EXE flag, shared library with UNIX flag, or bad phdr */
STATIC UINT32 TestCase(VOID)
{
VOID *handle = NULL;
CHAR *shellName = DSO_FULL_PATH("shell.sh");
CHAR *execName = DSO_FULL_PATH("Align4_dynamic_exec.so");
CHAR *x86Name = DSO_FULL_PATH("Align4_dynamic_x86.so");
handle = (VOID *)LOS_SoLoad(shellName, NULL);
ICUNIT_ASSERT_EQUAL(handle, NULL, handle);
handle = (VOID *)LOS_SoLoad(execName, NULL);
ICUNIT_ASSERT_EQUAL(handle, NULL, handle);
handle = (VOID *)LOS_SoLoad(x86Name, NULL);
ICUNIT_ASSERT_EQUAL(handle, NULL, handle);
return LOS_OK;
}
VOID ItLosDynlink004(VOID)
{
TEST_ADD_CASE("ItLosDynlink004", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (c) 2021-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 "los_dynlink.h"
#include "It_los_dynlink.h"
/* Test shared library with TLS or of align 0x1000 or without dynamic segment */
STATIC UINT32 TestCase(VOID)
{
VOID *handle = NULL;
CHAR *dsoNeedOthers = DSO_FULL_PATH("Align4_dynamic_need_others.so");
CHAR *dsoWithoutPIC = DSO_FULL_PATH("Align4_dynamic_nopic.so");
INT32 ret;
handle = (VOID *)LOS_SoLoad(dsoNeedOthers, NULL);
ICUNIT_ASSERT_EQUAL(handle, NULL, handle);
handle = (VOID *)LOS_SoLoad(dsoWithoutPIC, NULL);
ICUNIT_ASSERT_EQUAL(handle, NULL, handle);
return LOS_OK;
}
VOID ItLosDynlink005(VOID)
{
TEST_ADD_CASE("ItLosDynlink005", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright (c) 2021-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 "los_dynlink.h"
#include "It_los_dynlink.h"
/* Test symbol not found for reloc, it's upto shared library */
STATIC UINT32 TestCase(VOID)
{
VOID *handle = NULL;
CHAR *dsoNameUndVal = DSO_FULL_PATH("dynamic_undval.so");
CHAR *dsoNameUndFunc = DSO_FULL_PATH("dynamic_undfunc.so");
handle = (VOID *)LOS_SoLoad(dsoNameUndVal, NULL);
ICUNIT_ASSERT_EQUAL(handle, NULL, handle);
handle = (VOID *)LOS_SoLoad(dsoNameUndFunc, NULL);
ICUNIT_ASSERT_EQUAL(handle, NULL, handle);
return LOS_OK;
}
VOID ItLosDynlink006(VOID)
{
TEST_ADD_CASE("ItLosDynlink006", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright (c) 2021-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 "los_dynlink.h"
#include "It_los_dynlink.h"
/* Test pie */
STATIC UINT32 TestCase(VOID)
{
VOID *handle = NULL;
INT32 (*func)(INT32, INT32) = NULL;
INT32 ret;
CHAR *dsoName = DSO_FULL_PATH("Align4_dynamic_pie.so");
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle);
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, "test_api");
ICUNIT_GOTO_EQUAL(func, NULL, func, EXIT);
EXIT:
ret = LOS_SoUnload(handle);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return LOS_OK;
}
VOID ItLosDynlink007(VOID)
{
TEST_ADD_CASE("ItLosDynlink007", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
}

View File

@@ -0,0 +1,82 @@
/*
* Copyright (c) 2021-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 "los_dynlink.h"
#include "It_los_dynlink.h"
/* Test symbol not found */
STATIC UINT32 TestCase(VOID)
{
VOID *handle = NULL;
INT32 (*func)(INT32, INT32) = NULL;
CHAR *invalSymName1 = "A_invalid_api";
CHAR *invalSymName2 = "N_invalid_api";
CHAR *invalSymName3 = "Z_invalid_api";
CHAR *invalSymName4 = "a_invalid_api";
CHAR *invalSymName5 = "o_invalid_api";
CHAR *invalSymName6 = "z_invalid_api";
CHAR *invalSymName7 = "LOS_InvalidApi";
CHAR *dsoName = DSO_FULL_PATH("Align4_dynamic_align4.so");
INT32 ret;
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle);
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, invalSymName1);
ICUNIT_GOTO_EQUAL(func, NULL, func, EXIT);
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, invalSymName2);
ICUNIT_GOTO_EQUAL(func, NULL, func, EXIT);
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, invalSymName3);
ICUNIT_GOTO_EQUAL(func, NULL, func, EXIT);
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, invalSymName4);
ICUNIT_GOTO_EQUAL(func, NULL, func, EXIT);
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, invalSymName5);
ICUNIT_GOTO_EQUAL(func, NULL, func, EXIT);
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, invalSymName6);
ICUNIT_GOTO_EQUAL(func, NULL, func, EXIT);
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, invalSymName7);
ICUNIT_GOTO_EQUAL(func, NULL, func, EXIT);
EXIT:
ret = LOS_SoUnload(handle);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return LOS_OK;
}
VOID ItLosDynlink008(VOID)
{
TEST_ADD_CASE("ItLosDynlink008", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
}

View File

@@ -0,0 +1,61 @@
/*
* Copyright (c) 2021-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 "los_dynlink.h"
#include "It_los_dynlink.h"
/* Test Align4_dynamic_align4.so */
STATIC UINT32 TestCase(VOID)
{
VOID *handle = NULL;
INT32 (*func)(INT32, INT32) = NULL;
CHAR *symbolName = "test_api";
CHAR *dsoName = DSO_FULL_PATH("Align4_dynamic_align4.so");
INT32 ret;
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle);
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, symbolName);
ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT);
ret = func(1, 1);
ICUNIT_GOTO_EQUAL(ret, 14, ret, EXIT);
EXIT:
ret = LOS_SoUnload(handle);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return LOS_OK;
}
VOID ItLosDynlink009(VOID)
{
TEST_ADD_CASE("ItLosDynlink009", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
}

View File

@@ -0,0 +1,84 @@
/*
* Copyright (c) 2021-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 "los_dynlink.h"
#include "It_los_dynlink.h"
/* Test Align4_dynamic_align4.so */
STATIC UINT32 TestCase(VOID)
{
VOID *handle1 = NULL;
VOID *handle2 = NULL;
INT32 (*func)(INT32, INT32) = NULL;
CHAR *symbolName = "test_api";
CHAR *dsoName = DSO_FULL_PATH("Align4_dynamic_align4.so");
INT32 ret;
handle1 = (VOID *)LOS_SoLoad(dsoName, NULL);
ICUNIT_ASSERT_NOT_EQUAL(handle1, NULL, handle1);
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle1, symbolName);
ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT1);
ret = func(1, 1);
ICUNIT_GOTO_EQUAL(ret, 14, ret, EXIT1);
handle2 = (VOID *)LOS_SoLoad(dsoName, NULL);
ICUNIT_GOTO_NOT_EQUAL(handle2, NULL, handle2, EXIT1);
ICUNIT_GOTO_EQUAL(handle1, handle2, handle2, EXIT2);
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle2, symbolName);
ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT2);
ret = func(1, 1);
ICUNIT_GOTO_EQUAL(ret, 14, ret, EXIT2);
ret = LOS_SoUnload(handle2);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1);
ret = LOS_SoUnload(handle1);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = LOS_SoUnload(handle1);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
return LOS_OK;
EXIT2:
ret = LOS_SoUnload(handle2);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
EXIT1:
ret = LOS_SoUnload(handle1);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return LOS_OK;
}
VOID ItLosDynlink010(VOID)
{
TEST_ADD_CASE("ItLosDynlink010", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
}

View File

@@ -0,0 +1,65 @@
/*
* Copyright (c) 2021-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 "los_dynlink.h"
#include "It_los_dynlink.h"
/* Test that bss segment in dynamic_bss.so */
STATIC UINT32 TestCase(VOID)
{
VOID *handle = NULL;
INT32 (*func)() = NULL;
INT32 *pValue = NULL;
CHAR *symbolName1 = "dyn_bss_func";
CHAR *symbolName2 = "test_array";
CHAR *dsoName = DSO_FULL_PATH("dynamic_bss.so");
INT32 ret;
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle);
func = (INT32 (*)())LOS_FindSym(handle, symbolName1);
ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT);
ret = func();
ICUNIT_GOTO_EQUAL(ret, 2117, ret, EXIT);
pValue = LOS_FindSym(handle, symbolName2);
ICUNIT_GOTO_NOT_EQUAL(pValue, NULL, pValue, EXIT);
EXIT:
ret = LOS_SoUnload(handle);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return LOS_OK;
}
VOID ItLosDynlink011(VOID)
{
TEST_ADD_CASE("ItLosDynlink011", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright (c) 2021-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 "los_dynlink.h"
#include "It_los_dynlink.h"
/* Test that global symbol int dynamic_static.so */
STATIC UINT32 TestCase(VOID)
{
VOID *handle = NULL;
INT32 (*func)(INT32, INT32) = NULL;
CHAR *symbolName = "add_test";
CHAR *dsoName = DSO_FULL_PATH("dynamic_static.so");
INT32 ret;
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle);
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, symbolName);
ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT);
ret = func(2000, 16);
ICUNIT_GOTO_EQUAL(ret, 2017, ret, EXIT);
ret = func(2017, -1);
ICUNIT_GOTO_EQUAL(ret, 2017, ret, EXIT);
EXIT:
ret = LOS_SoUnload(handle);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return LOS_OK;
}
VOID ItLosDynlink012(VOID)
{
TEST_ADD_CASE("ItLosDynlink012", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
}

View File

@@ -0,0 +1,87 @@
/*
* Copyright (c) 2021-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 "los_dynlink.h"
#include "It_los_dynlink.h"
/* Test that function and value to find int dynamic_xxxxx.so */
STATIC UINT32 TestCase(VOID)
{
VOID *handle = NULL;
INT32 (*func)() = NULL;
INT32 *pValueAddr = NULL;
INT32 **ppValueAddr = NULL;
CHAR *symbolName1 = "get_value100";
CHAR *symbolName2 = "get_value200";
CHAR *symbolName3 = "g_value100";
CHAR *symbolName4 = "g_pValue100";
CHAR *symbolName5 = "pValue200";
CHAR *symbolName6 = "g_pValue200";
CHAR *dsoName = DSO_FULL_PATH("dynamic_xxxxx.so");
INT32 ret;
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle);
func = (INT32 (*)())LOS_FindSym(handle, symbolName1);
ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT);
ret = func();
ICUNIT_GOTO_EQUAL(ret, 100, ret, EXIT);
func = (INT32 (*)())LOS_FindSym(handle, symbolName2);
ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT);
ret = func();
ICUNIT_GOTO_EQUAL(ret, 200, ret, EXIT);
pValueAddr = LOS_FindSym(handle, symbolName3);
ICUNIT_GOTO_NOT_EQUAL(pValueAddr, NULL, pValueAddr, EXIT);
ICUNIT_GOTO_EQUAL(*pValueAddr, 100, *pValueAddr, EXIT);
ppValueAddr = LOS_FindSym(handle, symbolName4);
ICUNIT_GOTO_NOT_EQUAL(ppValueAddr, NULL, ppValueAddr, EXIT);
ICUNIT_GOTO_EQUAL(**ppValueAddr, 100, **ppValueAddr, EXIT);
pValueAddr = LOS_FindSym(handle, symbolName5);
ICUNIT_GOTO_EQUAL(pValueAddr, NULL, pValueAddr, EXIT);
ppValueAddr = LOS_FindSym(handle, symbolName6);
ICUNIT_GOTO_NOT_EQUAL(ppValueAddr, NULL, ppValueAddr, EXIT);
ICUNIT_GOTO_EQUAL(**ppValueAddr, 200, **ppValueAddr, EXIT);
EXIT:
ret = LOS_SoUnload(handle);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return LOS_OK;
}
VOID ItLosDynlink013(VOID)
{
TEST_ADD_CASE("ItLosDynlink013", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
}

View File

@@ -0,0 +1,75 @@
/*
* Copyright (c) 2021-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 "los_dynlink.h"
#include "It_los_dynlink.h"
/* Test that global and static symbol to find */
STATIC UINT32 TestCase(VOID)
{
VOID *handle = NULL;
INT32 (*func)(INT32, INT32) = NULL;
INT32 *pValueAddr = NULL;
INT32 *pStaticValueAddr = NULL;
CHAR *symbolName1 = "add_test";
CHAR *symbolName2 = "static_sub_test";
CHAR *symbolName3 = "g_param";
CHAR *symbolName4 = "staticParam";
CHAR *dsoName = DSO_FULL_PATH("dynamic_static.so");
INT32 ret;
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle);
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, symbolName1);
ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT);
ret = func(55, 66);
ICUNIT_GOTO_EQUAL(ret, 122, ret, EXIT);
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, symbolName2);
ICUNIT_GOTO_EQUAL(func, NULL, func, EXIT);
pValueAddr = LOS_FindSym(handle, symbolName3);
ICUNIT_GOTO_NOT_EQUAL(pValueAddr, NULL, pValueAddr, EXIT);
ICUNIT_GOTO_EQUAL(*pValueAddr, 10, *pValueAddr, EXIT);
pStaticValueAddr = LOS_FindSym(handle, symbolName4);
ICUNIT_GOTO_EQUAL(pStaticValueAddr, NULL, pStaticValueAddr, EXIT);
EXIT:
ret = LOS_SoUnload(handle);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return LOS_OK;
}
VOID ItLosDynlink014(VOID)
{
TEST_ADD_CASE("ItLosDynlink014", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
}

View File

@@ -0,0 +1,99 @@
/*
* Copyright (c) 2021-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 "los_dynlink.h"
#include "It_los_dynlink.h"
/* Test that interfaces in dynamic_athmtc.so */
STATIC UINT32 TestCase(VOID)
{
VOID *handle = NULL;
VOID (*func0)(INT32, INT32 *) = NULL;
VOID (*func1)(CHAR *, CHAR *) = NULL;
CHAR *symbolName1 = "It_dynlink_dowhile";
CHAR *symbolName2 = "It_dynlink_while";
CHAR *symbolName3 = "It_dynlink_for";
CHAR *symbolName4 = "It_dynlink_ifelse";
CHAR *symbolName5 = "It_dynlink_continue";
CHAR *symbolName6 = "It_dynlink_switch";
CHAR *dsoName = DSO_FULL_PATH("dynamic_athmtc.so");
INT32 out = 0;
CHAR inChar[3];
CHAR outChar[3] = { 0 };
INT32 ret;
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle);
func0 = (VOID (*)(INT32, INT32 *))LOS_FindSym(handle, symbolName1);
ICUNIT_GOTO_NOT_EQUAL(func0, NULL, func0, EXIT);
func0(1, &out);
ICUNIT_GOTO_EQUAL(out, 2, out, EXIT);
func0 = (VOID (*)(INT32, INT32 *))LOS_FindSym(handle, symbolName2);
ICUNIT_GOTO_NOT_EQUAL(func0, NULL, func0, EXIT);
func0(2, &out);
ICUNIT_GOTO_EQUAL(out, 3, out, EXIT);
func0 = (VOID (*)(INT32, INT32 *))LOS_FindSym(handle, symbolName3);
ICUNIT_GOTO_NOT_EQUAL(func0, NULL, func0, EXIT);
func0(3, &out);
ICUNIT_GOTO_EQUAL(out, 4, out, EXIT);
func0 = (VOID (*)(INT32, INT32 *))LOS_FindSym(handle, symbolName4);
ICUNIT_GOTO_NOT_EQUAL(func0, NULL, func0, EXIT);
func0(105, &out);
ICUNIT_GOTO_EQUAL(out, 105, out, EXIT);
func0 = (VOID (*)(INT32, INT32 *))LOS_FindSym(handle, symbolName5);
ICUNIT_GOTO_NOT_EQUAL(func0, NULL, func0, EXIT);
func0(10, &out);
ICUNIT_GOTO_EQUAL(out, 6, out, EXIT);
func1 = (VOID (*)(CHAR *, CHAR *))LOS_FindSym(handle, symbolName6);
ICUNIT_GOTO_NOT_EQUAL(func1, NULL, func1, EXIT);
inChar[0] = 'a';
inChar[1] = 'c';
inChar[2] = 'q';
func1(inChar, outChar);
ICUNIT_GOTO_EQUAL(outChar[0], 'b', outChar[0], EXIT);
ICUNIT_GOTO_EQUAL(outChar[1], 'd', outChar[1], EXIT);
ICUNIT_GOTO_EQUAL(outChar[2], 'z', outChar[2], EXIT);
EXIT:
ret = LOS_SoUnload(handle);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return LOS_OK;
}
VOID ItLosDynlink015(VOID)
{
TEST_ADD_CASE("ItLosDynlink015", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright (c) 2021-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 "los_dynlink.h"
#include "It_los_dynlink.h"
/* Test that shared library is not exist */
STATIC UINT32 TestCase(VOID)
{
VOID *handle = NULL;
CHAR *dsoName = DSO_FULL_PATH("dynamic_noexist.so");
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
ICUNIT_ASSERT_EQUAL(handle, NULL, handle);
return LOS_OK;
}
VOID ItLosDynlink016(VOID)
{
TEST_ADD_CASE("ItLosDynlink016", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
}

View File

@@ -0,0 +1,61 @@
/*
* Copyright (c) 2021-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 "los_dynlink.h"
#include "It_los_dynlink.h"
/* Test init fini segment */
STATIC UINT32 TestCase(VOID)
{
VOID *handle = NULL;
INT32 (*func)(INT32, INT32) = NULL;
CHAR *symbolName = "test_api";
CHAR *dsoName = DSO_FULL_PATH("Align4_dynamic_init_fini.so");
INT32 ret;
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle);
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, symbolName);
ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT);
ret = func(1, 1);
ICUNIT_GOTO_EQUAL(ret, 104, ret, EXIT);
EXIT:
ret = LOS_SoUnload(handle);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return LOS_OK;
}
VOID ItLosDynlink017(VOID)
{
TEST_ADD_CASE("ItLosDynlink017", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright (c) 2021-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 "los_dynlink.h"
#include "It_los_dynlink.h"
/* Test shared library with align 0x10000 */
STATIC UINT32 TestCase(VOID)
{
VOID *handle = NULL;
INT32 (*func)(INT32, INT32) = NULL;
CHAR *dsoName = DSO_FULL_PATH("dynamic_align10000.so");
INT32 ret;
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle);
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, "test_api");
ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT);
ret = func(1, 1);
ICUNIT_GOTO_EQUAL(ret, 14, ret, EXIT);
EXIT:
ret = LOS_SoUnload(handle);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return LOS_OK;
}
VOID ItLosDynlink018(VOID)
{
TEST_ADD_CASE("ItLosDynlink018", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
}

View File

@@ -0,0 +1,61 @@
/*
* Copyright (c) 2021-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 "los_dynlink.h"
#include "It_los_dynlink.h"
/* Test call global function */
STATIC UINT32 TestCase(VOID)
{
VOID *handle = NULL;
INT32 (*func)(INT32, INT32) = NULL;
CHAR *symbolName = "caller";
CHAR *dsoName = DSO_FULL_PATH("dynamic_sym.so");
INT32 ret;
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle);
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, symbolName);
ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT);
ret = func(1, 1);
ICUNIT_GOTO_EQUAL(ret, 2033, ret, EXIT);
EXIT:
ret = LOS_SoUnload(handle);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return LOS_OK;
}
VOID ItLosDynlink019(VOID)
{
TEST_ADD_CASE("ItLosDynlink019", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright (c) 2021-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 "los_dynlink.h"
#include "It_los_dynlink.h"
/* Test that Align4_dynamic_stdlib.so, libc.a not with fPIC */
STATIC UINT32 TestCase(VOID)
{
VOID *handle = NULL;
VOID (*func)(INT32, INT32) = NULL;
CHAR *dsoName = DSO_FULL_PATH("Align4_dynamic_stdlib.so");
INT32 ret;
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
ICUNIT_ASSERT_EQUAL(handle, NULL, handle);
return LOS_OK;
}
VOID ItLosDynlink020(VOID)
{
TEST_ADD_CASE("ItLosDynlink020", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
}

View File

@@ -0,0 +1,56 @@
GCC_PREFIX = arm-none-eabi-
CROSS_GCC = $(GCC_PREFIX)gcc
GCC = gcc
RM = -rm -rf
HIDE = @
PREFIX = Align4_
TESTCASENAME = dynamic_
CASE = $(TESTCASENAME)
AGCASE = $(PREFIX)$(TESTCASENAME)
SRCS = $(wildcard *.c)
SO = $(patsubst %.c,%.so,$(SRCS))
ALIGN_SO = $(patsubst %.c,$(PREFIX)%.so,$(SRCS))
# cpu
CPU = -mcpu=cortex-m4
# fpu
FPU = -mfpu=fpv4-sp-d16
# float-abi
FLOAT-ABI = -mfloat-abi=hard
# mcu
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
CFLAGS = -nostdlib -nostartfiles
ALIGN_CFLAGS = $(CFLAGS) -z max-page-size=4
INIT_FINI_CFLAGS = $(ALIGN_CFLAGS) -Wl,-init,init_first -Wl,-fini,fini_end
all: $(SO) $(ALIGN_SO)
$(SO): %.so : %.c
$(HIDE)$(CROSS_GCC) -fPIC -shared $(MCU) $(CFLAGS) $(CASE)athmtc.c -o $(CASE)athmtc.so
$(HIDE)$(CROSS_GCC) -fPIC -shared $(MCU) $(CFLAGS) $(CASE)bss.c -o $(CASE)bss.so
$(HIDE)$(CROSS_GCC) -fPIC -shared $(MCU) $(CFLAGS) $(CASE)initfini.c -o $(CASE)align10000.so
$(HIDE)$(CROSS_GCC) -fPIC -shared $(MCU) $(CFLAGS) $(CASE)static.c -o $(CASE)static.so
$(HIDE)$(CROSS_GCC) -fPIC -shared $(MCU) $(CFLAGS) $(CASE)sym.c -o $(CASE)sym.so
$(HIDE)$(CROSS_GCC) -fPIC -shared $(MCU) $(CFLAGS) $(CASE)undfunc.c -o $(CASE)undfunc.so
$(HIDE)$(CROSS_GCC) -fPIC -shared $(MCU) $(CFLAGS) $(CASE)undval.c -o $(CASE)undval.so
$(HIDE)$(CROSS_GCC) -fPIC -shared $(MCU) $(CFLAGS) $(CASE)xxxxx.c -o $(CASE)xxxxx.so
$(ALIGN_SO): $(PREFIX)%.so : %.c
$(HIDE)$(CROSS_GCC) -fPIC -shared $(MCU) $(ALIGN_CFLAGS) $(CASE)initfini.c -o $(AGCASE)align4.so
$(HIDE)$(CROSS_GCC) -fPIC -shared $(MCU) $(INIT_FINI_CFLAGS) $(CASE)initfini.c -o $(AGCASE)init_fini.so
# shared library not for need
$(HIDE)$(GCC) -fPIC -shared $(ALIGN_CFLAGS) $(CASE)initfini.c -o $(AGCASE)x86.so
$(HIDE)$(CROSS_GCC) -fPIE -pie $(MCU) $(ALIGN_CFLAGS) $(CASE)initfini.c -o $(AGCASE)pie.so
$(HIDE)$(CROSS_GCC) $(MCU) $(ALIGN_CFLAGS) $(CASE)initfini.c -o $(AGCASE)exec.so
$(HIDE)$(CROSS_GCC) -shared $(MCU) $(ALIGN_CFLAGS) $(CASE)initfini.c -o $(AGCASE)nopic.so
$(HIDE)$(CROSS_GCC) -fPIC -shared $(MCU) $(ALIGN_CFLAGS) $(AGCASE)align4.so $(CASE)initfini.c -o \
$(AGCASE)need_others.so
$(HIDE)$(CROSS_GCC) -fPIC -shared $(ALIGN_CFLAGS) $(CASE)initfini.c -o $(AGCASE)noThumb.so
$(HIDE)$(CROSS_GCC) -fPIC -shared $(MCU) $(CASE)initfini.c -o $(AGCASE)stdlib.so
clean:
$(HIDE)$(RM) *.so
.PHONY: all clean

View File

@@ -0,0 +1,134 @@
#define OK 0
#define NOK 1
void It_dynlink_dowhile(int cnt, int *out)
{
int outParam = 0;
cnt += 1;
do {
++outParam;
--cnt;
} while (cnt);
*out = outParam;
}
void It_dynlink_while(int cnt, int *out)
{
int index = 0;
int outParam = 0;
cnt += 1;
while ((index++) < cnt) {
outParam += 1;
}
*out = outParam;
}
void It_dynlink_for(int cnt, int *out)
{
int index = 0;
int outParam = 0;
cnt += 1;
for (; index < cnt; ++index) {
++outParam;
}
*out = outParam;
}
void It_dynlink_ifelse(int inVal, int *outVal)
{
int outParam;
if (inVal <= 101) {
outParam = 101;
} else if (inVal == 102) {
outParam = inVal;
} else if (inVal == 103) {
outParam = inVal;
} else if (inVal == 104) {
outParam = inVal;
} else if (inVal == 105) {
outParam = inVal;
} else if (inVal == 106) {
outParam = inVal;
} else if (inVal == 107) {
outParam = inVal;
} else if (inVal == 108) {
outParam = inVal + 1;
} else if (inVal == 109) {
outParam = 45;
} else {
outParam = 45;
}
*outVal = outParam;
}
void It_dynlink_continue(int cnt, int *out)
{
int index = 0;
int outParam = 0;
cnt += 2;
for (; index < cnt; ++index) {
if (index % 2) {
continue;
} else {
++outParam;
}
}
*out = outParam;
}
void It_dynlink_switch(char *inVal, char *outVal)
{
int i;
char outParam;
for (i = 0; i < 3; ++i) {
switch (inVal[i]) {
case 'A':
case 'a':
outParam = 'b';
break;
case 'B':
case 'b':
outParam = 'c';
break;
case 'C':
case 'c':
outParam = 'd';
break;
case 'D':
case 'd':
outParam = 'e';
break;
case 'E':
case 'e':
outParam = 'f';
break;
case 'F':
case 'f':
outParam = 'g';
break;
case 'G':
case 'g':
outParam = 'h';
break;
case 'H':
case 'h':
outParam = 'i';
break;
default:
outParam = 'z';
break;
}
outVal[i] = outParam;
}
}

View File

@@ -0,0 +1,7 @@
int test_array[100];
int dyn_bss_func(void)
{
test_array[0] += 100;
return 2017 + test_array[0];
}

View File

@@ -0,0 +1,38 @@
#include "stdio.h"
#include "stdlib.h"
void init_test(void) __attribute__((constructor));
void fini_test(void) __attribute((destructor));
int g_param = 10;
static int param = 2;
void init_first(void)
{
g_param = 100;
}
void init_test(void)
{
g_param += param;
}
void fini_end(void)
{
g_param = 0;
}
void fini_test(void)
{
param = 0;
}
int callee(int a, int b)
{
return g_param + a + b;
}
int test_api(int a, int b)
{
int c = callee(a, b);
return c;
}

View File

@@ -0,0 +1,16 @@
static int staticParam = 9;
int g_param = 10;
int add_test(int a, int b)
{
int c;
c = a + b + g_param - staticParam;
return c;
}
static int static_sub_test(int a, int b)
{
int c;
c = a - b + g_param - staticParam;
return c;
}

View File

@@ -0,0 +1,11 @@
int g_param = 10;
int callee(int a, int b)
{
return a + b + g_param;
}
int caller(int a, int b)
{
return 2021 + callee(a, b);
}

View File

@@ -0,0 +1,6 @@
extern int undef_func(int a, int b);
int caller(int a, int b)
{
return a + undef_func(a, b);
}

View File

@@ -0,0 +1,6 @@
extern int g_param;
int caller(int a, int b)
{
return a + b + g_param;
}

View File

@@ -0,0 +1,14 @@
int g_value100 = 100;
int *g_pValue100 = &g_value100;
static int value200 = 200;
int *g_pValue200 = &value200;
int get_value100(void)
{
return *g_pValue100;
}
int get_value200(void)
{
return *g_pValue200;
}

View File

@@ -0,0 +1,17 @@
#!/bin/bash
#Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
LOAD_FLAG=false