未验证 提交 cea704b5 编写于 作者: O openharmony_ci 提交者: Gitee

!983 Make exe can access ndk so

Merge pull request !983 from yinchuang/exe
......@@ -22,6 +22,13 @@ group("functional_test") {
test_sharedlib("dlopen_ns_dso") {
}
test_sharedlib("dlopen_so_dep_dlopen_ns_dso") {
deps = [ ":dlopen_ns_dso" ]
}
test_sharedlib("dlopen_for_load_by_global_dso") {
}
test_sharedlib("dlopen_for_load_by_local_dso") {
}
test_sharedlib("dlopen_dso") {
}
test_sharedlib("dlclose_reset_dso") {
......@@ -40,7 +47,10 @@ group("dso_shared") {
":atexit_dlclose_dso",
":dlclose_reset_dso",
":dlopen_dso",
":dlopen_for_load_by_global_dso",
":dlopen_for_load_by_local_dso",
":dlopen_ns_dso",
":dlopen_so_dep_dlopen_ns_dso",
":tls_align_dso",
":tls_init_dso",
]
......
#include <dlfcn.h>
#include "test.h"
#define SO_FOR_NO_DELETE "lib_for_no_delete.so"
#define SO_FOR_DLOPEN "lib_for_dlopen.so"
#define SO_LOAD_BY_LOCAL "libdlopen_for_load_by_local_dso.so"
#define SO_LOAD_BY_GLOBAL "libdlopen_for_load_by_global_dso.so"
typedef void(*TEST_PTR)(void);
void do_dlopen(const char *name, int mode)
{
void* handle = dlopen(name, mode);
if(!handle)
t_error("dlopen(name=%s, mode=%d) failed: %s\n", name, mode, dlerror());
if(dlclose(handle))
t_error("dlclose %s failed : %s \n", name, dlerror());
}
void dlopen_lazy()
{
do_dlopen(SO_FOR_DLOPEN, RTLD_LAZY);
}
void dlopen_now()
{
do_dlopen(SO_FOR_DLOPEN, RTLD_NOW);
}
void dlopen_global()
{
do_dlopen(SO_FOR_DLOPEN, RTLD_GLOBAL);
}
void dlopen_local()
{
do_dlopen(SO_FOR_DLOPEN, RTLD_LOCAL);
}
void dlopen_so_used_by_dlsym()
{
void* handle1 = dlopen(SO_LOAD_BY_LOCAL, RTLD_LOCAL);
if(!handle1)
t_error("dlopen(name=%s, mode=%d) failed: %s\n", SO_LOAD_BY_LOCAL, RTLD_LOCAL, dlerror());
// dlsym can't see the so which is loaded by RTLD_LOCAL.
TEST_PTR for_local_ptr = dlsym(RTLD_DEFAULT, "for_local");
if (for_local_ptr != NULL) {
t_error("dlsym RTLD_LOCAL so(%s) should failed but get succeed.\n", "for_local");
}
if(dlclose(handle1))
t_error("dlclose %s failed : %s \n", SO_LOAD_BY_LOCAL, dlerror());
void* handle2 = dlopen(SO_LOAD_BY_GLOBAL, RTLD_GLOBAL);
if(!handle2)
t_error("dlopen(name=%s, mode=%d) failed: %s\n", SO_LOAD_BY_GLOBAL, RTLD_LOCAL, dlerror());
// dlsym can see the so which is loaded by RTLD_DEFAULT even without dependencies.
TEST_PTR for_global_ptr = dlsym(RTLD_DEFAULT, "for_global");
if (!for_global_ptr) {
t_error("dlsym RTLD_GLOBAL so(%s) should succeed but get failed: %s \n", "for_global", dlerror());
}
if(dlclose(handle2))
t_error("dlclose %s failed : %s \n", SO_LOAD_BY_GLOBAL, dlerror());
}
void dlopen_nodelete_and_noload()
{
void* handle1 = dlopen(SO_FOR_NO_DELETE, RTLD_NODELETE);
if(!handle1)
t_error("dlopen(name=%s, mode=RTLD_NODELETE) failed: %s\n", SO_FOR_NO_DELETE, dlerror());
if(dlclose(handle1))
t_error("dlclose %s failed : %s \n", SO_FOR_NO_DELETE, dlerror());
void* handle2 = dlopen(SO_FOR_NO_DELETE, RTLD_NOLOAD);
if(!handle2)
t_error("dlopen(name=%s, mode=RTLD_NOLOAD) failed: %s\n", SO_FOR_NO_DELETE, dlerror());
if (handle1 != handle2) {
t_error("dlopen %s by RTLD_NODELETE but get different handle when dlopen by RTLD_NOLOAD again.\n", SO_FOR_NO_DELETE);
}
}
void dlopen_dlclose()
{
void* handle = dlopen(SO_FOR_DLOPEN, RTLD_LOCAL);
if(!handle)
t_error("dlopen(name=%s, mode=%d) failed: %s\n", SO_FOR_DLOPEN, RTLD_LOCAL, dlerror());
handle = dlopen(SO_FOR_DLOPEN, RTLD_LOCAL);
if(!handle)
t_error("dlopen(name=%s, mode=%d) failed: %s\n", SO_FOR_DLOPEN, RTLD_LOCAL, dlerror());
if(dlclose(handle))
t_error("dlclose %s failed : %s \n", SO_FOR_DLOPEN, dlerror());
// lib should still exist in memory.
handle = dlopen(SO_FOR_DLOPEN, RTLD_NOLOAD);
if(!handle)
t_error("dlopen(name=%s, mode=%d) failed: %s\n", SO_FOR_DLOPEN, RTLD_LOCAL, dlerror());
if(dlclose(handle))
t_error("dlclose %s failed : %s \n", SO_FOR_DLOPEN, dlerror());
// It need to do one more dlclose because call dlopen by RTLD_NOLOAD add reference counting.
if(dlclose(handle))
t_error("dlclose %s failed : %s \n", SO_FOR_DLOPEN, dlerror());
// dlopen and dlclose call counts match so the lib should not exist in memory.
handle = dlopen(SO_FOR_DLOPEN, RTLD_NOLOAD);
if(handle) {
t_error("dlopen(name=%s, mode=%d) failed: %s\n", SO_FOR_DLOPEN, RTLD_LOCAL, dlerror());
dlclose(handle);
}
}
int main(int argc, char *argv[])
{
void *h, *g;
......@@ -51,5 +171,14 @@ int main(int argc, char *argv[])
t_error("dlclose failed: %s\n", dlerror());
if (dlclose(h))
t_error("dlclose failed: %s\n", dlerror());
dlopen_lazy();
dlopen_now();
dlopen_global();
dlopen_local();
dlopen_so_used_by_dlsym();
dlopen_nodelete_and_noload();
dlopen_dlclose();
return t_status;
}
int i = 1;
void for_global(void)
{
i++;
}
\ No newline at end of file
int i = 1;
void for_local(void)
{
i++;
}
\ No newline at end of file
......@@ -3,176 +3,218 @@
#include <string.h>
#include "test.h"
typedef void(* FUNC)(); // 定义函数指针类型的别名
#define SO_HAS_DEPENDENCES "libdlopen_so_dep_dlopen_ns_dso.so"
const char* dllName = "libdlopen_ns_dso.so";
const char* dllName2 = "libdlopen_dso.so";
const char* errPath_ns = "src/common";
const char* errPath_ns = "/src/common";
const char* ndk_so = "libdlopen_ns_dso_ndk.so";
const char* system_so = "libdlopen_ns_dso_sys.so";
typedef void*(*CALL_DLOPEN_PTR)(const char *);
// 测试通过so路径打开. 命名空间非严格隔离时,通过路径总是可加载.
void test_open_by_path(const char* dllPath)
// Test whether it is ok for main to dlopen ndk so.
void main_dlopen_ndk_so()
{
void* handle = dlopen(dllPath, RTLD_LAZY);
if(!handle)
t_error("dlopen_by_path handle get error %s open failed: %s\n", dllName, dlerror());
void *handle = dlopen(ndk_so, RTLD_NOW);
if (!handle)
t_error("main dlopen ndk so %s failed: %s\n", ndk_so, dlerror());
if (dlclose(handle))
t_error("dlclose %s failed : %s \n", ndk_so, dlerror());
}
if(dlclose(handle))
t_error("dlclose_by_path handle %s close failed : %s \n", dllName, dlerror());
// Test whether it is ok for system so to dlopen ndk so.
void system_so_dlopen_ndk_so()
{
void *handle = dlopen(system_so, RTLD_NOW);
if (!handle) {
t_error("dlopen %s failed : %s \n", system_so, dlerror());
}
CALL_DLOPEN_PTR call_dlopen = dlsym(handle, "call_dlopen");
if (!call_dlopen) {
t_error("dlsym %s failed : %s \n", "call_dlopen", dlerror());
}
void *res = call_dlopen(ndk_so);
if (!res) {
t_error("default ns so(%s) can't dlopen ndk so(%s)", system_so, ndk_so);
}
}
//有配置文件时,通过短名称打开
void test_open_by_ini_name()
// Test whether it is ok for ndk so to dlopen system so.
void ndk_so_dlopen_default_ns_so()
{
Dl_namespace dlns;
dlns_init(&dlns, "ns1");
void* handle = dlopen_ns(&dlns, dllName, RTLD_LAZY);
if(!dlns_create(&dlns, errPath_ns))
t_error("dlns_create_by_ini_name should failed but succeed \n");
if(!handle)
t_error("dlopen_ns_by_ini_name handle get error %s open failed: %s\n", dllName, dlerror());
if(dlclose(handle))
t_error("dlclose_by_ini_name handle %s close failed : %s \n", dllName, dlerror());
dlns_init(&dlns, "ndk");
void *handle = dlopen_ns(&dlns, ndk_so, RTLD_NOW);
if (!handle) {
t_error("dlopen_ns(ns=%s, so=%s) failed : %s \n", "ndk", ndk_so, dlerror());
}
CALL_DLOPEN_PTR call_dlopen = dlsym(handle, "call_dlopen");
if (!call_dlopen) {
t_error("dlsym %s failed : %s \n", "call_dlopen", dlerror());
}
void *res = call_dlopen(system_so);
if (!res) {
t_error("ndk so(%s) can't dlopen system so(%s)", ndk_so, system_so);
}
}
//有配置文件时,测试通过api设置的namespace加载
void test_open_by_ini_api()
// Test whether dlopen same so twice by same ns to get same handle.
void dlopen_same_so_twice_by_same_ns(char * dllPath_ns)
{
Dl_namespace dlns1, dlns2;
dlns_init(&dlns1, "dlns_test");
dlns_init(&dlns2, "ns1");
dlns_create(&dlns1, NULL);
dlns_inherit(&dlns1, &dlns2 , dllName);
Dl_namespace dlns1;
dlns_init(&dlns1, "ns_for_dlopen_same_so_twice_by_same_ns");
dlns_create(&dlns1, dllPath_ns);
void* handle = dlopen_ns(&dlns1, dllName, RTLD_LAZY);
if(!handle)
t_error("dlopen_ns_by_ini_api handle get error %s open failed: %s\n", dllName, dlerror());
void* handle1 = dlopen_ns(&dlns1, dllName, RTLD_NOW);
if(!handle1)
t_error("dlopen_ns(ns=%s, name=%s) failed : %s \n", dlns1.name, dllName, dlerror());
if(dlclose(handle))
t_error("dlclose_by_ini_api handle %s close failed : %s \n", dllName, dlerror());
void* handle2 = dlopen_ns(&dlns1, dllName, RTLD_NOW);
if(!handle2)
t_error("dlopen_ns(ns=%s, name=%s) failed : %s \n", dlns1.name, dllName, dlerror());
if (handle1 != handle2)
t_error("dlopen same so(%s) by same ns but handle is different %s \n", dllName);
if(dlclose(handle1))
t_error("dlclose %s failed : %s \n", dllName, dlerror());
if(dlclose(handle2))
t_error("dlclose %s failed : %s \n", dllName, dlerror());
}
//不同命名空间打开相同so
void test_open_by_sameso_in_diff_ns(char * dllPath_ns)
// Test whether dlopen same so by different ns to get different handle.
void dlopen_same_so_by_different_ns(char * dllPath_ns)
{
Dl_namespace dlns1, dlns2;
dlns_init(&dlns1, "dlns_test1");
dlns_init(&dlns2, "dlns_test2");
Dl_namespace dlns1;
dlns_init(&dlns1, "ns_for_dlopen_same_so_by_different_ns_1");
dlns_create(&dlns1, dllPath_ns);
Dl_namespace dlns2;
dlns_init(&dlns2, "ns_for_dlopen_same_so_by_different_ns_2");
dlns_create(&dlns2, dllPath_ns);
void* handle1 = dlopen_ns(&dlns1, dllName, RTLD_LAZY);
void* handle1 = dlopen_ns(&dlns1, dllName, RTLD_NOW);
if(!handle1)
t_error("dlopen_ns_by_sameso_diff_ns handle1 get error %s open failed : %s \n", dllName, dlerror());
t_error("dlopen_ns(ns=%s, name=%s) failed : %s \n", dlns1.name, dllName, dlerror());
void* handle2 = dlopen_ns(&dlns2, dllName, RTLD_LAZY);
void* handle2 = dlopen_ns(&dlns2, dllName, RTLD_NOW);
if(!handle2)
t_error("dlopen_ns_by_sameso_diff_ns handle2 get error %s open failed : %s \n", dllName, dlerror());
t_error("dlopen_ns(ns=%s, name=%s) failed : %s \n", dlns2.name, dllName, dlerror());
if (handle1 == handle2)
t_error("dlopen same so(%s) by same ns but handle is different %s \n", dllName);
if(dlclose(handle1))
t_error("dlclose_by_sameso_diff_ns handle1 %s close failed : %s \n", dllName, dlerror());
t_error("dlclose %s failed : %s \n", dllName, dlerror());
if(dlclose(handle2))
t_error("dlclose_by_sameso_diff_ns handle2 %s close failed : %s \n", dllName, dlerror());
t_error("dlclose %s failed : %s \n", dllName, dlerror());
}
// 有配置文件时,测试在同一namespace多次加载相同动态库
void test_open_by_ini_mtso_ns()
// Test whether dlopen same so by inherit ns to get same handle.
void dlopen_same_so_by_different_inherit_ns(char * dllPath_ns)
{
Dl_namespace dlns;
dlns_init(&dlns, "ns1");
void* handle1 = dlopen_ns(&dlns, dllName, RTLD_LAZY);
Dl_namespace dlns1;
dlns_init(&dlns1, "ns_for_dlopen_same_so_by_different_inherit_ns_1");
dlns_create(&dlns1, dllPath_ns);
Dl_namespace dlns2;
dlns_init(&dlns2, "ns_for_dlopen_same_so_by_different_inherit_ns_2");
dlns_create2(&dlns2, errPath_ns, 0);
dlns_inherit(&dlns2, &dlns1, dllName);
void* handle1 = dlopen_ns(&dlns1, dllName, RTLD_NOW);
if(!handle1)
t_error("dlopen_ns_by_ini_mtso_ns handle1 get error %s open failed : %s \n" , dllName, dlerror());
t_error("dlopen_ns(ns=%s, name=%s) failed : %s \n", dlns1.name, dllName, dlerror());
void* handle2 = dlopen_ns(&dlns, dllName, RTLD_LAZY);
void* handle2 = dlopen_ns(&dlns2, dllName, RTLD_NOW);
if(!handle2)
t_error("dlopen_ns_by_ini_mtso_ns handle2 get error %s open failed : %s \n" , dllName, dlerror());
t_error("dlopen_ns(ns=%s, name=%s) failed : %s \n", dlns2.name, dllName, dlerror());
if (handle1 != handle2)
t_error("dlopen same so(%s) by inherit ns but handle is different %s \n", dllName);
if(dlclose(handle1))
t_error("dlclose %s failed : %s \n", dllName, dlerror());
if(dlclose(handle1) )
t_error("dlclose_by_ini_mtso_ns handle1 %s close failed : %s \n" , dllName, dlerror());
if(dlclose(handle2) )
t_error("dlclose_by_ini_mtso_ns handle2 %s close failed : %s \n" , dllName, dlerror());
if(dlclose(handle2))
t_error("dlclose %s failed : %s \n", dllName, dlerror());
}
//测试配置文件,隔离性严格隔离 两个有allowed_libs(其中一个不在env lib permitt 路径中),一个没有allowed_libs
void test_open_ini_separated(char* dllPath)
void dlopen_seperated(char * dllPath_ns)
{
Dl_namespace dlns2, dlns3, dlns4;
// ns2 , ns3 , ns4 为严格隔离情况
// ns2 的 so 在 lib_path 下,设置了 allowed_path
// ns3 的 lib_path 设置的错误路径,无 allowed_path.
// ns4 的 在allowed_lib 下给的是错误的so
dlns_init(&dlns2, "ns2");
dlns_init(&dlns3, "ns3");
dlns_init(&dlns4, "ns4");
void* handle_ns2 = dlopen_ns(&dlns2, dllPath, RTLD_LAZY);
if(!handle_ns2)
t_error("dlopen_ns_by_ini_separated handle_ns2 get error %s open failed : %s \n", dllName, dlerror());
void* handle_ns3 = dlopen_ns(&dlns3, dllPath, RTLD_LAZY);
if(handle_ns3){
t_error("dlopen_ns_by_ini_separated handle_ns3 %s should not open successfully \n", dllName);
dlclose(handle_ns3);
}
if(dlclose(handle_ns2))
t_error("dlclose_by_inherit_transitivity handle_ns2 %s close failed : %s\n", dllName, dlerror());
Dl_namespace dlns1;
dlns_init(&dlns1, "ns_for_no_seperated");
dlns_create2(&dlns1, errPath_ns, 0);
void* handle = NULL;
// current ns can't load this so.
handle = dlopen_ns(&dlns1, dllName, RTLD_NOW);
if(handle)
t_error("dlopen_ns(ns=%s, name=%s) failed : %s \n", dlns1.name, dllName, dlerror());
// current ns can load the so by absolute path.
char absolute_path_1[512];
snprintf(absolute_path_1, sizeof(absolute_path_1), "%s/%s", dllPath_ns, dllName);
handle = dlopen_ns(&dlns1, absolute_path_1, RTLD_NOW);
if (!handle)
t_error("%s can load %s by absolute path but failed : %s \n", dlns1.name, absolute_path_1, dlerror());
void* handle_ns4 = dlopen_ns(&dlns4, dllPath, RTLD_LAZY);
if(handle_ns4){
t_error("dlopen_ns_by_ini_separated handle_ns4 %s should not open successfully \n", dllName);
dlclose(handle_ns4);
}
if(dlclose(handle))
t_error("dlclose %s failed : %s \n", absolute_path_1, dlerror());
// current ns can't load the so by absolute path if it has inaccessible dependent so.
char absolute_path_2[512];
snprintf(absolute_path_2, sizeof(absolute_path_2), "%s/%s", dllPath_ns, SO_HAS_DEPENDENCES);
handle = dlopen_ns(&dlns1, absolute_path_2, RTLD_NOW);
if (handle)
t_error("%s can't load %s by absolute path because but it has inaccessible dependent so but succeed : %s \n", dlns1.name, absolute_path_2, dlerror());
}
//测试配置文件,非严格隔离情况, 传入短名称
void test_open_ini_by_falseseparated(char * dllPath_ns)
void dlopen_inherit(char* dllPath_ns)
{
Dl_namespace dlns5, dlns6;
//API 创建 ns5,ns6 为非严格隔离情况
dlns_init(&dlns5, "ns5");
dlns_init(&dlns6, "ns6");
dlns_create(&dlns5, dllPath_ns);
// ns6 传入lib_path 是错误路径,故打不开so
dlns_create(&dlns6, errPath_ns);
//根据短名称打开
void* handle_ns5 = dlopen_ns(&dlns5, dllName, RTLD_LAZY);
if(!handle_ns5)
t_error("dlopen_ns_by_ini_by_falseseparated handle_ns5 get error %s open failed : %s \n", dllName, dlerror());
void* handle_ns6 = dlopen_ns(&dlns6, dllName, RTLD_LAZY);
if(handle_ns6){
t_error("dlopen_ns_by_ini_separated handle_ns6 %s should not open successfully \n", dllName);
dlclose(handle_ns6);
Dl_namespace inherit_A, inherit_B;
dlns_init(&inherit_A, "inherir_error_lib_A");
dlns_init(&inherit_B, "inherir_error_lib_B");
dlns_create2(&inherit_A, NULL, 0);
dlns_create2(&inherit_B, dllPath_ns, 0);
// inherit_A can't load the so because search path is NULL.
void* handle1 = dlopen_ns(&inherit_A, dllName, RTLD_LAZY);
if(handle1){
t_error("dlopen_ns_by_ini_no_inherit handle %s should not open successfully \n", dllName);
dlclose(handle1);
}
if(dlclose(handle_ns5))
t_error("dlclose_by_ini_by_falseseparated handle_ns5 %s close failed : %s\n", dllName, dlerror());
// inherit_A can load the so by inherit_B.
dlns_inherit(&inherit_A, &inherit_B, dllName);
void* handle2 = dlopen_ns(&inherit_A, dllName, RTLD_LAZY);
if(!handle2)
t_error("dlopen_ns_by_dlns_inherir handle get error %s open failed : %s \n", dllName, dlerror());
if(dlclose(handle2))
t_error("dlclose_by_dlns_inherir handle %s close failed : %s\n", dllName, dlerror());
// inherit_A can't load the so by inherit ns if the so isn't in shared libs.
dlns_inherit(&inherit_A, &inherit_B, dllName2);
void* handle3 = dlopen_ns(&inherit_A, dllName, RTLD_LAZY);
if(handle3){
t_error("dlopen_ns_by_ini_no_inherit handle2 %s should not open successfully \n", dllName);
dlclose(handle3);
}
}
//检查继承是否具有传递性
void test_open_by_inherit_transitivity(char* dllPath_ns)
void dlopen_inherit_check_can_pass(char* dllPath_ns)
{
Dl_namespace transitivity_A, transitivity_B, transitivity_C;
dlns_init(&transitivity_A, "transitivity_A");
dlns_init(&transitivity_B, "transitivity_B");
dlns_init(&transitivity_C, "transitivity_C");
dlns_create(&transitivity_A, NULL);
dlns_create(&transitivity_B, NULL);
dlns_create(&transitivity_C, dllPath_ns);
dlns_create2(&transitivity_A, NULL, 0);
dlns_create2(&transitivity_B, NULL, 0);
dlns_create2(&transitivity_C, dllPath_ns, 0);
dlns_inherit(&transitivity_A, &transitivity_B, NULL);
dlns_inherit(&transitivity_B, &transitivity_C, dllName);
//如果A能打开,证明有传递性
void* handleA = dlopen_ns(&transitivity_A, dllName, RTLD_LAZY);
if(handleA){
t_error("dlopen_ns_by_inherit_transitivity handleA %s should not open successfully \n", dllName);
dlclose(handleA);
}
void* handleB = dlopen_ns(&transitivity_B, dllName, RTLD_LAZY);
if(!handleB)
......@@ -187,119 +229,31 @@ void test_open_by_inherit_transitivity(char* dllPath_ns)
if(dlclose(handleB))
t_error("dlclose_by_inherit_transitivity handleB %s close failed : %s\n", dllName, dlerror());
}
//在配置文件中A没有继承关系,A无法打开的库,通过调用继承接口去B(已加载该库)中尝试加载该库
void test_open_by_ini_no_inherit(char* dllPath_ns)
{
Dl_namespace no_inherit_A, no_inherit_B;
dlns_init(&no_inherit_A, "no_inherit_A"); //配置文件中A没有所继承的ns
dlns_init(&no_inherit_B, "no_inherit_B"); //用于接口中实现与A的继承关系所对应的ns
dlns_create(&no_inherit_A, NULL);
dlns_create(&no_inherit_B, dllPath_ns);
void* handle = dlopen_ns(&no_inherit_A, dllName, RTLD_LAZY); //libdlopenns_dso.so在A中无法找到
if(handle){
t_error("dlopen_ns_by_ini_no_inherit handle %s should not open successfully \n", dllName);
dlclose(handle);
// transitivity_A can't load so because inherit can't pass.
void* handleA = dlopen_ns(&transitivity_A, dllName, RTLD_LAZY);
if(handleA){
t_error("dlopen_ns_by_inherit_transitivity handleA %s should not open successfully \n", dllName);
dlclose(handleA);
}
void* handle2 = dlopen_ns(&no_inherit_B, dllName, RTLD_LAZY);
if(!handle2)
t_error("dlopen_ns_by_ini_no_inherit handle2 get error %s open failed : %s \n", dllName, dlerror());
dlns_inherit(&no_inherit_A, &no_inherit_B, dllName);
void* handle3 = dlopen_ns(&no_inherit_A, dllName, RTLD_LAZY); //通过B的继承关系再次加载库
if(!handle3)
t_error("dlopen_ns_by_ini_no_inherit handle3 get error %s open failed : %s \n", dllName, dlerror());
if(dlclose(handle3))
t_error("dlclose_by_ini_no_inherit handle3 %s close failed : %s\n", dllName, dlerror());
if(dlclose(handle2))
t_error("dlclose_by_ini_no_inherit handle2 %s close failed : %s\n", dllName, dlerror());
}
//dlns_inherit是否正常工作
void test_open_by_dlns_inherir(char* dllPath_ns)
void dlopen_test_dlns_create2()
{
Dl_namespace inherir_A, inherir_B;
dlns_init(&inherir_A, "inherir_A");
dlns_init(&inherir_B, "inherir_B");
dlns_create(&inherir_A, NULL);
dlns_create(&inherir_B, dllPath_ns);
dlns_inherit(&inherir_A, &inherir_B, NULL); //B共享所有库,有A要加载的库
void* handle = dlopen_ns(&inherir_A, dllName, RTLD_LAZY);
Dl_namespace dlns;
dlns_init(&dlns, "ns_for_create2");
// ns_for_create2 doesn't exist, it will use default ns to search so.
void* handle = dlopen_ns(&dlns, dllName, RTLD_LAZY);
if(!handle)
t_error("dlopen_ns_by_dlns_inherir handle get error %s open failed : %s \n", dllName, dlerror());
t_error("dlopen_ns %s use a non-existent ns failed: %s\n", dllName, dlerror());
if(dlclose(handle))
t_error("dlclose_by_dlns_inherir handle %s close failed : %s\n", dllName, dlerror());
dlns_inherit(&inherir_A, &inherir_B, dllName2); //B共享指定库,不是A要加载的库,覆盖原有继承关系
void* handle2 = dlopen_ns(&inherir_A, dllName, RTLD_LAZY);
if(handle2){
t_error("dlopen_ns_by_ini_no_inherit handle2 %s should not open successfully \n", dllName);
dlclose(handle2);
}
}
//A通过B、C共享项获取加载的库
void test_open_by_shared_libs(char* dllPath_ns)
{
Dl_namespace shared_libs_A, shared_libs_B, shared_libs_C;
dlns_init(&shared_libs_A, "shared_libs_A");
dlns_init(&shared_libs_B, "shared_libs_B");
dlns_init(&shared_libs_C, "shared_libs_C");
dlns_create(&shared_libs_A, NULL);
dlns_create(&shared_libs_B, errPath_ns);
dlns_create(&shared_libs_C, dllPath_ns);
dlns_inherit(&shared_libs_A, &shared_libs_B, NULL); //B共享所有库,但无A要加载的库
void* handle = dlopen_ns(&shared_libs_A, dllName, RTLD_LAZY);
if(handle){
t_error("dlopen_ns_by_shared_libs handle %s should not open successfully \n", dllName);
dlclose(handle);
}
void* handle2 = dlopen_ns(&shared_libs_B, dllName, RTLD_LAZY);
if(handle2){
t_error("dlopen_ns_by_shared_libs handle2 %s should not open successfully \n", dllName);
dlclose(handle2);
}
dlns_inherit(&shared_libs_A, &shared_libs_C, "libdlopen_dso.so:libdlopen_ns_dso.so"); //C共享固定库中包含A要加载的库
void* handle3 = dlopen_ns(&shared_libs_C, dllName, RTLD_LAZY);
if(!handle3)
t_error("dlopen_ns_by_shared_libs handle3 get error %s open failed : %s \n", dllName, dlerror());
t_error("dlclose %s failed : %s \n", dllName, dlerror());
void* handle4 = dlopen_ns(&shared_libs_A, dllName, RTLD_LAZY);
if(!handle4)
t_error("dlopen_ns_by_shared_libs handle4 get error %s open failed : %s \n", dllName, dlerror());
if(dlclose(handle4))
t_error("dlclose_by_shared_libs handle4 %s close failed : %s\n", dllName, dlerror());
if(dlclose(handle3))
t_error("dlclose_by_shared_libs handle3 %s close failed : %s\n", dllName, dlerror());
}
//add ini inherit test
void test_open_by_iinheritB_shared_libs(char* dllPath_ns)
{
Dl_namespace inherit_B;
dlns_init(&inherit_B, "inherit_B"); //配置文件中B继承自ns2
void* handle = dlopen_ns(&inherit_B, dllName, RTLD_LAZY); //inherit_b将从ns2中获取dllName库
if(!handle){
t_error("dlopen_ns_by_iinheritB_shared_libs handle get error %s open failed : %s \n", dllName, dlerror());
}
if(dlclose(handle))
t_error("dlopen_ns_by_iinheritB_shared_libs handle %s close failed : %s\n", dllName, dlerror());
// 0: ns_for_create2 doesn't inherit default ns.
dlns_create2(&dlns, errPath_ns, 0);
void* handle2 = dlopen_ns(&dlns, dllName, RTLD_LAZY);
if(handle2)
t_error("%s namespace can't see %s but dlopen succee.\n", "ns_for_create2", dllName);
}
......@@ -318,19 +272,17 @@ int main(int argc, char *argv[])
return 1;
}
path[strlen (path) -1 ] ='\0';
test_open_by_path(buf);
test_open_by_ini_name();
test_open_by_ini_api();
test_open_ini_separated(buf);
test_open_ini_by_falseseparated(path);
test_open_by_dlns_inherir(path);
test_open_by_ini_no_inherit(path);
test_open_by_shared_libs(path);
test_open_by_sameso_in_diff_ns(path);
test_open_by_ini_mtso_ns();
test_open_by_inherit_transitivity(path);
test_open_by_iinheritB_shared_libs(path);
main_dlopen_ndk_so();
system_so_dlopen_ndk_so();
ndk_so_dlopen_default_ns_so();
dlopen_same_so_twice_by_same_ns(path);
dlopen_same_so_by_different_ns(path);
dlopen_same_so_by_different_inherit_ns(path);
dlopen_seperated(path);
dlopen_test_dlns_create2();
dlopen_inherit(path);
dlopen_inherit_check_can_pass(path);
return t_status;
return t_status;
}
\ No newline at end of file
#include <stdio.h>
#include <dlfcn.h>
void sayhello()
{
printf ("hello world!\n");
}
void* call_dlopen(const char* name)
{
return dlopen(name, RTLD_NOW);
}
\ No newline at end of file
extern void* call_dlopen(const char *name);
void* call(const char *name)
{
return call_dlopen(name);
}
\ No newline at end of file
......@@ -37,7 +37,9 @@ ohos_executable("dlns_dlopen_test") {
"//third_party/musl/porting/linux/user/include",
"//third_party/musl/libc-test/src/common",
]
if (musl_arch == "arm") {
defines = [ "MUSL_ARM" ]
}
sources = [ "dlns_dlopen.c" ]
configs = [ "//third_party/musl/libc-test/src/common:config_runtest" ]
......
......@@ -41,8 +41,14 @@ static const char* dllName_inh_007 = "inherit_0700.so";
static const char* dllName_inh_008 = "inherit_0800.so";
static const char* dllName_inh_011 = "inherit_1100.so";
static const char* dllAcePath = "/system/lib/libace.z.so";
#if defined(MUSL_ARM)
static const char* dllAcePath = "/system/lib/platformsdk/libace.z.so";
static const char* dllDylibPath = "/system/lib/libstd.dylib.so";
#else
static const char* dllAcePath = "/system/lib64/platformsdk/libace.z.so";
static const char* dllDylibPath = "/system/lib64/libstd.dylib.so";
#endif
static const char* dllHashsysvPath = "/data/tests/libc-test/src/libdlopen_hash_sysv.so";
static const char* dllHashsysv = "libdlopen_hash_sysv.so";
static const char* dllFillRandom = "/data/tests/libc-test/src/libdlopen_fill_random.so";
......
......@@ -3,11 +3,17 @@
test = /data/tests/libc-test/src
[acquiescence]
namespace.default.lib.paths = /system/lib64:/vendor/lib64:/vendor/lib64/chipsetsdk:/vendor/lib64/chipset-sdk:/system/lib64/ndk:/system/lib64/chipset-pub-sdk:/system/lib64/chipset-sdk:/system/lib64/platformsdk:/system/lib64/priv-platformsdk:/system/lib64/priv-module:/system/lib64/module:/system/lib64/module/data:/system/lib64/module/multimedia:/system/lib64/module/security:/system/lib:/vendor/lib:/system/lib/ndk:/system/lib/chipset-pub-sdk:/system/lib/chipset-sdk:/system/lib/platformsdk:/system/lib/priv-platformsdk:/system/lib/priv-module:/system/lib/module:/system/lib/module/data:/system/lib/module/multimedia:/lib64:/lib:/usr/local/lib:/usr/lib:/lib64/platformsdk:/lib64/chipset-pub-sdk
namespace.default.asan.lib.paths = /system/lib64:/system/lib64/module:/vendor/lib64:/vendor/lib64/chipsetsdk:/vendor/lib64/chipset-sdk:/system/lib64/module/data:/system/lib64/module/multimedia:/system/lib64/module/security:/system/lib:/system/lib/module:/system/lib/module/data:/system/lib/module/multimedia:/lib64:/lib:/usr/local/lib:/usr/lib:/lib64/platformsdk:/lib64/chipset-pub-sdk
namespace.default.lib.paths = /data/tests/libc-test/src:/system/lib64:/vendor/lib64:/vendor/lib64/chipsetsdk:/vendor/lib64/chipset-sdk:/system/lib64/chipset-pub-sdk:/system/lib64/chipset-sdk:/system/lib64/platformsdk:/system/lib64/priv-platformsdk:/system/lib64/priv-module:/system/lib64/module:/system/lib64/module/data:/system/lib64/module/multimedia:/system/lib64/module/security:/system/lib:/vendor/lib:/system/lib/chipset-pub-sdk:/system/lib/chipset-sdk:/system/lib/platformsdk:/system/lib/priv-platformsdk:/system/lib/priv-module:/system/lib/module:/system/lib/module/data:/system/lib/module/multimedia:/lib64:/lib:/usr/local/lib:/usr/lib:/lib64/platformsdk:/lib64/chipset-pub-sdk
namespace.default.asan.lib.paths = /data/tests/libc-test/src:/system/lib64:/system/lib64/module:/vendor/lib64:/vendor/lib64/chipsetsdk:/vendor/lib64/chipset-sdk:/system/lib64/module/data:/system/lib64/module/multimedia:/system/lib64/module/security:/system/lib:/system/lib/module:/system/lib/module/data:/system/lib/module/multimedia:/lib64:/lib:/usr/local/lib:/usr/lib:/lib64/platformsdk:/lib64/chipset-pub-sdk
[test]
added.nslist=ns_no_allowed_libs,ns_normal,ns_wrong_lib_path,ns_wrong_allowed_path,for_inherit_A,for_inherit_AA,inherited_class,ns_separated_flase,ns_asan_lib_path,ns_asan_permit_path
added.nslist=ndk,ns_no_allowed_libs,ns_normal,ns_wrong_lib_path,ns_wrong_allowed_path,for_inherit_A,for_inherit_AA,inherited_class,ns_separated_flase,ns_asan_lib_path,ns_asan_permit_path
namespace.ndk.lib.paths = /system/lib64/ndk:/system/lib/ndk
namespace.default.inherits = ndk
namespace.default.inherit.ndk.shared.libs = allow_all_shared_libs
namespace.ndk.inherits = default
namespace.ndk.inherit.default.shared.libs = allow_all_shared_libs
#ns_no_allowed_libs ,allowed libs not configed
namespace.ns_no_allowed_libs.separated = true
......
......@@ -6,3 +6,7 @@
namespace.ndk.lib.paths = /system/lib64/ndk:/system/lib/ndk
namespace.default.lib.paths = /system/lib64:/vendor/lib64:/vendor/lib64/chipsetsdk:/vendor/lib64/chipset-sdk:/system/lib64/chipset-pub-sdk:/system/lib64/chipset-sdk:/system/lib64/platformsdk:/system/lib64/priv-platformsdk:/system/lib64/priv-module:/system/lib64/module:/system/lib64/module/data:/system/lib64/module/multimedia:/system/lib64/module/security:/system/lib:/vendor/lib:/system/lib/chipset-pub-sdk:/system/lib/chipset-sdk:/system/lib/platformsdk:/system/lib/priv-platformsdk:/system/lib/priv-module:/system/lib/module:/system/lib/module/data:/system/lib/module/multimedia:/lib64:/lib:/usr/local/lib:/usr/lib:/vendor/lib64/hw:/lib64/platformsdk:/lib64/chipset-pub-sdk
namespace.default.asan.lib.paths = /system/lib64:/system/lib64/module:/vendor/lib64:/vendor/lib64/chipsetsdk:/vendor/lib64/chipset-sdk:/system/lib64/module/data:/system/lib64/module/multimedia:/system/lib64/module/security:/system/lib:/system/lib/module:/system/lib/module/data:/system/lib/module/multimedia:/lib64:/lib:/usr/local/lib:/usr/lib:/vendor/lib64/hw:/lib64/platformsdk:/lib64/chipset-pub-sdk
namespace.default.inherits = ndk
namespace.default.inherit.ndk.shared.libs = allow_all_shared_libs
namespace.ndk.inherits = default
namespace.ndk.inherit.default.shared.libs = allow_all_shared_libs
\ No newline at end of file
......@@ -3,11 +3,17 @@
test = /data/tests/libc-test/src
[acquiescence]
namespace.default.lib.paths = /system/lib:/vendor/lib:/vendor/lib/chipsetsdk:/vendor/lib/chipset-sdk:/system/lib/ndk:/system/lib/chipset-pub-sdk:/system/lib/chipset-sdk:/system/lib/platformsdk:/system/lib/priv-platformsdk:/system/lib/priv-module:/system/lib/module:/system/lib/module/data:/system/lib/module/multimedia:/system/lib/module/security:/lib:/usr/local/lib:/usr/lib:/lib/platformsdk:/lib/chipset-pub-sdk
namespace.default.asan.lib.paths = /system/lib:/system/lib/module:/vendor/lib:/vendor/lib/chipsetsdk:/vendor/lib/chipset-sdk:/system/lib/module/data:/system/lib/module/multimedia:/system/lib/module/security:/lib:/usr/local/lib:/usr/lib:/lib/platformsdk:/lib/chipset-pub-sdk
namespace.default.lib.paths = /data/tests/libc-test/src:/system/lib:/vendor/lib:/vendor/lib/chipsetsdk:/vendor/lib/chipset-sdk:/system/lib/chipset-pub-sdk:/system/lib/chipset-sdk:/system/lib/platformsdk:/system/lib/priv-platformsdk:/system/lib/priv-module:/system/lib/module:/system/lib/module/data:/system/lib/module/multimedia:/system/lib/module/security:/lib:/usr/local/lib:/usr/lib:/lib/platformsdk:/lib/chipset-pub-sdk
namespace.default.asan.lib.paths = /data/tests/libc-test/src:/system/lib:/system/lib/module:/vendor/lib:/vendor/lib/chipsetsdk:/vendor/lib/chipset-sdk:/system/lib/module/data:/system/lib/module/multimedia:/system/lib/module/security:/lib:/usr/local/lib:/usr/lib:/lib/platformsdk:/lib/chipset-pub-sdk
[test]
added.nslist=ns_no_allowed_libs,ns_normal,ns_wrong_lib_path,ns_wrong_allowed_path,for_inherit_A,for_inherit_AA,inherited_class,ns_separated_flase,ns_asan_lib_path,ns_asan_permit_path
added.nslist=ndk,ns_no_allowed_libs,ns_normal,ns_wrong_lib_path,ns_wrong_allowed_path,for_inherit_A,for_inherit_AA,inherited_class,ns_separated_flase,ns_asan_lib_path,ns_asan_permit_path
namespace.ndk.lib.paths = /system/lib/ndk
namespace.default.inherits = ndk
namespace.default.inherit.ndk.shared.libs = allow_all_shared_libs
namespace.ndk.inherits = default
namespace.ndk.inherit.default.shared.libs = allow_all_shared_libs
#ns_no_allowed_libs ,allowed libs not configed
namespace.ns_no_allowed_libs.separated = true
......
......@@ -6,3 +6,7 @@
namespace.ndk.lib.paths = /system/lib/ndk
namespace.default.lib.paths = /system/lib:/vendor/lib:/vendor/lib/chipsetsdk:/vendor/lib/chipset-sdk:/system/lib/chipset-pub-sdk:/system/lib/chipset-sdk:/system/lib/platformsdk:/system/lib/priv-platformsdk:/system/lib/priv-module:/system/lib/module:/system/lib/module/data:/system/lib/module/multimedia:/system/lib/module/security:/lib:/usr/local/lib:/usr/lib:/lib/platformsdk:/lib/chipset-pub-sdk
namespace.default.asan.lib.paths = /system/lib:/system/lib/module:/vendor/lib:/vendor/lib/chipsetsdk:/vendor/lib/chipset-sdk:/system/lib/module/data:/system/lib/module/multimedia:/system/lib/module/security:/lib:/usr/local/lib:/usr/lib:/lib/platformsdk:/lib/chipset-pub-sdk
namespace.default.inherits = ndk
namespace.default.inherit.ndk.shared.libs = allow_all_shared_libs
namespace.ndk.inherits = default
namespace.ndk.inherit.default.shared.libs = allow_all_shared_libs
\ No newline at end of file
......@@ -3,11 +3,17 @@
test = /data/tests/libc-test/src
[acquiescence]
namespace.default.lib.paths = /system/lib64:/vendor/lib64:/vendor/lib64/chipsetsdk:/vendor/lib64/chipset-sdk:/system/lib64/ndk:/system/lib64/chipset-pub-sdk:/system/lib64/chipset-sdk:/system/lib64/platformsdk:/system/lib64/priv-platformsdk:/system/lib64/priv-module:/system/lib64/module:/system/lib64/module/data:/system/lib64/module/multimedia:/system/lib64/module/security:/lib64:/lib64/platformsdk:/lib64/chipset-pub-sdk
namespace.default.asan.lib.paths = /system/lib64:/system/lib64/module:/vendor/lib64:/vendor/lib64/chipsetsdk:/vendor/lib64/chipset-sdk:/system/lib64/module/data:/system/lib64/module/multimedia:/system/lib64/module/security:/lib64:/lib64/platformsdk:/lib64/chipset-pub-sdk
namespace.default.lib.paths = /data/tests/libc-test/src:/system/lib64:/vendor/lib64:/vendor/lib64/chipsetsdk:/vendor/lib64/chipset-sdk:/system/lib64/chipset-pub-sdk:/system/lib64/chipset-sdk:/system/lib64/platformsdk:/system/lib64/priv-platformsdk:/system/lib64/priv-module:/system/lib64/module:/system/lib64/module/data:/system/lib64/module/multimedia:/system/lib64/module/security:/lib64:/lib64/platformsdk:/lib64/chipset-pub-sdk
namespace.default.asan.lib.paths = /data/tests/libc-test/src:/system/lib64:/system/lib64/module:/vendor/lib64:/vendor/lib64/chipsetsdk:/vendor/lib64/chipset-sdk:/system/lib64/module/data:/system/lib64/module/multimedia:/system/lib64/module/security:/lib64:/lib64/platformsdk:/lib64/chipset-pub-sdk
[test]
added.nslist=ns_no_allowed_libs,ns_normal,ns_wrong_lib_path,ns_wrong_allowed_path,for_inherit_A,for_inherit_AA,inherited_class,ns_separated_flase,ns_asan_lib_path,ns_asan_permit_path
added.nslist=ndk,ns_no_allowed_libs,ns_normal,ns_wrong_lib_path,ns_wrong_allowed_path,for_inherit_A,for_inherit_AA,inherited_class,ns_separated_flase,ns_asan_lib_path,ns_asan_permit_path
namespace.ndk.lib.paths = /system/lib/ndk
namespace.default.inherits = ndk
namespace.default.inherit.ndk.shared.libs = allow_all_shared_libs
namespace.ndk.inherits = default
namespace.ndk.inherit.default.shared.libs = allow_all_shared_libs
#ns_no_allowed_libs ,allowed libs not configed
namespace.ns_no_allowed_libs.separated = true
......
......@@ -6,3 +6,7 @@
namespace.ndk.lib.paths = /system/lib64/ndk:/system/lib/ndk
namespace.default.lib.paths = /system/lib64:/vendor/lib64:/vendor/lib64/chipsetsdk:/vendor/lib64/chipset-sdk:/system/lib64/chipset-pub-sdk:/system/lib64/chipset-sdk:/system/lib64/platformsdk:/system/lib64/priv-platformsdk:/system/lib64/priv-module:/system/lib64/module:/system/lib64/module/data:/system/lib64/module/multimedia:/system/lib64/module/security:/lib64:/lib64/platformsdk:/lib64/chipset-pub-sdk
namespace.default.asan.lib.paths = /system/lib64:/system/lib64/module:/vendor/lib64:/vendor/lib64/chipsetsdk:/vendor/lib64/chipset-sdk:/system/lib64/module/data:/system/lib64/module/multimedia:/system/lib64/module/security:/lib64:/lib64/platformsdk:/lib64/chipset-pub-sdk
namespace.default.inherits = ndk
namespace.default.inherit.ndk.shared.libs = allow_all_shared_libs
namespace.ndk.inherits = default
namespace.ndk.inherit.default.shared.libs = allow_all_shared_libs
\ No newline at end of file
......@@ -37,7 +37,7 @@ ShieldedList=("trace_stresstest" "syslog" "vsyslog" "runtest"
"acoshl" "asinhl" "erfcl" "fenv" "fma" "fmaf" "fmal" "lgammal" "nearbyint" "nearbyintf"
"nearbyintl" "rint" "rintf" "rintl" "sqrt" "sqrtf" "sqrtl" "tgammal"
#TODO-arm32
"dlopen_ns" "malloc-brk-fail" "pthread_cancel" "res_send"
"malloc-brk-fail" "pthread_cancel" "res_send"
)
#TODO-aarch64
......
......@@ -82,6 +82,12 @@ hdc shell cp %REMOTE%/src/libdlopen_dso.so %REMOTE%/src/inherit_0700.so
hdc shell cp %REMOTE%/src/libdlopen_dso.so %REMOTE%/src/inherit_0800.so
hdc shell cp %REMOTE%/src/libdlopen_dso.so %REMOTE%/src/inherit_1100.so
hdc shell cp %REMOTE%/src/libdlopen_ns_dso.so /system/lib
hdc shell cp %REMOTE%/src/libdlopen_dso.so %REMOTE%/src/lib_for_no_delete.so
hdc shell cp %REMOTE%/src/libdlopen_dso.so %REMOTE%/src/lib_for_dlopen.so
hdc shell cp %REMOTE%/src/libdlopen_ns_dso.so /system/lib64/libdlopen_ns_dso_sys.so
hdc shell cp %REMOTE%/src/libdlopen_ns_dso.so /system/lib/libdlopen_ns_dso_sys.so
hdc shell cp %REMOTE%/src/libdlopen_ns_dso.so /system/lib64/ndk/libdlopen_ns_dso_ndk.so
hdc shell cp %REMOTE%/src/libdlopen_ns_dso.so /system/lib/ndk/libdlopen_ns_dso_ndk.so
hdc shell mv %REMOTE%/src/zh_CN /tmp/zh_CN
......
......@@ -110,6 +110,12 @@ ${CMD} shell cp ${REMOTE}/src/libdlopen_dso.so ${REMOTE}/src/inherit_0700.so
${CMD} shell cp ${REMOTE}/src/libdlopen_dso.so ${REMOTE}/src/inherit_0800.so
${CMD} shell cp ${REMOTE}/src/libdlopen_dso.so ${REMOTE}/src/inherit_1100.so
${CMD} shell cp ${REMOTE}/src/libdlopen_ns_dso.so /system/lib
${CMD} shell cp ${REMOTE}/src/libdlopen_dso.so ${REMOTE}/src/lib_for_no_delete.so
${CMD} shell cp ${REMOTE}/src/libdlopen_dso.so ${REMOTE}/src/lib_for_dlopen.so
${CMD} shell cp ${REMOTE}/src/libdlopen_ns_dso.so /system/lib64/libdlopen_ns_dso_sys.so
${CMD} shell cp ${REMOTE}/src/libdlopen_ns_dso.so /system/lib64/ndk/libdlopen_ns_dso_ndk.so
${CMD} shell cp ${REMOTE}/src/libdlopen_ns_dso.so /system/lib/libdlopen_ns_dso_sys.so
${CMD} shell cp ${REMOTE}/src/libdlopen_ns_dso.so /system/lib/ndk/libdlopen_ns_dso_ndk.so
${CMD} shell mv ${REMOTE}/src/zh_CN /tmp/zh_CN
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册