mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-25 12:23:20 -04:00
!18292 merge hspAOT into master
Support ArkTS-Sta AOT hsp loading Created-by: yuanyao14 Commit-by: yuanyao14 Merged-by: openharmony_ci Description: **IssueNo**: https://gitcode.com/openharmony/ability_ability_runtime/issues/14435 **Description**: ArkTS-Sta 支持Hsp aot加载 **稳定性自检:** | 自检项 | 自检结果 | | ------------------------------------------------------------ | -------- | | 涉及跨进程调用的相关操作需要抛至主线程或加锁防止并发 | 不涉及 | | 成员变量进行赋值或创建需要排查并发 | done | | 谨慎在lambda表达式中使用引用捕获 | 不涉及 | | 谨慎在未经拷贝的情况下使用外部传入的string、C字符串 | done | | map\vector\list\set等stl模板类使用时需要排查并发 | 不涉及 | | 谨慎考虑加锁范围 | 不涉及 | | 在IPC通信中谨慎使用同步通信方式 | 不涉及 | | 禁止传递this指针至其他模块或线程(特别是eventhandler任务) | 不涉及 | | 禁止将外部传入的裸指针在内部直接构造智能指针 | 不涉及 | | 禁止多个独立创建的智能指针管理同一地址 | 不涉及 | | 禁止在析构函数中抛异步任务 | 不涉及 | | 禁止js对象在非js线程(例如在IPC线程)创建、使用或销毁 | 不涉及 | | 禁止在对外接口中未经判空直接使用外部传入的指针 | 不涉及 | | 禁止接口返回局部变量引用 | 不涉及 | | 禁止在信号函数中加锁 | 不涉及 | | 禁止在关键流程(SA启动、应用启动等主流程)执行耗时的操作 | 不涉及 | | 禁止将同一个cpp编译在不同的so中 | 不涉及 | **安全编码自检:** | 自检项 | 自检结果 | | -------------------------------------------------------------- | -------- | | 裸指针避免通过隐式转换构造为sptr | 不涉及 | | json对象在取值之前必须先判断类型,避免类型不匹配 | 不涉及 | | 序列化时必须对传入的数组大小进行校验,避免出现超大数组 | 不涉及 | | 避免使用未明确位宽的整型,选择使用int8_t、uint8_t等类型 | 不涉及 | | 外部传入的路径要做规范化校验,对路径中的.、..、../等特殊字符严格校验 | done | | 指针变量、表示资源描述符的变量、bool变量必须赋初值 | 不涉及 | | readParcelable获取的对象使用前需要判空 | 不涉及 | | 分配和释放内存的函数需要成对出现 | 不涉及 | | 申请内存后异常退出前需要及时进行内存释放 | 不涉及 | | 内存申请前必须对内存大小进行合法性校验 | 不涉及 | | 内存分配后必须判断是否成功 | 不涉及 | | 禁止使用realloc、alloca函数 | 不涉及 | | 禁止打印文件路径、口令等敏感信息,如有需要,使用private修饰 | done | | 禁止打印内存地址 | done | | 整数之间运算时必须严格检查,确保不会出现溢出、反转、除0 | 不涉及 | | 禁止对有符号整数进行位操作符运算 | 不涉及 | | 禁止对指针进行逻辑或位运算 | 不涉及 | | 循环次数如果收外部数据控制,需要检验其合法性 | 不涉及 | | 禁止使用内存操作类危险函数,需要使用安全函数 | 不涉及 | | 谨慎使用不可重入函数 | 不涉及 | | 必须检查安全函数的返回值,并进行正确处理 | 不涉及 | | 禁止仅通过TokenType类型判断绕过权限校验 | 不涉及 | **TDD Result**: all passed **XTS Result**: all passed ### 是否已执行L0用例 - [x] 已验证 - [ ] 不涉及。如不涉及,请写明理由 See merge request: openharmony/ability_ability_runtime!18292
This commit is contained in:
@@ -626,7 +626,7 @@ bool ETSEnvironment::PostFork(void *napiEnv, const std::string &aotPath,
|
||||
std::vector<ani_option> options;
|
||||
std::string aotPathString = "";
|
||||
if (!aotPath.empty()) {
|
||||
aotPathString = "--ext:--aot-file=" + aotPath;
|
||||
aotPathString = "--ext:--aot-files=" + aotPath;
|
||||
options.push_back(ani_option { aotPathString.data(), nullptr });
|
||||
options.push_back(ani_option { "--ext:--enable-an", nullptr });
|
||||
TAG_LOGD(AAFwkTag::ETSRUNTIME, "aotPathString: %{public}s", aotPathString.c_str());
|
||||
|
||||
@@ -296,6 +296,7 @@ HWTEST_F(EtsEnvironmentTest, LoadAbcLinker_0200, TestSize.Level0)
|
||||
etsEnv->vmEntry_.abcLinkerRef_ = reinterpret_cast<ani_ref>(0x123);
|
||||
|
||||
OHOS::AbilityRuntime::CommonHspBundleInfo info;
|
||||
info.versionCode = 0;
|
||||
info.bundleName = "bundle";
|
||||
info.moduleName = "module";
|
||||
info.hapPath = "/data/app/el1/bundle/public/hsp/test.hsp";
|
||||
@@ -599,6 +600,7 @@ HWTEST_F(EtsEnvironmentTest, SetHspAbcFiles_0300, TestSize.Level0)
|
||||
ASSERT_NE(etsEnv, nullptr);
|
||||
|
||||
OHOS::AbilityRuntime::CommonHspBundleInfo info;
|
||||
info.versionCode = 0;
|
||||
info.bundleName = "bundle";
|
||||
info.moduleName = "module";
|
||||
info.hapPath = "/data/app/el1/bundle/public/hsp/test.hsp";
|
||||
@@ -630,6 +632,7 @@ HWTEST_F(EtsEnvironmentTest, SetHspAbcFiles_0400, TestSize.Level0)
|
||||
ASSERT_NE(etsEnv, nullptr);
|
||||
|
||||
OHOS::AbilityRuntime::CommonHspBundleInfo info;
|
||||
info.versionCode = 0;
|
||||
info.bundleName = "bundle";
|
||||
info.moduleName = "module";
|
||||
info.hapPath = "/data/app/el1/bundle/public/hsp/test.hsp";
|
||||
@@ -656,6 +659,7 @@ HWTEST_F(EtsEnvironmentTest, SetHspAbcFiles_0500, TestSize.Level0)
|
||||
ASSERT_NE(etsEnv, nullptr);
|
||||
|
||||
OHOS::AbilityRuntime::CommonHspBundleInfo info;
|
||||
info.versionCode = 0;
|
||||
info.bundleName = "bundle";
|
||||
info.moduleName = "module";
|
||||
info.hapPath = "/data/app/el1/bundle/public/hsp/test.hsp";
|
||||
@@ -682,6 +686,7 @@ HWTEST_F(EtsEnvironmentTest, SetHspAbcFiles_0600, TestSize.Level0)
|
||||
ASSERT_NE(etsEnv, nullptr);
|
||||
|
||||
OHOS::AbilityRuntime::CommonHspBundleInfo info;
|
||||
info.versionCode = 0;
|
||||
info.bundleName = "bundle";
|
||||
info.moduleName = "module";
|
||||
info.hapPath = "/data/app/el1/bundle/public/hsp/test.hsp";
|
||||
|
||||
@@ -1801,7 +1801,8 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
|
||||
}
|
||||
}
|
||||
for (const auto &hsp : hspList) {
|
||||
options.commonHspBundleInfos.push_back({hsp.bundleName, hsp.moduleName, hsp.hapPath, hsp.moduleArkTSMode});
|
||||
options.commonHspBundleInfos.push_back({hsp.versionCode, hsp.bundleName, hsp.moduleName,
|
||||
hsp.hapPath, hsp.moduleArkTSMode});
|
||||
}
|
||||
options.enableWarmStartupSmartGC =
|
||||
(appLaunchData.GetAppPreloadMode() == AppExecFwk::PreloadMode::PRE_MAKE ||
|
||||
|
||||
@@ -62,7 +62,10 @@ const std::string ETS_SYSLIB_PATH =
|
||||
#endif
|
||||
constexpr char BUNDLE_INSTALL_PATH[] = "/data/storage/el1/bundle/";
|
||||
constexpr char SANDBOX_ARK_CACHE_PATH[] = "/data/storage/ark-cache/";
|
||||
constexpr char SANDBOX_SHARED_BUNDLE_ARK_CACHE_PATH[] =
|
||||
"/data/service/el1/public/for-all-app/shared_bundles_ark_cache/";
|
||||
constexpr char MERGE_ABC_PATH[] = "/ets/modules_static.abc";
|
||||
const std::string SYS_HSP_FILE_PATH_PREFIX = "/system/app/";
|
||||
|
||||
const char *ETS_ENV_LIBNAME = "libets_environment.z.so";
|
||||
const char *ETS_ENV_REGISTER_FUNCS = "OHOS_ETS_ENV_RegisterFuncs";
|
||||
@@ -157,6 +160,48 @@ void ETSRuntime::PreloadLibrary()
|
||||
}
|
||||
}
|
||||
|
||||
std::string ETSRuntime::GetAotPath(const Options &options)
|
||||
{
|
||||
std::vector<std::string> aotFiles;
|
||||
if (!options.arkNativeFilePath.empty()) {
|
||||
// Handle Hap and Inner Hsp
|
||||
// path: <sandbox_path>/arm64/<moduleName>.an
|
||||
for (const auto& status: options.aotCompileStatusMap) {
|
||||
if (status.second) {
|
||||
aotFiles.push_back(SANDBOX_ARK_CACHE_PATH + options.arkNativeFilePath + status.first + ".an");
|
||||
}
|
||||
}
|
||||
|
||||
// Handle Outer Hsp
|
||||
for (const auto& bundleInfo: options.commonHspBundleInfos) {
|
||||
if (bundleInfo.moduleArkTSMode == AppExecFwk::Constants::ARKTS_MODE_DYNAMIC) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (bundleInfo.hapPath.compare(0, SYS_HSP_FILE_PATH_PREFIX.size(), SYS_HSP_FILE_PATH_PREFIX) != 0 &&
|
||||
bundleInfo.hapPath.rfind('/') == std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// path: <sandbox_path>/<bundleName>/v<versionCode>/arm64/<moduleName>.an
|
||||
std::string outerHspAnPath = SANDBOX_SHARED_BUNDLE_ARK_CACHE_PATH + bundleInfo.bundleName +
|
||||
std::string(AbilityBase::Constants::FILE_SEPARATOR) + std::to_string(bundleInfo.versionCode) +
|
||||
std::string(AbilityBase::Constants::FILE_SEPARATOR) + options.arkNativeFilePath +
|
||||
bundleInfo.moduleName + ".an";
|
||||
aotFiles.push_back(outerHspAnPath);
|
||||
}
|
||||
}
|
||||
|
||||
std::string aotFilePath;
|
||||
for (const auto& path: aotFiles) {
|
||||
if (!aotFilePath.empty()) {
|
||||
aotFilePath += ":";
|
||||
}
|
||||
aotFilePath += path;
|
||||
}
|
||||
return aotFilePath;
|
||||
}
|
||||
|
||||
bool ETSRuntime::PostFork(const Options &options, std::unique_ptr<Runtime> &jsRuntime, bool isMove)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::ETSRUNTIME, "PostFork begin");
|
||||
@@ -184,12 +229,7 @@ bool ETSRuntime::PostFork(const Options &options, std::unique_ptr<Runtime> &jsRu
|
||||
vm, HybridJsModuleReader(options.bundleName, options.hapPath, options.isUnique));
|
||||
}
|
||||
|
||||
std::string aotFilePath = "";
|
||||
if (!options.arkNativeFilePath.empty()) {
|
||||
aotFilePath = SANDBOX_ARK_CACHE_PATH + options.arkNativeFilePath + options.moduleName + ".an";
|
||||
}
|
||||
|
||||
g_etsEnvFuncs->PostFork(reinterpret_cast<void *>(napiEnv), aotFilePath, options.appInnerHspPathList,
|
||||
g_etsEnvFuncs->PostFork(reinterpret_cast<void *>(napiEnv), GetAotPath(options), options.appInnerHspPathList,
|
||||
options.commonHspBundleInfos, options.eventRunner);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -107,6 +107,7 @@ private:
|
||||
std::unique_ptr<AppExecFwk::ETSNativeReference> LoadEtsModule(const std::string &moduleName,
|
||||
const std::string &fileName, const std::string &hapPath, const std::string &srcEntrance);
|
||||
bool PostFork(const Options &options, std::unique_ptr<Runtime> &jsRuntime, bool isMove = true);
|
||||
std::string GetAotPath(const Options &options);
|
||||
std::string HandleOhmUrlSrcEntry(const std::string &srcEntry);
|
||||
void HandleOhmUrlFileName(std::string &fileName);
|
||||
static void PreloadLibrary();
|
||||
|
||||
@@ -28,6 +28,7 @@ class EventRunner;
|
||||
} // namespace AppExecFwk
|
||||
namespace AbilityRuntime {
|
||||
struct CommonHspBundleInfo {
|
||||
uint32_t versionCode;
|
||||
std::string bundleName;
|
||||
std::string moduleName;
|
||||
std::string hapPath;
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "ets_runtime.h"
|
||||
#undef private
|
||||
#undef protected
|
||||
#include "bundle_constants.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "js_runtime.h"
|
||||
#include "runtime.h"
|
||||
@@ -338,5 +339,250 @@ HWTEST_F(EtsRuntimeTest, SetExtensionApiCheckCallback_100, TestSize.Level1)
|
||||
etsRuntime->SetExtensionApiCheckCallback(callback);
|
||||
EXPECT_EQ(etsRuntime->GetJsRuntime(), nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetHspPathList_100
|
||||
* @tc.desc: EtsRuntime test for GetHspPathList.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(EtsRuntimeTest, GetHspPathList_100, TestSize.Level1)
|
||||
{
|
||||
std::unique_ptr<EtsEnv::ETSEnvironment> etsEnvironment = std::make_unique<EtsEnv::ETSEnvironment>();
|
||||
etsEnvironment->commonHspBundleInfos_ = {};
|
||||
auto hspPathList = etsEnvironment->GetHspPathList();
|
||||
EXPECT_EQ(hspPathList.size(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetHspPathList_200
|
||||
* @tc.desc: EtsRuntime test for GetHspPathList.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(EtsRuntimeTest, GetHspPathList_200, TestSize.Level1)
|
||||
{
|
||||
std::unique_ptr<EtsEnv::ETSEnvironment> etsEnvironment = std::make_unique<EtsEnv::ETSEnvironment>();
|
||||
etsEnvironment->commonHspBundleInfos_ = {{0, "", "", "/system/app/path1", "static"}};
|
||||
auto hspPathList = etsEnvironment->GetHspPathList();
|
||||
EXPECT_EQ(hspPathList[0], "/system/app/path1");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAotPath_001
|
||||
* @tc.desc: EtsRuntime test for GetAotPath with empty arkNativeFilePath.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(EtsRuntimeTest, GetAotPath_001, TestSize.Level1)
|
||||
{
|
||||
auto etsRuntime = std::make_unique<ETSRuntime>();
|
||||
Runtime::Options options;
|
||||
options.arkNativeFilePath = "";
|
||||
auto result = etsRuntime->GetAotPath(options);
|
||||
EXPECT_EQ(result, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAotPath_002
|
||||
* @tc.desc: EtsRuntime test for GetAotPath with arkNativeFilePath but empty maps.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(EtsRuntimeTest, GetAotPath_002, TestSize.Level1)
|
||||
{
|
||||
auto etsRuntime = std::make_unique<ETSRuntime>();
|
||||
Runtime::Options options;
|
||||
options.arkNativeFilePath = "arm64/";
|
||||
options.moduleName = "testModule";
|
||||
options.aotCompileStatusMap = {};
|
||||
options.commonHspBundleInfos = {};
|
||||
auto result = etsRuntime->GetAotPath(options);
|
||||
EXPECT_EQ(result, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAotPath_003
|
||||
* @tc.desc: EtsRuntime test for GetAotPath with aotCompileStatusMap having true values.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(EtsRuntimeTest, GetAotPath_003, TestSize.Level1)
|
||||
{
|
||||
auto etsRuntime = std::make_unique<ETSRuntime>();
|
||||
Runtime::Options options;
|
||||
options.arkNativeFilePath = "arm64/";
|
||||
options.moduleName = "entry";
|
||||
options.aotCompileStatusMap = {{"entry", true}, {"module1", true}, {"module2", false}};
|
||||
options.commonHspBundleInfos = {};
|
||||
auto result = etsRuntime->GetAotPath(options);
|
||||
// Should contain entry.an and module1.an (true values only)
|
||||
EXPECT_NE(result.find("entry.an"), std::string::npos);
|
||||
EXPECT_NE(result.find("module1.an"), std::string::npos);
|
||||
EXPECT_EQ(result.find("module2.an"), std::string::npos);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAotPath_004
|
||||
* @tc.desc: EtsRuntime test for GetAotPath with aotCompileStatusMap all false.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(EtsRuntimeTest, GetAotPath_004, TestSize.Level1)
|
||||
{
|
||||
auto etsRuntime = std::make_unique<ETSRuntime>();
|
||||
Runtime::Options options;
|
||||
options.arkNativeFilePath = "arm64/";
|
||||
options.moduleName = "test";
|
||||
options.aotCompileStatusMap = {{"module1", false}, {"module2", false}};
|
||||
options.commonHspBundleInfos = {};
|
||||
auto result = etsRuntime->GetAotPath(options);
|
||||
EXPECT_EQ(result, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAotPath_005
|
||||
* @tc.desc: EtsRuntime test for GetAotPath with commonHspBundleInfos ARKTS_MODE_DYNAMIC.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(EtsRuntimeTest, GetAotPath_005, TestSize.Level1)
|
||||
{
|
||||
auto etsRuntime = std::make_unique<ETSRuntime>();
|
||||
Runtime::Options options;
|
||||
options.arkNativeFilePath = "arm64/";
|
||||
options.moduleName = "entry";
|
||||
options.aotCompileStatusMap = {};
|
||||
// ARKTS_MODE_DYNAMIC should be skipped
|
||||
std::vector<OHOS::AbilityRuntime::CommonHspBundleInfo> hspInfos = {
|
||||
{1001, "com.example.hsp1", "hspModule1", "/system/app/hsp1.hap", AppExecFwk::Constants::ARKTS_MODE_DYNAMIC}
|
||||
};
|
||||
options.commonHspBundleInfos = hspInfos;
|
||||
auto result = etsRuntime->GetAotPath(options);
|
||||
EXPECT_EQ(result, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAotPath_006
|
||||
* @tc.desc: EtsRuntime test for GetAotPath with commonHspBundleInfos static mode, system path.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(EtsRuntimeTest, GetAotPath_006, TestSize.Level1)
|
||||
{
|
||||
auto etsRuntime = std::make_unique<ETSRuntime>();
|
||||
Runtime::Options options;
|
||||
options.arkNativeFilePath = "arm64/";
|
||||
options.moduleName = "entry";
|
||||
options.aotCompileStatusMap = {};
|
||||
// Static mode with system app path - should be included
|
||||
std::vector<OHOS::AbilityRuntime::CommonHspBundleInfo> hspInfos = {
|
||||
{1001, "com.example.hsp1", "hspModule1", "/system/app/hsp1.hap", AppExecFwk::Constants::ARKTS_MODE_STATIC}
|
||||
};
|
||||
options.commonHspBundleInfos = hspInfos;
|
||||
auto result = etsRuntime->GetAotPath(options);
|
||||
// Should contain the outer HSP path
|
||||
EXPECT_NE(result.find("/data/service/el1/public/for-all-app/shared_bundles_ark_cache/"), std::string::npos);
|
||||
EXPECT_NE(result.find("com.example.hsp1"), std::string::npos);
|
||||
EXPECT_NE(result.find("hspModule1.an"), std::string::npos);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAotPath_007
|
||||
* @tc.desc: EtsRuntime test for GetAotPath with commonHspBundleInfos non-system path without slash.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(EtsRuntimeTest, GetAotPath_007, TestSize.Level1)
|
||||
{
|
||||
auto etsRuntime = std::make_unique<ETSRuntime>();
|
||||
Runtime::Options options;
|
||||
options.arkNativeFilePath = "arm64/";
|
||||
options.moduleName = "entry";
|
||||
options.aotCompileStatusMap = {};
|
||||
// Non-system path (doesn't start with /system/app/) and has no '/' - should be skipped
|
||||
std::vector<OHOS::AbilityRuntime::CommonHspBundleInfo> hspInfos = {
|
||||
{1001, "com.example.hsp1", "hspModule1", "relativePathWithoutSlash", AppExecFwk::Constants::ARKTS_MODE_STATIC}
|
||||
};
|
||||
options.commonHspBundleInfos = hspInfos;
|
||||
auto result = etsRuntime->GetAotPath(options);
|
||||
EXPECT_EQ(result, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAotPath_008
|
||||
* @tc.desc: EtsRuntime test for GetAotPath with commonHspBundleInfos non-system path with slash.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(EtsRuntimeTest, GetAotPath_008, TestSize.Level1)
|
||||
{
|
||||
auto etsRuntime = std::make_unique<ETSRuntime>();
|
||||
Runtime::Options options;
|
||||
options.arkNativeFilePath = "arm64/";
|
||||
options.moduleName = "entry";
|
||||
options.aotCompileStatusMap = {};
|
||||
// Non-system path but has '/' - should be included
|
||||
std::vector<OHOS::AbilityRuntime::CommonHspBundleInfo> hspInfos = {
|
||||
{1001, "com.example.hsp1", "hspModule1", "/data/app/hsp1.hap", AppExecFwk::Constants::ARKTS_MODE_STATIC}
|
||||
};
|
||||
options.commonHspBundleInfos = hspInfos;
|
||||
auto result = etsRuntime->GetAotPath(options);
|
||||
// Should contain the outer HSP path
|
||||
EXPECT_NE(result.find("com.example.hsp1"), std::string::npos);
|
||||
EXPECT_NE(result.find("hspModule1.an"), std::string::npos);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAotPath_009
|
||||
* @tc.desc: EtsRuntime test for GetAotPath with multiple commonHspBundleInfos entries.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(EtsRuntimeTest, GetAotPath_009, TestSize.Level1)
|
||||
{
|
||||
auto etsRuntime = std::make_unique<ETSRuntime>();
|
||||
Runtime::Options options;
|
||||
options.arkNativeFilePath = "arm64/";
|
||||
options.moduleName = "entry";
|
||||
options.aotCompileStatusMap = {{"entry", true}};
|
||||
// Mix of different HSP types
|
||||
std::vector<OHOS::AbilityRuntime::CommonHspBundleInfo> hspInfos = {
|
||||
// Dynamic mode - should be skipped
|
||||
{1001, "com.example.hsp1", "hspModule1", "/system/app/hsp1.hap", AppExecFwk::Constants::ARKTS_MODE_DYNAMIC},
|
||||
// Static mode, system path - should be included
|
||||
{1002, "com.example.hsp2", "hspModule2", "/system/app/hsp2.hap", AppExecFwk::Constants::ARKTS_MODE_STATIC},
|
||||
// Static mode, non-system path with slash - should be included
|
||||
{1003, "com.example.hsp3", "hspModule3", "/data/app/hsp3.hap", AppExecFwk::Constants::ARKTS_MODE_STATIC},
|
||||
// Non-system path without slash - should be skipped
|
||||
{1004, "com.example.hsp4", "hspModule4", "relativePath", AppExecFwk::Constants::ARKTS_MODE_STATIC}
|
||||
};
|
||||
options.commonHspBundleInfos = hspInfos;
|
||||
auto result = etsRuntime->GetAotPath(options);
|
||||
// Should contain entry.an (from aotCompileStatusMap)
|
||||
EXPECT_NE(result.find("entry.an"), std::string::npos);
|
||||
// Should contain hsp2 (static mode, system path)
|
||||
EXPECT_NE(result.find("hspModule2.an"), std::string::npos);
|
||||
// Should contain hsp3 (non-system path with slash)
|
||||
EXPECT_NE(result.find("hspModule3.an"), std::string::npos);
|
||||
// Should NOT contain hsp1 (dynamic mode)
|
||||
EXPECT_EQ(result.find("hspModule1.an"), std::string::npos);
|
||||
// Should NOT contain hsp4 (relative path without slash)
|
||||
EXPECT_EQ(result.find("hspModule4.an"), std::string::npos);
|
||||
// Check that paths are separated by colons
|
||||
EXPECT_NE(result.find(":"), std::string::npos);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAotPath_010
|
||||
* @tc.desc: EtsRuntime test for GetAotPath with complete options including versionCode.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(EtsRuntimeTest, GetAotPath_010, TestSize.Level1)
|
||||
{
|
||||
auto etsRuntime = std::make_unique<ETSRuntime>();
|
||||
Runtime::Options options;
|
||||
options.arkNativeFilePath = "arm64/";
|
||||
options.moduleName = "entry";
|
||||
options.aotCompileStatusMap = {{"entry", true}};
|
||||
std::vector<OHOS::AbilityRuntime::CommonHspBundleInfo> hspInfos = {
|
||||
{1002003, "com.example.hsp", "hspModule", "/system/app/hsp.hap", AppExecFwk::Constants::ARKTS_MODE_STATIC}
|
||||
};
|
||||
options.commonHspBundleInfos = hspInfos;
|
||||
auto result = etsRuntime->GetAotPath(options);
|
||||
// Should include version in the path
|
||||
EXPECT_NE(result.find("1002003"), std::string::npos);
|
||||
// Should have proper path structure
|
||||
EXPECT_NE(result.find("/data/service/el1/public/for-all-app/shared_bundles_ark_cache/"), std::string::npos);
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
} // namespace OHOS
|
||||
|
||||
Reference in New Issue
Block a user