ArkTS-Sta AOT loading checking aotCompileStatus

Issue: https://gitcode.com/openharmony/ability_ability_runtime/issues/14663

Signed-off-by: yuanyao14 <yuanyao14@huawei.com>
This commit is contained in:
yuanyao14
2026-03-07 14:39:03 +08:00
parent 288e2508ca
commit 34e9fc36f6
7 changed files with 179 additions and 22 deletions
@@ -297,6 +297,7 @@ HWTEST_F(EtsEnvironmentTest, LoadAbcLinker_0200, TestSize.Level0)
OHOS::AbilityRuntime::CommonHspBundleInfo info;
info.versionCode = 0;
info.aotCompileStatus = 0;
info.bundleName = "bundle";
info.moduleName = "module";
info.hapPath = "/data/app/el1/bundle/public/hsp/test.hsp";
@@ -699,6 +700,7 @@ HWTEST_F(EtsEnvironmentTest, SetHspAbcFiles_0300, TestSize.Level0)
OHOS::AbilityRuntime::CommonHspBundleInfo info;
info.versionCode = 0;
info.aotCompileStatus = 0;
info.bundleName = "bundle";
info.moduleName = "module";
info.hapPath = "/data/app/el1/bundle/public/hsp/test.hsp";
@@ -731,6 +733,7 @@ HWTEST_F(EtsEnvironmentTest, SetHspAbcFiles_0400, TestSize.Level0)
OHOS::AbilityRuntime::CommonHspBundleInfo info;
info.versionCode = 0;
info.aotCompileStatus = 0;
info.bundleName = "bundle";
info.moduleName = "module";
info.hapPath = "/data/app/el1/bundle/public/hsp/test.hsp";
@@ -758,6 +761,7 @@ HWTEST_F(EtsEnvironmentTest, SetHspAbcFiles_0500, TestSize.Level0)
OHOS::AbilityRuntime::CommonHspBundleInfo info;
info.versionCode = 0;
info.aotCompileStatus = 0;
info.bundleName = "bundle";
info.moduleName = "module";
info.hapPath = "/data/app/el1/bundle/public/hsp/test.hsp";
@@ -785,6 +789,7 @@ HWTEST_F(EtsEnvironmentTest, SetHspAbcFiles_0600, TestSize.Level0)
OHOS::AbilityRuntime::CommonHspBundleInfo info;
info.versionCode = 0;
info.aotCompileStatus = 0;
info.bundleName = "bundle";
info.moduleName = "module";
info.hapPath = "/data/app/el1/bundle/public/hsp/test.hsp";
+3 -2
View File
@@ -1806,8 +1806,9 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
}
}
for (const auto &hsp : hspList) {
options.commonHspBundleInfos.push_back({hsp.versionCode, hsp.bundleName, hsp.moduleName,
hsp.hapPath, hsp.moduleArkTSMode});
options.commonHspBundleInfos.push_back({hsp.versionCode,
static_cast<int32_t>(hsp.aotCompileStatus),
hsp.bundleName, hsp.moduleName, hsp.hapPath, hsp.moduleArkTSMode});
}
options.enableWarmStartupSmartGC =
(appLaunchData.GetAppPreloadMode() == AppExecFwk::PreloadMode::PRE_MAKE ||
+13 -5
View File
@@ -28,6 +28,7 @@
#include "constants.h"
#include "ets_interface.h"
#include "file_path_utils.h"
#include "hap_module_info.h"
#include "hilog_tag_wrapper.h"
#include "hdc_register.h"
#include "hitrace_meter.h"
@@ -66,6 +67,7 @@ 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 std::string ARK_CACHE_NATIVE_PATH = "arm64/";
const char *ETS_ENV_LIBNAME = "libets_environment.z.so";
const char *ETS_ENV_REGISTER_FUNCS = "OHOS_ETS_ENV_RegisterFuncs";
@@ -160,20 +162,27 @@ void ETSRuntime::PreloadLibrary()
}
}
bool ETSRuntime::IsAotCompiledSuccess(int32_t status)
{
return status == static_cast<int32_t>(AppExecFwk::AOTCompileStatus::IDLE_COMPILE_SUCCESS) ||
status == static_cast<int32_t>(AppExecFwk::AOTCompileStatus::INSTALL_COMPILE_SUCCESS);
}
std::string ETSRuntime::GetAotPath(const Options &options)
{
std::vector<std::string> aotFiles;
// 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");
if (IsAotCompiledSuccess(status.second)) {
aotFiles.push_back(SANDBOX_ARK_CACHE_PATH + ARK_CACHE_NATIVE_PATH + status.first + ".an");
}
}
// Handle Outer Hsp
for (const auto& bundleInfo: options.commonHspBundleInfos) {
if (bundleInfo.moduleArkTSMode == AppExecFwk::Constants::ARKTS_MODE_DYNAMIC) {
if (!IsAotCompiledSuccess(bundleInfo.aotCompileStatus) ||
bundleInfo.moduleArkTSMode == AppExecFwk::Constants::ARKTS_MODE_DYNAMIC) {
continue;
}
@@ -185,8 +194,7 @@ std::string ETSRuntime::GetAotPath(const Options &options)
// 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";
std::string(AbilityBase::Constants::FILE_SEPARATOR) + ARK_CACHE_NATIVE_PATH + bundleInfo.moduleName + ".an";
aotFiles.push_back(outerHspAnPath);
}
@@ -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);
bool IsAotCompiledSuccess(int32_t status);
std::string GetAotPath(const Options &options);
std::string HandleOhmUrlSrcEntry(const std::string &srcEntry);
void HandleOhmUrlFileName(std::string &fileName);
@@ -29,6 +29,7 @@ class EventRunner;
namespace AbilityRuntime {
struct CommonHspBundleInfo {
uint32_t versionCode;
int32_t aotCompileStatus;
std::string bundleName;
std::string moduleName;
std::string hapPath;
+1
View File
@@ -296,6 +296,7 @@ ohos_unittest("ets_runtime_test") {
external_deps = [
"ability_base:string_utils",
"ability_runtime:runtime",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"eventhandler:libeventhandler",
+155 -15
View File
@@ -27,6 +27,7 @@
#include "js_runtime.h"
#include "runtime.h"
#include "ets_environment.h"
#include "hap_module_info.h"
using namespace testing;
using namespace testing::ext;
@@ -361,7 +362,7 @@ HWTEST_F(EtsRuntimeTest, GetHspPathList_100, TestSize.Level1)
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"}};
etsEnvironment->commonHspBundleInfos_ = {{0, 0, "", "", "/system/app/path1", "static"}};
auto hspPathList = etsEnvironment->GetHspPathList();
EXPECT_EQ(hspPathList[0], "/system/app/path1");
}
@@ -408,7 +409,11 @@ HWTEST_F(EtsRuntimeTest, GetAotPath_003, TestSize.Level1)
Runtime::Options options;
options.arkNativeFilePath = "arm64/";
options.moduleName = "entry";
options.aotCompileStatusMap = {{"entry", true}, {"module1", true}, {"module2", false}};
options.aotCompileStatusMap = {
{"entry", static_cast<int32_t>(AppExecFwk::AOTCompileStatus::IDLE_COMPILE_SUCCESS)},
{"module1", static_cast<int32_t>(AppExecFwk::AOTCompileStatus::IDLE_COMPILE_SUCCESS)},
{"module2", static_cast<int32_t>(AppExecFwk::AOTCompileStatus::NOT_COMPILED)}
};
options.commonHspBundleInfos = {};
auto result = etsRuntime->GetAotPath(options);
// Should contain entry.an and module1.an (true values only)
@@ -428,7 +433,10 @@ HWTEST_F(EtsRuntimeTest, GetAotPath_004, TestSize.Level1)
Runtime::Options options;
options.arkNativeFilePath = "arm64/";
options.moduleName = "test";
options.aotCompileStatusMap = {{"module1", false}, {"module2", false}};
options.aotCompileStatusMap = {
{"module1", static_cast<int32_t>(AppExecFwk::AOTCompileStatus::NOT_COMPILED)},
{"module2", static_cast<int32_t>(AppExecFwk::AOTCompileStatus::NOT_COMPILED)}
};
options.commonHspBundleInfos = {};
auto result = etsRuntime->GetAotPath(options);
EXPECT_EQ(result, "");
@@ -448,7 +456,8 @@ HWTEST_F(EtsRuntimeTest, GetAotPath_005, TestSize.Level1)
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}
{1001, static_cast<int32_t>(AppExecFwk::AOTCompileStatus::NOT_COMPILED), "com.example.hsp1", "hspModule1",
"/system/app/hsp1.hap", AppExecFwk::Constants::ARKTS_MODE_DYNAMIC}
};
options.commonHspBundleInfos = hspInfos;
auto result = etsRuntime->GetAotPath(options);
@@ -469,7 +478,8 @@ HWTEST_F(EtsRuntimeTest, GetAotPath_006, TestSize.Level1)
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}
{1001, static_cast<int32_t>(AppExecFwk::AOTCompileStatus::NOT_COMPILED), "com.example.hsp1", "hspModule1",
"/system/app/hsp1.hap", AppExecFwk::Constants::ARKTS_MODE_STATIC}
};
options.commonHspBundleInfos = hspInfos;
auto result = etsRuntime->GetAotPath(options);
@@ -493,7 +503,8 @@ HWTEST_F(EtsRuntimeTest, GetAotPath_007, TestSize.Level1)
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}
{1001, static_cast<int32_t>(AppExecFwk::AOTCompileStatus::NOT_COMPILED), "com.example.hsp1", "hspModule1",
"relativePathWithoutSlash", AppExecFwk::Constants::ARKTS_MODE_STATIC}
};
options.commonHspBundleInfos = hspInfos;
auto result = etsRuntime->GetAotPath(options);
@@ -514,7 +525,8 @@ HWTEST_F(EtsRuntimeTest, GetAotPath_008, TestSize.Level1)
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}
{1001, static_cast<int32_t>(AppExecFwk::AOTCompileStatus::NOT_COMPILED), "com.example.hsp1", "hspModule1",
"/data/app/hsp1.hap", AppExecFwk::Constants::ARKTS_MODE_STATIC}
};
options.commonHspBundleInfos = hspInfos;
auto result = etsRuntime->GetAotPath(options);
@@ -538,20 +550,24 @@ HWTEST_F(EtsRuntimeTest, GetAotPath_009, TestSize.Level1)
// 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},
{1001, static_cast<int32_t>(AppExecFwk::AOTCompileStatus::NOT_COMPILED), "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},
{1002, static_cast<int32_t>(AppExecFwk::AOTCompileStatus::NOT_COMPILED), "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},
{1003, static_cast<int32_t>(AppExecFwk::AOTCompileStatus::INSTALL_COMPILE_SUCCESS), "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}
{1004, static_cast<int32_t>(AppExecFwk::AOTCompileStatus::NOT_COMPILED), "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 not contain hsp2 (static mode, system path) since compile status is not compiled
EXPECT_EQ(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)
@@ -573,9 +589,12 @@ HWTEST_F(EtsRuntimeTest, GetAotPath_010, TestSize.Level1)
Runtime::Options options;
options.arkNativeFilePath = "arm64/";
options.moduleName = "entry";
options.aotCompileStatusMap = {{"entry", true}};
options.aotCompileStatusMap = {
{"entry", static_cast<int32_t>(AppExecFwk::AOTCompileStatus::IDLE_COMPILE_SUCCESS)}
};
std::vector<OHOS::AbilityRuntime::CommonHspBundleInfo> hspInfos = {
{1002003, "com.example.hsp", "hspModule", "/system/app/hsp.hap", AppExecFwk::Constants::ARKTS_MODE_STATIC}
{1002003, static_cast<int32_t>(AppExecFwk::AOTCompileStatus::IDLE_COMPILE_SUCCESS), "com.example.hsp",
"hspModule", "/system/app/hsp.hap", AppExecFwk::Constants::ARKTS_MODE_STATIC}
};
options.commonHspBundleInfos = hspInfos;
auto result = etsRuntime->GetAotPath(options);
@@ -584,5 +603,126 @@ HWTEST_F(EtsRuntimeTest, GetAotPath_010, TestSize.Level1)
// Should have proper path structure
EXPECT_NE(result.find("/data/service/el1/public/for-all-app/shared_bundles_ark_cache/"), std::string::npos);
}
/**
* @tc.name: IsAotCompiledSuccess_001
* @tc.desc: Test IsAotCompiledSuccess with IDLE_COMPILE_SUCCESS status.
* @tc.type: FUNC
*/
HWTEST_F(EtsRuntimeTest, IsAotCompiledSuccess_001, TestSize.Level1)
{
auto etsRuntime = std::make_unique<ETSRuntime>();
bool result = etsRuntime->IsAotCompiledSuccess(
static_cast<int32_t>(AppExecFwk::AOTCompileStatus::IDLE_COMPILE_SUCCESS));
EXPECT_TRUE(result);
}
/**
* @tc.name: IsAotCompiledSuccess_002
* @tc.desc: Test IsAotCompiledSuccess with INSTALL_COMPILE_SUCCESS status.
* @tc.type: FUNC
*/
HWTEST_F(EtsRuntimeTest, IsAotCompiledSuccess_002, TestSize.Level1)
{
auto etsRuntime = std::make_unique<ETSRuntime>();
bool result = etsRuntime->IsAotCompiledSuccess(
static_cast<int32_t>(AppExecFwk::AOTCompileStatus::INSTALL_COMPILE_SUCCESS));
EXPECT_TRUE(result);
}
/**
* @tc.name: IsAotCompiledSuccess_003
* @tc.desc: Test IsAotCompiledSuccess with NOT_COMPILED status.
* @tc.type: FUNC
*/
HWTEST_F(EtsRuntimeTest, IsAotCompiledSuccess_003, TestSize.Level1)
{
auto etsRuntime = std::make_unique<ETSRuntime>();
bool result = etsRuntime->IsAotCompiledSuccess(
static_cast<int32_t>(AppExecFwk::AOTCompileStatus::NOT_COMPILED));
EXPECT_FALSE(result);
}
/**
* @tc.name: IsAotCompiledSuccess_004
* @tc.desc: Test IsAotCompiledSuccess with COMPILE_FAILED status.
* @tc.type: FUNC
*/
HWTEST_F(EtsRuntimeTest, IsAotCompiledSuccess_004, TestSize.Level1)
{
auto etsRuntime = std::make_unique<ETSRuntime>();
bool result = etsRuntime->IsAotCompiledSuccess(
static_cast<int32_t>(AppExecFwk::AOTCompileStatus::COMPILE_FAILED));
EXPECT_FALSE(result);
}
/**
* @tc.name: IsAotCompiledSuccess_005
* @tc.desc: Test IsAotCompiledSuccess with COMPILE_CRASH status.
* @tc.type: FUNC
*/
HWTEST_F(EtsRuntimeTest, IsAotCompiledSuccess_005, TestSize.Level1)
{
auto etsRuntime = std::make_unique<ETSRuntime>();
bool result = etsRuntime->IsAotCompiledSuccess(
static_cast<int32_t>(AppExecFwk::AOTCompileStatus::COMPILE_CRASH));
EXPECT_FALSE(result);
}
/**
* @tc.name: IsAotCompiledSuccess_006
* @tc.desc: Test IsAotCompiledSuccess with COMPILE_CANCELLED status.
* @tc.type: FUNC
*/
HWTEST_F(EtsRuntimeTest, IsAotCompiledSuccess_006, TestSize.Level1)
{
auto etsRuntime = std::make_unique<ETSRuntime>();
bool result = etsRuntime->IsAotCompiledSuccess(
static_cast<int32_t>(AppExecFwk::AOTCompileStatus::COMPILE_CANCELLED));
EXPECT_FALSE(result);
}
/**
* @tc.name: GetAotPath_011
* @tc.desc: Test GetAotPath with IDLE_COMPILE_SUCCESS status in aotCompileStatusMap.
* @tc.type: FUNC
*/
HWTEST_F(EtsRuntimeTest, GetAotPath_011, TestSize.Level1)
{
auto etsRuntime = std::make_unique<ETSRuntime>();
Runtime::Options options;
options.arkNativeFilePath = "arm64/";
options.moduleName = "entry";
options.aotCompileStatusMap = {
{"entry", static_cast<int32_t>(AppExecFwk::AOTCompileStatus::IDLE_COMPILE_SUCCESS)},
{"module1", static_cast<int32_t>(AppExecFwk::AOTCompileStatus::COMPILE_FAILED)}
};
options.commonHspBundleInfos = {};
auto result = etsRuntime->GetAotPath(options);
EXPECT_NE(result.find("entry.an"), std::string::npos);
EXPECT_EQ(result.find("module1.an"), std::string::npos);
}
/**
* @tc.name: GetAotPath_012
* @tc.desc: Test GetAotPath with INSTALL_COMPILE_SUCCESS status in commonHspBundleInfos.
* @tc.type: FUNC
*/
HWTEST_F(EtsRuntimeTest, GetAotPath_012, TestSize.Level1)
{
auto etsRuntime = std::make_unique<ETSRuntime>();
Runtime::Options options;
options.arkNativeFilePath = "arm64/";
options.moduleName = "entry";
options.aotCompileStatusMap = {};
std::vector<OHOS::AbilityRuntime::CommonHspBundleInfo> hspInfos = {
{1001, static_cast<int32_t>(AppExecFwk::AOTCompileStatus::INSTALL_COMPILE_SUCCESS),
"com.example.hsp1", "hspModule1", "/system/app/hsp1.hap",
AppExecFwk::Constants::ARKTS_MODE_STATIC}
};
options.commonHspBundleInfos = hspInfos;
auto result = etsRuntime->GetAotPath(options);
EXPECT_NE(result.find("hspModule1.an"), std::string::npos);
}
} // namespace AbilityRuntime
} // namespace OHOS