diff --git a/ets_environment/test/unittest/ets_environment_test/ets_environment_test.cpp b/ets_environment/test/unittest/ets_environment_test/ets_environment_test.cpp index 3695ec4db7..fc5207e4d4 100644 --- a/ets_environment/test/unittest/ets_environment_test/ets_environment_test.cpp +++ b/ets_environment/test/unittest/ets_environment_test/ets_environment_test.cpp @@ -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"; diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 6a56625fdc..2415bd0f4f 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -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(hsp.aotCompileStatus), + hsp.bundleName, hsp.moduleName, hsp.hapPath, hsp.moduleArkTSMode}); } options.enableWarmStartupSmartGC = (appLaunchData.GetAppPreloadMode() == AppExecFwk::PreloadMode::PRE_MAKE || diff --git a/frameworks/native/runtime/ets_runtime.cpp b/frameworks/native/runtime/ets_runtime.cpp index c052f887cd..de75b904e5 100644 --- a/frameworks/native/runtime/ets_runtime.cpp +++ b/frameworks/native/runtime/ets_runtime.cpp @@ -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(AppExecFwk::AOTCompileStatus::IDLE_COMPILE_SUCCESS) || + status == static_cast(AppExecFwk::AOTCompileStatus::INSTALL_COMPILE_SUCCESS); +} + std::string ETSRuntime::GetAotPath(const Options &options) { std::vector aotFiles; // Handle Hap and Inner Hsp // path: /arm64/.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: //v/arm64/.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); } diff --git a/interfaces/inner_api/runtime/include/ets_runtime.h b/interfaces/inner_api/runtime/include/ets_runtime.h index 7d7b1ae424..31507aa3d5 100644 --- a/interfaces/inner_api/runtime/include/ets_runtime.h +++ b/interfaces/inner_api/runtime/include/ets_runtime.h @@ -107,6 +107,7 @@ private: std::unique_ptr 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 &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); diff --git a/interfaces/inner_api/runtime/include/runtime.h b/interfaces/inner_api/runtime/include/runtime.h index b08d29c275..30dfd9213f 100644 --- a/interfaces/inner_api/runtime/include/runtime.h +++ b/interfaces/inner_api/runtime/include/runtime.h @@ -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; diff --git a/test/unittest/runtime_test/BUILD.gn b/test/unittest/runtime_test/BUILD.gn index 30663ca9fb..dd2c73f82b 100644 --- a/test/unittest/runtime_test/BUILD.gn +++ b/test/unittest/runtime_test/BUILD.gn @@ -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", diff --git a/test/unittest/runtime_test/ets_runtime_test.cpp b/test/unittest/runtime_test/ets_runtime_test.cpp index fdada9029a..ddccb7ba3f 100644 --- a/test/unittest/runtime_test/ets_runtime_test.cpp +++ b/test/unittest/runtime_test/ets_runtime_test.cpp @@ -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 etsEnvironment = std::make_unique(); - 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(AppExecFwk::AOTCompileStatus::IDLE_COMPILE_SUCCESS)}, + {"module1", static_cast(AppExecFwk::AOTCompileStatus::IDLE_COMPILE_SUCCESS)}, + {"module2", static_cast(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(AppExecFwk::AOTCompileStatus::NOT_COMPILED)}, + {"module2", static_cast(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 hspInfos = { - {1001, "com.example.hsp1", "hspModule1", "/system/app/hsp1.hap", AppExecFwk::Constants::ARKTS_MODE_DYNAMIC} + {1001, static_cast(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 hspInfos = { - {1001, "com.example.hsp1", "hspModule1", "/system/app/hsp1.hap", AppExecFwk::Constants::ARKTS_MODE_STATIC} + {1001, static_cast(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 hspInfos = { - {1001, "com.example.hsp1", "hspModule1", "relativePathWithoutSlash", AppExecFwk::Constants::ARKTS_MODE_STATIC} + {1001, static_cast(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 hspInfos = { - {1001, "com.example.hsp1", "hspModule1", "/data/app/hsp1.hap", AppExecFwk::Constants::ARKTS_MODE_STATIC} + {1001, static_cast(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 hspInfos = { // Dynamic mode - should be skipped - {1001, "com.example.hsp1", "hspModule1", "/system/app/hsp1.hap", AppExecFwk::Constants::ARKTS_MODE_DYNAMIC}, + {1001, static_cast(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(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(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(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(AppExecFwk::AOTCompileStatus::IDLE_COMPILE_SUCCESS)} + }; std::vector hspInfos = { - {1002003, "com.example.hsp", "hspModule", "/system/app/hsp.hap", AppExecFwk::Constants::ARKTS_MODE_STATIC} + {1002003, static_cast(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(); + bool result = etsRuntime->IsAotCompiledSuccess( + static_cast(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(); + bool result = etsRuntime->IsAotCompiledSuccess( + static_cast(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(); + bool result = etsRuntime->IsAotCompiledSuccess( + static_cast(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(); + bool result = etsRuntime->IsAotCompiledSuccess( + static_cast(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(); + bool result = etsRuntime->IsAotCompiledSuccess( + static_cast(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(); + bool result = etsRuntime->IsAotCompiledSuccess( + static_cast(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(); + Runtime::Options options; + options.arkNativeFilePath = "arm64/"; + options.moduleName = "entry"; + options.aotCompileStatusMap = { + {"entry", static_cast(AppExecFwk::AOTCompileStatus::IDLE_COMPILE_SUCCESS)}, + {"module1", static_cast(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(); + Runtime::Options options; + options.arkNativeFilePath = "arm64/"; + options.moduleName = "entry"; + options.aotCompileStatusMap = {}; + std::vector hspInfos = { + {1001, static_cast(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